]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.1-3.18.9-201503071142.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.1-3.18.9-201503071142.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 62b3338..fba6407 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..b5e38b1a 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 40b3ee98..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..9beabc9d 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 bc3fc4f..e2483f0 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 270bbd4..c01932a 100644
6873 --- a/arch/mips/kvm/mips.c
6874 +++ b/arch/mips/kvm/mips.c
6875 @@ -815,7 +815,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..53936a1 100644
8829 --- a/arch/powerpc/kernel/Makefile
8830 +++ b/arch/powerpc/kernel/Makefile
8831 @@ -15,6 +15,11 @@ CFLAGS_prom_init.o += -fPIC
8832 CFLAGS_btext.o += -fPIC
8833 endif
8834
8835 +CFLAGS_REMOVE_cputable.o = $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8836 +CFLAGS_REMOVE_prom_init.o = $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8837 +CFLAGS_REMOVE_btext.o = $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8838 +CFLAGS_REMOVE_prom.o = $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8839 +
8840 ifdef CONFIG_FUNCTION_TRACER
8841 # Do not trace early boot code
8842 CFLAGS_REMOVE_cputable.o = -pg -mno-sched-epilog
8843 @@ -27,6 +32,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8844 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8845 endif
8846
8847 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8848 +
8849 obj-y := cputable.o ptrace.o syscalls.o \
8850 irq.o align.o signal_32.o pmc.o vdso.o \
8851 process.o systbl.o idle.o \
8852 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8853 index 3e68d1c..72a5ee6 100644
8854 --- a/arch/powerpc/kernel/exceptions-64e.S
8855 +++ b/arch/powerpc/kernel/exceptions-64e.S
8856 @@ -1010,6 +1010,7 @@ storage_fault_common:
8857 std r14,_DAR(r1)
8858 std r15,_DSISR(r1)
8859 addi r3,r1,STACK_FRAME_OVERHEAD
8860 + bl save_nvgprs
8861 mr r4,r14
8862 mr r5,r15
8863 ld r14,PACA_EXGEN+EX_R14(r13)
8864 @@ -1018,8 +1019,7 @@ storage_fault_common:
8865 cmpdi r3,0
8866 bne- 1f
8867 b ret_from_except_lite
8868 -1: bl save_nvgprs
8869 - mr r5,r3
8870 +1: mr r5,r3
8871 addi r3,r1,STACK_FRAME_OVERHEAD
8872 ld r4,_DAR(r1)
8873 bl bad_page_fault
8874 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8875 index 72e783e..fe058e2 100644
8876 --- a/arch/powerpc/kernel/exceptions-64s.S
8877 +++ b/arch/powerpc/kernel/exceptions-64s.S
8878 @@ -1588,10 +1588,10 @@ handle_page_fault:
8879 11: ld r4,_DAR(r1)
8880 ld r5,_DSISR(r1)
8881 addi r3,r1,STACK_FRAME_OVERHEAD
8882 + bl save_nvgprs
8883 bl do_page_fault
8884 cmpdi r3,0
8885 beq+ 12f
8886 - bl save_nvgprs
8887 mr r5,r3
8888 addi r3,r1,STACK_FRAME_OVERHEAD
8889 lwz r4,_DAR(r1)
8890 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8891 index c143835..5a9697f 100644
8892 --- a/arch/powerpc/kernel/irq.c
8893 +++ b/arch/powerpc/kernel/irq.c
8894 @@ -461,6 +461,8 @@ void migrate_irqs(void)
8895 }
8896 #endif
8897
8898 +extern void gr_handle_kernel_exploit(void);
8899 +
8900 static inline void check_stack_overflow(void)
8901 {
8902 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8903 @@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8904 pr_err("do_IRQ: stack overflow: %ld\n",
8905 sp - sizeof(struct thread_info));
8906 dump_stack();
8907 + gr_handle_kernel_exploit();
8908 }
8909 #endif
8910 }
8911 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8912 index c94d2e0..992a9ce 100644
8913 --- a/arch/powerpc/kernel/module_32.c
8914 +++ b/arch/powerpc/kernel/module_32.c
8915 @@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8916 me->arch.core_plt_section = i;
8917 }
8918 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8919 - pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8920 + pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8921 return -ENOEXEC;
8922 }
8923
8924 @@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8925
8926 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8927 /* Init, or core PLT? */
8928 - if (location >= mod->module_core
8929 - && location < mod->module_core + mod->core_size)
8930 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8931 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8932 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8933 - else
8934 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8935 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8936 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8937 + else {
8938 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8939 + return ~0UL;
8940 + }
8941
8942 /* Find this entry, or if that fails, the next avail. entry */
8943 while (entry->jump[0]) {
8944 @@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8945 }
8946 #ifdef CONFIG_DYNAMIC_FTRACE
8947 module->arch.tramp =
8948 - do_plt_call(module->module_core,
8949 + do_plt_call(module->module_core_rx,
8950 (unsigned long)ftrace_caller,
8951 sechdrs, module);
8952 #endif
8953 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8954 index 923cd2d..ae782a9 100644
8955 --- a/arch/powerpc/kernel/process.c
8956 +++ b/arch/powerpc/kernel/process.c
8957 @@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8958 * Lookup NIP late so we have the best change of getting the
8959 * above info out without failing
8960 */
8961 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8962 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8963 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8964 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8965 #endif
8966 show_stack(current, (unsigned long *) regs->gpr[1]);
8967 if (!user_mode(regs))
8968 @@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8969 newsp = stack[0];
8970 ip = stack[STACK_FRAME_LR_SAVE];
8971 if (!firstframe || ip != lr) {
8972 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8973 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8974 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8975 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8976 - printk(" (%pS)",
8977 + printk(" (%pA)",
8978 (void *)current->ret_stack[curr_frame].ret);
8979 curr_frame--;
8980 }
8981 @@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8982 struct pt_regs *regs = (struct pt_regs *)
8983 (sp + STACK_FRAME_OVERHEAD);
8984 lr = regs->link;
8985 - printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8986 + printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8987 regs->trap, (void *)regs->nip, (void *)lr);
8988 firstframe = 1;
8989 }
8990 @@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8991 mtspr(SPRN_CTRLT, ctrl);
8992 }
8993 #endif /* CONFIG_PPC64 */
8994 -
8995 -unsigned long arch_align_stack(unsigned long sp)
8996 -{
8997 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8998 - sp -= get_random_int() & ~PAGE_MASK;
8999 - return sp & ~0xf;
9000 -}
9001 -
9002 -static inline unsigned long brk_rnd(void)
9003 -{
9004 - unsigned long rnd = 0;
9005 -
9006 - /* 8MB for 32bit, 1GB for 64bit */
9007 - if (is_32bit_task())
9008 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9009 - else
9010 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9011 -
9012 - return rnd << PAGE_SHIFT;
9013 -}
9014 -
9015 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9016 -{
9017 - unsigned long base = mm->brk;
9018 - unsigned long ret;
9019 -
9020 -#ifdef CONFIG_PPC_STD_MMU_64
9021 - /*
9022 - * If we are using 1TB segments and we are allowed to randomise
9023 - * the heap, we can put it above 1TB so it is backed by a 1TB
9024 - * segment. Otherwise the heap will be in the bottom 1TB
9025 - * which always uses 256MB segments and this may result in a
9026 - * performance penalty.
9027 - */
9028 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9029 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9030 -#endif
9031 -
9032 - ret = PAGE_ALIGN(base + brk_rnd());
9033 -
9034 - if (ret < mm->brk)
9035 - return mm->brk;
9036 -
9037 - return ret;
9038 -}
9039 -
9040 -unsigned long randomize_et_dyn(unsigned long base)
9041 -{
9042 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9043 -
9044 - if (ret < base)
9045 - return base;
9046 -
9047 - return ret;
9048 -}
9049 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9050 index f21897b..28c0428 100644
9051 --- a/arch/powerpc/kernel/ptrace.c
9052 +++ b/arch/powerpc/kernel/ptrace.c
9053 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9054 return ret;
9055 }
9056
9057 +#ifdef CONFIG_GRKERNSEC_SETXID
9058 +extern void gr_delayed_cred_worker(void);
9059 +#endif
9060 +
9061 /*
9062 * We must return the syscall number to actually look up in the table.
9063 * This can be -1L to skip running any syscall at all.
9064 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9065
9066 secure_computing_strict(regs->gpr[0]);
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 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9074 tracehook_report_syscall_entry(regs))
9075 /*
9076 @@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9077 {
9078 int step;
9079
9080 +#ifdef CONFIG_GRKERNSEC_SETXID
9081 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9082 + gr_delayed_cred_worker();
9083 +#endif
9084 +
9085 audit_syscall_exit(regs);
9086
9087 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9088 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9089 index b171001..4ac7ac5 100644
9090 --- a/arch/powerpc/kernel/signal_32.c
9091 +++ b/arch/powerpc/kernel/signal_32.c
9092 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9093 /* Save user registers on the stack */
9094 frame = &rt_sf->uc.uc_mcontext;
9095 addr = frame;
9096 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9097 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9098 sigret = 0;
9099 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9100 } else {
9101 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9102 index 2cb0c94..c0c0bc9 100644
9103 --- a/arch/powerpc/kernel/signal_64.c
9104 +++ b/arch/powerpc/kernel/signal_64.c
9105 @@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9106 current->thread.fp_state.fpscr = 0;
9107
9108 /* Set up to return from userspace. */
9109 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9110 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9111 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9112 } else {
9113 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9114 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9115 index 0dc43f9..a885d33 100644
9116 --- a/arch/powerpc/kernel/traps.c
9117 +++ b/arch/powerpc/kernel/traps.c
9118 @@ -36,6 +36,7 @@
9119 #include <linux/debugfs.h>
9120 #include <linux/ratelimit.h>
9121 #include <linux/context_tracking.h>
9122 +#include <linux/uaccess.h>
9123
9124 #include <asm/emulated_ops.h>
9125 #include <asm/pgtable.h>
9126 @@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9127 return flags;
9128 }
9129
9130 +extern void gr_handle_kernel_exploit(void);
9131 +
9132 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9133 int signr)
9134 {
9135 @@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9136 panic("Fatal exception in interrupt");
9137 if (panic_on_oops)
9138 panic("Fatal exception");
9139 +
9140 + gr_handle_kernel_exploit();
9141 +
9142 do_exit(signr);
9143 }
9144
9145 @@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9146 enum ctx_state prev_state = exception_enter();
9147 unsigned int reason = get_reason(regs);
9148
9149 +#ifdef CONFIG_PAX_REFCOUNT
9150 + unsigned int bkpt;
9151 + const struct exception_table_entry *entry;
9152 +
9153 + if (reason & REASON_ILLEGAL) {
9154 + /* Check if PaX bad instruction */
9155 + if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9156 + current->thread.trap_nr = 0;
9157 + pax_report_refcount_overflow(regs);
9158 + /* fixup_exception() for PowerPC does not exist, simulate its job */
9159 + if ((entry = search_exception_tables(regs->nip)) != NULL) {
9160 + regs->nip = entry->fixup;
9161 + return;
9162 + }
9163 + /* fixup_exception() could not handle */
9164 + goto bail;
9165 + }
9166 + }
9167 +#endif
9168 +
9169 /* We can now get here via a FP Unavailable exception if the core
9170 * has no FPU, in that case the reason flags will be 0 */
9171
9172 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9173 index f174351..5722009 100644
9174 --- a/arch/powerpc/kernel/vdso.c
9175 +++ b/arch/powerpc/kernel/vdso.c
9176 @@ -35,6 +35,7 @@
9177 #include <asm/vdso.h>
9178 #include <asm/vdso_datapage.h>
9179 #include <asm/setup.h>
9180 +#include <asm/mman.h>
9181
9182 #undef DEBUG
9183
9184 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9185 vdso_base = VDSO32_MBASE;
9186 #endif
9187
9188 - current->mm->context.vdso_base = 0;
9189 + current->mm->context.vdso_base = ~0UL;
9190
9191 /* vDSO has a problem and was disabled, just don't "enable" it for the
9192 * process
9193 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9194 vdso_base = get_unmapped_area(NULL, vdso_base,
9195 (vdso_pages << PAGE_SHIFT) +
9196 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9197 - 0, 0);
9198 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
9199 if (IS_ERR_VALUE(vdso_base)) {
9200 rc = vdso_base;
9201 goto fail_mmapsem;
9202 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9203 index c1f8f53..71a3b96 100644
9204 --- a/arch/powerpc/kvm/powerpc.c
9205 +++ b/arch/powerpc/kvm/powerpc.c
9206 @@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9207 }
9208 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9209
9210 -int kvm_arch_init(void *opaque)
9211 +int kvm_arch_init(const void *opaque)
9212 {
9213 return 0;
9214 }
9215 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9216 index 5eea6f3..5d10396 100644
9217 --- a/arch/powerpc/lib/usercopy_64.c
9218 +++ b/arch/powerpc/lib/usercopy_64.c
9219 @@ -9,22 +9,6 @@
9220 #include <linux/module.h>
9221 #include <asm/uaccess.h>
9222
9223 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9224 -{
9225 - if (likely(access_ok(VERIFY_READ, from, n)))
9226 - n = __copy_from_user(to, from, n);
9227 - else
9228 - memset(to, 0, n);
9229 - return n;
9230 -}
9231 -
9232 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9233 -{
9234 - if (likely(access_ok(VERIFY_WRITE, to, n)))
9235 - n = __copy_to_user(to, from, n);
9236 - return n;
9237 -}
9238 -
9239 unsigned long copy_in_user(void __user *to, const void __user *from,
9240 unsigned long n)
9241 {
9242 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9243 return n;
9244 }
9245
9246 -EXPORT_SYMBOL(copy_from_user);
9247 -EXPORT_SYMBOL(copy_to_user);
9248 EXPORT_SYMBOL(copy_in_user);
9249
9250 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9251 index f06b56b..ffb2fb4 100644
9252 --- a/arch/powerpc/mm/fault.c
9253 +++ b/arch/powerpc/mm/fault.c
9254 @@ -33,6 +33,10 @@
9255 #include <linux/ratelimit.h>
9256 #include <linux/context_tracking.h>
9257 #include <linux/hugetlb.h>
9258 +#include <linux/slab.h>
9259 +#include <linux/pagemap.h>
9260 +#include <linux/compiler.h>
9261 +#include <linux/unistd.h>
9262
9263 #include <asm/firmware.h>
9264 #include <asm/page.h>
9265 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9266 }
9267 #endif
9268
9269 +#ifdef CONFIG_PAX_PAGEEXEC
9270 +/*
9271 + * PaX: decide what to do with offenders (regs->nip = fault address)
9272 + *
9273 + * returns 1 when task should be killed
9274 + */
9275 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9276 +{
9277 + return 1;
9278 +}
9279 +
9280 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9281 +{
9282 + unsigned long i;
9283 +
9284 + printk(KERN_ERR "PAX: bytes at PC: ");
9285 + for (i = 0; i < 5; i++) {
9286 + unsigned int c;
9287 + if (get_user(c, (unsigned int __user *)pc+i))
9288 + printk(KERN_CONT "???????? ");
9289 + else
9290 + printk(KERN_CONT "%08x ", c);
9291 + }
9292 + printk("\n");
9293 +}
9294 +#endif
9295 +
9296 /*
9297 * Check whether the instruction at regs->nip is a store using
9298 * an update addressing form which will update r1.
9299 @@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9300 * indicate errors in DSISR but can validly be set in SRR1.
9301 */
9302 if (trap == 0x400)
9303 - error_code &= 0x48200000;
9304 + error_code &= 0x58200000;
9305 else
9306 is_write = error_code & DSISR_ISSTORE;
9307 #else
9308 @@ -390,7 +421,7 @@ good_area:
9309 * "undefined". Of those that can be set, this is the only
9310 * one which seems bad.
9311 */
9312 - if (error_code & 0x10000000)
9313 + if (error_code & DSISR_GUARDED)
9314 /* Guarded storage error. */
9315 goto bad_area;
9316 #endif /* CONFIG_8xx */
9317 @@ -405,7 +436,7 @@ good_area:
9318 * processors use the same I/D cache coherency mechanism
9319 * as embedded.
9320 */
9321 - if (error_code & DSISR_PROTFAULT)
9322 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9323 goto bad_area;
9324 #endif /* CONFIG_PPC_STD_MMU */
9325
9326 @@ -497,6 +528,23 @@ bad_area:
9327 bad_area_nosemaphore:
9328 /* User mode accesses cause a SIGSEGV */
9329 if (user_mode(regs)) {
9330 +
9331 +#ifdef CONFIG_PAX_PAGEEXEC
9332 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9333 +#ifdef CONFIG_PPC_STD_MMU
9334 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9335 +#else
9336 + if (is_exec && regs->nip == address) {
9337 +#endif
9338 + switch (pax_handle_fetch_fault(regs)) {
9339 + }
9340 +
9341 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9342 + do_group_exit(SIGKILL);
9343 + }
9344 + }
9345 +#endif
9346 +
9347 _exception(SIGSEGV, regs, code, address);
9348 goto bail;
9349 }
9350 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9351 index cb8bdbe..cde4bc7 100644
9352 --- a/arch/powerpc/mm/mmap.c
9353 +++ b/arch/powerpc/mm/mmap.c
9354 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9355 return sysctl_legacy_va_layout;
9356 }
9357
9358 -static unsigned long mmap_rnd(void)
9359 +static unsigned long mmap_rnd(struct mm_struct *mm)
9360 {
9361 unsigned long rnd = 0;
9362
9363 +#ifdef CONFIG_PAX_RANDMMAP
9364 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9365 +#endif
9366 +
9367 if (current->flags & PF_RANDOMIZE) {
9368 /* 8MB for 32bit, 1GB for 64bit */
9369 if (is_32bit_task())
9370 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9371 return rnd << PAGE_SHIFT;
9372 }
9373
9374 -static inline unsigned long mmap_base(void)
9375 +static inline unsigned long mmap_base(struct mm_struct *mm)
9376 {
9377 unsigned long gap = rlimit(RLIMIT_STACK);
9378
9379 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9380 else if (gap > MAX_GAP)
9381 gap = MAX_GAP;
9382
9383 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9384 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9385 }
9386
9387 /*
9388 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9389 */
9390 if (mmap_is_legacy()) {
9391 mm->mmap_base = TASK_UNMAPPED_BASE;
9392 +
9393 +#ifdef CONFIG_PAX_RANDMMAP
9394 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9395 + mm->mmap_base += mm->delta_mmap;
9396 +#endif
9397 +
9398 mm->get_unmapped_area = arch_get_unmapped_area;
9399 } else {
9400 - mm->mmap_base = mmap_base();
9401 + mm->mmap_base = mmap_base(mm);
9402 +
9403 +#ifdef CONFIG_PAX_RANDMMAP
9404 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9405 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9406 +#endif
9407 +
9408 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9409 }
9410 }
9411 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9412 index ded0ea1..f213a9b 100644
9413 --- a/arch/powerpc/mm/slice.c
9414 +++ b/arch/powerpc/mm/slice.c
9415 @@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9416 if ((mm->task_size - len) < addr)
9417 return 0;
9418 vma = find_vma(mm, addr);
9419 - return (!vma || (addr + len) <= vma->vm_start);
9420 + return check_heap_stack_gap(vma, addr, len, 0);
9421 }
9422
9423 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9424 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9425 info.align_offset = 0;
9426
9427 addr = TASK_UNMAPPED_BASE;
9428 +
9429 +#ifdef CONFIG_PAX_RANDMMAP
9430 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9431 + addr += mm->delta_mmap;
9432 +#endif
9433 +
9434 while (addr < TASK_SIZE) {
9435 info.low_limit = addr;
9436 if (!slice_scan_available(addr, available, 1, &addr))
9437 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9438 if (fixed && addr > (mm->task_size - len))
9439 return -ENOMEM;
9440
9441 +#ifdef CONFIG_PAX_RANDMMAP
9442 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9443 + addr = 0;
9444 +#endif
9445 +
9446 /* If hint, make sure it matches our alignment restrictions */
9447 if (!fixed && addr) {
9448 addr = _ALIGN_UP(addr, 1ul << pshift);
9449 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9450 index 4278acf..67fd0e6 100644
9451 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9452 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9453 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9454 }
9455
9456 static struct pci_ops scc_pciex_pci_ops = {
9457 - scc_pciex_read_config,
9458 - scc_pciex_write_config,
9459 + .read = scc_pciex_read_config,
9460 + .write = scc_pciex_write_config,
9461 };
9462
9463 static void pciex_clear_intr_all(unsigned int __iomem *base)
9464 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9465 index d966bbe..372124a 100644
9466 --- a/arch/powerpc/platforms/cell/spufs/file.c
9467 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9468 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9469 return VM_FAULT_NOPAGE;
9470 }
9471
9472 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9473 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9474 unsigned long address,
9475 - void *buf, int len, int write)
9476 + void *buf, size_t len, int write)
9477 {
9478 struct spu_context *ctx = vma->vm_file->private_data;
9479 unsigned long offset = address - vma->vm_start;
9480 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9481 index fa934fe..c296056 100644
9482 --- a/arch/s390/include/asm/atomic.h
9483 +++ b/arch/s390/include/asm/atomic.h
9484 @@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9485 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9486 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9487
9488 +#define atomic64_read_unchecked(v) atomic64_read(v)
9489 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9490 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9491 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9492 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9493 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9494 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9495 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9496 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9497 +
9498 #endif /* __ARCH_S390_ATOMIC__ */
9499 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9500 index b5dce65..8aca09a 100644
9501 --- a/arch/s390/include/asm/barrier.h
9502 +++ b/arch/s390/include/asm/barrier.h
9503 @@ -39,7 +39,7 @@
9504 do { \
9505 compiletime_assert_atomic_type(*p); \
9506 barrier(); \
9507 - ACCESS_ONCE(*p) = (v); \
9508 + ACCESS_ONCE_RW(*p) = (v); \
9509 } while (0)
9510
9511 #define smp_load_acquire(p) \
9512 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9513 index 4d7ccac..d03d0ad 100644
9514 --- a/arch/s390/include/asm/cache.h
9515 +++ b/arch/s390/include/asm/cache.h
9516 @@ -9,8 +9,10 @@
9517 #ifndef __ARCH_S390_CACHE_H
9518 #define __ARCH_S390_CACHE_H
9519
9520 -#define L1_CACHE_BYTES 256
9521 +#include <linux/const.h>
9522 +
9523 #define L1_CACHE_SHIFT 8
9524 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9525 #define NET_SKB_PAD 32
9526
9527 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9528 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9529 index f6e43d3..5f57681 100644
9530 --- a/arch/s390/include/asm/elf.h
9531 +++ b/arch/s390/include/asm/elf.h
9532 @@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9533 the loader. We need to make sure that it is out of the way of the program
9534 that it will "exec", and that there is sufficient room for the brk. */
9535
9536 -extern unsigned long randomize_et_dyn(unsigned long base);
9537 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9538 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9539 +
9540 +#ifdef CONFIG_PAX_ASLR
9541 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9542 +
9543 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9544 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9545 +#endif
9546
9547 /* This yields a mask that user programs can use to figure out what
9548 instruction set this CPU supports. */
9549 @@ -223,9 +229,6 @@ struct linux_binprm;
9550 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9551 int arch_setup_additional_pages(struct linux_binprm *, int);
9552
9553 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9554 -#define arch_randomize_brk arch_randomize_brk
9555 -
9556 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9557
9558 #endif
9559 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9560 index c4a93d6..4d2a9b4 100644
9561 --- a/arch/s390/include/asm/exec.h
9562 +++ b/arch/s390/include/asm/exec.h
9563 @@ -7,6 +7,6 @@
9564 #ifndef __ASM_EXEC_H
9565 #define __ASM_EXEC_H
9566
9567 -extern unsigned long arch_align_stack(unsigned long sp);
9568 +#define arch_align_stack(x) ((x) & ~0xfUL)
9569
9570 #endif /* __ASM_EXEC_H */
9571 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9572 index cd4c68e..6764641 100644
9573 --- a/arch/s390/include/asm/uaccess.h
9574 +++ b/arch/s390/include/asm/uaccess.h
9575 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9576 __range_ok((unsigned long)(addr), (size)); \
9577 })
9578
9579 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9580 #define access_ok(type, addr, size) __access_ok(addr, size)
9581
9582 /*
9583 @@ -275,6 +276,10 @@ static inline unsigned long __must_check
9584 copy_to_user(void __user *to, const void *from, unsigned long n)
9585 {
9586 might_fault();
9587 +
9588 + if ((long)n < 0)
9589 + return n;
9590 +
9591 return __copy_to_user(to, from, n);
9592 }
9593
9594 @@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9595 static inline unsigned long __must_check
9596 copy_from_user(void *to, const void __user *from, unsigned long n)
9597 {
9598 - unsigned int sz = __compiletime_object_size(to);
9599 + size_t sz = __compiletime_object_size(to);
9600
9601 might_fault();
9602 - if (unlikely(sz != -1 && sz < n)) {
9603 +
9604 + if ((long)n < 0)
9605 + return n;
9606 +
9607 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9608 copy_from_user_overflow();
9609 return n;
9610 }
9611 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9612 index b89b591..fd9609d 100644
9613 --- a/arch/s390/kernel/module.c
9614 +++ b/arch/s390/kernel/module.c
9615 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9616
9617 /* Increase core size by size of got & plt and set start
9618 offsets for got and plt. */
9619 - me->core_size = ALIGN(me->core_size, 4);
9620 - me->arch.got_offset = me->core_size;
9621 - me->core_size += me->arch.got_size;
9622 - me->arch.plt_offset = me->core_size;
9623 - me->core_size += me->arch.plt_size;
9624 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9625 + me->arch.got_offset = me->core_size_rw;
9626 + me->core_size_rw += me->arch.got_size;
9627 + me->arch.plt_offset = me->core_size_rx;
9628 + me->core_size_rx += me->arch.plt_size;
9629 return 0;
9630 }
9631
9632 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9633 if (info->got_initialized == 0) {
9634 Elf_Addr *gotent;
9635
9636 - gotent = me->module_core + me->arch.got_offset +
9637 + gotent = me->module_core_rw + me->arch.got_offset +
9638 info->got_offset;
9639 *gotent = val;
9640 info->got_initialized = 1;
9641 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9642 rc = apply_rela_bits(loc, val, 0, 64, 0);
9643 else if (r_type == R_390_GOTENT ||
9644 r_type == R_390_GOTPLTENT) {
9645 - val += (Elf_Addr) me->module_core - loc;
9646 + val += (Elf_Addr) me->module_core_rw - loc;
9647 rc = apply_rela_bits(loc, val, 1, 32, 1);
9648 }
9649 break;
9650 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9651 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9652 if (info->plt_initialized == 0) {
9653 unsigned int *ip;
9654 - ip = me->module_core + me->arch.plt_offset +
9655 + ip = me->module_core_rx + me->arch.plt_offset +
9656 info->plt_offset;
9657 #ifndef CONFIG_64BIT
9658 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9659 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9660 val - loc + 0xffffUL < 0x1ffffeUL) ||
9661 (r_type == R_390_PLT32DBL &&
9662 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9663 - val = (Elf_Addr) me->module_core +
9664 + val = (Elf_Addr) me->module_core_rx +
9665 me->arch.plt_offset +
9666 info->plt_offset;
9667 val += rela->r_addend - loc;
9668 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9669 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9670 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9671 val = val + rela->r_addend -
9672 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9673 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9674 if (r_type == R_390_GOTOFF16)
9675 rc = apply_rela_bits(loc, val, 0, 16, 0);
9676 else if (r_type == R_390_GOTOFF32)
9677 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9678 break;
9679 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9680 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9681 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9682 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9683 rela->r_addend - loc;
9684 if (r_type == R_390_GOTPC)
9685 rc = apply_rela_bits(loc, val, 1, 32, 0);
9686 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9687 index ed84cc2..c05a9d2 100644
9688 --- a/arch/s390/kernel/process.c
9689 +++ b/arch/s390/kernel/process.c
9690 @@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9691 }
9692 return 0;
9693 }
9694 -
9695 -unsigned long arch_align_stack(unsigned long sp)
9696 -{
9697 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9698 - sp -= get_random_int() & ~PAGE_MASK;
9699 - return sp & ~0xf;
9700 -}
9701 -
9702 -static inline unsigned long brk_rnd(void)
9703 -{
9704 - /* 8MB for 32bit, 1GB for 64bit */
9705 - if (is_32bit_task())
9706 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9707 - else
9708 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9709 -}
9710 -
9711 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9712 -{
9713 - unsigned long ret;
9714 -
9715 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9716 - return (ret > mm->brk) ? ret : mm->brk;
9717 -}
9718 -
9719 -unsigned long randomize_et_dyn(unsigned long base)
9720 -{
9721 - unsigned long ret;
9722 -
9723 - if (!(current->flags & PF_RANDOMIZE))
9724 - return base;
9725 - ret = PAGE_ALIGN(base + brk_rnd());
9726 - return (ret > base) ? ret : base;
9727 -}
9728 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9729 index 9b436c2..54fbf0a 100644
9730 --- a/arch/s390/mm/mmap.c
9731 +++ b/arch/s390/mm/mmap.c
9732 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9733 */
9734 if (mmap_is_legacy()) {
9735 mm->mmap_base = mmap_base_legacy();
9736 +
9737 +#ifdef CONFIG_PAX_RANDMMAP
9738 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9739 + mm->mmap_base += mm->delta_mmap;
9740 +#endif
9741 +
9742 mm->get_unmapped_area = arch_get_unmapped_area;
9743 } else {
9744 mm->mmap_base = mmap_base();
9745 +
9746 +#ifdef CONFIG_PAX_RANDMMAP
9747 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9748 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9749 +#endif
9750 +
9751 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9752 }
9753 }
9754 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9755 */
9756 if (mmap_is_legacy()) {
9757 mm->mmap_base = mmap_base_legacy();
9758 +
9759 +#ifdef CONFIG_PAX_RANDMMAP
9760 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9761 + mm->mmap_base += mm->delta_mmap;
9762 +#endif
9763 +
9764 mm->get_unmapped_area = s390_get_unmapped_area;
9765 } else {
9766 mm->mmap_base = mmap_base();
9767 +
9768 +#ifdef CONFIG_PAX_RANDMMAP
9769 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9770 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9771 +#endif
9772 +
9773 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9774 }
9775 }
9776 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9777 index ae3d59f..f65f075 100644
9778 --- a/arch/score/include/asm/cache.h
9779 +++ b/arch/score/include/asm/cache.h
9780 @@ -1,7 +1,9 @@
9781 #ifndef _ASM_SCORE_CACHE_H
9782 #define _ASM_SCORE_CACHE_H
9783
9784 +#include <linux/const.h>
9785 +
9786 #define L1_CACHE_SHIFT 4
9787 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9788 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9789
9790 #endif /* _ASM_SCORE_CACHE_H */
9791 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9792 index f9f3cd5..58ff438 100644
9793 --- a/arch/score/include/asm/exec.h
9794 +++ b/arch/score/include/asm/exec.h
9795 @@ -1,6 +1,6 @@
9796 #ifndef _ASM_SCORE_EXEC_H
9797 #define _ASM_SCORE_EXEC_H
9798
9799 -extern unsigned long arch_align_stack(unsigned long sp);
9800 +#define arch_align_stack(x) (x)
9801
9802 #endif /* _ASM_SCORE_EXEC_H */
9803 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9804 index a1519ad3..e8ac1ff 100644
9805 --- a/arch/score/kernel/process.c
9806 +++ b/arch/score/kernel/process.c
9807 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9808
9809 return task_pt_regs(task)->cp0_epc;
9810 }
9811 -
9812 -unsigned long arch_align_stack(unsigned long sp)
9813 -{
9814 - return sp;
9815 -}
9816 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9817 index ef9e555..331bd29 100644
9818 --- a/arch/sh/include/asm/cache.h
9819 +++ b/arch/sh/include/asm/cache.h
9820 @@ -9,10 +9,11 @@
9821 #define __ASM_SH_CACHE_H
9822 #ifdef __KERNEL__
9823
9824 +#include <linux/const.h>
9825 #include <linux/init.h>
9826 #include <cpu/cache.h>
9827
9828 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9829 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9830
9831 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9832
9833 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9834 index 6777177..cb5e44f 100644
9835 --- a/arch/sh/mm/mmap.c
9836 +++ b/arch/sh/mm/mmap.c
9837 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9838 struct mm_struct *mm = current->mm;
9839 struct vm_area_struct *vma;
9840 int do_colour_align;
9841 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9842 struct vm_unmapped_area_info info;
9843
9844 if (flags & MAP_FIXED) {
9845 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9846 if (filp || (flags & MAP_SHARED))
9847 do_colour_align = 1;
9848
9849 +#ifdef CONFIG_PAX_RANDMMAP
9850 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9851 +#endif
9852 +
9853 if (addr) {
9854 if (do_colour_align)
9855 addr = COLOUR_ALIGN(addr, pgoff);
9856 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9857 addr = PAGE_ALIGN(addr);
9858
9859 vma = find_vma(mm, addr);
9860 - if (TASK_SIZE - len >= addr &&
9861 - (!vma || addr + len <= vma->vm_start))
9862 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9863 return addr;
9864 }
9865
9866 info.flags = 0;
9867 info.length = len;
9868 - info.low_limit = TASK_UNMAPPED_BASE;
9869 + info.low_limit = mm->mmap_base;
9870 info.high_limit = TASK_SIZE;
9871 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9872 info.align_offset = pgoff << PAGE_SHIFT;
9873 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9874 struct mm_struct *mm = current->mm;
9875 unsigned long addr = addr0;
9876 int do_colour_align;
9877 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9878 struct vm_unmapped_area_info info;
9879
9880 if (flags & MAP_FIXED) {
9881 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9882 if (filp || (flags & MAP_SHARED))
9883 do_colour_align = 1;
9884
9885 +#ifdef CONFIG_PAX_RANDMMAP
9886 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9887 +#endif
9888 +
9889 /* requesting a specific address */
9890 if (addr) {
9891 if (do_colour_align)
9892 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9893 addr = PAGE_ALIGN(addr);
9894
9895 vma = find_vma(mm, addr);
9896 - if (TASK_SIZE - len >= addr &&
9897 - (!vma || addr + len <= vma->vm_start))
9898 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9899 return addr;
9900 }
9901
9902 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9903 VM_BUG_ON(addr != -ENOMEM);
9904 info.flags = 0;
9905 info.low_limit = TASK_UNMAPPED_BASE;
9906 +
9907 +#ifdef CONFIG_PAX_RANDMMAP
9908 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9909 + info.low_limit += mm->delta_mmap;
9910 +#endif
9911 +
9912 info.high_limit = TASK_SIZE;
9913 addr = vm_unmapped_area(&info);
9914 }
9915 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9916 index 4082749..fd97781 100644
9917 --- a/arch/sparc/include/asm/atomic_64.h
9918 +++ b/arch/sparc/include/asm/atomic_64.h
9919 @@ -15,18 +15,38 @@
9920 #define ATOMIC64_INIT(i) { (i) }
9921
9922 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9923 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9924 +{
9925 + return ACCESS_ONCE(v->counter);
9926 +}
9927 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9928 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9929 +{
9930 + return ACCESS_ONCE(v->counter);
9931 +}
9932
9933 #define atomic_set(v, i) (((v)->counter) = i)
9934 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9935 +{
9936 + v->counter = i;
9937 +}
9938 #define atomic64_set(v, i) (((v)->counter) = i)
9939 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9940 +{
9941 + v->counter = i;
9942 +}
9943
9944 -#define ATOMIC_OP(op) \
9945 -void atomic_##op(int, atomic_t *); \
9946 -void atomic64_##op(long, atomic64_t *);
9947 +#define __ATOMIC_OP(op, suffix) \
9948 +void atomic_##op##suffix(int, atomic##suffix##_t *); \
9949 +void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9950
9951 -#define ATOMIC_OP_RETURN(op) \
9952 -int atomic_##op##_return(int, atomic_t *); \
9953 -long atomic64_##op##_return(long, atomic64_t *);
9954 +#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9955 +
9956 +#define __ATOMIC_OP_RETURN(op, suffix) \
9957 +int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9958 +long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9959 +
9960 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9961
9962 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9963
9964 @@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9965
9966 #undef ATOMIC_OPS
9967 #undef ATOMIC_OP_RETURN
9968 +#undef __ATOMIC_OP_RETURN
9969 #undef ATOMIC_OP
9970 +#undef __ATOMIC_OP
9971
9972 #define atomic_dec_return(v) atomic_sub_return(1, v)
9973 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9974
9975 #define atomic_inc_return(v) atomic_add_return(1, v)
9976 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9977 +{
9978 + return atomic_add_return_unchecked(1, v);
9979 +}
9980 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9981 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9982 +{
9983 + return atomic64_add_return_unchecked(1, v);
9984 +}
9985
9986 /*
9987 * atomic_inc_and_test - increment and test
9988 @@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9989 * other cases.
9990 */
9991 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9992 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9993 +{
9994 + return atomic_inc_return_unchecked(v) == 0;
9995 +}
9996 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9997
9998 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9999 @@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
10000 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
10001
10002 #define atomic_inc(v) atomic_add(1, v)
10003 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10004 +{
10005 + atomic_add_unchecked(1, v);
10006 +}
10007 #define atomic64_inc(v) atomic64_add(1, v)
10008 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10009 +{
10010 + atomic64_add_unchecked(1, v);
10011 +}
10012
10013 #define atomic_dec(v) atomic_sub(1, v)
10014 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10015 +{
10016 + atomic_sub_unchecked(1, v);
10017 +}
10018 #define atomic64_dec(v) atomic64_sub(1, v)
10019 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10020 +{
10021 + atomic64_sub_unchecked(1, v);
10022 +}
10023
10024 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10025 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10026
10027 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10028 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10029 +{
10030 + return cmpxchg(&v->counter, old, new);
10031 +}
10032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10034 +{
10035 + return xchg(&v->counter, new);
10036 +}
10037
10038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10039 {
10040 - int c, old;
10041 + int c, old, new;
10042 c = atomic_read(v);
10043 for (;;) {
10044 - if (unlikely(c == (u)))
10045 + if (unlikely(c == u))
10046 break;
10047 - old = atomic_cmpxchg((v), c, c + (a));
10048 +
10049 + asm volatile("addcc %2, %0, %0\n"
10050 +
10051 +#ifdef CONFIG_PAX_REFCOUNT
10052 + "tvs %%icc, 6\n"
10053 +#endif
10054 +
10055 + : "=r" (new)
10056 + : "0" (c), "ir" (a)
10057 + : "cc");
10058 +
10059 + old = atomic_cmpxchg(v, c, new);
10060 if (likely(old == c))
10061 break;
10062 c = old;
10063 @@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10064 #define atomic64_cmpxchg(v, o, n) \
10065 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10066 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10067 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10068 +{
10069 + return xchg(&v->counter, new);
10070 +}
10071
10072 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10073 {
10074 - long c, old;
10075 + long c, old, new;
10076 c = atomic64_read(v);
10077 for (;;) {
10078 - if (unlikely(c == (u)))
10079 + if (unlikely(c == u))
10080 break;
10081 - old = atomic64_cmpxchg((v), c, c + (a));
10082 +
10083 + asm volatile("addcc %2, %0, %0\n"
10084 +
10085 +#ifdef CONFIG_PAX_REFCOUNT
10086 + "tvs %%xcc, 6\n"
10087 +#endif
10088 +
10089 + : "=r" (new)
10090 + : "0" (c), "ir" (a)
10091 + : "cc");
10092 +
10093 + old = atomic64_cmpxchg(v, c, new);
10094 if (likely(old == c))
10095 break;
10096 c = old;
10097 }
10098 - return c != (u);
10099 + return c != u;
10100 }
10101
10102 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10103 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10104 index 305dcc3..7835030 100644
10105 --- a/arch/sparc/include/asm/barrier_64.h
10106 +++ b/arch/sparc/include/asm/barrier_64.h
10107 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10108 do { \
10109 compiletime_assert_atomic_type(*p); \
10110 barrier(); \
10111 - ACCESS_ONCE(*p) = (v); \
10112 + ACCESS_ONCE_RW(*p) = (v); \
10113 } while (0)
10114
10115 #define smp_load_acquire(p) \
10116 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10117 index 5bb6991..5c2132e 100644
10118 --- a/arch/sparc/include/asm/cache.h
10119 +++ b/arch/sparc/include/asm/cache.h
10120 @@ -7,10 +7,12 @@
10121 #ifndef _SPARC_CACHE_H
10122 #define _SPARC_CACHE_H
10123
10124 +#include <linux/const.h>
10125 +
10126 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10127
10128 #define L1_CACHE_SHIFT 5
10129 -#define L1_CACHE_BYTES 32
10130 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10131
10132 #ifdef CONFIG_SPARC32
10133 #define SMP_CACHE_BYTES_SHIFT 5
10134 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10135 index a24e41f..47677ff 100644
10136 --- a/arch/sparc/include/asm/elf_32.h
10137 +++ b/arch/sparc/include/asm/elf_32.h
10138 @@ -114,6 +114,13 @@ typedef struct {
10139
10140 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10141
10142 +#ifdef CONFIG_PAX_ASLR
10143 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
10144 +
10145 +#define PAX_DELTA_MMAP_LEN 16
10146 +#define PAX_DELTA_STACK_LEN 16
10147 +#endif
10148 +
10149 /* This yields a mask that user programs can use to figure out what
10150 instruction set this cpu supports. This can NOT be done in userspace
10151 on Sparc. */
10152 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10153 index 370ca1e..d4f4a98 100644
10154 --- a/arch/sparc/include/asm/elf_64.h
10155 +++ b/arch/sparc/include/asm/elf_64.h
10156 @@ -189,6 +189,13 @@ typedef struct {
10157 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10158 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10159
10160 +#ifdef CONFIG_PAX_ASLR
10161 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10162 +
10163 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10164 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10165 +#endif
10166 +
10167 extern unsigned long sparc64_elf_hwcap;
10168 #define ELF_HWCAP sparc64_elf_hwcap
10169
10170 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10171 index a3890da..f6a408e 100644
10172 --- a/arch/sparc/include/asm/pgalloc_32.h
10173 +++ b/arch/sparc/include/asm/pgalloc_32.h
10174 @@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10175 }
10176
10177 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10178 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10179
10180 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10181 unsigned long address)
10182 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10183 index 5e31871..13469c6 100644
10184 --- a/arch/sparc/include/asm/pgalloc_64.h
10185 +++ b/arch/sparc/include/asm/pgalloc_64.h
10186 @@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10187 }
10188
10189 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10190 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10191
10192 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10193 {
10194 @@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10195 }
10196
10197 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10198 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10199
10200 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10201 {
10202 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10203 index 59ba6f6..4518128 100644
10204 --- a/arch/sparc/include/asm/pgtable.h
10205 +++ b/arch/sparc/include/asm/pgtable.h
10206 @@ -5,4 +5,8 @@
10207 #else
10208 #include <asm/pgtable_32.h>
10209 #endif
10210 +
10211 +#define ktla_ktva(addr) (addr)
10212 +#define ktva_ktla(addr) (addr)
10213 +
10214 #endif
10215 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10216 index b9b91ae..950b91e 100644
10217 --- a/arch/sparc/include/asm/pgtable_32.h
10218 +++ b/arch/sparc/include/asm/pgtable_32.h
10219 @@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10220 #define PAGE_SHARED SRMMU_PAGE_SHARED
10221 #define PAGE_COPY SRMMU_PAGE_COPY
10222 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10223 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10224 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10225 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10226 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10227
10228 /* Top-level page directory - dummy used by init-mm.
10229 @@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10230
10231 /* xwr */
10232 #define __P000 PAGE_NONE
10233 -#define __P001 PAGE_READONLY
10234 -#define __P010 PAGE_COPY
10235 -#define __P011 PAGE_COPY
10236 +#define __P001 PAGE_READONLY_NOEXEC
10237 +#define __P010 PAGE_COPY_NOEXEC
10238 +#define __P011 PAGE_COPY_NOEXEC
10239 #define __P100 PAGE_READONLY
10240 #define __P101 PAGE_READONLY
10241 #define __P110 PAGE_COPY
10242 #define __P111 PAGE_COPY
10243
10244 #define __S000 PAGE_NONE
10245 -#define __S001 PAGE_READONLY
10246 -#define __S010 PAGE_SHARED
10247 -#define __S011 PAGE_SHARED
10248 +#define __S001 PAGE_READONLY_NOEXEC
10249 +#define __S010 PAGE_SHARED_NOEXEC
10250 +#define __S011 PAGE_SHARED_NOEXEC
10251 #define __S100 PAGE_READONLY
10252 #define __S101 PAGE_READONLY
10253 #define __S110 PAGE_SHARED
10254 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10255 index 79da178..c2eede8 100644
10256 --- a/arch/sparc/include/asm/pgtsrmmu.h
10257 +++ b/arch/sparc/include/asm/pgtsrmmu.h
10258 @@ -115,6 +115,11 @@
10259 SRMMU_EXEC | SRMMU_REF)
10260 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10261 SRMMU_EXEC | SRMMU_REF)
10262 +
10263 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10264 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10265 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10266 +
10267 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10268 SRMMU_DIRTY | SRMMU_REF)
10269
10270 diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10271 index 29d64b1..4272fe8 100644
10272 --- a/arch/sparc/include/asm/setup.h
10273 +++ b/arch/sparc/include/asm/setup.h
10274 @@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10275 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10276
10277 /* init_64.c */
10278 -extern atomic_t dcpage_flushes;
10279 -extern atomic_t dcpage_flushes_xcall;
10280 +extern atomic_unchecked_t dcpage_flushes;
10281 +extern atomic_unchecked_t dcpage_flushes_xcall;
10282
10283 extern int sysctl_tsb_ratio;
10284 #endif
10285 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10286 index 9689176..63c18ea 100644
10287 --- a/arch/sparc/include/asm/spinlock_64.h
10288 +++ b/arch/sparc/include/asm/spinlock_64.h
10289 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10290
10291 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10292
10293 -static void inline arch_read_lock(arch_rwlock_t *lock)
10294 +static inline void arch_read_lock(arch_rwlock_t *lock)
10295 {
10296 unsigned long tmp1, tmp2;
10297
10298 __asm__ __volatile__ (
10299 "1: ldsw [%2], %0\n"
10300 " brlz,pn %0, 2f\n"
10301 -"4: add %0, 1, %1\n"
10302 +"4: addcc %0, 1, %1\n"
10303 +
10304 +#ifdef CONFIG_PAX_REFCOUNT
10305 +" tvs %%icc, 6\n"
10306 +#endif
10307 +
10308 " cas [%2], %0, %1\n"
10309 " cmp %0, %1\n"
10310 " bne,pn %%icc, 1b\n"
10311 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10312 " .previous"
10313 : "=&r" (tmp1), "=&r" (tmp2)
10314 : "r" (lock)
10315 - : "memory");
10316 + : "memory", "cc");
10317 }
10318
10319 -static int inline arch_read_trylock(arch_rwlock_t *lock)
10320 +static inline int arch_read_trylock(arch_rwlock_t *lock)
10321 {
10322 int tmp1, tmp2;
10323
10324 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10325 "1: ldsw [%2], %0\n"
10326 " brlz,a,pn %0, 2f\n"
10327 " mov 0, %0\n"
10328 -" add %0, 1, %1\n"
10329 +" addcc %0, 1, %1\n"
10330 +
10331 +#ifdef CONFIG_PAX_REFCOUNT
10332 +" tvs %%icc, 6\n"
10333 +#endif
10334 +
10335 " cas [%2], %0, %1\n"
10336 " cmp %0, %1\n"
10337 " bne,pn %%icc, 1b\n"
10338 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10339 return tmp1;
10340 }
10341
10342 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10343 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10344 {
10345 unsigned long tmp1, tmp2;
10346
10347 __asm__ __volatile__(
10348 "1: lduw [%2], %0\n"
10349 -" sub %0, 1, %1\n"
10350 +" subcc %0, 1, %1\n"
10351 +
10352 +#ifdef CONFIG_PAX_REFCOUNT
10353 +" tvs %%icc, 6\n"
10354 +#endif
10355 +
10356 " cas [%2], %0, %1\n"
10357 " cmp %0, %1\n"
10358 " bne,pn %%xcc, 1b\n"
10359 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10360 : "memory");
10361 }
10362
10363 -static void inline arch_write_lock(arch_rwlock_t *lock)
10364 +static inline void arch_write_lock(arch_rwlock_t *lock)
10365 {
10366 unsigned long mask, tmp1, tmp2;
10367
10368 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10369 : "memory");
10370 }
10371
10372 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10373 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10374 {
10375 __asm__ __volatile__(
10376 " stw %%g0, [%0]"
10377 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10378 : "memory");
10379 }
10380
10381 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10382 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10383 {
10384 unsigned long mask, tmp1, tmp2, result;
10385
10386 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10387 index 025c984..a216504 100644
10388 --- a/arch/sparc/include/asm/thread_info_32.h
10389 +++ b/arch/sparc/include/asm/thread_info_32.h
10390 @@ -49,6 +49,8 @@ struct thread_info {
10391 unsigned long w_saved;
10392
10393 struct restart_block restart_block;
10394 +
10395 + unsigned long lowest_stack;
10396 };
10397
10398 /*
10399 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10400 index 798f027..b009941 100644
10401 --- a/arch/sparc/include/asm/thread_info_64.h
10402 +++ b/arch/sparc/include/asm/thread_info_64.h
10403 @@ -63,6 +63,8 @@ struct thread_info {
10404 struct pt_regs *kern_una_regs;
10405 unsigned int kern_una_insn;
10406
10407 + unsigned long lowest_stack;
10408 +
10409 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10410 __attribute__ ((aligned(64)));
10411 };
10412 @@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10413 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10414 /* flag bit 4 is available */
10415 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10416 -/* flag bit 6 is available */
10417 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10418 #define TIF_32BIT 7 /* 32-bit binary */
10419 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10420 #define TIF_SECCOMP 9 /* secure computing */
10421 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10422 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10423 +
10424 /* NOTE: Thread flags >= 12 should be ones we have no interest
10425 * in using in assembly, else we can't use the mask as
10426 * an immediate value in instructions such as andcc.
10427 @@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10428 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10429 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10430 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10431 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10432
10433 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10434 _TIF_DO_NOTIFY_RESUME_MASK | \
10435 _TIF_NEED_RESCHED)
10436 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10437
10438 +#define _TIF_WORK_SYSCALL \
10439 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10440 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10441 +
10442 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10443
10444 /*
10445 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10446 index bd56c28..4b63d83 100644
10447 --- a/arch/sparc/include/asm/uaccess.h
10448 +++ b/arch/sparc/include/asm/uaccess.h
10449 @@ -1,5 +1,6 @@
10450 #ifndef ___ASM_SPARC_UACCESS_H
10451 #define ___ASM_SPARC_UACCESS_H
10452 +
10453 #if defined(__sparc__) && defined(__arch64__)
10454 #include <asm/uaccess_64.h>
10455 #else
10456 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10457 index 9634d08..f55fe4f 100644
10458 --- a/arch/sparc/include/asm/uaccess_32.h
10459 +++ b/arch/sparc/include/asm/uaccess_32.h
10460 @@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10461
10462 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10463 {
10464 - if (n && __access_ok((unsigned long) to, n))
10465 + if ((long)n < 0)
10466 + return n;
10467 +
10468 + if (n && __access_ok((unsigned long) to, n)) {
10469 + if (!__builtin_constant_p(n))
10470 + check_object_size(from, n, true);
10471 return __copy_user(to, (__force void __user *) from, n);
10472 - else
10473 + } else
10474 return n;
10475 }
10476
10477 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10478 {
10479 + if ((long)n < 0)
10480 + return n;
10481 +
10482 + if (!__builtin_constant_p(n))
10483 + check_object_size(from, n, true);
10484 +
10485 return __copy_user(to, (__force void __user *) from, n);
10486 }
10487
10488 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10489 {
10490 - if (n && __access_ok((unsigned long) from, n))
10491 + if ((long)n < 0)
10492 + return n;
10493 +
10494 + if (n && __access_ok((unsigned long) from, n)) {
10495 + if (!__builtin_constant_p(n))
10496 + check_object_size(to, n, false);
10497 return __copy_user((__force void __user *) to, from, n);
10498 - else
10499 + } else
10500 return n;
10501 }
10502
10503 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10504 {
10505 + if ((long)n < 0)
10506 + return n;
10507 +
10508 return __copy_user((__force void __user *) to, from, n);
10509 }
10510
10511 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10512 index c990a5e..f17b9c1 100644
10513 --- a/arch/sparc/include/asm/uaccess_64.h
10514 +++ b/arch/sparc/include/asm/uaccess_64.h
10515 @@ -10,6 +10,7 @@
10516 #include <linux/compiler.h>
10517 #include <linux/string.h>
10518 #include <linux/thread_info.h>
10519 +#include <linux/kernel.h>
10520 #include <asm/asi.h>
10521 #include <asm/spitfire.h>
10522 #include <asm-generic/uaccess-unaligned.h>
10523 @@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10524 static inline unsigned long __must_check
10525 copy_from_user(void *to, const void __user *from, unsigned long size)
10526 {
10527 - unsigned long ret = ___copy_from_user(to, from, size);
10528 + unsigned long ret;
10529
10530 + if ((long)size < 0 || size > INT_MAX)
10531 + return size;
10532 +
10533 + if (!__builtin_constant_p(size))
10534 + check_object_size(to, size, false);
10535 +
10536 + ret = ___copy_from_user(to, from, size);
10537 if (unlikely(ret))
10538 ret = copy_from_user_fixup(to, from, size);
10539
10540 @@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10541 static inline unsigned long __must_check
10542 copy_to_user(void __user *to, const void *from, unsigned long size)
10543 {
10544 - unsigned long ret = ___copy_to_user(to, from, size);
10545 + unsigned long ret;
10546
10547 + if ((long)size < 0 || size > INT_MAX)
10548 + return size;
10549 +
10550 + if (!__builtin_constant_p(size))
10551 + check_object_size(from, size, true);
10552 +
10553 + ret = ___copy_to_user(to, from, size);
10554 if (unlikely(ret))
10555 ret = copy_to_user_fixup(to, from, size);
10556 return ret;
10557 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10558 index 7cf9c6e..6206648 100644
10559 --- a/arch/sparc/kernel/Makefile
10560 +++ b/arch/sparc/kernel/Makefile
10561 @@ -4,7 +4,7 @@
10562 #
10563
10564 asflags-y := -ansi
10565 -ccflags-y := -Werror
10566 +#ccflags-y := -Werror
10567
10568 extra-y := head_$(BITS).o
10569
10570 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10571 index 50e7b62..79fae35 100644
10572 --- a/arch/sparc/kernel/process_32.c
10573 +++ b/arch/sparc/kernel/process_32.c
10574 @@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10575
10576 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10577 r->psr, r->pc, r->npc, r->y, print_tainted());
10578 - printk("PC: <%pS>\n", (void *) r->pc);
10579 + printk("PC: <%pA>\n", (void *) r->pc);
10580 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10581 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10582 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10583 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10584 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10585 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10586 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10587 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10588
10589 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10590 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10591 @@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10592 rw = (struct reg_window32 *) fp;
10593 pc = rw->ins[7];
10594 printk("[%08lx : ", pc);
10595 - printk("%pS ] ", (void *) pc);
10596 + printk("%pA ] ", (void *) pc);
10597 fp = rw->ins[6];
10598 } while (++count < 16);
10599 printk("\n");
10600 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10601 index 0be7bf9..2b1cba8 100644
10602 --- a/arch/sparc/kernel/process_64.c
10603 +++ b/arch/sparc/kernel/process_64.c
10604 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10605 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10606 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10607 if (regs->tstate & TSTATE_PRIV)
10608 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10609 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10610 }
10611
10612 void show_regs(struct pt_regs *regs)
10613 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10614
10615 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10616 regs->tpc, regs->tnpc, regs->y, print_tainted());
10617 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10618 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10619 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10620 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10621 regs->u_regs[3]);
10622 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10623 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10624 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10625 regs->u_regs[15]);
10626 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10627 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10628 show_regwindow(regs);
10629 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10630 }
10631 @@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10632 ((tp && tp->task) ? tp->task->pid : -1));
10633
10634 if (gp->tstate & TSTATE_PRIV) {
10635 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10636 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10637 (void *) gp->tpc,
10638 (void *) gp->o7,
10639 (void *) gp->i7,
10640 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10641 index 79cc0d1..ec62734 100644
10642 --- a/arch/sparc/kernel/prom_common.c
10643 +++ b/arch/sparc/kernel/prom_common.c
10644 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10645
10646 unsigned int prom_early_allocated __initdata;
10647
10648 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10649 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10650 .nextprop = prom_common_nextprop,
10651 .getproplen = prom_getproplen,
10652 .getproperty = prom_getproperty,
10653 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10654 index 9ddc492..27a5619 100644
10655 --- a/arch/sparc/kernel/ptrace_64.c
10656 +++ b/arch/sparc/kernel/ptrace_64.c
10657 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10658 return ret;
10659 }
10660
10661 +#ifdef CONFIG_GRKERNSEC_SETXID
10662 +extern void gr_delayed_cred_worker(void);
10663 +#endif
10664 +
10665 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10666 {
10667 int ret = 0;
10668 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(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 if (test_thread_flag(TIF_SYSCALL_TRACE))
10678 ret = tracehook_report_syscall_entry(regs);
10679
10680 @@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10681 if (test_thread_flag(TIF_NOHZ))
10682 user_exit();
10683
10684 +#ifdef CONFIG_GRKERNSEC_SETXID
10685 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10686 + gr_delayed_cred_worker();
10687 +#endif
10688 +
10689 audit_syscall_exit(regs);
10690
10691 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10692 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10693 index da6f1a7..e5dea8f 100644
10694 --- a/arch/sparc/kernel/smp_64.c
10695 +++ b/arch/sparc/kernel/smp_64.c
10696 @@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10697 return;
10698
10699 #ifdef CONFIG_DEBUG_DCFLUSH
10700 - atomic_inc(&dcpage_flushes);
10701 + atomic_inc_unchecked(&dcpage_flushes);
10702 #endif
10703
10704 this_cpu = get_cpu();
10705 @@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10706 xcall_deliver(data0, __pa(pg_addr),
10707 (u64) pg_addr, cpumask_of(cpu));
10708 #ifdef CONFIG_DEBUG_DCFLUSH
10709 - atomic_inc(&dcpage_flushes_xcall);
10710 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10711 #endif
10712 }
10713 }
10714 @@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10715 preempt_disable();
10716
10717 #ifdef CONFIG_DEBUG_DCFLUSH
10718 - atomic_inc(&dcpage_flushes);
10719 + atomic_inc_unchecked(&dcpage_flushes);
10720 #endif
10721 data0 = 0;
10722 pg_addr = page_address(page);
10723 @@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10724 xcall_deliver(data0, __pa(pg_addr),
10725 (u64) pg_addr, cpu_online_mask);
10726 #ifdef CONFIG_DEBUG_DCFLUSH
10727 - atomic_inc(&dcpage_flushes_xcall);
10728 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10729 #endif
10730 }
10731 __local_flush_dcache_page(page);
10732 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10733 index 646988d..b88905f 100644
10734 --- a/arch/sparc/kernel/sys_sparc_32.c
10735 +++ b/arch/sparc/kernel/sys_sparc_32.c
10736 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10737 if (len > TASK_SIZE - PAGE_SIZE)
10738 return -ENOMEM;
10739 if (!addr)
10740 - addr = TASK_UNMAPPED_BASE;
10741 + addr = current->mm->mmap_base;
10742
10743 info.flags = 0;
10744 info.length = len;
10745 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10746 index c85403d..6af95c9 100644
10747 --- a/arch/sparc/kernel/sys_sparc_64.c
10748 +++ b/arch/sparc/kernel/sys_sparc_64.c
10749 @@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10750 struct vm_area_struct * vma;
10751 unsigned long task_size = TASK_SIZE;
10752 int do_color_align;
10753 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10754 struct vm_unmapped_area_info info;
10755
10756 if (flags & MAP_FIXED) {
10757 /* We do not accept a shared mapping if it would violate
10758 * cache aliasing constraints.
10759 */
10760 - if ((flags & MAP_SHARED) &&
10761 + if ((filp || (flags & MAP_SHARED)) &&
10762 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10763 return -EINVAL;
10764 return addr;
10765 @@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10766 if (filp || (flags & MAP_SHARED))
10767 do_color_align = 1;
10768
10769 +#ifdef CONFIG_PAX_RANDMMAP
10770 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10771 +#endif
10772 +
10773 if (addr) {
10774 if (do_color_align)
10775 addr = COLOR_ALIGN(addr, pgoff);
10776 @@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10777 addr = PAGE_ALIGN(addr);
10778
10779 vma = find_vma(mm, addr);
10780 - if (task_size - len >= addr &&
10781 - (!vma || addr + len <= vma->vm_start))
10782 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10783 return addr;
10784 }
10785
10786 info.flags = 0;
10787 info.length = len;
10788 - info.low_limit = TASK_UNMAPPED_BASE;
10789 + info.low_limit = mm->mmap_base;
10790 info.high_limit = min(task_size, VA_EXCLUDE_START);
10791 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10792 info.align_offset = pgoff << PAGE_SHIFT;
10793 + info.threadstack_offset = offset;
10794 addr = vm_unmapped_area(&info);
10795
10796 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10797 VM_BUG_ON(addr != -ENOMEM);
10798 info.low_limit = VA_EXCLUDE_END;
10799 +
10800 +#ifdef CONFIG_PAX_RANDMMAP
10801 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10802 + info.low_limit += mm->delta_mmap;
10803 +#endif
10804 +
10805 info.high_limit = task_size;
10806 addr = vm_unmapped_area(&info);
10807 }
10808 @@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10809 unsigned long task_size = STACK_TOP32;
10810 unsigned long addr = addr0;
10811 int do_color_align;
10812 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10813 struct vm_unmapped_area_info info;
10814
10815 /* This should only ever run for 32-bit processes. */
10816 @@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10817 /* We do not accept a shared mapping if it would violate
10818 * cache aliasing constraints.
10819 */
10820 - if ((flags & MAP_SHARED) &&
10821 + if ((filp || (flags & MAP_SHARED)) &&
10822 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10823 return -EINVAL;
10824 return addr;
10825 @@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10826 if (filp || (flags & MAP_SHARED))
10827 do_color_align = 1;
10828
10829 +#ifdef CONFIG_PAX_RANDMMAP
10830 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10831 +#endif
10832 +
10833 /* requesting a specific address */
10834 if (addr) {
10835 if (do_color_align)
10836 @@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10837 addr = PAGE_ALIGN(addr);
10838
10839 vma = find_vma(mm, addr);
10840 - if (task_size - len >= addr &&
10841 - (!vma || addr + len <= vma->vm_start))
10842 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10843 return addr;
10844 }
10845
10846 @@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10847 info.high_limit = mm->mmap_base;
10848 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10849 info.align_offset = pgoff << PAGE_SHIFT;
10850 + info.threadstack_offset = offset;
10851 addr = vm_unmapped_area(&info);
10852
10853 /*
10854 @@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10855 VM_BUG_ON(addr != -ENOMEM);
10856 info.flags = 0;
10857 info.low_limit = TASK_UNMAPPED_BASE;
10858 +
10859 +#ifdef CONFIG_PAX_RANDMMAP
10860 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10861 + info.low_limit += mm->delta_mmap;
10862 +#endif
10863 +
10864 info.high_limit = STACK_TOP32;
10865 addr = vm_unmapped_area(&info);
10866 }
10867 @@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10868 EXPORT_SYMBOL(get_fb_unmapped_area);
10869
10870 /* Essentially the same as PowerPC. */
10871 -static unsigned long mmap_rnd(void)
10872 +static unsigned long mmap_rnd(struct mm_struct *mm)
10873 {
10874 unsigned long rnd = 0UL;
10875
10876 +#ifdef CONFIG_PAX_RANDMMAP
10877 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10878 +#endif
10879 +
10880 if (current->flags & PF_RANDOMIZE) {
10881 unsigned long val = get_random_int();
10882 if (test_thread_flag(TIF_32BIT))
10883 @@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10884
10885 void arch_pick_mmap_layout(struct mm_struct *mm)
10886 {
10887 - unsigned long random_factor = mmap_rnd();
10888 + unsigned long random_factor = mmap_rnd(mm);
10889 unsigned long gap;
10890
10891 /*
10892 @@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10893 gap == RLIM_INFINITY ||
10894 sysctl_legacy_va_layout) {
10895 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10896 +
10897 +#ifdef CONFIG_PAX_RANDMMAP
10898 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10899 + mm->mmap_base += mm->delta_mmap;
10900 +#endif
10901 +
10902 mm->get_unmapped_area = arch_get_unmapped_area;
10903 } else {
10904 /* We know it's 32-bit */
10905 @@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10906 gap = (task_size / 6 * 5);
10907
10908 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10909 +
10910 +#ifdef CONFIG_PAX_RANDMMAP
10911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10912 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10913 +#endif
10914 +
10915 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10916 }
10917 }
10918 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10919 index 33a17e7..d87fb1f 100644
10920 --- a/arch/sparc/kernel/syscalls.S
10921 +++ b/arch/sparc/kernel/syscalls.S
10922 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10923 #endif
10924 .align 32
10925 1: ldx [%g6 + TI_FLAGS], %l5
10926 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10927 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10928 be,pt %icc, rtrap
10929 nop
10930 call syscall_trace_leave
10931 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10932
10933 srl %i3, 0, %o3 ! IEU0
10934 srl %i2, 0, %o2 ! IEU0 Group
10935 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10936 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10937 bne,pn %icc, linux_syscall_trace32 ! CTI
10938 mov %i0, %l5 ! IEU1
10939 5: call %l7 ! CTI Group brk forced
10940 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10941
10942 mov %i3, %o3 ! IEU1
10943 mov %i4, %o4 ! IEU0 Group
10944 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10945 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10946 bne,pn %icc, linux_syscall_trace ! CTI Group
10947 mov %i0, %l5 ! IEU0
10948 2: call %l7 ! CTI Group brk forced
10949 @@ -223,7 +223,7 @@ ret_sys_call:
10950
10951 cmp %o0, -ERESTART_RESTARTBLOCK
10952 bgeu,pn %xcc, 1f
10953 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10954 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10955 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10956
10957 2:
10958 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10959 index 6fd386c5..6907d81 100644
10960 --- a/arch/sparc/kernel/traps_32.c
10961 +++ b/arch/sparc/kernel/traps_32.c
10962 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10963 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10964 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10965
10966 +extern void gr_handle_kernel_exploit(void);
10967 +
10968 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10969 {
10970 static int die_counter;
10971 @@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10972 count++ < 30 &&
10973 (((unsigned long) rw) >= PAGE_OFFSET) &&
10974 !(((unsigned long) rw) & 0x7)) {
10975 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10976 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10977 (void *) rw->ins[7]);
10978 rw = (struct reg_window32 *)rw->ins[6];
10979 }
10980 }
10981 printk("Instruction DUMP:");
10982 instruction_dump ((unsigned long *) regs->pc);
10983 - if(regs->psr & PSR_PS)
10984 + if(regs->psr & PSR_PS) {
10985 + gr_handle_kernel_exploit();
10986 do_exit(SIGKILL);
10987 + }
10988 do_exit(SIGSEGV);
10989 }
10990
10991 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10992 index 981a769..d906eda 100644
10993 --- a/arch/sparc/kernel/traps_64.c
10994 +++ b/arch/sparc/kernel/traps_64.c
10995 @@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10996 i + 1,
10997 p->trapstack[i].tstate, p->trapstack[i].tpc,
10998 p->trapstack[i].tnpc, p->trapstack[i].tt);
10999 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11000 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11001 }
11002 }
11003
11004 @@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11005
11006 lvl -= 0x100;
11007 if (regs->tstate & TSTATE_PRIV) {
11008 +
11009 +#ifdef CONFIG_PAX_REFCOUNT
11010 + if (lvl == 6)
11011 + pax_report_refcount_overflow(regs);
11012 +#endif
11013 +
11014 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11015 die_if_kernel(buffer, regs);
11016 }
11017 @@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11018 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11019 {
11020 char buffer[32];
11021 -
11022 +
11023 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11024 0, lvl, SIGTRAP) == NOTIFY_STOP)
11025 return;
11026
11027 +#ifdef CONFIG_PAX_REFCOUNT
11028 + if (lvl == 6)
11029 + pax_report_refcount_overflow(regs);
11030 +#endif
11031 +
11032 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11033
11034 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11035 @@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11036 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11037 printk("%s" "ERROR(%d): ",
11038 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11039 - printk("TPC<%pS>\n", (void *) regs->tpc);
11040 + printk("TPC<%pA>\n", (void *) regs->tpc);
11041 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11042 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11043 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11044 @@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11045 smp_processor_id(),
11046 (type & 0x1) ? 'I' : 'D',
11047 regs->tpc);
11048 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11049 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11050 panic("Irrecoverable Cheetah+ parity error.");
11051 }
11052
11053 @@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11054 smp_processor_id(),
11055 (type & 0x1) ? 'I' : 'D',
11056 regs->tpc);
11057 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11058 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11059 }
11060
11061 struct sun4v_error_entry {
11062 @@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11063 /*0x38*/u64 reserved_5;
11064 };
11065
11066 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11067 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11068 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11069 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11070
11071 static const char *sun4v_err_type_to_str(u8 type)
11072 {
11073 @@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11074 }
11075
11076 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11077 - int cpu, const char *pfx, atomic_t *ocnt)
11078 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11079 {
11080 u64 *raw_ptr = (u64 *) ent;
11081 u32 attrs;
11082 @@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11083
11084 show_regs(regs);
11085
11086 - if ((cnt = atomic_read(ocnt)) != 0) {
11087 - atomic_set(ocnt, 0);
11088 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11089 + atomic_set_unchecked(ocnt, 0);
11090 wmb();
11091 printk("%s: Queue overflowed %d times.\n",
11092 pfx, cnt);
11093 @@ -2048,7 +2059,7 @@ out:
11094 */
11095 void sun4v_resum_overflow(struct pt_regs *regs)
11096 {
11097 - atomic_inc(&sun4v_resum_oflow_cnt);
11098 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11099 }
11100
11101 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11102 @@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11103 /* XXX Actually even this can make not that much sense. Perhaps
11104 * XXX we should just pull the plug and panic directly from here?
11105 */
11106 - atomic_inc(&sun4v_nonresum_oflow_cnt);
11107 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11108 }
11109
11110 static void sun4v_tlb_error(struct pt_regs *regs)
11111 @@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11112
11113 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11114 regs->tpc, tl);
11115 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11116 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11117 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11118 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11119 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11120 (void *) regs->u_regs[UREG_I7]);
11121 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11122 "pte[%lx] error[%lx]\n",
11123 @@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11124
11125 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11126 regs->tpc, tl);
11127 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11128 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11129 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11130 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11131 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11132 (void *) regs->u_regs[UREG_I7]);
11133 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11134 "pte[%lx] error[%lx]\n",
11135 @@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11136 fp = (unsigned long)sf->fp + STACK_BIAS;
11137 }
11138
11139 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11140 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11141 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11142 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11143 int index = tsk->curr_ret_stack;
11144 if (tsk->ret_stack && index >= graph) {
11145 pc = tsk->ret_stack[index - graph].ret;
11146 - printk(" [%016lx] %pS\n", pc, (void *) pc);
11147 + printk(" [%016lx] %pA\n", pc, (void *) pc);
11148 graph++;
11149 }
11150 }
11151 @@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11152 return (struct reg_window *) (fp + STACK_BIAS);
11153 }
11154
11155 +extern void gr_handle_kernel_exploit(void);
11156 +
11157 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11158 {
11159 static int die_counter;
11160 @@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11161 while (rw &&
11162 count++ < 30 &&
11163 kstack_valid(tp, (unsigned long) rw)) {
11164 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
11165 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
11166 (void *) rw->ins[7]);
11167
11168 rw = kernel_stack_up(rw);
11169 @@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11170 }
11171 user_instruction_dump ((unsigned int __user *) regs->tpc);
11172 }
11173 - if (regs->tstate & TSTATE_PRIV)
11174 + if (regs->tstate & TSTATE_PRIV) {
11175 + gr_handle_kernel_exploit();
11176 do_exit(SIGKILL);
11177 + }
11178 do_exit(SIGSEGV);
11179 }
11180 EXPORT_SYMBOL(die_if_kernel);
11181 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11182 index 62098a8..547ab2c 100644
11183 --- a/arch/sparc/kernel/unaligned_64.c
11184 +++ b/arch/sparc/kernel/unaligned_64.c
11185 @@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11186 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11187
11188 if (__ratelimit(&ratelimit)) {
11189 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
11190 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
11191 regs->tpc, (void *) regs->tpc);
11192 }
11193 }
11194 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11195 index 3269b02..64f5231 100644
11196 --- a/arch/sparc/lib/Makefile
11197 +++ b/arch/sparc/lib/Makefile
11198 @@ -2,7 +2,7 @@
11199 #
11200
11201 asflags-y := -ansi -DST_DIV0=0x02
11202 -ccflags-y := -Werror
11203 +#ccflags-y := -Werror
11204
11205 lib-$(CONFIG_SPARC32) += ashrdi3.o
11206 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11207 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11208 index 05dac43..76f8ed4 100644
11209 --- a/arch/sparc/lib/atomic_64.S
11210 +++ b/arch/sparc/lib/atomic_64.S
11211 @@ -15,11 +15,22 @@
11212 * a value and does the barriers.
11213 */
11214
11215 -#define ATOMIC_OP(op) \
11216 -ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11217 +#ifdef CONFIG_PAX_REFCOUNT
11218 +#define __REFCOUNT_OP(op) op##cc
11219 +#define __OVERFLOW_IOP tvs %icc, 6;
11220 +#define __OVERFLOW_XOP tvs %xcc, 6;
11221 +#else
11222 +#define __REFCOUNT_OP(op) op
11223 +#define __OVERFLOW_IOP
11224 +#define __OVERFLOW_XOP
11225 +#endif
11226 +
11227 +#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11228 +ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11229 BACKOFF_SETUP(%o2); \
11230 1: lduw [%o1], %g1; \
11231 - op %g1, %o0, %g7; \
11232 + asm_op %g1, %o0, %g7; \
11233 + post_op \
11234 cas [%o1], %g1, %g7; \
11235 cmp %g1, %g7; \
11236 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11237 @@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11238 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11239 ENDPROC(atomic_##op); \
11240
11241 -#define ATOMIC_OP_RETURN(op) \
11242 -ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11243 +#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11244 + __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11245 +
11246 +#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11247 +ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11248 BACKOFF_SETUP(%o2); \
11249 1: lduw [%o1], %g1; \
11250 - op %g1, %o0, %g7; \
11251 + asm_op %g1, %o0, %g7; \
11252 + post_op \
11253 cas [%o1], %g1, %g7; \
11254 cmp %g1, %g7; \
11255 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11256 @@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11257 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11258 ENDPROC(atomic_##op##_return);
11259
11260 +#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11261 + __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11262 +
11263 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11264
11265 ATOMIC_OPS(add)
11266 @@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11267
11268 #undef ATOMIC_OPS
11269 #undef ATOMIC_OP_RETURN
11270 +#undef __ATOMIC_OP_RETURN
11271 #undef ATOMIC_OP
11272 +#undef __ATOMIC_OP
11273
11274 -#define ATOMIC64_OP(op) \
11275 -ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11276 +#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11277 +ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11278 BACKOFF_SETUP(%o2); \
11279 1: ldx [%o1], %g1; \
11280 - op %g1, %o0, %g7; \
11281 + asm_op %g1, %o0, %g7; \
11282 + post_op \
11283 casx [%o1], %g1, %g7; \
11284 cmp %g1, %g7; \
11285 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11286 @@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11287 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11288 ENDPROC(atomic64_##op); \
11289
11290 -#define ATOMIC64_OP_RETURN(op) \
11291 -ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11292 +#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11293 + __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11294 +
11295 +#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11296 +ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11297 BACKOFF_SETUP(%o2); \
11298 1: ldx [%o1], %g1; \
11299 - op %g1, %o0, %g7; \
11300 + asm_op %g1, %o0, %g7; \
11301 + post_op \
11302 casx [%o1], %g1, %g7; \
11303 cmp %g1, %g7; \
11304 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11305 @@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11306 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11307 ENDPROC(atomic64_##op##_return);
11308
11309 +#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11310 +i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11311 +
11312 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11313
11314 ATOMIC64_OPS(add)
11315 @@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11316
11317 #undef ATOMIC64_OPS
11318 #undef ATOMIC64_OP_RETURN
11319 +#undef __ATOMIC64_OP_RETURN
11320 #undef ATOMIC64_OP
11321 +#undef __ATOMIC64_OP
11322 +#undef __OVERFLOW_XOP
11323 +#undef __OVERFLOW_IOP
11324 +#undef __REFCOUNT_OP
11325
11326 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11327 BACKOFF_SETUP(%o2)
11328 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11329 index 1d649a9..fbc5bfc 100644
11330 --- a/arch/sparc/lib/ksyms.c
11331 +++ b/arch/sparc/lib/ksyms.c
11332 @@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11333 /* Atomic counter implementation. */
11334 #define ATOMIC_OP(op) \
11335 EXPORT_SYMBOL(atomic_##op); \
11336 -EXPORT_SYMBOL(atomic64_##op);
11337 +EXPORT_SYMBOL(atomic_##op##_unchecked); \
11338 +EXPORT_SYMBOL(atomic64_##op); \
11339 +EXPORT_SYMBOL(atomic64_##op##_unchecked);
11340
11341 #define ATOMIC_OP_RETURN(op) \
11342 EXPORT_SYMBOL(atomic_##op##_return); \
11343 @@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11344 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11345
11346 ATOMIC_OPS(add)
11347 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11348 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11349 ATOMIC_OPS(sub)
11350
11351 #undef ATOMIC_OPS
11352 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11353 index 30c3ecc..736f015 100644
11354 --- a/arch/sparc/mm/Makefile
11355 +++ b/arch/sparc/mm/Makefile
11356 @@ -2,7 +2,7 @@
11357 #
11358
11359 asflags-y := -ansi
11360 -ccflags-y := -Werror
11361 +#ccflags-y := -Werror
11362
11363 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11364 obj-y += fault_$(BITS).o
11365 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11366 index 70d8171..274c6c0 100644
11367 --- a/arch/sparc/mm/fault_32.c
11368 +++ b/arch/sparc/mm/fault_32.c
11369 @@ -21,6 +21,9 @@
11370 #include <linux/perf_event.h>
11371 #include <linux/interrupt.h>
11372 #include <linux/kdebug.h>
11373 +#include <linux/slab.h>
11374 +#include <linux/pagemap.h>
11375 +#include <linux/compiler.h>
11376
11377 #include <asm/page.h>
11378 #include <asm/pgtable.h>
11379 @@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11380 return safe_compute_effective_address(regs, insn);
11381 }
11382
11383 +#ifdef CONFIG_PAX_PAGEEXEC
11384 +#ifdef CONFIG_PAX_DLRESOLVE
11385 +static void pax_emuplt_close(struct vm_area_struct *vma)
11386 +{
11387 + vma->vm_mm->call_dl_resolve = 0UL;
11388 +}
11389 +
11390 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11391 +{
11392 + unsigned int *kaddr;
11393 +
11394 + vmf->page = alloc_page(GFP_HIGHUSER);
11395 + if (!vmf->page)
11396 + return VM_FAULT_OOM;
11397 +
11398 + kaddr = kmap(vmf->page);
11399 + memset(kaddr, 0, PAGE_SIZE);
11400 + kaddr[0] = 0x9DE3BFA8U; /* save */
11401 + flush_dcache_page(vmf->page);
11402 + kunmap(vmf->page);
11403 + return VM_FAULT_MAJOR;
11404 +}
11405 +
11406 +static const struct vm_operations_struct pax_vm_ops = {
11407 + .close = pax_emuplt_close,
11408 + .fault = pax_emuplt_fault
11409 +};
11410 +
11411 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11412 +{
11413 + int ret;
11414 +
11415 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11416 + vma->vm_mm = current->mm;
11417 + vma->vm_start = addr;
11418 + vma->vm_end = addr + PAGE_SIZE;
11419 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11420 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11421 + vma->vm_ops = &pax_vm_ops;
11422 +
11423 + ret = insert_vm_struct(current->mm, vma);
11424 + if (ret)
11425 + return ret;
11426 +
11427 + ++current->mm->total_vm;
11428 + return 0;
11429 +}
11430 +#endif
11431 +
11432 +/*
11433 + * PaX: decide what to do with offenders (regs->pc = fault address)
11434 + *
11435 + * returns 1 when task should be killed
11436 + * 2 when patched PLT trampoline was detected
11437 + * 3 when unpatched PLT trampoline was detected
11438 + */
11439 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11440 +{
11441 +
11442 +#ifdef CONFIG_PAX_EMUPLT
11443 + int err;
11444 +
11445 + do { /* PaX: patched PLT emulation #1 */
11446 + unsigned int sethi1, sethi2, jmpl;
11447 +
11448 + err = get_user(sethi1, (unsigned int *)regs->pc);
11449 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11450 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11451 +
11452 + if (err)
11453 + break;
11454 +
11455 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11456 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11457 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11458 + {
11459 + unsigned int addr;
11460 +
11461 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11462 + addr = regs->u_regs[UREG_G1];
11463 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11464 + regs->pc = addr;
11465 + regs->npc = addr+4;
11466 + return 2;
11467 + }
11468 + } while (0);
11469 +
11470 + do { /* PaX: patched PLT emulation #2 */
11471 + unsigned int ba;
11472 +
11473 + err = get_user(ba, (unsigned int *)regs->pc);
11474 +
11475 + if (err)
11476 + break;
11477 +
11478 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11479 + unsigned int addr;
11480 +
11481 + if ((ba & 0xFFC00000U) == 0x30800000U)
11482 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11483 + else
11484 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11485 + regs->pc = addr;
11486 + regs->npc = addr+4;
11487 + return 2;
11488 + }
11489 + } while (0);
11490 +
11491 + do { /* PaX: patched PLT emulation #3 */
11492 + unsigned int sethi, bajmpl, nop;
11493 +
11494 + err = get_user(sethi, (unsigned int *)regs->pc);
11495 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11496 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11497 +
11498 + if (err)
11499 + break;
11500 +
11501 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11502 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11503 + nop == 0x01000000U)
11504 + {
11505 + unsigned int addr;
11506 +
11507 + addr = (sethi & 0x003FFFFFU) << 10;
11508 + regs->u_regs[UREG_G1] = addr;
11509 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11510 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11511 + else
11512 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11513 + regs->pc = addr;
11514 + regs->npc = addr+4;
11515 + return 2;
11516 + }
11517 + } while (0);
11518 +
11519 + do { /* PaX: unpatched PLT emulation step 1 */
11520 + unsigned int sethi, ba, nop;
11521 +
11522 + err = get_user(sethi, (unsigned int *)regs->pc);
11523 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11524 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11525 +
11526 + if (err)
11527 + break;
11528 +
11529 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11530 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11531 + nop == 0x01000000U)
11532 + {
11533 + unsigned int addr, save, call;
11534 +
11535 + if ((ba & 0xFFC00000U) == 0x30800000U)
11536 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11537 + else
11538 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11539 +
11540 + err = get_user(save, (unsigned int *)addr);
11541 + err |= get_user(call, (unsigned int *)(addr+4));
11542 + err |= get_user(nop, (unsigned int *)(addr+8));
11543 + if (err)
11544 + break;
11545 +
11546 +#ifdef CONFIG_PAX_DLRESOLVE
11547 + if (save == 0x9DE3BFA8U &&
11548 + (call & 0xC0000000U) == 0x40000000U &&
11549 + nop == 0x01000000U)
11550 + {
11551 + struct vm_area_struct *vma;
11552 + unsigned long call_dl_resolve;
11553 +
11554 + down_read(&current->mm->mmap_sem);
11555 + call_dl_resolve = current->mm->call_dl_resolve;
11556 + up_read(&current->mm->mmap_sem);
11557 + if (likely(call_dl_resolve))
11558 + goto emulate;
11559 +
11560 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11561 +
11562 + down_write(&current->mm->mmap_sem);
11563 + if (current->mm->call_dl_resolve) {
11564 + call_dl_resolve = current->mm->call_dl_resolve;
11565 + up_write(&current->mm->mmap_sem);
11566 + if (vma)
11567 + kmem_cache_free(vm_area_cachep, vma);
11568 + goto emulate;
11569 + }
11570 +
11571 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11572 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11573 + up_write(&current->mm->mmap_sem);
11574 + if (vma)
11575 + kmem_cache_free(vm_area_cachep, vma);
11576 + return 1;
11577 + }
11578 +
11579 + if (pax_insert_vma(vma, call_dl_resolve)) {
11580 + up_write(&current->mm->mmap_sem);
11581 + kmem_cache_free(vm_area_cachep, vma);
11582 + return 1;
11583 + }
11584 +
11585 + current->mm->call_dl_resolve = call_dl_resolve;
11586 + up_write(&current->mm->mmap_sem);
11587 +
11588 +emulate:
11589 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11590 + regs->pc = call_dl_resolve;
11591 + regs->npc = addr+4;
11592 + return 3;
11593 + }
11594 +#endif
11595 +
11596 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11597 + if ((save & 0xFFC00000U) == 0x05000000U &&
11598 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11599 + nop == 0x01000000U)
11600 + {
11601 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11602 + regs->u_regs[UREG_G2] = addr + 4;
11603 + addr = (save & 0x003FFFFFU) << 10;
11604 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11605 + regs->pc = addr;
11606 + regs->npc = addr+4;
11607 + return 3;
11608 + }
11609 + }
11610 + } while (0);
11611 +
11612 + do { /* PaX: unpatched PLT emulation step 2 */
11613 + unsigned int save, call, nop;
11614 +
11615 + err = get_user(save, (unsigned int *)(regs->pc-4));
11616 + err |= get_user(call, (unsigned int *)regs->pc);
11617 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11618 + if (err)
11619 + break;
11620 +
11621 + if (save == 0x9DE3BFA8U &&
11622 + (call & 0xC0000000U) == 0x40000000U &&
11623 + nop == 0x01000000U)
11624 + {
11625 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11626 +
11627 + regs->u_regs[UREG_RETPC] = regs->pc;
11628 + regs->pc = dl_resolve;
11629 + regs->npc = dl_resolve+4;
11630 + return 3;
11631 + }
11632 + } while (0);
11633 +#endif
11634 +
11635 + return 1;
11636 +}
11637 +
11638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11639 +{
11640 + unsigned long i;
11641 +
11642 + printk(KERN_ERR "PAX: bytes at PC: ");
11643 + for (i = 0; i < 8; i++) {
11644 + unsigned int c;
11645 + if (get_user(c, (unsigned int *)pc+i))
11646 + printk(KERN_CONT "???????? ");
11647 + else
11648 + printk(KERN_CONT "%08x ", c);
11649 + }
11650 + printk("\n");
11651 +}
11652 +#endif
11653 +
11654 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11655 int text_fault)
11656 {
11657 @@ -226,6 +500,24 @@ good_area:
11658 if (!(vma->vm_flags & VM_WRITE))
11659 goto bad_area;
11660 } else {
11661 +
11662 +#ifdef CONFIG_PAX_PAGEEXEC
11663 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11664 + up_read(&mm->mmap_sem);
11665 + switch (pax_handle_fetch_fault(regs)) {
11666 +
11667 +#ifdef CONFIG_PAX_EMUPLT
11668 + case 2:
11669 + case 3:
11670 + return;
11671 +#endif
11672 +
11673 + }
11674 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11675 + do_group_exit(SIGKILL);
11676 + }
11677 +#endif
11678 +
11679 /* Allow reads even for write-only mappings */
11680 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11681 goto bad_area;
11682 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11683 index 4798232..f76e3aa 100644
11684 --- a/arch/sparc/mm/fault_64.c
11685 +++ b/arch/sparc/mm/fault_64.c
11686 @@ -22,6 +22,9 @@
11687 #include <linux/kdebug.h>
11688 #include <linux/percpu.h>
11689 #include <linux/context_tracking.h>
11690 +#include <linux/slab.h>
11691 +#include <linux/pagemap.h>
11692 +#include <linux/compiler.h>
11693
11694 #include <asm/page.h>
11695 #include <asm/pgtable.h>
11696 @@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11697 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11698 regs->tpc);
11699 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11700 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11701 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11702 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11703 dump_stack();
11704 unhandled_fault(regs->tpc, current, regs);
11705 @@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11706 show_regs(regs);
11707 }
11708
11709 +#ifdef CONFIG_PAX_PAGEEXEC
11710 +#ifdef CONFIG_PAX_DLRESOLVE
11711 +static void pax_emuplt_close(struct vm_area_struct *vma)
11712 +{
11713 + vma->vm_mm->call_dl_resolve = 0UL;
11714 +}
11715 +
11716 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11717 +{
11718 + unsigned int *kaddr;
11719 +
11720 + vmf->page = alloc_page(GFP_HIGHUSER);
11721 + if (!vmf->page)
11722 + return VM_FAULT_OOM;
11723 +
11724 + kaddr = kmap(vmf->page);
11725 + memset(kaddr, 0, PAGE_SIZE);
11726 + kaddr[0] = 0x9DE3BFA8U; /* save */
11727 + flush_dcache_page(vmf->page);
11728 + kunmap(vmf->page);
11729 + return VM_FAULT_MAJOR;
11730 +}
11731 +
11732 +static const struct vm_operations_struct pax_vm_ops = {
11733 + .close = pax_emuplt_close,
11734 + .fault = pax_emuplt_fault
11735 +};
11736 +
11737 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11738 +{
11739 + int ret;
11740 +
11741 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11742 + vma->vm_mm = current->mm;
11743 + vma->vm_start = addr;
11744 + vma->vm_end = addr + PAGE_SIZE;
11745 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11746 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11747 + vma->vm_ops = &pax_vm_ops;
11748 +
11749 + ret = insert_vm_struct(current->mm, vma);
11750 + if (ret)
11751 + return ret;
11752 +
11753 + ++current->mm->total_vm;
11754 + return 0;
11755 +}
11756 +#endif
11757 +
11758 +/*
11759 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11760 + *
11761 + * returns 1 when task should be killed
11762 + * 2 when patched PLT trampoline was detected
11763 + * 3 when unpatched PLT trampoline was detected
11764 + */
11765 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11766 +{
11767 +
11768 +#ifdef CONFIG_PAX_EMUPLT
11769 + int err;
11770 +
11771 + do { /* PaX: patched PLT emulation #1 */
11772 + unsigned int sethi1, sethi2, jmpl;
11773 +
11774 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11775 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11776 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11777 +
11778 + if (err)
11779 + break;
11780 +
11781 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11782 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11783 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11784 + {
11785 + unsigned long addr;
11786 +
11787 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11788 + addr = regs->u_regs[UREG_G1];
11789 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11790 +
11791 + if (test_thread_flag(TIF_32BIT))
11792 + addr &= 0xFFFFFFFFUL;
11793 +
11794 + regs->tpc = addr;
11795 + regs->tnpc = addr+4;
11796 + return 2;
11797 + }
11798 + } while (0);
11799 +
11800 + do { /* PaX: patched PLT emulation #2 */
11801 + unsigned int ba;
11802 +
11803 + err = get_user(ba, (unsigned int *)regs->tpc);
11804 +
11805 + if (err)
11806 + break;
11807 +
11808 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11809 + unsigned long addr;
11810 +
11811 + if ((ba & 0xFFC00000U) == 0x30800000U)
11812 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11813 + else
11814 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11815 +
11816 + if (test_thread_flag(TIF_32BIT))
11817 + addr &= 0xFFFFFFFFUL;
11818 +
11819 + regs->tpc = addr;
11820 + regs->tnpc = addr+4;
11821 + return 2;
11822 + }
11823 + } while (0);
11824 +
11825 + do { /* PaX: patched PLT emulation #3 */
11826 + unsigned int sethi, bajmpl, nop;
11827 +
11828 + err = get_user(sethi, (unsigned int *)regs->tpc);
11829 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11830 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11831 +
11832 + if (err)
11833 + break;
11834 +
11835 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11836 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11837 + nop == 0x01000000U)
11838 + {
11839 + unsigned long addr;
11840 +
11841 + addr = (sethi & 0x003FFFFFU) << 10;
11842 + regs->u_regs[UREG_G1] = addr;
11843 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11844 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11845 + else
11846 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11847 +
11848 + if (test_thread_flag(TIF_32BIT))
11849 + addr &= 0xFFFFFFFFUL;
11850 +
11851 + regs->tpc = addr;
11852 + regs->tnpc = addr+4;
11853 + return 2;
11854 + }
11855 + } while (0);
11856 +
11857 + do { /* PaX: patched PLT emulation #4 */
11858 + unsigned int sethi, mov1, call, mov2;
11859 +
11860 + err = get_user(sethi, (unsigned int *)regs->tpc);
11861 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11862 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11863 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11864 +
11865 + if (err)
11866 + break;
11867 +
11868 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11869 + mov1 == 0x8210000FU &&
11870 + (call & 0xC0000000U) == 0x40000000U &&
11871 + mov2 == 0x9E100001U)
11872 + {
11873 + unsigned long addr;
11874 +
11875 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11876 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11877 +
11878 + if (test_thread_flag(TIF_32BIT))
11879 + addr &= 0xFFFFFFFFUL;
11880 +
11881 + regs->tpc = addr;
11882 + regs->tnpc = addr+4;
11883 + return 2;
11884 + }
11885 + } while (0);
11886 +
11887 + do { /* PaX: patched PLT emulation #5 */
11888 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11889 +
11890 + err = get_user(sethi, (unsigned int *)regs->tpc);
11891 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11892 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11893 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11894 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11895 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11896 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11897 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11898 +
11899 + if (err)
11900 + break;
11901 +
11902 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11903 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11904 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11905 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11906 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11907 + sllx == 0x83287020U &&
11908 + jmpl == 0x81C04005U &&
11909 + nop == 0x01000000U)
11910 + {
11911 + unsigned long addr;
11912 +
11913 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11914 + regs->u_regs[UREG_G1] <<= 32;
11915 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11916 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11917 + regs->tpc = addr;
11918 + regs->tnpc = addr+4;
11919 + return 2;
11920 + }
11921 + } while (0);
11922 +
11923 + do { /* PaX: patched PLT emulation #6 */
11924 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11925 +
11926 + err = get_user(sethi, (unsigned int *)regs->tpc);
11927 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11928 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11929 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11930 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11931 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11932 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11933 +
11934 + if (err)
11935 + break;
11936 +
11937 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11938 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11939 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11940 + sllx == 0x83287020U &&
11941 + (or & 0xFFFFE000U) == 0x8A116000U &&
11942 + jmpl == 0x81C04005U &&
11943 + nop == 0x01000000U)
11944 + {
11945 + unsigned long addr;
11946 +
11947 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11948 + regs->u_regs[UREG_G1] <<= 32;
11949 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11950 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11951 + regs->tpc = addr;
11952 + regs->tnpc = addr+4;
11953 + return 2;
11954 + }
11955 + } while (0);
11956 +
11957 + do { /* PaX: unpatched PLT emulation step 1 */
11958 + unsigned int sethi, ba, nop;
11959 +
11960 + err = get_user(sethi, (unsigned int *)regs->tpc);
11961 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11962 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11963 +
11964 + if (err)
11965 + break;
11966 +
11967 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11968 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11969 + nop == 0x01000000U)
11970 + {
11971 + unsigned long addr;
11972 + unsigned int save, call;
11973 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11974 +
11975 + if ((ba & 0xFFC00000U) == 0x30800000U)
11976 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11977 + else
11978 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11979 +
11980 + if (test_thread_flag(TIF_32BIT))
11981 + addr &= 0xFFFFFFFFUL;
11982 +
11983 + err = get_user(save, (unsigned int *)addr);
11984 + err |= get_user(call, (unsigned int *)(addr+4));
11985 + err |= get_user(nop, (unsigned int *)(addr+8));
11986 + if (err)
11987 + break;
11988 +
11989 +#ifdef CONFIG_PAX_DLRESOLVE
11990 + if (save == 0x9DE3BFA8U &&
11991 + (call & 0xC0000000U) == 0x40000000U &&
11992 + nop == 0x01000000U)
11993 + {
11994 + struct vm_area_struct *vma;
11995 + unsigned long call_dl_resolve;
11996 +
11997 + down_read(&current->mm->mmap_sem);
11998 + call_dl_resolve = current->mm->call_dl_resolve;
11999 + up_read(&current->mm->mmap_sem);
12000 + if (likely(call_dl_resolve))
12001 + goto emulate;
12002 +
12003 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12004 +
12005 + down_write(&current->mm->mmap_sem);
12006 + if (current->mm->call_dl_resolve) {
12007 + call_dl_resolve = current->mm->call_dl_resolve;
12008 + up_write(&current->mm->mmap_sem);
12009 + if (vma)
12010 + kmem_cache_free(vm_area_cachep, vma);
12011 + goto emulate;
12012 + }
12013 +
12014 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12015 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12016 + up_write(&current->mm->mmap_sem);
12017 + if (vma)
12018 + kmem_cache_free(vm_area_cachep, vma);
12019 + return 1;
12020 + }
12021 +
12022 + if (pax_insert_vma(vma, call_dl_resolve)) {
12023 + up_write(&current->mm->mmap_sem);
12024 + kmem_cache_free(vm_area_cachep, vma);
12025 + return 1;
12026 + }
12027 +
12028 + current->mm->call_dl_resolve = call_dl_resolve;
12029 + up_write(&current->mm->mmap_sem);
12030 +
12031 +emulate:
12032 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033 + regs->tpc = call_dl_resolve;
12034 + regs->tnpc = addr+4;
12035 + return 3;
12036 + }
12037 +#endif
12038 +
12039 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12040 + if ((save & 0xFFC00000U) == 0x05000000U &&
12041 + (call & 0xFFFFE000U) == 0x85C0A000U &&
12042 + nop == 0x01000000U)
12043 + {
12044 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12045 + regs->u_regs[UREG_G2] = addr + 4;
12046 + addr = (save & 0x003FFFFFU) << 10;
12047 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12048 +
12049 + if (test_thread_flag(TIF_32BIT))
12050 + addr &= 0xFFFFFFFFUL;
12051 +
12052 + regs->tpc = addr;
12053 + regs->tnpc = addr+4;
12054 + return 3;
12055 + }
12056 +
12057 + /* PaX: 64-bit PLT stub */
12058 + err = get_user(sethi1, (unsigned int *)addr);
12059 + err |= get_user(sethi2, (unsigned int *)(addr+4));
12060 + err |= get_user(or1, (unsigned int *)(addr+8));
12061 + err |= get_user(or2, (unsigned int *)(addr+12));
12062 + err |= get_user(sllx, (unsigned int *)(addr+16));
12063 + err |= get_user(add, (unsigned int *)(addr+20));
12064 + err |= get_user(jmpl, (unsigned int *)(addr+24));
12065 + err |= get_user(nop, (unsigned int *)(addr+28));
12066 + if (err)
12067 + break;
12068 +
12069 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12070 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12071 + (or1 & 0xFFFFE000U) == 0x88112000U &&
12072 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
12073 + sllx == 0x89293020U &&
12074 + add == 0x8A010005U &&
12075 + jmpl == 0x89C14000U &&
12076 + nop == 0x01000000U)
12077 + {
12078 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12079 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12080 + regs->u_regs[UREG_G4] <<= 32;
12081 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12082 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12083 + regs->u_regs[UREG_G4] = addr + 24;
12084 + addr = regs->u_regs[UREG_G5];
12085 + regs->tpc = addr;
12086 + regs->tnpc = addr+4;
12087 + return 3;
12088 + }
12089 + }
12090 + } while (0);
12091 +
12092 +#ifdef CONFIG_PAX_DLRESOLVE
12093 + do { /* PaX: unpatched PLT emulation step 2 */
12094 + unsigned int save, call, nop;
12095 +
12096 + err = get_user(save, (unsigned int *)(regs->tpc-4));
12097 + err |= get_user(call, (unsigned int *)regs->tpc);
12098 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12099 + if (err)
12100 + break;
12101 +
12102 + if (save == 0x9DE3BFA8U &&
12103 + (call & 0xC0000000U) == 0x40000000U &&
12104 + nop == 0x01000000U)
12105 + {
12106 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12107 +
12108 + if (test_thread_flag(TIF_32BIT))
12109 + dl_resolve &= 0xFFFFFFFFUL;
12110 +
12111 + regs->u_regs[UREG_RETPC] = regs->tpc;
12112 + regs->tpc = dl_resolve;
12113 + regs->tnpc = dl_resolve+4;
12114 + return 3;
12115 + }
12116 + } while (0);
12117 +#endif
12118 +
12119 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12120 + unsigned int sethi, ba, nop;
12121 +
12122 + err = get_user(sethi, (unsigned int *)regs->tpc);
12123 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12124 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12125 +
12126 + if (err)
12127 + break;
12128 +
12129 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12130 + (ba & 0xFFF00000U) == 0x30600000U &&
12131 + nop == 0x01000000U)
12132 + {
12133 + unsigned long addr;
12134 +
12135 + addr = (sethi & 0x003FFFFFU) << 10;
12136 + regs->u_regs[UREG_G1] = addr;
12137 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12138 +
12139 + if (test_thread_flag(TIF_32BIT))
12140 + addr &= 0xFFFFFFFFUL;
12141 +
12142 + regs->tpc = addr;
12143 + regs->tnpc = addr+4;
12144 + return 2;
12145 + }
12146 + } while (0);
12147 +
12148 +#endif
12149 +
12150 + return 1;
12151 +}
12152 +
12153 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12154 +{
12155 + unsigned long i;
12156 +
12157 + printk(KERN_ERR "PAX: bytes at PC: ");
12158 + for (i = 0; i < 8; i++) {
12159 + unsigned int c;
12160 + if (get_user(c, (unsigned int *)pc+i))
12161 + printk(KERN_CONT "???????? ");
12162 + else
12163 + printk(KERN_CONT "%08x ", c);
12164 + }
12165 + printk("\n");
12166 +}
12167 +#endif
12168 +
12169 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12170 {
12171 enum ctx_state prev_state = exception_enter();
12172 @@ -353,6 +816,29 @@ retry:
12173 if (!vma)
12174 goto bad_area;
12175
12176 +#ifdef CONFIG_PAX_PAGEEXEC
12177 + /* PaX: detect ITLB misses on non-exec pages */
12178 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12179 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12180 + {
12181 + if (address != regs->tpc)
12182 + goto good_area;
12183 +
12184 + up_read(&mm->mmap_sem);
12185 + switch (pax_handle_fetch_fault(regs)) {
12186 +
12187 +#ifdef CONFIG_PAX_EMUPLT
12188 + case 2:
12189 + case 3:
12190 + return;
12191 +#endif
12192 +
12193 + }
12194 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12195 + do_group_exit(SIGKILL);
12196 + }
12197 +#endif
12198 +
12199 /* Pure DTLB misses do not tell us whether the fault causing
12200 * load/store/atomic was a write or not, it only says that there
12201 * was no match. So in such a case we (carefully) read the
12202 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12203 index d329537..2c3746a 100644
12204 --- a/arch/sparc/mm/hugetlbpage.c
12205 +++ b/arch/sparc/mm/hugetlbpage.c
12206 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12207 unsigned long addr,
12208 unsigned long len,
12209 unsigned long pgoff,
12210 - unsigned long flags)
12211 + unsigned long flags,
12212 + unsigned long offset)
12213 {
12214 + struct mm_struct *mm = current->mm;
12215 unsigned long task_size = TASK_SIZE;
12216 struct vm_unmapped_area_info info;
12217
12218 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12219
12220 info.flags = 0;
12221 info.length = len;
12222 - info.low_limit = TASK_UNMAPPED_BASE;
12223 + info.low_limit = mm->mmap_base;
12224 info.high_limit = min(task_size, VA_EXCLUDE_START);
12225 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12226 info.align_offset = 0;
12227 + info.threadstack_offset = offset;
12228 addr = vm_unmapped_area(&info);
12229
12230 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12231 VM_BUG_ON(addr != -ENOMEM);
12232 info.low_limit = VA_EXCLUDE_END;
12233 +
12234 +#ifdef CONFIG_PAX_RANDMMAP
12235 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12236 + info.low_limit += mm->delta_mmap;
12237 +#endif
12238 +
12239 info.high_limit = task_size;
12240 addr = vm_unmapped_area(&info);
12241 }
12242 @@ -55,7 +64,8 @@ static unsigned long
12243 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12244 const unsigned long len,
12245 const unsigned long pgoff,
12246 - const unsigned long flags)
12247 + const unsigned long flags,
12248 + const unsigned long offset)
12249 {
12250 struct mm_struct *mm = current->mm;
12251 unsigned long addr = addr0;
12252 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12253 info.high_limit = mm->mmap_base;
12254 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12255 info.align_offset = 0;
12256 + info.threadstack_offset = offset;
12257 addr = vm_unmapped_area(&info);
12258
12259 /*
12260 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12261 VM_BUG_ON(addr != -ENOMEM);
12262 info.flags = 0;
12263 info.low_limit = TASK_UNMAPPED_BASE;
12264 +
12265 +#ifdef CONFIG_PAX_RANDMMAP
12266 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12267 + info.low_limit += mm->delta_mmap;
12268 +#endif
12269 +
12270 info.high_limit = STACK_TOP32;
12271 addr = vm_unmapped_area(&info);
12272 }
12273 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12274 struct mm_struct *mm = current->mm;
12275 struct vm_area_struct *vma;
12276 unsigned long task_size = TASK_SIZE;
12277 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12278
12279 if (test_thread_flag(TIF_32BIT))
12280 task_size = STACK_TOP32;
12281 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12282 return addr;
12283 }
12284
12285 +#ifdef CONFIG_PAX_RANDMMAP
12286 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12287 +#endif
12288 +
12289 if (addr) {
12290 addr = ALIGN(addr, HPAGE_SIZE);
12291 vma = find_vma(mm, addr);
12292 - if (task_size - len >= addr &&
12293 - (!vma || addr + len <= vma->vm_start))
12294 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12295 return addr;
12296 }
12297 if (mm->get_unmapped_area == arch_get_unmapped_area)
12298 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12299 - pgoff, flags);
12300 + pgoff, flags, offset);
12301 else
12302 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12303 - pgoff, flags);
12304 + pgoff, flags, offset);
12305 }
12306
12307 pte_t *huge_pte_alloc(struct mm_struct *mm,
12308 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12309 index 2d91c62..17a8fff 100644
12310 --- a/arch/sparc/mm/init_64.c
12311 +++ b/arch/sparc/mm/init_64.c
12312 @@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12313 int num_kernel_image_mappings;
12314
12315 #ifdef CONFIG_DEBUG_DCFLUSH
12316 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12317 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12318 #ifdef CONFIG_SMP
12319 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12320 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12321 #endif
12322 #endif
12323
12324 @@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12325 {
12326 BUG_ON(tlb_type == hypervisor);
12327 #ifdef CONFIG_DEBUG_DCFLUSH
12328 - atomic_inc(&dcpage_flushes);
12329 + atomic_inc_unchecked(&dcpage_flushes);
12330 #endif
12331
12332 #ifdef DCACHE_ALIASING_POSSIBLE
12333 @@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12334
12335 #ifdef CONFIG_DEBUG_DCFLUSH
12336 seq_printf(m, "DCPageFlushes\t: %d\n",
12337 - atomic_read(&dcpage_flushes));
12338 + atomic_read_unchecked(&dcpage_flushes));
12339 #ifdef CONFIG_SMP
12340 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12341 - atomic_read(&dcpage_flushes_xcall));
12342 + atomic_read_unchecked(&dcpage_flushes_xcall));
12343 #endif /* CONFIG_SMP */
12344 #endif /* CONFIG_DEBUG_DCFLUSH */
12345 }
12346 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12347 index 7cca418..53fc030 100644
12348 --- a/arch/tile/Kconfig
12349 +++ b/arch/tile/Kconfig
12350 @@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12351
12352 config KEXEC
12353 bool "kexec system call"
12354 + depends on !GRKERNSEC_KMEM
12355 ---help---
12356 kexec is a system call that implements the ability to shutdown your
12357 current kernel, and to start another kernel. It is like a reboot
12358 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12359 index 7b11c5f..755a026 100644
12360 --- a/arch/tile/include/asm/atomic_64.h
12361 +++ b/arch/tile/include/asm/atomic_64.h
12362 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12363
12364 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12365
12366 +#define atomic64_read_unchecked(v) atomic64_read(v)
12367 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12368 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12369 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12370 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12371 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12372 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12373 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12374 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12375 +
12376 /* Define this to indicate that cmpxchg is an efficient operation. */
12377 #define __HAVE_ARCH_CMPXCHG
12378
12379 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12380 index 6160761..00cac88 100644
12381 --- a/arch/tile/include/asm/cache.h
12382 +++ b/arch/tile/include/asm/cache.h
12383 @@ -15,11 +15,12 @@
12384 #ifndef _ASM_TILE_CACHE_H
12385 #define _ASM_TILE_CACHE_H
12386
12387 +#include <linux/const.h>
12388 #include <arch/chip.h>
12389
12390 /* bytes per L1 data cache line */
12391 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12392 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12393 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12394
12395 /* bytes per L2 cache line */
12396 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12397 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12398 index b6cde32..c0cb736 100644
12399 --- a/arch/tile/include/asm/uaccess.h
12400 +++ b/arch/tile/include/asm/uaccess.h
12401 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12402 const void __user *from,
12403 unsigned long n)
12404 {
12405 - int sz = __compiletime_object_size(to);
12406 + size_t sz = __compiletime_object_size(to);
12407
12408 - if (likely(sz == -1 || sz >= n))
12409 + if (likely(sz == (size_t)-1 || sz >= n))
12410 n = _copy_from_user(to, from, n);
12411 else
12412 copy_from_user_overflow();
12413 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12414 index e514899..f8743c4 100644
12415 --- a/arch/tile/mm/hugetlbpage.c
12416 +++ b/arch/tile/mm/hugetlbpage.c
12417 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12418 info.high_limit = TASK_SIZE;
12419 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12420 info.align_offset = 0;
12421 + info.threadstack_offset = 0;
12422 return vm_unmapped_area(&info);
12423 }
12424
12425 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12426 info.high_limit = current->mm->mmap_base;
12427 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12428 info.align_offset = 0;
12429 + info.threadstack_offset = 0;
12430 addr = vm_unmapped_area(&info);
12431
12432 /*
12433 diff --git a/arch/um/Makefile b/arch/um/Makefile
12434 index e4b1a96..16162f8 100644
12435 --- a/arch/um/Makefile
12436 +++ b/arch/um/Makefile
12437 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12438 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12439 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12440
12441 +ifdef CONSTIFY_PLUGIN
12442 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12443 +endif
12444 +
12445 #This will adjust *FLAGS accordingly to the platform.
12446 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12447
12448 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12449 index 19e1bdd..3665b77 100644
12450 --- a/arch/um/include/asm/cache.h
12451 +++ b/arch/um/include/asm/cache.h
12452 @@ -1,6 +1,7 @@
12453 #ifndef __UM_CACHE_H
12454 #define __UM_CACHE_H
12455
12456 +#include <linux/const.h>
12457
12458 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12459 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12460 @@ -12,6 +13,6 @@
12461 # define L1_CACHE_SHIFT 5
12462 #endif
12463
12464 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12465 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12466
12467 #endif
12468 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12469 index 2e0a6b1..a64d0f5 100644
12470 --- a/arch/um/include/asm/kmap_types.h
12471 +++ b/arch/um/include/asm/kmap_types.h
12472 @@ -8,6 +8,6 @@
12473
12474 /* No more #include "asm/arch/kmap_types.h" ! */
12475
12476 -#define KM_TYPE_NR 14
12477 +#define KM_TYPE_NR 15
12478
12479 #endif
12480 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12481 index 71c5d13..4c7b9f1 100644
12482 --- a/arch/um/include/asm/page.h
12483 +++ b/arch/um/include/asm/page.h
12484 @@ -14,6 +14,9 @@
12485 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12486 #define PAGE_MASK (~(PAGE_SIZE-1))
12487
12488 +#define ktla_ktva(addr) (addr)
12489 +#define ktva_ktla(addr) (addr)
12490 +
12491 #ifndef __ASSEMBLY__
12492
12493 struct page;
12494 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12495 index 0032f92..cd151e0 100644
12496 --- a/arch/um/include/asm/pgtable-3level.h
12497 +++ b/arch/um/include/asm/pgtable-3level.h
12498 @@ -58,6 +58,7 @@
12499 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12500 #define pud_populate(mm, pud, pmd) \
12501 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12502 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12503
12504 #ifdef CONFIG_64BIT
12505 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12506 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12507 index f17bca8..48adb87 100644
12508 --- a/arch/um/kernel/process.c
12509 +++ b/arch/um/kernel/process.c
12510 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12511 return 2;
12512 }
12513
12514 -/*
12515 - * Only x86 and x86_64 have an arch_align_stack().
12516 - * All other arches have "#define arch_align_stack(x) (x)"
12517 - * in their asm/exec.h
12518 - * As this is included in UML from asm-um/system-generic.h,
12519 - * we can use it to behave as the subarch does.
12520 - */
12521 -#ifndef arch_align_stack
12522 -unsigned long arch_align_stack(unsigned long sp)
12523 -{
12524 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12525 - sp -= get_random_int() % 8192;
12526 - return sp & ~0xf;
12527 -}
12528 -#endif
12529 -
12530 unsigned long get_wchan(struct task_struct *p)
12531 {
12532 unsigned long stack_page, sp, ip;
12533 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12534 index ad8f795..2c7eec6 100644
12535 --- a/arch/unicore32/include/asm/cache.h
12536 +++ b/arch/unicore32/include/asm/cache.h
12537 @@ -12,8 +12,10 @@
12538 #ifndef __UNICORE_CACHE_H__
12539 #define __UNICORE_CACHE_H__
12540
12541 -#define L1_CACHE_SHIFT (5)
12542 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12543 +#include <linux/const.h>
12544 +
12545 +#define L1_CACHE_SHIFT 5
12546 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12547
12548 /*
12549 * Memory returned by kmalloc() may be used for DMA, so we must make
12550 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12551 index 3635fff..c1f9fab 100644
12552 --- a/arch/x86/Kconfig
12553 +++ b/arch/x86/Kconfig
12554 @@ -129,7 +129,7 @@ config X86
12555 select RTC_LIB
12556 select HAVE_DEBUG_STACKOVERFLOW
12557 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12558 - select HAVE_CC_STACKPROTECTOR
12559 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12560 select GENERIC_CPU_AUTOPROBE
12561 select HAVE_ARCH_AUDITSYSCALL
12562 select ARCH_SUPPORTS_ATOMIC_RMW
12563 @@ -262,7 +262,7 @@ config X86_HT
12564
12565 config X86_32_LAZY_GS
12566 def_bool y
12567 - depends on X86_32 && !CC_STACKPROTECTOR
12568 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12569
12570 config ARCH_HWEIGHT_CFLAGS
12571 string
12572 @@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12573
12574 menuconfig HYPERVISOR_GUEST
12575 bool "Linux guest support"
12576 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12577 ---help---
12578 Say Y here to enable options for running Linux under various hyper-
12579 visors. This option enables basic hypervisor detection and platform
12580 @@ -977,6 +978,7 @@ config VM86
12581
12582 config X86_16BIT
12583 bool "Enable support for 16-bit segments" if EXPERT
12584 + depends on !GRKERNSEC
12585 default y
12586 ---help---
12587 This option is required by programs like Wine to run 16-bit
12588 @@ -1132,6 +1134,7 @@ choice
12589
12590 config NOHIGHMEM
12591 bool "off"
12592 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12593 ---help---
12594 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12595 However, the address space of 32-bit x86 processors is only 4
12596 @@ -1168,6 +1171,7 @@ config NOHIGHMEM
12597
12598 config HIGHMEM4G
12599 bool "4GB"
12600 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12601 ---help---
12602 Select this if you have a 32-bit processor and between 1 and 4
12603 gigabytes of physical RAM.
12604 @@ -1220,7 +1224,7 @@ config PAGE_OFFSET
12605 hex
12606 default 0xB0000000 if VMSPLIT_3G_OPT
12607 default 0x80000000 if VMSPLIT_2G
12608 - default 0x78000000 if VMSPLIT_2G_OPT
12609 + default 0x70000000 if VMSPLIT_2G_OPT
12610 default 0x40000000 if VMSPLIT_1G
12611 default 0xC0000000
12612 depends on X86_32
12613 @@ -1635,6 +1639,7 @@ source kernel/Kconfig.hz
12614
12615 config KEXEC
12616 bool "kexec system call"
12617 + depends on !GRKERNSEC_KMEM
12618 ---help---
12619 kexec is a system call that implements the ability to shutdown your
12620 current kernel, and to start another kernel. It is like a reboot
12621 @@ -1820,7 +1825,9 @@ config X86_NEED_RELOCS
12622
12623 config PHYSICAL_ALIGN
12624 hex "Alignment value to which kernel should be aligned"
12625 - default "0x200000"
12626 + default "0x1000000"
12627 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12628 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12629 range 0x2000 0x1000000 if X86_32
12630 range 0x200000 0x1000000 if X86_64
12631 ---help---
12632 @@ -1903,6 +1910,7 @@ config COMPAT_VDSO
12633 def_bool n
12634 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12635 depends on X86_32 || IA32_EMULATION
12636 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12637 ---help---
12638 Certain buggy versions of glibc will crash if they are
12639 presented with a 32-bit vDSO that is not mapped at the address
12640 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12641 index 6983314..54ad7e8 100644
12642 --- a/arch/x86/Kconfig.cpu
12643 +++ b/arch/x86/Kconfig.cpu
12644 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12645
12646 config X86_F00F_BUG
12647 def_bool y
12648 - depends on M586MMX || M586TSC || M586 || M486
12649 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12650
12651 config X86_INVD_BUG
12652 def_bool y
12653 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12654
12655 config X86_ALIGNMENT_16
12656 def_bool y
12657 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12658 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12659
12660 config X86_INTEL_USERCOPY
12661 def_bool y
12662 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12663 # generates cmov.
12664 config X86_CMOV
12665 def_bool y
12666 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12667 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12668
12669 config X86_MINIMUM_CPU_FAMILY
12670 int
12671 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12672 index 61bd2ad..50b625d 100644
12673 --- a/arch/x86/Kconfig.debug
12674 +++ b/arch/x86/Kconfig.debug
12675 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12676 config DEBUG_RODATA
12677 bool "Write protect kernel read-only data structures"
12678 default y
12679 - depends on DEBUG_KERNEL
12680 + depends on DEBUG_KERNEL && BROKEN
12681 ---help---
12682 Mark the kernel read-only data as write-protected in the pagetables,
12683 in order to catch accidental (and incorrect) writes to such const
12684 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12685
12686 config DEBUG_SET_MODULE_RONX
12687 bool "Set loadable kernel module data as NX and text as RO"
12688 - depends on MODULES
12689 + depends on MODULES && BROKEN
12690 ---help---
12691 This option helps catch unintended modifications to loadable
12692 kernel module's text and read-only data. It also prevents execution
12693 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12694 index 920e616..ac3d4df 100644
12695 --- a/arch/x86/Makefile
12696 +++ b/arch/x86/Makefile
12697 @@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12698 # CPU-specific tuning. Anything which can be shared with UML should go here.
12699 include $(srctree)/arch/x86/Makefile_32.cpu
12700 KBUILD_CFLAGS += $(cflags-y)
12701 -
12702 - # temporary until string.h is fixed
12703 - KBUILD_CFLAGS += -ffreestanding
12704 else
12705 BITS := 64
12706 UTS_MACHINE := x86_64
12707 @@ -107,6 +104,9 @@ else
12708 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12709 endif
12710
12711 +# temporary until string.h is fixed
12712 +KBUILD_CFLAGS += -ffreestanding
12713 +
12714 # Make sure compiler does not have buggy stack-protector support.
12715 ifdef CONFIG_CC_STACKPROTECTOR
12716 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12717 @@ -180,6 +180,7 @@ archheaders:
12718 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12719
12720 archprepare:
12721 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12722 ifeq ($(CONFIG_KEXEC_FILE),y)
12723 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12724 endif
12725 @@ -263,3 +264,9 @@ define archhelp
12726 echo ' FDARGS="..." arguments for the booted kernel'
12727 echo ' FDINITRD=file initrd for the booted kernel'
12728 endef
12729 +
12730 +define OLD_LD
12731 +
12732 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12733 +*** Please upgrade your binutils to 2.18 or newer
12734 +endef
12735 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12736 index 3db07f3..9d81d0f 100644
12737 --- a/arch/x86/boot/Makefile
12738 +++ b/arch/x86/boot/Makefile
12739 @@ -56,6 +56,9 @@ clean-files += cpustr.h
12740 # ---------------------------------------------------------------------------
12741
12742 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12743 +ifdef CONSTIFY_PLUGIN
12744 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12745 +endif
12746 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12747 GCOV_PROFILE := n
12748
12749 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12750 index 878e4b9..20537ab 100644
12751 --- a/arch/x86/boot/bitops.h
12752 +++ b/arch/x86/boot/bitops.h
12753 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12754 u8 v;
12755 const u32 *p = (const u32 *)addr;
12756
12757 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12758 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12759 return v;
12760 }
12761
12762 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12763
12764 static inline void set_bit(int nr, void *addr)
12765 {
12766 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12767 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12768 }
12769
12770 #endif /* BOOT_BITOPS_H */
12771 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12772 index bd49ec6..94c7f58 100644
12773 --- a/arch/x86/boot/boot.h
12774 +++ b/arch/x86/boot/boot.h
12775 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12776 static inline u16 ds(void)
12777 {
12778 u16 seg;
12779 - asm("movw %%ds,%0" : "=rm" (seg));
12780 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12781 return seg;
12782 }
12783
12784 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12785 index 30c0acf..48c3a77 100644
12786 --- a/arch/x86/boot/compressed/Makefile
12787 +++ b/arch/x86/boot/compressed/Makefile
12788 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12789 KBUILD_CFLAGS += -mno-mmx -mno-sse
12790 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12791 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12792 +ifdef CONSTIFY_PLUGIN
12793 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12794 +endif
12795
12796 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12797 GCOV_PROFILE := n
12798 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12799 index a53440e..c3dbf1e 100644
12800 --- a/arch/x86/boot/compressed/efi_stub_32.S
12801 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12802 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12803 * parameter 2, ..., param n. To make things easy, we save the return
12804 * address of efi_call_phys in a global variable.
12805 */
12806 - popl %ecx
12807 - movl %ecx, saved_return_addr(%edx)
12808 - /* get the function pointer into ECX*/
12809 - popl %ecx
12810 - movl %ecx, efi_rt_function_ptr(%edx)
12811 + popl saved_return_addr(%edx)
12812 + popl efi_rt_function_ptr(%edx)
12813
12814 /*
12815 * 3. Call the physical function.
12816 */
12817 - call *%ecx
12818 + call *efi_rt_function_ptr(%edx)
12819
12820 /*
12821 * 4. Balance the stack. And because EAX contain the return value,
12822 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12823 1: popl %edx
12824 subl $1b, %edx
12825
12826 - movl efi_rt_function_ptr(%edx), %ecx
12827 - pushl %ecx
12828 + pushl efi_rt_function_ptr(%edx)
12829
12830 /*
12831 * 10. Push the saved return address onto the stack and return.
12832 */
12833 - movl saved_return_addr(%edx), %ecx
12834 - pushl %ecx
12835 - ret
12836 + jmpl *saved_return_addr(%edx)
12837 ENDPROC(efi_call_phys)
12838 .previous
12839
12840 diff --git a/arch/x86/boot/compressed/efi_thunk_64.S b/arch/x86/boot/compressed/efi_thunk_64.S
12841 index 630384a..278e788 100644
12842 --- a/arch/x86/boot/compressed/efi_thunk_64.S
12843 +++ b/arch/x86/boot/compressed/efi_thunk_64.S
12844 @@ -189,8 +189,8 @@ efi_gdt64:
12845 .long 0 /* Filled out by user */
12846 .word 0
12847 .quad 0x0000000000000000 /* NULL descriptor */
12848 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12849 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12850 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12851 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12852 .quad 0x0080890000000000 /* TS descriptor */
12853 .quad 0x0000000000000000 /* TS continued */
12854 efi_gdt64_end:
12855 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12856 index 1d7fbbc..36ecd58 100644
12857 --- a/arch/x86/boot/compressed/head_32.S
12858 +++ b/arch/x86/boot/compressed/head_32.S
12859 @@ -140,10 +140,10 @@ preferred_addr:
12860 addl %eax, %ebx
12861 notl %eax
12862 andl %eax, %ebx
12863 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12864 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12865 jge 1f
12866 #endif
12867 - movl $LOAD_PHYSICAL_ADDR, %ebx
12868 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12869 1:
12870
12871 /* Target address to relocate to for decompression */
12872 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12873 index 6b1766c..ad465c9 100644
12874 --- a/arch/x86/boot/compressed/head_64.S
12875 +++ b/arch/x86/boot/compressed/head_64.S
12876 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12877 addl %eax, %ebx
12878 notl %eax
12879 andl %eax, %ebx
12880 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12881 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12882 jge 1f
12883 #endif
12884 - movl $LOAD_PHYSICAL_ADDR, %ebx
12885 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12886 1:
12887
12888 /* Target address to relocate to for decompression */
12889 @@ -322,10 +322,10 @@ preferred_addr:
12890 addq %rax, %rbp
12891 notq %rax
12892 andq %rax, %rbp
12893 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12894 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12895 jge 1f
12896 #endif
12897 - movq $LOAD_PHYSICAL_ADDR, %rbp
12898 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12899 1:
12900
12901 /* Target address to relocate to for decompression */
12902 @@ -434,8 +434,8 @@ gdt:
12903 .long gdt
12904 .word 0
12905 .quad 0x0000000000000000 /* NULL descriptor */
12906 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12907 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12908 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12909 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12910 .quad 0x0080890000000000 /* TS descriptor */
12911 .quad 0x0000000000000000 /* TS continued */
12912 gdt_end:
12913 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12914 index 0c33a7c..be226ed 100644
12915 --- a/arch/x86/boot/compressed/misc.c
12916 +++ b/arch/x86/boot/compressed/misc.c
12917 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12918 * Calculate the delta between where vmlinux was linked to load
12919 * and where it was actually loaded.
12920 */
12921 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12922 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12923 if (!delta) {
12924 debug_putstr("No relocation needed... ");
12925 return;
12926 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12927 Elf32_Ehdr ehdr;
12928 Elf32_Phdr *phdrs, *phdr;
12929 #endif
12930 - void *dest;
12931 + void *dest, *prev;
12932 int i;
12933
12934 memcpy(&ehdr, output, sizeof(ehdr));
12935 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12936 case PT_LOAD:
12937 #ifdef CONFIG_RELOCATABLE
12938 dest = output;
12939 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12940 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12941 #else
12942 dest = (void *)(phdr->p_paddr);
12943 #endif
12944 memcpy(dest,
12945 output + phdr->p_offset,
12946 phdr->p_filesz);
12947 + if (i)
12948 + memset(prev, 0xff, dest - prev);
12949 + prev = dest + phdr->p_filesz;
12950 break;
12951 default: /* Ignore other PT_* */ break;
12952 }
12953 @@ -404,7 +407,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12954 error("Destination address too large");
12955 #endif
12956 #ifndef CONFIG_RELOCATABLE
12957 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12958 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12959 error("Wrong destination address");
12960 #endif
12961
12962 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12963 index 1fd7d57..0f7d096 100644
12964 --- a/arch/x86/boot/cpucheck.c
12965 +++ b/arch/x86/boot/cpucheck.c
12966 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12967 u32 ecx = MSR_K7_HWCR;
12968 u32 eax, edx;
12969
12970 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12972 eax &= ~(1 << 15);
12973 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12974 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12975
12976 get_cpuflags(); /* Make sure it really did something */
12977 err = check_cpuflags();
12978 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12979 u32 ecx = MSR_VIA_FCR;
12980 u32 eax, edx;
12981
12982 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12983 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12984 eax |= (1<<1)|(1<<7);
12985 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12986 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12987
12988 set_bit(X86_FEATURE_CX8, cpu.flags);
12989 err = check_cpuflags();
12990 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12991 u32 eax, edx;
12992 u32 level = 1;
12993
12994 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12995 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12996 - asm("cpuid"
12997 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12998 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12999 + asm volatile("cpuid"
13000 : "+a" (level), "=d" (cpu.flags[0])
13001 : : "ecx", "ebx");
13002 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13003 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13004
13005 err = check_cpuflags();
13006 } else if (err == 0x01 &&
13007 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13008 index 16ef025..91e033b 100644
13009 --- a/arch/x86/boot/header.S
13010 +++ b/arch/x86/boot/header.S
13011 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13012 # single linked list of
13013 # struct setup_data
13014
13015 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13016 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13017
13018 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13019 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13020 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13021 +#else
13022 #define VO_INIT_SIZE (VO__end - VO__text)
13023 +#endif
13024 #if ZO_INIT_SIZE > VO_INIT_SIZE
13025 #define INIT_SIZE ZO_INIT_SIZE
13026 #else
13027 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13028 index db75d07..8e6d0af 100644
13029 --- a/arch/x86/boot/memory.c
13030 +++ b/arch/x86/boot/memory.c
13031 @@ -19,7 +19,7 @@
13032
13033 static int detect_memory_e820(void)
13034 {
13035 - int count = 0;
13036 + unsigned int count = 0;
13037 struct biosregs ireg, oreg;
13038 struct e820entry *desc = boot_params.e820_map;
13039 static struct e820entry buf; /* static so it is zeroed */
13040 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13041 index ba3e100..6501b8f 100644
13042 --- a/arch/x86/boot/video-vesa.c
13043 +++ b/arch/x86/boot/video-vesa.c
13044 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13045
13046 boot_params.screen_info.vesapm_seg = oreg.es;
13047 boot_params.screen_info.vesapm_off = oreg.di;
13048 + boot_params.screen_info.vesapm_size = oreg.cx;
13049 }
13050
13051 /*
13052 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13053 index 43eda28..5ab5fdb 100644
13054 --- a/arch/x86/boot/video.c
13055 +++ b/arch/x86/boot/video.c
13056 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13057 static unsigned int get_entry(void)
13058 {
13059 char entry_buf[4];
13060 - int i, len = 0;
13061 + unsigned int i, len = 0;
13062 int key;
13063 unsigned int v;
13064
13065 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13066 index 9105655..41779c1 100644
13067 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13068 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13069 @@ -8,6 +8,8 @@
13070 * including this sentence is retained in full.
13071 */
13072
13073 +#include <asm/alternative-asm.h>
13074 +
13075 .extern crypto_ft_tab
13076 .extern crypto_it_tab
13077 .extern crypto_fl_tab
13078 @@ -70,6 +72,8 @@
13079 je B192; \
13080 leaq 32(r9),r9;
13081
13082 +#define ret pax_force_retaddr; ret
13083 +
13084 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13085 movq r1,r2; \
13086 movq r3,r4; \
13087 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13088 index 477e9d7..c92c7d8 100644
13089 --- a/arch/x86/crypto/aesni-intel_asm.S
13090 +++ b/arch/x86/crypto/aesni-intel_asm.S
13091 @@ -31,6 +31,7 @@
13092
13093 #include <linux/linkage.h>
13094 #include <asm/inst.h>
13095 +#include <asm/alternative-asm.h>
13096
13097 #ifdef __x86_64__
13098 .data
13099 @@ -205,7 +206,7 @@ enc: .octa 0x2
13100 * num_initial_blocks = b mod 4
13101 * encrypt the initial num_initial_blocks blocks and apply ghash on
13102 * the ciphertext
13103 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13104 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13105 * are clobbered
13106 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13107 */
13108 @@ -214,8 +215,8 @@ enc: .octa 0x2
13109 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13110 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13111 mov arg7, %r10 # %r10 = AAD
13112 - mov arg8, %r12 # %r12 = aadLen
13113 - mov %r12, %r11
13114 + mov arg8, %r15 # %r15 = aadLen
13115 + mov %r15, %r11
13116 pxor %xmm\i, %xmm\i
13117 _get_AAD_loop\num_initial_blocks\operation:
13118 movd (%r10), \TMP1
13119 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13120 psrldq $4, %xmm\i
13121 pxor \TMP1, %xmm\i
13122 add $4, %r10
13123 - sub $4, %r12
13124 + sub $4, %r15
13125 jne _get_AAD_loop\num_initial_blocks\operation
13126 cmp $16, %r11
13127 je _get_AAD_loop2_done\num_initial_blocks\operation
13128 - mov $16, %r12
13129 + mov $16, %r15
13130 _get_AAD_loop2\num_initial_blocks\operation:
13131 psrldq $4, %xmm\i
13132 - sub $4, %r12
13133 - cmp %r11, %r12
13134 + sub $4, %r15
13135 + cmp %r11, %r15
13136 jne _get_AAD_loop2\num_initial_blocks\operation
13137 _get_AAD_loop2_done\num_initial_blocks\operation:
13138 movdqa SHUF_MASK(%rip), %xmm14
13139 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13140 * num_initial_blocks = b mod 4
13141 * encrypt the initial num_initial_blocks blocks and apply ghash on
13142 * the ciphertext
13143 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13144 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13145 * are clobbered
13146 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13147 */
13148 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13149 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13150 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13151 mov arg7, %r10 # %r10 = AAD
13152 - mov arg8, %r12 # %r12 = aadLen
13153 - mov %r12, %r11
13154 + mov arg8, %r15 # %r15 = aadLen
13155 + mov %r15, %r11
13156 pxor %xmm\i, %xmm\i
13157 _get_AAD_loop\num_initial_blocks\operation:
13158 movd (%r10), \TMP1
13159 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13160 psrldq $4, %xmm\i
13161 pxor \TMP1, %xmm\i
13162 add $4, %r10
13163 - sub $4, %r12
13164 + sub $4, %r15
13165 jne _get_AAD_loop\num_initial_blocks\operation
13166 cmp $16, %r11
13167 je _get_AAD_loop2_done\num_initial_blocks\operation
13168 - mov $16, %r12
13169 + mov $16, %r15
13170 _get_AAD_loop2\num_initial_blocks\operation:
13171 psrldq $4, %xmm\i
13172 - sub $4, %r12
13173 - cmp %r11, %r12
13174 + sub $4, %r15
13175 + cmp %r11, %r15
13176 jne _get_AAD_loop2\num_initial_blocks\operation
13177 _get_AAD_loop2_done\num_initial_blocks\operation:
13178 movdqa SHUF_MASK(%rip), %xmm14
13179 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13180 *
13181 *****************************************************************************/
13182 ENTRY(aesni_gcm_dec)
13183 - push %r12
13184 + push %r15
13185 push %r13
13186 push %r14
13187 mov %rsp, %r14
13188 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13189 */
13190 sub $VARIABLE_OFFSET, %rsp
13191 and $~63, %rsp # align rsp to 64 bytes
13192 - mov %arg6, %r12
13193 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13194 + mov %arg6, %r15
13195 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13196 movdqa SHUF_MASK(%rip), %xmm2
13197 PSHUFB_XMM %xmm2, %xmm13
13198
13199 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13200 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13201 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13202 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13203 - mov %r13, %r12
13204 - and $(3<<4), %r12
13205 + mov %r13, %r15
13206 + and $(3<<4), %r15
13207 jz _initial_num_blocks_is_0_decrypt
13208 - cmp $(2<<4), %r12
13209 + cmp $(2<<4), %r15
13210 jb _initial_num_blocks_is_1_decrypt
13211 je _initial_num_blocks_is_2_decrypt
13212 _initial_num_blocks_is_3_decrypt:
13213 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13214 sub $16, %r11
13215 add %r13, %r11
13216 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13217 - lea SHIFT_MASK+16(%rip), %r12
13218 - sub %r13, %r12
13219 + lea SHIFT_MASK+16(%rip), %r15
13220 + sub %r13, %r15
13221 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13222 # (%r13 is the number of bytes in plaintext mod 16)
13223 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13224 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13225 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13226
13227 movdqa %xmm1, %xmm2
13228 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13229 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13230 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13231 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13232 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13233 pand %xmm1, %xmm2
13234 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13235 sub $1, %r13
13236 jne _less_than_8_bytes_left_decrypt
13237 _multiple_of_16_bytes_decrypt:
13238 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13239 - shl $3, %r12 # convert into number of bits
13240 - movd %r12d, %xmm15 # len(A) in %xmm15
13241 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13242 + shl $3, %r15 # convert into number of bits
13243 + movd %r15d, %xmm15 # len(A) in %xmm15
13244 shl $3, %arg4 # len(C) in bits (*128)
13245 MOVQ_R64_XMM %arg4, %xmm1
13246 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13247 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13248 mov %r14, %rsp
13249 pop %r14
13250 pop %r13
13251 - pop %r12
13252 + pop %r15
13253 + pax_force_retaddr
13254 ret
13255 ENDPROC(aesni_gcm_dec)
13256
13257 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13258 * poly = x^128 + x^127 + x^126 + x^121 + 1
13259 ***************************************************************************/
13260 ENTRY(aesni_gcm_enc)
13261 - push %r12
13262 + push %r15
13263 push %r13
13264 push %r14
13265 mov %rsp, %r14
13266 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13267 #
13268 sub $VARIABLE_OFFSET, %rsp
13269 and $~63, %rsp
13270 - mov %arg6, %r12
13271 - movdqu (%r12), %xmm13
13272 + mov %arg6, %r15
13273 + movdqu (%r15), %xmm13
13274 movdqa SHUF_MASK(%rip), %xmm2
13275 PSHUFB_XMM %xmm2, %xmm13
13276
13277 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13278 movdqa %xmm13, HashKey(%rsp)
13279 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13280 and $-16, %r13
13281 - mov %r13, %r12
13282 + mov %r13, %r15
13283
13284 # Encrypt first few blocks
13285
13286 - and $(3<<4), %r12
13287 + and $(3<<4), %r15
13288 jz _initial_num_blocks_is_0_encrypt
13289 - cmp $(2<<4), %r12
13290 + cmp $(2<<4), %r15
13291 jb _initial_num_blocks_is_1_encrypt
13292 je _initial_num_blocks_is_2_encrypt
13293 _initial_num_blocks_is_3_encrypt:
13294 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13295 sub $16, %r11
13296 add %r13, %r11
13297 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13298 - lea SHIFT_MASK+16(%rip), %r12
13299 - sub %r13, %r12
13300 + lea SHIFT_MASK+16(%rip), %r15
13301 + sub %r13, %r15
13302 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13303 # (%r13 is the number of bytes in plaintext mod 16)
13304 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13305 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13306 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13307 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13308 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13309 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13310 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13311 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13312 movdqa SHUF_MASK(%rip), %xmm10
13313 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13314 sub $1, %r13
13315 jne _less_than_8_bytes_left_encrypt
13316 _multiple_of_16_bytes_encrypt:
13317 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13318 - shl $3, %r12
13319 - movd %r12d, %xmm15 # len(A) in %xmm15
13320 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13321 + shl $3, %r15
13322 + movd %r15d, %xmm15 # len(A) in %xmm15
13323 shl $3, %arg4 # len(C) in bits (*128)
13324 MOVQ_R64_XMM %arg4, %xmm1
13325 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13326 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13327 mov %r14, %rsp
13328 pop %r14
13329 pop %r13
13330 - pop %r12
13331 + pop %r15
13332 + pax_force_retaddr
13333 ret
13334 ENDPROC(aesni_gcm_enc)
13335
13336 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13337 pxor %xmm1, %xmm0
13338 movaps %xmm0, (TKEYP)
13339 add $0x10, TKEYP
13340 + pax_force_retaddr
13341 ret
13342 ENDPROC(_key_expansion_128)
13343 ENDPROC(_key_expansion_256a)
13344 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13345 shufps $0b01001110, %xmm2, %xmm1
13346 movaps %xmm1, 0x10(TKEYP)
13347 add $0x20, TKEYP
13348 + pax_force_retaddr
13349 ret
13350 ENDPROC(_key_expansion_192a)
13351
13352 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13353
13354 movaps %xmm0, (TKEYP)
13355 add $0x10, TKEYP
13356 + pax_force_retaddr
13357 ret
13358 ENDPROC(_key_expansion_192b)
13359
13360 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13361 pxor %xmm1, %xmm2
13362 movaps %xmm2, (TKEYP)
13363 add $0x10, TKEYP
13364 + pax_force_retaddr
13365 ret
13366 ENDPROC(_key_expansion_256b)
13367
13368 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13369 #ifndef __x86_64__
13370 popl KEYP
13371 #endif
13372 + pax_force_retaddr
13373 ret
13374 ENDPROC(aesni_set_key)
13375
13376 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13377 popl KLEN
13378 popl KEYP
13379 #endif
13380 + pax_force_retaddr
13381 ret
13382 ENDPROC(aesni_enc)
13383
13384 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13385 AESENC KEY STATE
13386 movaps 0x70(TKEYP), KEY
13387 AESENCLAST KEY STATE
13388 + pax_force_retaddr
13389 ret
13390 ENDPROC(_aesni_enc1)
13391
13392 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13393 AESENCLAST KEY STATE2
13394 AESENCLAST KEY STATE3
13395 AESENCLAST KEY STATE4
13396 + pax_force_retaddr
13397 ret
13398 ENDPROC(_aesni_enc4)
13399
13400 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13401 popl KLEN
13402 popl KEYP
13403 #endif
13404 + pax_force_retaddr
13405 ret
13406 ENDPROC(aesni_dec)
13407
13408 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13409 AESDEC KEY STATE
13410 movaps 0x70(TKEYP), KEY
13411 AESDECLAST KEY STATE
13412 + pax_force_retaddr
13413 ret
13414 ENDPROC(_aesni_dec1)
13415
13416 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13417 AESDECLAST KEY STATE2
13418 AESDECLAST KEY STATE3
13419 AESDECLAST KEY STATE4
13420 + pax_force_retaddr
13421 ret
13422 ENDPROC(_aesni_dec4)
13423
13424 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13425 popl KEYP
13426 popl LEN
13427 #endif
13428 + pax_force_retaddr
13429 ret
13430 ENDPROC(aesni_ecb_enc)
13431
13432 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13433 popl KEYP
13434 popl LEN
13435 #endif
13436 + pax_force_retaddr
13437 ret
13438 ENDPROC(aesni_ecb_dec)
13439
13440 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13441 popl LEN
13442 popl IVP
13443 #endif
13444 + pax_force_retaddr
13445 ret
13446 ENDPROC(aesni_cbc_enc)
13447
13448 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13449 popl LEN
13450 popl IVP
13451 #endif
13452 + pax_force_retaddr
13453 ret
13454 ENDPROC(aesni_cbc_dec)
13455
13456 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13457 mov $1, TCTR_LOW
13458 MOVQ_R64_XMM TCTR_LOW INC
13459 MOVQ_R64_XMM CTR TCTR_LOW
13460 + pax_force_retaddr
13461 ret
13462 ENDPROC(_aesni_inc_init)
13463
13464 @@ -2579,6 +2598,7 @@ _aesni_inc:
13465 .Linc_low:
13466 movaps CTR, IV
13467 PSHUFB_XMM BSWAP_MASK IV
13468 + pax_force_retaddr
13469 ret
13470 ENDPROC(_aesni_inc)
13471
13472 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13473 .Lctr_enc_ret:
13474 movups IV, (IVP)
13475 .Lctr_enc_just_ret:
13476 + pax_force_retaddr
13477 ret
13478 ENDPROC(aesni_ctr_enc)
13479
13480 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13481 pxor INC, STATE4
13482 movdqu STATE4, 0x70(OUTP)
13483
13484 + pax_force_retaddr
13485 ret
13486 ENDPROC(aesni_xts_crypt8)
13487
13488 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13489 index 246c670..466e2d6 100644
13490 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13491 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13492 @@ -21,6 +21,7 @@
13493 */
13494
13495 #include <linux/linkage.h>
13496 +#include <asm/alternative-asm.h>
13497
13498 .file "blowfish-x86_64-asm.S"
13499 .text
13500 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13501 jnz .L__enc_xor;
13502
13503 write_block();
13504 + pax_force_retaddr
13505 ret;
13506 .L__enc_xor:
13507 xor_block();
13508 + pax_force_retaddr
13509 ret;
13510 ENDPROC(__blowfish_enc_blk)
13511
13512 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13513
13514 movq %r11, %rbp;
13515
13516 + pax_force_retaddr
13517 ret;
13518 ENDPROC(blowfish_dec_blk)
13519
13520 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13521
13522 popq %rbx;
13523 popq %rbp;
13524 + pax_force_retaddr
13525 ret;
13526
13527 .L__enc_xor4:
13528 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13529
13530 popq %rbx;
13531 popq %rbp;
13532 + pax_force_retaddr
13533 ret;
13534 ENDPROC(__blowfish_enc_blk_4way)
13535
13536 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13537 popq %rbx;
13538 popq %rbp;
13539
13540 + pax_force_retaddr
13541 ret;
13542 ENDPROC(blowfish_dec_blk_4way)
13543 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13544 index ce71f92..1dce7ec 100644
13545 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13546 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13547 @@ -16,6 +16,7 @@
13548 */
13549
13550 #include <linux/linkage.h>
13551 +#include <asm/alternative-asm.h>
13552
13553 #define CAMELLIA_TABLE_BYTE_LEN 272
13554
13555 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13556 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13557 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13558 %rcx, (%r9));
13559 + pax_force_retaddr
13560 ret;
13561 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13562
13563 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13564 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13565 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13566 %rax, (%r9));
13567 + pax_force_retaddr
13568 ret;
13569 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13570
13571 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13572 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13573 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13574
13575 + pax_force_retaddr
13576 ret;
13577
13578 .align 8
13579 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13580 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13581 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13582
13583 + pax_force_retaddr
13584 ret;
13585
13586 .align 8
13587 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13588 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13589 %xmm8, %rsi);
13590
13591 + pax_force_retaddr
13592 ret;
13593 ENDPROC(camellia_ecb_enc_16way)
13594
13595 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13596 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13597 %xmm8, %rsi);
13598
13599 + pax_force_retaddr
13600 ret;
13601 ENDPROC(camellia_ecb_dec_16way)
13602
13603 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13604 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13605 %xmm8, %rsi);
13606
13607 + pax_force_retaddr
13608 ret;
13609 ENDPROC(camellia_cbc_dec_16way)
13610
13611 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13612 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13613 %xmm8, %rsi);
13614
13615 + pax_force_retaddr
13616 ret;
13617 ENDPROC(camellia_ctr_16way)
13618
13619 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13620 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13621 %xmm8, %rsi);
13622
13623 + pax_force_retaddr
13624 ret;
13625 ENDPROC(camellia_xts_crypt_16way)
13626
13627 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13628 index 0e0b886..5a3123c 100644
13629 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13630 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13631 @@ -11,6 +11,7 @@
13632 */
13633
13634 #include <linux/linkage.h>
13635 +#include <asm/alternative-asm.h>
13636
13637 #define CAMELLIA_TABLE_BYTE_LEN 272
13638
13639 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13640 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13641 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13642 %rcx, (%r9));
13643 + pax_force_retaddr
13644 ret;
13645 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13646
13647 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13648 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13649 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13650 %rax, (%r9));
13651 + pax_force_retaddr
13652 ret;
13653 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13654
13655 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13656 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13657 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13658
13659 + pax_force_retaddr
13660 ret;
13661
13662 .align 8
13663 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13664 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13665 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13666
13667 + pax_force_retaddr
13668 ret;
13669
13670 .align 8
13671 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13672
13673 vzeroupper;
13674
13675 + pax_force_retaddr
13676 ret;
13677 ENDPROC(camellia_ecb_enc_32way)
13678
13679 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13680
13681 vzeroupper;
13682
13683 + pax_force_retaddr
13684 ret;
13685 ENDPROC(camellia_ecb_dec_32way)
13686
13687 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13688
13689 vzeroupper;
13690
13691 + pax_force_retaddr
13692 ret;
13693 ENDPROC(camellia_cbc_dec_32way)
13694
13695 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13696
13697 vzeroupper;
13698
13699 + pax_force_retaddr
13700 ret;
13701 ENDPROC(camellia_ctr_32way)
13702
13703 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13704
13705 vzeroupper;
13706
13707 + pax_force_retaddr
13708 ret;
13709 ENDPROC(camellia_xts_crypt_32way)
13710
13711 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13712 index 310319c..db3d7b5 100644
13713 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13714 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13715 @@ -21,6 +21,7 @@
13716 */
13717
13718 #include <linux/linkage.h>
13719 +#include <asm/alternative-asm.h>
13720
13721 .file "camellia-x86_64-asm_64.S"
13722 .text
13723 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13724 enc_outunpack(mov, RT1);
13725
13726 movq RRBP, %rbp;
13727 + pax_force_retaddr
13728 ret;
13729
13730 .L__enc_xor:
13731 enc_outunpack(xor, RT1);
13732
13733 movq RRBP, %rbp;
13734 + pax_force_retaddr
13735 ret;
13736 ENDPROC(__camellia_enc_blk)
13737
13738 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13739 dec_outunpack();
13740
13741 movq RRBP, %rbp;
13742 + pax_force_retaddr
13743 ret;
13744 ENDPROC(camellia_dec_blk)
13745
13746 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13747
13748 movq RRBP, %rbp;
13749 popq %rbx;
13750 + pax_force_retaddr
13751 ret;
13752
13753 .L__enc2_xor:
13754 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13755
13756 movq RRBP, %rbp;
13757 popq %rbx;
13758 + pax_force_retaddr
13759 ret;
13760 ENDPROC(__camellia_enc_blk_2way)
13761
13762 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13763
13764 movq RRBP, %rbp;
13765 movq RXOR, %rbx;
13766 + pax_force_retaddr
13767 ret;
13768 ENDPROC(camellia_dec_blk_2way)
13769 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13770 index c35fd5d..2d8c7db 100644
13771 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13772 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13773 @@ -24,6 +24,7 @@
13774 */
13775
13776 #include <linux/linkage.h>
13777 +#include <asm/alternative-asm.h>
13778
13779 .file "cast5-avx-x86_64-asm_64.S"
13780
13781 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13782 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13783 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13784
13785 + pax_force_retaddr
13786 ret;
13787 ENDPROC(__cast5_enc_blk16)
13788
13789 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13790 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13791 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13792
13793 + pax_force_retaddr
13794 ret;
13795
13796 .L__skip_dec:
13797 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13798 vmovdqu RR4, (6*4*4)(%r11);
13799 vmovdqu RL4, (7*4*4)(%r11);
13800
13801 + pax_force_retaddr
13802 ret;
13803 ENDPROC(cast5_ecb_enc_16way)
13804
13805 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13806 vmovdqu RR4, (6*4*4)(%r11);
13807 vmovdqu RL4, (7*4*4)(%r11);
13808
13809 + pax_force_retaddr
13810 ret;
13811 ENDPROC(cast5_ecb_dec_16way)
13812
13813 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13814 * %rdx: src
13815 */
13816
13817 - pushq %r12;
13818 + pushq %r14;
13819
13820 movq %rsi, %r11;
13821 - movq %rdx, %r12;
13822 + movq %rdx, %r14;
13823
13824 vmovdqu (0*16)(%rdx), RL1;
13825 vmovdqu (1*16)(%rdx), RR1;
13826 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13827 call __cast5_dec_blk16;
13828
13829 /* xor with src */
13830 - vmovq (%r12), RX;
13831 + vmovq (%r14), RX;
13832 vpshufd $0x4f, RX, RX;
13833 vpxor RX, RR1, RR1;
13834 - vpxor 0*16+8(%r12), RL1, RL1;
13835 - vpxor 1*16+8(%r12), RR2, RR2;
13836 - vpxor 2*16+8(%r12), RL2, RL2;
13837 - vpxor 3*16+8(%r12), RR3, RR3;
13838 - vpxor 4*16+8(%r12), RL3, RL3;
13839 - vpxor 5*16+8(%r12), RR4, RR4;
13840 - vpxor 6*16+8(%r12), RL4, RL4;
13841 + vpxor 0*16+8(%r14), RL1, RL1;
13842 + vpxor 1*16+8(%r14), RR2, RR2;
13843 + vpxor 2*16+8(%r14), RL2, RL2;
13844 + vpxor 3*16+8(%r14), RR3, RR3;
13845 + vpxor 4*16+8(%r14), RL3, RL3;
13846 + vpxor 5*16+8(%r14), RR4, RR4;
13847 + vpxor 6*16+8(%r14), RL4, RL4;
13848
13849 vmovdqu RR1, (0*16)(%r11);
13850 vmovdqu RL1, (1*16)(%r11);
13851 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13852 vmovdqu RR4, (6*16)(%r11);
13853 vmovdqu RL4, (7*16)(%r11);
13854
13855 - popq %r12;
13856 + popq %r14;
13857
13858 + pax_force_retaddr
13859 ret;
13860 ENDPROC(cast5_cbc_dec_16way)
13861
13862 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13863 * %rcx: iv (big endian, 64bit)
13864 */
13865
13866 - pushq %r12;
13867 + pushq %r14;
13868
13869 movq %rsi, %r11;
13870 - movq %rdx, %r12;
13871 + movq %rdx, %r14;
13872
13873 vpcmpeqd RTMP, RTMP, RTMP;
13874 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13875 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13876 call __cast5_enc_blk16;
13877
13878 /* dst = src ^ iv */
13879 - vpxor (0*16)(%r12), RR1, RR1;
13880 - vpxor (1*16)(%r12), RL1, RL1;
13881 - vpxor (2*16)(%r12), RR2, RR2;
13882 - vpxor (3*16)(%r12), RL2, RL2;
13883 - vpxor (4*16)(%r12), RR3, RR3;
13884 - vpxor (5*16)(%r12), RL3, RL3;
13885 - vpxor (6*16)(%r12), RR4, RR4;
13886 - vpxor (7*16)(%r12), RL4, RL4;
13887 + vpxor (0*16)(%r14), RR1, RR1;
13888 + vpxor (1*16)(%r14), RL1, RL1;
13889 + vpxor (2*16)(%r14), RR2, RR2;
13890 + vpxor (3*16)(%r14), RL2, RL2;
13891 + vpxor (4*16)(%r14), RR3, RR3;
13892 + vpxor (5*16)(%r14), RL3, RL3;
13893 + vpxor (6*16)(%r14), RR4, RR4;
13894 + vpxor (7*16)(%r14), RL4, RL4;
13895 vmovdqu RR1, (0*16)(%r11);
13896 vmovdqu RL1, (1*16)(%r11);
13897 vmovdqu RR2, (2*16)(%r11);
13898 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13899 vmovdqu RR4, (6*16)(%r11);
13900 vmovdqu RL4, (7*16)(%r11);
13901
13902 - popq %r12;
13903 + popq %r14;
13904
13905 + pax_force_retaddr
13906 ret;
13907 ENDPROC(cast5_ctr_16way)
13908 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13909 index e3531f8..e123f35 100644
13910 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13911 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13912 @@ -24,6 +24,7 @@
13913 */
13914
13915 #include <linux/linkage.h>
13916 +#include <asm/alternative-asm.h>
13917 #include "glue_helper-asm-avx.S"
13918
13919 .file "cast6-avx-x86_64-asm_64.S"
13920 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13921 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13922 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13923
13924 + pax_force_retaddr
13925 ret;
13926 ENDPROC(__cast6_enc_blk8)
13927
13928 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13929 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13930 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13931
13932 + pax_force_retaddr
13933 ret;
13934 ENDPROC(__cast6_dec_blk8)
13935
13936 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13937
13938 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13939
13940 + pax_force_retaddr
13941 ret;
13942 ENDPROC(cast6_ecb_enc_8way)
13943
13944 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13945
13946 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13947
13948 + pax_force_retaddr
13949 ret;
13950 ENDPROC(cast6_ecb_dec_8way)
13951
13952 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13953 * %rdx: src
13954 */
13955
13956 - pushq %r12;
13957 + pushq %r14;
13958
13959 movq %rsi, %r11;
13960 - movq %rdx, %r12;
13961 + movq %rdx, %r14;
13962
13963 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13964
13965 call __cast6_dec_blk8;
13966
13967 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13969
13970 - popq %r12;
13971 + popq %r14;
13972
13973 + pax_force_retaddr
13974 ret;
13975 ENDPROC(cast6_cbc_dec_8way)
13976
13977 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13978 * %rcx: iv (little endian, 128bit)
13979 */
13980
13981 - pushq %r12;
13982 + pushq %r14;
13983
13984 movq %rsi, %r11;
13985 - movq %rdx, %r12;
13986 + movq %rdx, %r14;
13987
13988 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13989 RD2, RX, RKR, RKM);
13990
13991 call __cast6_enc_blk8;
13992
13993 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13994 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13995
13996 - popq %r12;
13997 + popq %r14;
13998
13999 + pax_force_retaddr
14000 ret;
14001 ENDPROC(cast6_ctr_8way)
14002
14003 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14004 /* dst <= regs xor IVs(in dst) */
14005 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14006
14007 + pax_force_retaddr
14008 ret;
14009 ENDPROC(cast6_xts_enc_8way)
14010
14011 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14012 /* dst <= regs xor IVs(in dst) */
14013 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14014
14015 + pax_force_retaddr
14016 ret;
14017 ENDPROC(cast6_xts_dec_8way)
14018 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14019 index 26d49eb..c0a8c84 100644
14020 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14021 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14022 @@ -45,6 +45,7 @@
14023
14024 #include <asm/inst.h>
14025 #include <linux/linkage.h>
14026 +#include <asm/alternative-asm.h>
14027
14028 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14029
14030 @@ -309,6 +310,7 @@ do_return:
14031 popq %rsi
14032 popq %rdi
14033 popq %rbx
14034 + pax_force_retaddr
14035 ret
14036
14037 ################################################################
14038 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14039 index 5d1e007..098cb4f 100644
14040 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14041 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14042 @@ -18,6 +18,7 @@
14043
14044 #include <linux/linkage.h>
14045 #include <asm/inst.h>
14046 +#include <asm/alternative-asm.h>
14047
14048 .data
14049
14050 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14051 psrlq $1, T2
14052 pxor T2, T1
14053 pxor T1, DATA
14054 + pax_force_retaddr
14055 ret
14056 ENDPROC(__clmul_gf128mul_ble)
14057
14058 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14059 call __clmul_gf128mul_ble
14060 PSHUFB_XMM BSWAP DATA
14061 movups DATA, (%rdi)
14062 + pax_force_retaddr
14063 ret
14064 ENDPROC(clmul_ghash_mul)
14065
14066 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14067 PSHUFB_XMM BSWAP DATA
14068 movups DATA, (%rdi)
14069 .Lupdate_just_ret:
14070 + pax_force_retaddr
14071 ret
14072 ENDPROC(clmul_ghash_update)
14073 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14074 index 9279e0b..c4b3d2c 100644
14075 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14076 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14077 @@ -1,4 +1,5 @@
14078 #include <linux/linkage.h>
14079 +#include <asm/alternative-asm.h>
14080
14081 # enter salsa20_encrypt_bytes
14082 ENTRY(salsa20_encrypt_bytes)
14083 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14084 add %r11,%rsp
14085 mov %rdi,%rax
14086 mov %rsi,%rdx
14087 + pax_force_retaddr
14088 ret
14089 # bytesatleast65:
14090 ._bytesatleast65:
14091 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14092 add %r11,%rsp
14093 mov %rdi,%rax
14094 mov %rsi,%rdx
14095 + pax_force_retaddr
14096 ret
14097 ENDPROC(salsa20_keysetup)
14098
14099 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14100 add %r11,%rsp
14101 mov %rdi,%rax
14102 mov %rsi,%rdx
14103 + pax_force_retaddr
14104 ret
14105 ENDPROC(salsa20_ivsetup)
14106 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14107 index 2f202f4..d9164d6 100644
14108 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14109 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14110 @@ -24,6 +24,7 @@
14111 */
14112
14113 #include <linux/linkage.h>
14114 +#include <asm/alternative-asm.h>
14115 #include "glue_helper-asm-avx.S"
14116
14117 .file "serpent-avx-x86_64-asm_64.S"
14118 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14119 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14120 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14121
14122 + pax_force_retaddr
14123 ret;
14124 ENDPROC(__serpent_enc_blk8_avx)
14125
14126 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14127 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14128 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14129
14130 + pax_force_retaddr
14131 ret;
14132 ENDPROC(__serpent_dec_blk8_avx)
14133
14134 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14135
14136 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138 + pax_force_retaddr
14139 ret;
14140 ENDPROC(serpent_ecb_enc_8way_avx)
14141
14142 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14143
14144 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14145
14146 + pax_force_retaddr
14147 ret;
14148 ENDPROC(serpent_ecb_dec_8way_avx)
14149
14150 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14151
14152 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14153
14154 + pax_force_retaddr
14155 ret;
14156 ENDPROC(serpent_cbc_dec_8way_avx)
14157
14158 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14159
14160 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14161
14162 + pax_force_retaddr
14163 ret;
14164 ENDPROC(serpent_ctr_8way_avx)
14165
14166 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14167 /* dst <= regs xor IVs(in dst) */
14168 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14169
14170 + pax_force_retaddr
14171 ret;
14172 ENDPROC(serpent_xts_enc_8way_avx)
14173
14174 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14175 /* dst <= regs xor IVs(in dst) */
14176 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14177
14178 + pax_force_retaddr
14179 ret;
14180 ENDPROC(serpent_xts_dec_8way_avx)
14181 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14182 index b222085..abd483c 100644
14183 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14184 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14185 @@ -15,6 +15,7 @@
14186 */
14187
14188 #include <linux/linkage.h>
14189 +#include <asm/alternative-asm.h>
14190 #include "glue_helper-asm-avx2.S"
14191
14192 .file "serpent-avx2-asm_64.S"
14193 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14194 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14195 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14196
14197 + pax_force_retaddr
14198 ret;
14199 ENDPROC(__serpent_enc_blk16)
14200
14201 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14202 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14203 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14204
14205 + pax_force_retaddr
14206 ret;
14207 ENDPROC(__serpent_dec_blk16)
14208
14209 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14210
14211 vzeroupper;
14212
14213 + pax_force_retaddr
14214 ret;
14215 ENDPROC(serpent_ecb_enc_16way)
14216
14217 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14218
14219 vzeroupper;
14220
14221 + pax_force_retaddr
14222 ret;
14223 ENDPROC(serpent_ecb_dec_16way)
14224
14225 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14226
14227 vzeroupper;
14228
14229 + pax_force_retaddr
14230 ret;
14231 ENDPROC(serpent_cbc_dec_16way)
14232
14233 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14234
14235 vzeroupper;
14236
14237 + pax_force_retaddr
14238 ret;
14239 ENDPROC(serpent_ctr_16way)
14240
14241 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14242
14243 vzeroupper;
14244
14245 + pax_force_retaddr
14246 ret;
14247 ENDPROC(serpent_xts_enc_16way)
14248
14249 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14250
14251 vzeroupper;
14252
14253 + pax_force_retaddr
14254 ret;
14255 ENDPROC(serpent_xts_dec_16way)
14256 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14257 index acc066c..1559cc4 100644
14258 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14259 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14260 @@ -25,6 +25,7 @@
14261 */
14262
14263 #include <linux/linkage.h>
14264 +#include <asm/alternative-asm.h>
14265
14266 .file "serpent-sse2-x86_64-asm_64.S"
14267 .text
14268 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14269 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14270 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14271
14272 + pax_force_retaddr
14273 ret;
14274
14275 .L__enc_xor8:
14276 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14277 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14278
14279 + pax_force_retaddr
14280 ret;
14281 ENDPROC(__serpent_enc_blk_8way)
14282
14283 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14284 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14285 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14286
14287 + pax_force_retaddr
14288 ret;
14289 ENDPROC(serpent_dec_blk_8way)
14290 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14291 index a410950..9dfe7ad 100644
14292 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14293 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14294 @@ -29,6 +29,7 @@
14295 */
14296
14297 #include <linux/linkage.h>
14298 +#include <asm/alternative-asm.h>
14299
14300 #define CTX %rdi // arg1
14301 #define BUF %rsi // arg2
14302 @@ -75,9 +76,9 @@
14303
14304 push %rbx
14305 push %rbp
14306 - push %r12
14307 + push %r14
14308
14309 - mov %rsp, %r12
14310 + mov %rsp, %r14
14311 sub $64, %rsp # allocate workspace
14312 and $~15, %rsp # align stack
14313
14314 @@ -99,11 +100,12 @@
14315 xor %rax, %rax
14316 rep stosq
14317
14318 - mov %r12, %rsp # deallocate workspace
14319 + mov %r14, %rsp # deallocate workspace
14320
14321 - pop %r12
14322 + pop %r14
14323 pop %rbp
14324 pop %rbx
14325 + pax_force_retaddr
14326 ret
14327
14328 ENDPROC(\name)
14329 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14330 index 642f156..51a513c 100644
14331 --- a/arch/x86/crypto/sha256-avx-asm.S
14332 +++ b/arch/x86/crypto/sha256-avx-asm.S
14333 @@ -49,6 +49,7 @@
14334
14335 #ifdef CONFIG_AS_AVX
14336 #include <linux/linkage.h>
14337 +#include <asm/alternative-asm.h>
14338
14339 ## assume buffers not aligned
14340 #define VMOVDQ vmovdqu
14341 @@ -460,6 +461,7 @@ done_hash:
14342 popq %r13
14343 popq %rbp
14344 popq %rbx
14345 + pax_force_retaddr
14346 ret
14347 ENDPROC(sha256_transform_avx)
14348
14349 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14350 index 9e86944..3795e6a 100644
14351 --- a/arch/x86/crypto/sha256-avx2-asm.S
14352 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14353 @@ -50,6 +50,7 @@
14354
14355 #ifdef CONFIG_AS_AVX2
14356 #include <linux/linkage.h>
14357 +#include <asm/alternative-asm.h>
14358
14359 ## assume buffers not aligned
14360 #define VMOVDQ vmovdqu
14361 @@ -720,6 +721,7 @@ done_hash:
14362 popq %r12
14363 popq %rbp
14364 popq %rbx
14365 + pax_force_retaddr
14366 ret
14367 ENDPROC(sha256_transform_rorx)
14368
14369 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14370 index f833b74..8c62a9e 100644
14371 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14372 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14373 @@ -47,6 +47,7 @@
14374 ########################################################################
14375
14376 #include <linux/linkage.h>
14377 +#include <asm/alternative-asm.h>
14378
14379 ## assume buffers not aligned
14380 #define MOVDQ movdqu
14381 @@ -471,6 +472,7 @@ done_hash:
14382 popq %rbp
14383 popq %rbx
14384
14385 + pax_force_retaddr
14386 ret
14387 ENDPROC(sha256_transform_ssse3)
14388
14389 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14390 index 974dde9..a823ff9 100644
14391 --- a/arch/x86/crypto/sha512-avx-asm.S
14392 +++ b/arch/x86/crypto/sha512-avx-asm.S
14393 @@ -49,6 +49,7 @@
14394
14395 #ifdef CONFIG_AS_AVX
14396 #include <linux/linkage.h>
14397 +#include <asm/alternative-asm.h>
14398
14399 .text
14400
14401 @@ -364,6 +365,7 @@ updateblock:
14402 mov frame_RSPSAVE(%rsp), %rsp
14403
14404 nowork:
14405 + pax_force_retaddr
14406 ret
14407 ENDPROC(sha512_transform_avx)
14408
14409 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14410 index 568b961..ed20c37 100644
14411 --- a/arch/x86/crypto/sha512-avx2-asm.S
14412 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14413 @@ -51,6 +51,7 @@
14414
14415 #ifdef CONFIG_AS_AVX2
14416 #include <linux/linkage.h>
14417 +#include <asm/alternative-asm.h>
14418
14419 .text
14420
14421 @@ -678,6 +679,7 @@ done_hash:
14422
14423 # Restore Stack Pointer
14424 mov frame_RSPSAVE(%rsp), %rsp
14425 + pax_force_retaddr
14426 ret
14427 ENDPROC(sha512_transform_rorx)
14428
14429 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14430 index fb56855..6edd768 100644
14431 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14432 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14433 @@ -48,6 +48,7 @@
14434 ########################################################################
14435
14436 #include <linux/linkage.h>
14437 +#include <asm/alternative-asm.h>
14438
14439 .text
14440
14441 @@ -363,6 +364,7 @@ updateblock:
14442 mov frame_RSPSAVE(%rsp), %rsp
14443
14444 nowork:
14445 + pax_force_retaddr
14446 ret
14447 ENDPROC(sha512_transform_ssse3)
14448
14449 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14450 index 0505813..b067311 100644
14451 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14452 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14453 @@ -24,6 +24,7 @@
14454 */
14455
14456 #include <linux/linkage.h>
14457 +#include <asm/alternative-asm.h>
14458 #include "glue_helper-asm-avx.S"
14459
14460 .file "twofish-avx-x86_64-asm_64.S"
14461 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14462 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14463 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14464
14465 + pax_force_retaddr
14466 ret;
14467 ENDPROC(__twofish_enc_blk8)
14468
14469 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14470 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14471 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14472
14473 + pax_force_retaddr
14474 ret;
14475 ENDPROC(__twofish_dec_blk8)
14476
14477 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14478
14479 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14480
14481 + pax_force_retaddr
14482 ret;
14483 ENDPROC(twofish_ecb_enc_8way)
14484
14485 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14486
14487 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14488
14489 + pax_force_retaddr
14490 ret;
14491 ENDPROC(twofish_ecb_dec_8way)
14492
14493 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14494 * %rdx: src
14495 */
14496
14497 - pushq %r12;
14498 + pushq %r14;
14499
14500 movq %rsi, %r11;
14501 - movq %rdx, %r12;
14502 + movq %rdx, %r14;
14503
14504 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14505
14506 call __twofish_dec_blk8;
14507
14508 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14509 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14510
14511 - popq %r12;
14512 + popq %r14;
14513
14514 + pax_force_retaddr
14515 ret;
14516 ENDPROC(twofish_cbc_dec_8way)
14517
14518 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14519 * %rcx: iv (little endian, 128bit)
14520 */
14521
14522 - pushq %r12;
14523 + pushq %r14;
14524
14525 movq %rsi, %r11;
14526 - movq %rdx, %r12;
14527 + movq %rdx, %r14;
14528
14529 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14530 RD2, RX0, RX1, RY0);
14531
14532 call __twofish_enc_blk8;
14533
14534 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14535 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14536
14537 - popq %r12;
14538 + popq %r14;
14539
14540 + pax_force_retaddr
14541 ret;
14542 ENDPROC(twofish_ctr_8way)
14543
14544 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14545 /* dst <= regs xor IVs(in dst) */
14546 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14547
14548 + pax_force_retaddr
14549 ret;
14550 ENDPROC(twofish_xts_enc_8way)
14551
14552 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14553 /* dst <= regs xor IVs(in dst) */
14554 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14555
14556 + pax_force_retaddr
14557 ret;
14558 ENDPROC(twofish_xts_dec_8way)
14559 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14560 index 1c3b7ce..02f578d 100644
14561 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14562 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14563 @@ -21,6 +21,7 @@
14564 */
14565
14566 #include <linux/linkage.h>
14567 +#include <asm/alternative-asm.h>
14568
14569 .file "twofish-x86_64-asm-3way.S"
14570 .text
14571 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14572 popq %r13;
14573 popq %r14;
14574 popq %r15;
14575 + pax_force_retaddr
14576 ret;
14577
14578 .L__enc_xor3:
14579 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14580 popq %r13;
14581 popq %r14;
14582 popq %r15;
14583 + pax_force_retaddr
14584 ret;
14585 ENDPROC(__twofish_enc_blk_3way)
14586
14587 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14588 popq %r13;
14589 popq %r14;
14590 popq %r15;
14591 + pax_force_retaddr
14592 ret;
14593 ENDPROC(twofish_dec_blk_3way)
14594 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14595 index a039d21..524b8b2 100644
14596 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14597 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14598 @@ -22,6 +22,7 @@
14599
14600 #include <linux/linkage.h>
14601 #include <asm/asm-offsets.h>
14602 +#include <asm/alternative-asm.h>
14603
14604 #define a_offset 0
14605 #define b_offset 4
14606 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14607
14608 popq R1
14609 movq $1,%rax
14610 + pax_force_retaddr
14611 ret
14612 ENDPROC(twofish_enc_blk)
14613
14614 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14615
14616 popq R1
14617 movq $1,%rax
14618 + pax_force_retaddr
14619 ret
14620 ENDPROC(twofish_dec_blk)
14621 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14622 index df91466..74b31cb 100644
14623 --- a/arch/x86/ia32/ia32_aout.c
14624 +++ b/arch/x86/ia32/ia32_aout.c
14625 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14626 unsigned long dump_start, dump_size;
14627 struct user32 dump;
14628
14629 + memset(&dump, 0, sizeof(dump));
14630 +
14631 fs = get_fs();
14632 set_fs(KERNEL_DS);
14633 has_dumped = 1;
14634 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14635 index f9e181a..300544c 100644
14636 --- a/arch/x86/ia32/ia32_signal.c
14637 +++ b/arch/x86/ia32/ia32_signal.c
14638 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14639 if (__get_user(set.sig[0], &frame->sc.oldmask)
14640 || (_COMPAT_NSIG_WORDS > 1
14641 && __copy_from_user((((char *) &set.sig) + 4),
14642 - &frame->extramask,
14643 + frame->extramask,
14644 sizeof(frame->extramask))))
14645 goto badframe;
14646
14647 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14648 sp -= frame_size;
14649 /* Align the stack pointer according to the i386 ABI,
14650 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14651 - sp = ((sp + 4) & -16ul) - 4;
14652 + sp = ((sp - 12) & -16ul) - 4;
14653 return (void __user *) sp;
14654 }
14655
14656 @@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14657 } else {
14658 /* Return stub is in 32bit vsyscall page */
14659 if (current->mm->context.vdso)
14660 - restorer = current->mm->context.vdso +
14661 - selected_vdso32->sym___kernel_sigreturn;
14662 + restorer = (void __force_user *)(current->mm->context.vdso +
14663 + selected_vdso32->sym___kernel_sigreturn);
14664 else
14665 - restorer = &frame->retcode;
14666 + restorer = frame->retcode;
14667 }
14668
14669 put_user_try {
14670 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14671 * These are actually not used anymore, but left because some
14672 * gdb versions depend on them as a marker.
14673 */
14674 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14675 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14676 } put_user_catch(err);
14677
14678 if (err)
14679 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14680 0xb8,
14681 __NR_ia32_rt_sigreturn,
14682 0x80cd,
14683 - 0,
14684 + 0
14685 };
14686
14687 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14688 @@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14689
14690 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14691 restorer = ksig->ka.sa.sa_restorer;
14692 + else if (current->mm->context.vdso)
14693 + /* Return stub is in 32bit vsyscall page */
14694 + restorer = (void __force_user *)(current->mm->context.vdso +
14695 + selected_vdso32->sym___kernel_rt_sigreturn);
14696 else
14697 - restorer = current->mm->context.vdso +
14698 - selected_vdso32->sym___kernel_rt_sigreturn;
14699 + restorer = frame->retcode;
14700 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14701
14702 /*
14703 * Not actually used anymore, but left because some gdb
14704 * versions need it.
14705 */
14706 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14707 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14708 } put_user_catch(err);
14709
14710 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14711 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14712 index ffe7122..899bad3 100644
14713 --- a/arch/x86/ia32/ia32entry.S
14714 +++ b/arch/x86/ia32/ia32entry.S
14715 @@ -15,8 +15,10 @@
14716 #include <asm/irqflags.h>
14717 #include <asm/asm.h>
14718 #include <asm/smap.h>
14719 +#include <asm/pgtable.h>
14720 #include <linux/linkage.h>
14721 #include <linux/err.h>
14722 +#include <asm/alternative-asm.h>
14723
14724 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14725 #include <linux/elf-em.h>
14726 @@ -62,12 +64,12 @@
14727 */
14728 .macro LOAD_ARGS32 offset, _r9=0
14729 .if \_r9
14730 - movl \offset+16(%rsp),%r9d
14731 + movl \offset+R9(%rsp),%r9d
14732 .endif
14733 - movl \offset+40(%rsp),%ecx
14734 - movl \offset+48(%rsp),%edx
14735 - movl \offset+56(%rsp),%esi
14736 - movl \offset+64(%rsp),%edi
14737 + movl \offset+RCX(%rsp),%ecx
14738 + movl \offset+RDX(%rsp),%edx
14739 + movl \offset+RSI(%rsp),%esi
14740 + movl \offset+RDI(%rsp),%edi
14741 movl %eax,%eax /* zero extension */
14742 .endm
14743
14744 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14745 ENDPROC(native_irq_enable_sysexit)
14746 #endif
14747
14748 + .macro pax_enter_kernel_user
14749 + pax_set_fptr_mask
14750 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14751 + call pax_enter_kernel_user
14752 +#endif
14753 + .endm
14754 +
14755 + .macro pax_exit_kernel_user
14756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14757 + call pax_exit_kernel_user
14758 +#endif
14759 +#ifdef CONFIG_PAX_RANDKSTACK
14760 + pushq %rax
14761 + pushq %r11
14762 + call pax_randomize_kstack
14763 + popq %r11
14764 + popq %rax
14765 +#endif
14766 + .endm
14767 +
14768 + .macro pax_erase_kstack
14769 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14770 + call pax_erase_kstack
14771 +#endif
14772 + .endm
14773 +
14774 /*
14775 * 32bit SYSENTER instruction entry.
14776 *
14777 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14778 CFI_REGISTER rsp,rbp
14779 SWAPGS_UNSAFE_STACK
14780 movq PER_CPU_VAR(kernel_stack), %rsp
14781 - addq $(KERNEL_STACK_OFFSET),%rsp
14782 - /*
14783 - * No need to follow this irqs on/off section: the syscall
14784 - * disabled irqs, here we enable it straight after entry:
14785 - */
14786 - ENABLE_INTERRUPTS(CLBR_NONE)
14787 movl %ebp,%ebp /* zero extension */
14788 pushq_cfi $__USER32_DS
14789 /*CFI_REL_OFFSET ss,0*/
14790 @@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14791 CFI_REL_OFFSET rsp,0
14792 pushfq_cfi
14793 /*CFI_REL_OFFSET rflags,0*/
14794 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14795 - CFI_REGISTER rip,r10
14796 + orl $X86_EFLAGS_IF,(%rsp)
14797 + GET_THREAD_INFO(%r11)
14798 + movl TI_sysenter_return(%r11), %r11d
14799 + CFI_REGISTER rip,r11
14800 pushq_cfi $__USER32_CS
14801 /*CFI_REL_OFFSET cs,0*/
14802 movl %eax, %eax
14803 - pushq_cfi %r10
14804 + pushq_cfi %r11
14805 CFI_REL_OFFSET rip,0
14806 pushq_cfi %rax
14807 cld
14808 SAVE_ARGS 0,1,0
14809 + pax_enter_kernel_user
14810 +
14811 +#ifdef CONFIG_PAX_RANDKSTACK
14812 + pax_erase_kstack
14813 +#endif
14814 +
14815 + /*
14816 + * No need to follow this irqs on/off section: the syscall
14817 + * disabled irqs, here we enable it straight after entry:
14818 + */
14819 + ENABLE_INTERRUPTS(CLBR_NONE)
14820 /* no need to do an access_ok check here because rbp has been
14821 32bit zero extended */
14822 +
14823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14824 + addq pax_user_shadow_base,%rbp
14825 + ASM_PAX_OPEN_USERLAND
14826 +#endif
14827 +
14828 ASM_STAC
14829 1: movl (%rbp),%ebp
14830 _ASM_EXTABLE(1b,ia32_badarg)
14831 ASM_CLAC
14832
14833 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14834 + ASM_PAX_CLOSE_USERLAND
14835 +#endif
14836 +
14837 /*
14838 * Sysenter doesn't filter flags, so we need to clear NT
14839 * ourselves. To save a few cycles, we can check whether
14840 @@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14841 jnz sysenter_fix_flags
14842 sysenter_flags_fixed:
14843
14844 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14845 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14846 + GET_THREAD_INFO(%r11)
14847 + orl $TS_COMPAT,TI_status(%r11)
14848 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14849 CFI_REMEMBER_STATE
14850 jnz sysenter_tracesys
14851 cmpq $(IA32_NR_syscalls-1),%rax
14852 @@ -172,15 +218,18 @@ sysenter_do_call:
14853 sysenter_dispatch:
14854 call *ia32_sys_call_table(,%rax,8)
14855 movq %rax,RAX-ARGOFFSET(%rsp)
14856 + GET_THREAD_INFO(%r11)
14857 DISABLE_INTERRUPTS(CLBR_NONE)
14858 TRACE_IRQS_OFF
14859 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14860 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14861 jnz sysexit_audit
14862 sysexit_from_sys_call:
14863 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14864 + pax_exit_kernel_user
14865 + pax_erase_kstack
14866 + andl $~TS_COMPAT,TI_status(%r11)
14867 /* clear IF, that popfq doesn't enable interrupts early */
14868 - andl $~0x200,EFLAGS-R11(%rsp)
14869 - movl RIP-R11(%rsp),%edx /* User %eip */
14870 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14871 + movl RIP(%rsp),%edx /* User %eip */
14872 CFI_REGISTER rip,rdx
14873 RESTORE_ARGS 0,24,0,0,0,0
14874 xorq %r8,%r8
14875 @@ -205,6 +254,9 @@ sysexit_from_sys_call:
14876 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14877 movl %eax,%edi /* 1st arg: syscall number */
14878 call __audit_syscall_entry
14879 +
14880 + pax_erase_kstack
14881 +
14882 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14883 cmpq $(IA32_NR_syscalls-1),%rax
14884 ja ia32_badsys
14885 @@ -216,7 +268,7 @@ sysexit_from_sys_call:
14886 .endm
14887
14888 .macro auditsys_exit exit
14889 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14890 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14891 jnz ia32_ret_from_sys_call
14892 TRACE_IRQS_ON
14893 ENABLE_INTERRUPTS(CLBR_NONE)
14894 @@ -227,11 +279,12 @@ sysexit_from_sys_call:
14895 1: setbe %al /* 1 if error, 0 if not */
14896 movzbl %al,%edi /* zero-extend that into %edi */
14897 call __audit_syscall_exit
14898 + GET_THREAD_INFO(%r11)
14899 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14900 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14901 DISABLE_INTERRUPTS(CLBR_NONE)
14902 TRACE_IRQS_OFF
14903 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14904 + testl %edi,TI_flags(%r11)
14905 jz \exit
14906 CLEAR_RREGS -ARGOFFSET
14907 jmp int_with_check
14908 @@ -253,7 +306,7 @@ sysenter_fix_flags:
14909
14910 sysenter_tracesys:
14911 #ifdef CONFIG_AUDITSYSCALL
14912 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14913 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14914 jz sysenter_auditsys
14915 #endif
14916 SAVE_REST
14917 @@ -265,6 +318,9 @@ sysenter_tracesys:
14918 RESTORE_REST
14919 cmpq $(IA32_NR_syscalls-1),%rax
14920 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14921 +
14922 + pax_erase_kstack
14923 +
14924 jmp sysenter_do_call
14925 CFI_ENDPROC
14926 ENDPROC(ia32_sysenter_target)
14927 @@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14928 ENTRY(ia32_cstar_target)
14929 CFI_STARTPROC32 simple
14930 CFI_SIGNAL_FRAME
14931 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14932 + CFI_DEF_CFA rsp,0
14933 CFI_REGISTER rip,rcx
14934 /*CFI_REGISTER rflags,r11*/
14935 SWAPGS_UNSAFE_STACK
14936 movl %esp,%r8d
14937 CFI_REGISTER rsp,r8
14938 movq PER_CPU_VAR(kernel_stack),%rsp
14939 + SAVE_ARGS 8*6,0,0
14940 + pax_enter_kernel_user
14941 +
14942 +#ifdef CONFIG_PAX_RANDKSTACK
14943 + pax_erase_kstack
14944 +#endif
14945 +
14946 /*
14947 * No need to follow this irqs on/off section: the syscall
14948 * disabled irqs and here we enable it straight after entry:
14949 */
14950 ENABLE_INTERRUPTS(CLBR_NONE)
14951 - SAVE_ARGS 8,0,0
14952 movl %eax,%eax /* zero extension */
14953 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14954 movq %rcx,RIP-ARGOFFSET(%rsp)
14955 @@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14956 /* no need to do an access_ok check here because r8 has been
14957 32bit zero extended */
14958 /* hardware stack frame is complete now */
14959 +
14960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14961 + ASM_PAX_OPEN_USERLAND
14962 + movq pax_user_shadow_base,%r8
14963 + addq RSP-ARGOFFSET(%rsp),%r8
14964 +#endif
14965 +
14966 ASM_STAC
14967 1: movl (%r8),%r9d
14968 _ASM_EXTABLE(1b,ia32_badarg)
14969 ASM_CLAC
14970 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14971 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14972 +
14973 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14974 + ASM_PAX_CLOSE_USERLAND
14975 +#endif
14976 +
14977 + GET_THREAD_INFO(%r11)
14978 + orl $TS_COMPAT,TI_status(%r11)
14979 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14980 CFI_REMEMBER_STATE
14981 jnz cstar_tracesys
14982 cmpq $IA32_NR_syscalls-1,%rax
14983 @@ -335,13 +410,16 @@ cstar_do_call:
14984 cstar_dispatch:
14985 call *ia32_sys_call_table(,%rax,8)
14986 movq %rax,RAX-ARGOFFSET(%rsp)
14987 + GET_THREAD_INFO(%r11)
14988 DISABLE_INTERRUPTS(CLBR_NONE)
14989 TRACE_IRQS_OFF
14990 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14991 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14992 jnz sysretl_audit
14993 sysretl_from_sys_call:
14994 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14995 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14996 + pax_exit_kernel_user
14997 + pax_erase_kstack
14998 + andl $~TS_COMPAT,TI_status(%r11)
14999 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15000 movl RIP-ARGOFFSET(%rsp),%ecx
15001 CFI_REGISTER rip,rcx
15002 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15003 @@ -368,7 +446,7 @@ sysretl_audit:
15004
15005 cstar_tracesys:
15006 #ifdef CONFIG_AUDITSYSCALL
15007 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15008 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15009 jz cstar_auditsys
15010 #endif
15011 xchgl %r9d,%ebp
15012 @@ -382,11 +460,19 @@ cstar_tracesys:
15013 xchgl %ebp,%r9d
15014 cmpq $(IA32_NR_syscalls-1),%rax
15015 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15016 +
15017 + pax_erase_kstack
15018 +
15019 jmp cstar_do_call
15020 END(ia32_cstar_target)
15021
15022 ia32_badarg:
15023 ASM_CLAC
15024 +
15025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15026 + ASM_PAX_CLOSE_USERLAND
15027 +#endif
15028 +
15029 movq $-EFAULT,%rax
15030 jmp ia32_sysret
15031 CFI_ENDPROC
15032 @@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15033 CFI_REL_OFFSET rip,RIP-RIP
15034 PARAVIRT_ADJUST_EXCEPTION_FRAME
15035 SWAPGS
15036 - /*
15037 - * No need to follow this irqs on/off section: the syscall
15038 - * disabled irqs and here we enable it straight after entry:
15039 - */
15040 - ENABLE_INTERRUPTS(CLBR_NONE)
15041 movl %eax,%eax
15042 pushq_cfi %rax
15043 cld
15044 /* note the registers are not zero extended to the sf.
15045 this could be a problem. */
15046 SAVE_ARGS 0,1,0
15047 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15048 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15049 + pax_enter_kernel_user
15050 +
15051 +#ifdef CONFIG_PAX_RANDKSTACK
15052 + pax_erase_kstack
15053 +#endif
15054 +
15055 + /*
15056 + * No need to follow this irqs on/off section: the syscall
15057 + * disabled irqs and here we enable it straight after entry:
15058 + */
15059 + ENABLE_INTERRUPTS(CLBR_NONE)
15060 + GET_THREAD_INFO(%r11)
15061 + orl $TS_COMPAT,TI_status(%r11)
15062 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15063 jnz ia32_tracesys
15064 cmpq $(IA32_NR_syscalls-1),%rax
15065 ja ia32_badsys
15066 @@ -458,6 +551,9 @@ ia32_tracesys:
15067 RESTORE_REST
15068 cmpq $(IA32_NR_syscalls-1),%rax
15069 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15070 +
15071 + pax_erase_kstack
15072 +
15073 jmp ia32_do_call
15074 END(ia32_syscall)
15075
15076 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15077 index 8e0ceec..af13504 100644
15078 --- a/arch/x86/ia32/sys_ia32.c
15079 +++ b/arch/x86/ia32/sys_ia32.c
15080 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15081 */
15082 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15083 {
15084 - typeof(ubuf->st_uid) uid = 0;
15085 - typeof(ubuf->st_gid) gid = 0;
15086 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15087 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15088 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15089 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15090 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15091 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15092 index 372231c..51b537d 100644
15093 --- a/arch/x86/include/asm/alternative-asm.h
15094 +++ b/arch/x86/include/asm/alternative-asm.h
15095 @@ -18,6 +18,45 @@
15096 .endm
15097 #endif
15098
15099 +#ifdef KERNEXEC_PLUGIN
15100 + .macro pax_force_retaddr_bts rip=0
15101 + btsq $63,\rip(%rsp)
15102 + .endm
15103 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15104 + .macro pax_force_retaddr rip=0, reload=0
15105 + btsq $63,\rip(%rsp)
15106 + .endm
15107 + .macro pax_force_fptr ptr
15108 + btsq $63,\ptr
15109 + .endm
15110 + .macro pax_set_fptr_mask
15111 + .endm
15112 +#endif
15113 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15114 + .macro pax_force_retaddr rip=0, reload=0
15115 + .if \reload
15116 + pax_set_fptr_mask
15117 + .endif
15118 + orq %r12,\rip(%rsp)
15119 + .endm
15120 + .macro pax_force_fptr ptr
15121 + orq %r12,\ptr
15122 + .endm
15123 + .macro pax_set_fptr_mask
15124 + movabs $0x8000000000000000,%r12
15125 + .endm
15126 +#endif
15127 +#else
15128 + .macro pax_force_retaddr rip=0, reload=0
15129 + .endm
15130 + .macro pax_force_fptr ptr
15131 + .endm
15132 + .macro pax_force_retaddr_bts rip=0
15133 + .endm
15134 + .macro pax_set_fptr_mask
15135 + .endm
15136 +#endif
15137 +
15138 .macro altinstruction_entry orig alt feature orig_len alt_len
15139 .long \orig - .
15140 .long \alt - .
15141 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15142 index 473bdbe..b1e3377 100644
15143 --- a/arch/x86/include/asm/alternative.h
15144 +++ b/arch/x86/include/asm/alternative.h
15145 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15146 ".pushsection .discard,\"aw\",@progbits\n" \
15147 DISCARD_ENTRY(1) \
15148 ".popsection\n" \
15149 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15150 + ".pushsection .altinstr_replacement, \"a\"\n" \
15151 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15152 ".popsection"
15153
15154 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15155 DISCARD_ENTRY(1) \
15156 DISCARD_ENTRY(2) \
15157 ".popsection\n" \
15158 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15159 + ".pushsection .altinstr_replacement, \"a\"\n" \
15160 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15161 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15162 ".popsection"
15163 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15164 index 465b309..ab7e51f 100644
15165 --- a/arch/x86/include/asm/apic.h
15166 +++ b/arch/x86/include/asm/apic.h
15167 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15168
15169 #ifdef CONFIG_X86_LOCAL_APIC
15170
15171 -extern unsigned int apic_verbosity;
15172 +extern int apic_verbosity;
15173 extern int local_apic_timer_c2_ok;
15174
15175 extern int disable_apic;
15176 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15177 index 20370c6..a2eb9b0 100644
15178 --- a/arch/x86/include/asm/apm.h
15179 +++ b/arch/x86/include/asm/apm.h
15180 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15181 __asm__ __volatile__(APM_DO_ZERO_SEGS
15182 "pushl %%edi\n\t"
15183 "pushl %%ebp\n\t"
15184 - "lcall *%%cs:apm_bios_entry\n\t"
15185 + "lcall *%%ss:apm_bios_entry\n\t"
15186 "setc %%al\n\t"
15187 "popl %%ebp\n\t"
15188 "popl %%edi\n\t"
15189 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15190 __asm__ __volatile__(APM_DO_ZERO_SEGS
15191 "pushl %%edi\n\t"
15192 "pushl %%ebp\n\t"
15193 - "lcall *%%cs:apm_bios_entry\n\t"
15194 + "lcall *%%ss:apm_bios_entry\n\t"
15195 "setc %%bl\n\t"
15196 "popl %%ebp\n\t"
15197 "popl %%edi\n\t"
15198 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15199 index 5e5cd12..3d18208 100644
15200 --- a/arch/x86/include/asm/atomic.h
15201 +++ b/arch/x86/include/asm/atomic.h
15202 @@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15203 }
15204
15205 /**
15206 + * atomic_read_unchecked - read atomic variable
15207 + * @v: pointer of type atomic_unchecked_t
15208 + *
15209 + * Atomically reads the value of @v.
15210 + */
15211 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15212 +{
15213 + return ACCESS_ONCE((v)->counter);
15214 +}
15215 +
15216 +/**
15217 * atomic_set - set atomic variable
15218 * @v: pointer of type atomic_t
15219 * @i: required value
15220 @@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15221 }
15222
15223 /**
15224 + * atomic_set_unchecked - set atomic variable
15225 + * @v: pointer of type atomic_unchecked_t
15226 + * @i: required value
15227 + *
15228 + * Atomically sets the value of @v to @i.
15229 + */
15230 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15231 +{
15232 + v->counter = i;
15233 +}
15234 +
15235 +/**
15236 * atomic_add - add integer to atomic variable
15237 * @i: integer value to add
15238 * @v: pointer of type atomic_t
15239 @@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15240 */
15241 static inline void atomic_add(int i, atomic_t *v)
15242 {
15243 - asm volatile(LOCK_PREFIX "addl %1,%0"
15244 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15245 +
15246 +#ifdef CONFIG_PAX_REFCOUNT
15247 + "jno 0f\n"
15248 + LOCK_PREFIX "subl %1,%0\n"
15249 + "int $4\n0:\n"
15250 + _ASM_EXTABLE(0b, 0b)
15251 +#endif
15252 +
15253 + : "+m" (v->counter)
15254 + : "ir" (i));
15255 +}
15256 +
15257 +/**
15258 + * atomic_add_unchecked - add integer to atomic variable
15259 + * @i: integer value to add
15260 + * @v: pointer of type atomic_unchecked_t
15261 + *
15262 + * Atomically adds @i to @v.
15263 + */
15264 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15265 +{
15266 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15267 : "+m" (v->counter)
15268 : "ir" (i));
15269 }
15270 @@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15271 */
15272 static inline void atomic_sub(int i, atomic_t *v)
15273 {
15274 - asm volatile(LOCK_PREFIX "subl %1,%0"
15275 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15276 +
15277 +#ifdef CONFIG_PAX_REFCOUNT
15278 + "jno 0f\n"
15279 + LOCK_PREFIX "addl %1,%0\n"
15280 + "int $4\n0:\n"
15281 + _ASM_EXTABLE(0b, 0b)
15282 +#endif
15283 +
15284 + : "+m" (v->counter)
15285 + : "ir" (i));
15286 +}
15287 +
15288 +/**
15289 + * atomic_sub_unchecked - subtract integer from atomic variable
15290 + * @i: integer value to subtract
15291 + * @v: pointer of type atomic_unchecked_t
15292 + *
15293 + * Atomically subtracts @i from @v.
15294 + */
15295 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15296 +{
15297 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15298 : "+m" (v->counter)
15299 : "ir" (i));
15300 }
15301 @@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15302 */
15303 static inline int atomic_sub_and_test(int i, atomic_t *v)
15304 {
15305 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15306 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15307 }
15308
15309 /**
15310 @@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15311 */
15312 static inline void atomic_inc(atomic_t *v)
15313 {
15314 - asm volatile(LOCK_PREFIX "incl %0"
15315 + asm volatile(LOCK_PREFIX "incl %0\n"
15316 +
15317 +#ifdef CONFIG_PAX_REFCOUNT
15318 + "jno 0f\n"
15319 + LOCK_PREFIX "decl %0\n"
15320 + "int $4\n0:\n"
15321 + _ASM_EXTABLE(0b, 0b)
15322 +#endif
15323 +
15324 + : "+m" (v->counter));
15325 +}
15326 +
15327 +/**
15328 + * atomic_inc_unchecked - increment atomic variable
15329 + * @v: pointer of type atomic_unchecked_t
15330 + *
15331 + * Atomically increments @v by 1.
15332 + */
15333 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15334 +{
15335 + asm volatile(LOCK_PREFIX "incl %0\n"
15336 : "+m" (v->counter));
15337 }
15338
15339 @@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15340 */
15341 static inline void atomic_dec(atomic_t *v)
15342 {
15343 - asm volatile(LOCK_PREFIX "decl %0"
15344 + asm volatile(LOCK_PREFIX "decl %0\n"
15345 +
15346 +#ifdef CONFIG_PAX_REFCOUNT
15347 + "jno 0f\n"
15348 + LOCK_PREFIX "incl %0\n"
15349 + "int $4\n0:\n"
15350 + _ASM_EXTABLE(0b, 0b)
15351 +#endif
15352 +
15353 + : "+m" (v->counter));
15354 +}
15355 +
15356 +/**
15357 + * atomic_dec_unchecked - decrement atomic variable
15358 + * @v: pointer of type atomic_unchecked_t
15359 + *
15360 + * Atomically decrements @v by 1.
15361 + */
15362 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15363 +{
15364 + asm volatile(LOCK_PREFIX "decl %0\n"
15365 : "+m" (v->counter));
15366 }
15367
15368 @@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15369 */
15370 static inline int atomic_dec_and_test(atomic_t *v)
15371 {
15372 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15373 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15374 }
15375
15376 /**
15377 @@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15378 */
15379 static inline int atomic_inc_and_test(atomic_t *v)
15380 {
15381 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15382 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15383 +}
15384 +
15385 +/**
15386 + * atomic_inc_and_test_unchecked - increment and test
15387 + * @v: pointer of type atomic_unchecked_t
15388 + *
15389 + * Atomically increments @v by 1
15390 + * and returns true if the result is zero, or false for all
15391 + * other cases.
15392 + */
15393 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15394 +{
15395 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15396 }
15397
15398 /**
15399 @@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15400 */
15401 static inline int atomic_add_negative(int i, atomic_t *v)
15402 {
15403 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15404 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15405 }
15406
15407 /**
15408 @@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15409 *
15410 * Atomically adds @i to @v and returns @i + @v
15411 */
15412 -static inline int atomic_add_return(int i, atomic_t *v)
15413 +static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15414 +{
15415 + return i + xadd_check_overflow(&v->counter, i);
15416 +}
15417 +
15418 +/**
15419 + * atomic_add_return_unchecked - add integer and return
15420 + * @i: integer value to add
15421 + * @v: pointer of type atomic_unchecked_t
15422 + *
15423 + * Atomically adds @i to @v and returns @i + @v
15424 + */
15425 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15426 {
15427 return i + xadd(&v->counter, i);
15428 }
15429 @@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15430 *
15431 * Atomically subtracts @i from @v and returns @v - @i
15432 */
15433 -static inline int atomic_sub_return(int i, atomic_t *v)
15434 +static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15435 {
15436 return atomic_add_return(-i, v);
15437 }
15438
15439 #define atomic_inc_return(v) (atomic_add_return(1, v))
15440 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15441 +{
15442 + return atomic_add_return_unchecked(1, v);
15443 +}
15444 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15445
15446 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15447 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15448 +{
15449 + return cmpxchg(&v->counter, old, new);
15450 +}
15451 +
15452 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15453 {
15454 return cmpxchg(&v->counter, old, new);
15455 }
15456 @@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15457 return xchg(&v->counter, new);
15458 }
15459
15460 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15461 +{
15462 + return xchg(&v->counter, new);
15463 +}
15464 +
15465 /**
15466 * __atomic_add_unless - add unless the number is already a given value
15467 * @v: pointer of type atomic_t
15468 @@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15469 * Atomically adds @a to @v, so long as @v was not already @u.
15470 * Returns the old value of @v.
15471 */
15472 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15473 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15474 {
15475 - int c, old;
15476 + int c, old, new;
15477 c = atomic_read(v);
15478 for (;;) {
15479 - if (unlikely(c == (u)))
15480 + if (unlikely(c == u))
15481 break;
15482 - old = atomic_cmpxchg((v), c, c + (a));
15483 +
15484 + asm volatile("addl %2,%0\n"
15485 +
15486 +#ifdef CONFIG_PAX_REFCOUNT
15487 + "jno 0f\n"
15488 + "subl %2,%0\n"
15489 + "int $4\n0:\n"
15490 + _ASM_EXTABLE(0b, 0b)
15491 +#endif
15492 +
15493 + : "=r" (new)
15494 + : "0" (c), "ir" (a));
15495 +
15496 + old = atomic_cmpxchg(v, c, new);
15497 if (likely(old == c))
15498 break;
15499 c = old;
15500 @@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15501 }
15502
15503 /**
15504 + * atomic_inc_not_zero_hint - increment if not null
15505 + * @v: pointer of type atomic_t
15506 + * @hint: probable value of the atomic before the increment
15507 + *
15508 + * This version of atomic_inc_not_zero() gives a hint of probable
15509 + * value of the atomic. This helps processor to not read the memory
15510 + * before doing the atomic read/modify/write cycle, lowering
15511 + * number of bus transactions on some arches.
15512 + *
15513 + * Returns: 0 if increment was not done, 1 otherwise.
15514 + */
15515 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15516 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15517 +{
15518 + int val, c = hint, new;
15519 +
15520 + /* sanity test, should be removed by compiler if hint is a constant */
15521 + if (!hint)
15522 + return __atomic_add_unless(v, 1, 0);
15523 +
15524 + do {
15525 + asm volatile("incl %0\n"
15526 +
15527 +#ifdef CONFIG_PAX_REFCOUNT
15528 + "jno 0f\n"
15529 + "decl %0\n"
15530 + "int $4\n0:\n"
15531 + _ASM_EXTABLE(0b, 0b)
15532 +#endif
15533 +
15534 + : "=r" (new)
15535 + : "0" (c));
15536 +
15537 + val = atomic_cmpxchg(v, c, new);
15538 + if (val == c)
15539 + return 1;
15540 + c = val;
15541 + } while (c);
15542 +
15543 + return 0;
15544 +}
15545 +
15546 +/**
15547 * atomic_inc_short - increment of a short integer
15548 * @v: pointer to type int
15549 *
15550 @@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15551 }
15552
15553 /* These are x86-specific, used by some header files */
15554 -#define atomic_clear_mask(mask, addr) \
15555 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15556 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15557 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15558 +{
15559 + asm volatile(LOCK_PREFIX "andl %1,%0"
15560 + : "+m" (v->counter)
15561 + : "r" (~(mask))
15562 + : "memory");
15563 +}
15564
15565 -#define atomic_set_mask(mask, addr) \
15566 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15567 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15568 - : "memory")
15569 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15570 +{
15571 + asm volatile(LOCK_PREFIX "andl %1,%0"
15572 + : "+m" (v->counter)
15573 + : "r" (~(mask))
15574 + : "memory");
15575 +}
15576 +
15577 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15578 +{
15579 + asm volatile(LOCK_PREFIX "orl %1,%0"
15580 + : "+m" (v->counter)
15581 + : "r" (mask)
15582 + : "memory");
15583 +}
15584 +
15585 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15586 +{
15587 + asm volatile(LOCK_PREFIX "orl %1,%0"
15588 + : "+m" (v->counter)
15589 + : "r" (mask)
15590 + : "memory");
15591 +}
15592
15593 #ifdef CONFIG_X86_32
15594 # include <asm/atomic64_32.h>
15595 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15596 index b154de7..bf18a5a 100644
15597 --- a/arch/x86/include/asm/atomic64_32.h
15598 +++ b/arch/x86/include/asm/atomic64_32.h
15599 @@ -12,6 +12,14 @@ typedef struct {
15600 u64 __aligned(8) counter;
15601 } atomic64_t;
15602
15603 +#ifdef CONFIG_PAX_REFCOUNT
15604 +typedef struct {
15605 + u64 __aligned(8) counter;
15606 +} atomic64_unchecked_t;
15607 +#else
15608 +typedef atomic64_t atomic64_unchecked_t;
15609 +#endif
15610 +
15611 #define ATOMIC64_INIT(val) { (val) }
15612
15613 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15614 @@ -37,21 +45,31 @@ typedef struct {
15615 ATOMIC64_DECL_ONE(sym##_386)
15616
15617 ATOMIC64_DECL_ONE(add_386);
15618 +ATOMIC64_DECL_ONE(add_unchecked_386);
15619 ATOMIC64_DECL_ONE(sub_386);
15620 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15621 ATOMIC64_DECL_ONE(inc_386);
15622 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15623 ATOMIC64_DECL_ONE(dec_386);
15624 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15625 #endif
15626
15627 #define alternative_atomic64(f, out, in...) \
15628 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15629
15630 ATOMIC64_DECL(read);
15631 +ATOMIC64_DECL(read_unchecked);
15632 ATOMIC64_DECL(set);
15633 +ATOMIC64_DECL(set_unchecked);
15634 ATOMIC64_DECL(xchg);
15635 ATOMIC64_DECL(add_return);
15636 +ATOMIC64_DECL(add_return_unchecked);
15637 ATOMIC64_DECL(sub_return);
15638 +ATOMIC64_DECL(sub_return_unchecked);
15639 ATOMIC64_DECL(inc_return);
15640 +ATOMIC64_DECL(inc_return_unchecked);
15641 ATOMIC64_DECL(dec_return);
15642 +ATOMIC64_DECL(dec_return_unchecked);
15643 ATOMIC64_DECL(dec_if_positive);
15644 ATOMIC64_DECL(inc_not_zero);
15645 ATOMIC64_DECL(add_unless);
15646 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15647 }
15648
15649 /**
15650 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15651 + * @p: pointer to type atomic64_unchecked_t
15652 + * @o: expected value
15653 + * @n: new value
15654 + *
15655 + * Atomically sets @v to @n if it was equal to @o and returns
15656 + * the old value.
15657 + */
15658 +
15659 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15660 +{
15661 + return cmpxchg64(&v->counter, o, n);
15662 +}
15663 +
15664 +/**
15665 * atomic64_xchg - xchg atomic64 variable
15666 * @v: pointer to type atomic64_t
15667 * @n: value to assign
15668 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15669 }
15670
15671 /**
15672 + * atomic64_set_unchecked - set atomic64 variable
15673 + * @v: pointer to type atomic64_unchecked_t
15674 + * @n: value to assign
15675 + *
15676 + * Atomically sets the value of @v to @n.
15677 + */
15678 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15679 +{
15680 + unsigned high = (unsigned)(i >> 32);
15681 + unsigned low = (unsigned)i;
15682 + alternative_atomic64(set, /* no output */,
15683 + "S" (v), "b" (low), "c" (high)
15684 + : "eax", "edx", "memory");
15685 +}
15686 +
15687 +/**
15688 * atomic64_read - read atomic64 variable
15689 * @v: pointer to type atomic64_t
15690 *
15691 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15692 }
15693
15694 /**
15695 + * atomic64_read_unchecked - read atomic64 variable
15696 + * @v: pointer to type atomic64_unchecked_t
15697 + *
15698 + * Atomically reads the value of @v and returns it.
15699 + */
15700 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15701 +{
15702 + long long r;
15703 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15704 + return r;
15705 + }
15706 +
15707 +/**
15708 * atomic64_add_return - add and return
15709 * @i: integer value to add
15710 * @v: pointer to type atomic64_t
15711 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15712 return i;
15713 }
15714
15715 +/**
15716 + * atomic64_add_return_unchecked - add and return
15717 + * @i: integer value to add
15718 + * @v: pointer to type atomic64_unchecked_t
15719 + *
15720 + * Atomically adds @i to @v and returns @i + *@v
15721 + */
15722 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15723 +{
15724 + alternative_atomic64(add_return_unchecked,
15725 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15726 + ASM_NO_INPUT_CLOBBER("memory"));
15727 + return i;
15728 +}
15729 +
15730 /*
15731 * Other variants with different arithmetic operators:
15732 */
15733 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15734 return a;
15735 }
15736
15737 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15738 +{
15739 + long long a;
15740 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15741 + "S" (v) : "memory", "ecx");
15742 + return a;
15743 +}
15744 +
15745 static inline long long atomic64_dec_return(atomic64_t *v)
15746 {
15747 long long a;
15748 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15749 }
15750
15751 /**
15752 + * atomic64_add_unchecked - add integer to atomic64 variable
15753 + * @i: integer value to add
15754 + * @v: pointer to type atomic64_unchecked_t
15755 + *
15756 + * Atomically adds @i to @v.
15757 + */
15758 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15759 +{
15760 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15761 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15762 + ASM_NO_INPUT_CLOBBER("memory"));
15763 + return i;
15764 +}
15765 +
15766 +/**
15767 * atomic64_sub - subtract the atomic64 variable
15768 * @i: integer value to subtract
15769 * @v: pointer to type atomic64_t
15770 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15771 index f8d273e..02f39f3 100644
15772 --- a/arch/x86/include/asm/atomic64_64.h
15773 +++ b/arch/x86/include/asm/atomic64_64.h
15774 @@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15775 }
15776
15777 /**
15778 + * atomic64_read_unchecked - read atomic64 variable
15779 + * @v: pointer of type atomic64_unchecked_t
15780 + *
15781 + * Atomically reads the value of @v.
15782 + * Doesn't imply a read memory barrier.
15783 + */
15784 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15785 +{
15786 + return ACCESS_ONCE((v)->counter);
15787 +}
15788 +
15789 +/**
15790 * atomic64_set - set atomic64 variable
15791 * @v: pointer to type atomic64_t
15792 * @i: required value
15793 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15794 }
15795
15796 /**
15797 + * atomic64_set_unchecked - set atomic64 variable
15798 + * @v: pointer to type atomic64_unchecked_t
15799 + * @i: required value
15800 + *
15801 + * Atomically sets the value of @v to @i.
15802 + */
15803 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15804 +{
15805 + v->counter = i;
15806 +}
15807 +
15808 +/**
15809 * atomic64_add - add integer to atomic64 variable
15810 * @i: integer value to add
15811 * @v: pointer to type atomic64_t
15812 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15813 */
15814 static inline void atomic64_add(long i, atomic64_t *v)
15815 {
15816 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15817 +
15818 +#ifdef CONFIG_PAX_REFCOUNT
15819 + "jno 0f\n"
15820 + LOCK_PREFIX "subq %1,%0\n"
15821 + "int $4\n0:\n"
15822 + _ASM_EXTABLE(0b, 0b)
15823 +#endif
15824 +
15825 + : "=m" (v->counter)
15826 + : "er" (i), "m" (v->counter));
15827 +}
15828 +
15829 +/**
15830 + * atomic64_add_unchecked - add integer to atomic64 variable
15831 + * @i: integer value to add
15832 + * @v: pointer to type atomic64_unchecked_t
15833 + *
15834 + * Atomically adds @i to @v.
15835 + */
15836 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15837 +{
15838 asm volatile(LOCK_PREFIX "addq %1,%0"
15839 : "=m" (v->counter)
15840 : "er" (i), "m" (v->counter));
15841 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15842 */
15843 static inline void atomic64_sub(long i, atomic64_t *v)
15844 {
15845 - asm volatile(LOCK_PREFIX "subq %1,%0"
15846 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15847 +
15848 +#ifdef CONFIG_PAX_REFCOUNT
15849 + "jno 0f\n"
15850 + LOCK_PREFIX "addq %1,%0\n"
15851 + "int $4\n0:\n"
15852 + _ASM_EXTABLE(0b, 0b)
15853 +#endif
15854 +
15855 + : "=m" (v->counter)
15856 + : "er" (i), "m" (v->counter));
15857 +}
15858 +
15859 +/**
15860 + * atomic64_sub_unchecked - subtract the atomic64 variable
15861 + * @i: integer value to subtract
15862 + * @v: pointer to type atomic64_unchecked_t
15863 + *
15864 + * Atomically subtracts @i from @v.
15865 + */
15866 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15867 +{
15868 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15869 : "=m" (v->counter)
15870 : "er" (i), "m" (v->counter));
15871 }
15872 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15873 */
15874 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15875 {
15876 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15877 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15878 }
15879
15880 /**
15881 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15882 */
15883 static inline void atomic64_inc(atomic64_t *v)
15884 {
15885 + asm volatile(LOCK_PREFIX "incq %0\n"
15886 +
15887 +#ifdef CONFIG_PAX_REFCOUNT
15888 + "jno 0f\n"
15889 + LOCK_PREFIX "decq %0\n"
15890 + "int $4\n0:\n"
15891 + _ASM_EXTABLE(0b, 0b)
15892 +#endif
15893 +
15894 + : "=m" (v->counter)
15895 + : "m" (v->counter));
15896 +}
15897 +
15898 +/**
15899 + * atomic64_inc_unchecked - increment atomic64 variable
15900 + * @v: pointer to type atomic64_unchecked_t
15901 + *
15902 + * Atomically increments @v by 1.
15903 + */
15904 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15905 +{
15906 asm volatile(LOCK_PREFIX "incq %0"
15907 : "=m" (v->counter)
15908 : "m" (v->counter));
15909 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15910 */
15911 static inline void atomic64_dec(atomic64_t *v)
15912 {
15913 - asm volatile(LOCK_PREFIX "decq %0"
15914 + asm volatile(LOCK_PREFIX "decq %0\n"
15915 +
15916 +#ifdef CONFIG_PAX_REFCOUNT
15917 + "jno 0f\n"
15918 + LOCK_PREFIX "incq %0\n"
15919 + "int $4\n0:\n"
15920 + _ASM_EXTABLE(0b, 0b)
15921 +#endif
15922 +
15923 + : "=m" (v->counter)
15924 + : "m" (v->counter));
15925 +}
15926 +
15927 +/**
15928 + * atomic64_dec_unchecked - decrement atomic64 variable
15929 + * @v: pointer to type atomic64_t
15930 + *
15931 + * Atomically decrements @v by 1.
15932 + */
15933 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15934 +{
15935 + asm volatile(LOCK_PREFIX "decq %0\n"
15936 : "=m" (v->counter)
15937 : "m" (v->counter));
15938 }
15939 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15940 */
15941 static inline int atomic64_dec_and_test(atomic64_t *v)
15942 {
15943 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15944 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15945 }
15946
15947 /**
15948 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15949 */
15950 static inline int atomic64_inc_and_test(atomic64_t *v)
15951 {
15952 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15953 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15954 }
15955
15956 /**
15957 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15958 */
15959 static inline int atomic64_add_negative(long i, atomic64_t *v)
15960 {
15961 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15962 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15963 }
15964
15965 /**
15966 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15967 */
15968 static inline long atomic64_add_return(long i, atomic64_t *v)
15969 {
15970 + return i + xadd_check_overflow(&v->counter, i);
15971 +}
15972 +
15973 +/**
15974 + * atomic64_add_return_unchecked - add and return
15975 + * @i: integer value to add
15976 + * @v: pointer to type atomic64_unchecked_t
15977 + *
15978 + * Atomically adds @i to @v and returns @i + @v
15979 + */
15980 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15981 +{
15982 return i + xadd(&v->counter, i);
15983 }
15984
15985 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15986 }
15987
15988 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15989 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15990 +{
15991 + return atomic64_add_return_unchecked(1, v);
15992 +}
15993 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15994
15995 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15996 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15997 return cmpxchg(&v->counter, old, new);
15998 }
15999
16000 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16001 +{
16002 + return cmpxchg(&v->counter, old, new);
16003 +}
16004 +
16005 static inline long atomic64_xchg(atomic64_t *v, long new)
16006 {
16007 return xchg(&v->counter, new);
16008 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16009 */
16010 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16011 {
16012 - long c, old;
16013 + long c, old, new;
16014 c = atomic64_read(v);
16015 for (;;) {
16016 - if (unlikely(c == (u)))
16017 + if (unlikely(c == u))
16018 break;
16019 - old = atomic64_cmpxchg((v), c, c + (a));
16020 +
16021 + asm volatile("add %2,%0\n"
16022 +
16023 +#ifdef CONFIG_PAX_REFCOUNT
16024 + "jno 0f\n"
16025 + "sub %2,%0\n"
16026 + "int $4\n0:\n"
16027 + _ASM_EXTABLE(0b, 0b)
16028 +#endif
16029 +
16030 + : "=r" (new)
16031 + : "0" (c), "ir" (a));
16032 +
16033 + old = atomic64_cmpxchg(v, c, new);
16034 if (likely(old == c))
16035 break;
16036 c = old;
16037 }
16038 - return c != (u);
16039 + return c != u;
16040 }
16041
16042 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16043 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16044 index 0f4460b..fa1ee19 100644
16045 --- a/arch/x86/include/asm/barrier.h
16046 +++ b/arch/x86/include/asm/barrier.h
16047 @@ -107,7 +107,7 @@
16048 do { \
16049 compiletime_assert_atomic_type(*p); \
16050 smp_mb(); \
16051 - ACCESS_ONCE(*p) = (v); \
16052 + ACCESS_ONCE_RW(*p) = (v); \
16053 } while (0)
16054
16055 #define smp_load_acquire(p) \
16056 @@ -124,7 +124,7 @@ do { \
16057 do { \
16058 compiletime_assert_atomic_type(*p); \
16059 barrier(); \
16060 - ACCESS_ONCE(*p) = (v); \
16061 + ACCESS_ONCE_RW(*p) = (v); \
16062 } while (0)
16063
16064 #define smp_load_acquire(p) \
16065 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16066 index cfe3b95..d01b118 100644
16067 --- a/arch/x86/include/asm/bitops.h
16068 +++ b/arch/x86/include/asm/bitops.h
16069 @@ -50,7 +50,7 @@
16070 * a mask operation on a byte.
16071 */
16072 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16073 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16074 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16075 #define CONST_MASK(nr) (1 << ((nr) & 7))
16076
16077 /**
16078 @@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16079 */
16080 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16081 {
16082 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16083 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16084 }
16085
16086 /**
16087 @@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16088 */
16089 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16090 {
16091 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16092 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16093 }
16094
16095 /**
16096 @@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16097 */
16098 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16099 {
16100 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16101 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16102 }
16103
16104 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16105 @@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16106 *
16107 * Undefined if no bit exists, so code should check against 0 first.
16108 */
16109 -static inline unsigned long __ffs(unsigned long word)
16110 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16111 {
16112 asm("rep; bsf %1,%0"
16113 : "=r" (word)
16114 @@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16115 *
16116 * Undefined if no zero exists, so code should check against ~0UL first.
16117 */
16118 -static inline unsigned long ffz(unsigned long word)
16119 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16120 {
16121 asm("rep; bsf %1,%0"
16122 : "=r" (word)
16123 @@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16124 *
16125 * Undefined if no set bit exists, so code should check against 0 first.
16126 */
16127 -static inline unsigned long __fls(unsigned long word)
16128 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16129 {
16130 asm("bsr %1,%0"
16131 : "=r" (word)
16132 @@ -434,7 +434,7 @@ static inline int ffs(int x)
16133 * set bit if value is nonzero. The last (most significant) bit is
16134 * at position 32.
16135 */
16136 -static inline int fls(int x)
16137 +static inline int __intentional_overflow(-1) fls(int x)
16138 {
16139 int r;
16140
16141 @@ -476,7 +476,7 @@ static inline int fls(int x)
16142 * at position 64.
16143 */
16144 #ifdef CONFIG_X86_64
16145 -static __always_inline int fls64(__u64 x)
16146 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16147 {
16148 int bitpos = -1;
16149 /*
16150 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16151 index 4fa687a..60f2d39 100644
16152 --- a/arch/x86/include/asm/boot.h
16153 +++ b/arch/x86/include/asm/boot.h
16154 @@ -6,10 +6,15 @@
16155 #include <uapi/asm/boot.h>
16156
16157 /* Physical address where kernel should be loaded. */
16158 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16159 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16160 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16161 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16162
16163 +#ifndef __ASSEMBLY__
16164 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16165 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16166 +#endif
16167 +
16168 /* Minimum kernel alignment, as a power of two */
16169 #ifdef CONFIG_X86_64
16170 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16171 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16172 index 48f99f1..d78ebf9 100644
16173 --- a/arch/x86/include/asm/cache.h
16174 +++ b/arch/x86/include/asm/cache.h
16175 @@ -5,12 +5,13 @@
16176
16177 /* L1 cache line size */
16178 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16179 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16180 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16181
16182 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16183 +#define __read_only __attribute__((__section__(".data..read_only")))
16184
16185 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16186 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16187 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16188
16189 #ifdef CONFIG_X86_VSMP
16190 #ifdef CONFIG_SMP
16191 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16192 index 9863ee3..4a1f8e1 100644
16193 --- a/arch/x86/include/asm/cacheflush.h
16194 +++ b/arch/x86/include/asm/cacheflush.h
16195 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16196 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16197
16198 if (pg_flags == _PGMT_DEFAULT)
16199 - return -1;
16200 + return ~0UL;
16201 else if (pg_flags == _PGMT_WC)
16202 return _PAGE_CACHE_WC;
16203 else if (pg_flags == _PGMT_UC_MINUS)
16204 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16205 index 76659b6..72b8439 100644
16206 --- a/arch/x86/include/asm/calling.h
16207 +++ b/arch/x86/include/asm/calling.h
16208 @@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16209 #define RSP 152
16210 #define SS 160
16211
16212 -#define ARGOFFSET R11
16213 -#define SWFRAME ORIG_RAX
16214 +#define ARGOFFSET R15
16215
16216 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16217 - subq $9*8+\addskip, %rsp
16218 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16219 - movq_cfi rdi, 8*8
16220 - movq_cfi rsi, 7*8
16221 - movq_cfi rdx, 6*8
16222 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16223 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16224 + movq_cfi rdi, RDI
16225 + movq_cfi rsi, RSI
16226 + movq_cfi rdx, RDX
16227
16228 .if \save_rcx
16229 - movq_cfi rcx, 5*8
16230 + movq_cfi rcx, RCX
16231 .endif
16232
16233 .if \rax_enosys
16234 - movq $-ENOSYS, 4*8(%rsp)
16235 + movq $-ENOSYS, RAX(%rsp)
16236 .else
16237 - movq_cfi rax, 4*8
16238 + movq_cfi rax, RAX
16239 .endif
16240
16241 .if \save_r891011
16242 - movq_cfi r8, 3*8
16243 - movq_cfi r9, 2*8
16244 - movq_cfi r10, 1*8
16245 - movq_cfi r11, 0*8
16246 + movq_cfi r8, R8
16247 + movq_cfi r9, R9
16248 + movq_cfi r10, R10
16249 + movq_cfi r11, R11
16250 .endif
16251
16252 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16253 + movq_cfi r12, R12
16254 +#endif
16255 +
16256 .endm
16257
16258 -#define ARG_SKIP (9*8)
16259 +#define ARG_SKIP ORIG_RAX
16260
16261 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16262 rstor_r8910=1, rstor_rdx=1
16263 +
16264 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16265 + movq_cfi_restore R12, r12
16266 +#endif
16267 +
16268 .if \rstor_r11
16269 - movq_cfi_restore 0*8, r11
16270 + movq_cfi_restore R11, r11
16271 .endif
16272
16273 .if \rstor_r8910
16274 - movq_cfi_restore 1*8, r10
16275 - movq_cfi_restore 2*8, r9
16276 - movq_cfi_restore 3*8, r8
16277 + movq_cfi_restore R10, r10
16278 + movq_cfi_restore R9, r9
16279 + movq_cfi_restore R8, r8
16280 .endif
16281
16282 .if \rstor_rax
16283 - movq_cfi_restore 4*8, rax
16284 + movq_cfi_restore RAX, rax
16285 .endif
16286
16287 .if \rstor_rcx
16288 - movq_cfi_restore 5*8, rcx
16289 + movq_cfi_restore RCX, rcx
16290 .endif
16291
16292 .if \rstor_rdx
16293 - movq_cfi_restore 6*8, rdx
16294 + movq_cfi_restore RDX, rdx
16295 .endif
16296
16297 - movq_cfi_restore 7*8, rsi
16298 - movq_cfi_restore 8*8, rdi
16299 + movq_cfi_restore RSI, rsi
16300 + movq_cfi_restore RDI, rdi
16301
16302 - .if ARG_SKIP+\addskip > 0
16303 - addq $ARG_SKIP+\addskip, %rsp
16304 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16305 + .if ORIG_RAX+\addskip > 0
16306 + addq $ORIG_RAX+\addskip, %rsp
16307 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16308 .endif
16309 .endm
16310
16311 - .macro LOAD_ARGS offset, skiprax=0
16312 - movq \offset(%rsp), %r11
16313 - movq \offset+8(%rsp), %r10
16314 - movq \offset+16(%rsp), %r9
16315 - movq \offset+24(%rsp), %r8
16316 - movq \offset+40(%rsp), %rcx
16317 - movq \offset+48(%rsp), %rdx
16318 - movq \offset+56(%rsp), %rsi
16319 - movq \offset+64(%rsp), %rdi
16320 + .macro LOAD_ARGS skiprax=0
16321 + movq R11(%rsp), %r11
16322 + movq R10(%rsp), %r10
16323 + movq R9(%rsp), %r9
16324 + movq R8(%rsp), %r8
16325 + movq RCX(%rsp), %rcx
16326 + movq RDX(%rsp), %rdx
16327 + movq RSI(%rsp), %rsi
16328 + movq RDI(%rsp), %rdi
16329 .if \skiprax
16330 .else
16331 - movq \offset+72(%rsp), %rax
16332 + movq ORIG_RAX(%rsp), %rax
16333 .endif
16334 .endm
16335
16336 -#define REST_SKIP (6*8)
16337 -
16338 .macro SAVE_REST
16339 - subq $REST_SKIP, %rsp
16340 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16341 - movq_cfi rbx, 5*8
16342 - movq_cfi rbp, 4*8
16343 - movq_cfi r12, 3*8
16344 - movq_cfi r13, 2*8
16345 - movq_cfi r14, 1*8
16346 - movq_cfi r15, 0*8
16347 + movq_cfi rbx, RBX
16348 + movq_cfi rbp, RBP
16349 +
16350 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16351 + movq_cfi r12, R12
16352 +#endif
16353 +
16354 + movq_cfi r13, R13
16355 + movq_cfi r14, R14
16356 + movq_cfi r15, R15
16357 .endm
16358
16359 .macro RESTORE_REST
16360 - movq_cfi_restore 0*8, r15
16361 - movq_cfi_restore 1*8, r14
16362 - movq_cfi_restore 2*8, r13
16363 - movq_cfi_restore 3*8, r12
16364 - movq_cfi_restore 4*8, rbp
16365 - movq_cfi_restore 5*8, rbx
16366 - addq $REST_SKIP, %rsp
16367 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16368 + movq_cfi_restore R15, r15
16369 + movq_cfi_restore R14, r14
16370 + movq_cfi_restore R13, r13
16371 +
16372 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16373 + movq_cfi_restore R12, r12
16374 +#endif
16375 +
16376 + movq_cfi_restore RBP, rbp
16377 + movq_cfi_restore RBX, rbx
16378 .endm
16379
16380 .macro SAVE_ALL
16381 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16382 index f50de69..2b0a458 100644
16383 --- a/arch/x86/include/asm/checksum_32.h
16384 +++ b/arch/x86/include/asm/checksum_32.h
16385 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16386 int len, __wsum sum,
16387 int *src_err_ptr, int *dst_err_ptr);
16388
16389 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16390 + int len, __wsum sum,
16391 + int *src_err_ptr, int *dst_err_ptr);
16392 +
16393 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16394 + int len, __wsum sum,
16395 + int *src_err_ptr, int *dst_err_ptr);
16396 +
16397 /*
16398 * Note: when you get a NULL pointer exception here this means someone
16399 * passed in an incorrect kernel address to one of these functions.
16400 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16401
16402 might_sleep();
16403 stac();
16404 - ret = csum_partial_copy_generic((__force void *)src, dst,
16405 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16406 len, sum, err_ptr, NULL);
16407 clac();
16408
16409 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16410 might_sleep();
16411 if (access_ok(VERIFY_WRITE, dst, len)) {
16412 stac();
16413 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16414 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16415 len, sum, NULL, err_ptr);
16416 clac();
16417 return ret;
16418 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16419 index 99c105d7..2f667ac 100644
16420 --- a/arch/x86/include/asm/cmpxchg.h
16421 +++ b/arch/x86/include/asm/cmpxchg.h
16422 @@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16423 __compiletime_error("Bad argument size for cmpxchg");
16424 extern void __xadd_wrong_size(void)
16425 __compiletime_error("Bad argument size for xadd");
16426 +extern void __xadd_check_overflow_wrong_size(void)
16427 + __compiletime_error("Bad argument size for xadd_check_overflow");
16428 extern void __add_wrong_size(void)
16429 __compiletime_error("Bad argument size for add");
16430 +extern void __add_check_overflow_wrong_size(void)
16431 + __compiletime_error("Bad argument size for add_check_overflow");
16432
16433 /*
16434 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16435 @@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16436 __ret; \
16437 })
16438
16439 +#ifdef CONFIG_PAX_REFCOUNT
16440 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16441 + ({ \
16442 + __typeof__ (*(ptr)) __ret = (arg); \
16443 + switch (sizeof(*(ptr))) { \
16444 + case __X86_CASE_L: \
16445 + asm volatile (lock #op "l %0, %1\n" \
16446 + "jno 0f\n" \
16447 + "mov %0,%1\n" \
16448 + "int $4\n0:\n" \
16449 + _ASM_EXTABLE(0b, 0b) \
16450 + : "+r" (__ret), "+m" (*(ptr)) \
16451 + : : "memory", "cc"); \
16452 + break; \
16453 + case __X86_CASE_Q: \
16454 + asm volatile (lock #op "q %q0, %1\n" \
16455 + "jno 0f\n" \
16456 + "mov %0,%1\n" \
16457 + "int $4\n0:\n" \
16458 + _ASM_EXTABLE(0b, 0b) \
16459 + : "+r" (__ret), "+m" (*(ptr)) \
16460 + : : "memory", "cc"); \
16461 + break; \
16462 + default: \
16463 + __ ## op ## _check_overflow_wrong_size(); \
16464 + } \
16465 + __ret; \
16466 + })
16467 +#else
16468 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16469 +#endif
16470 +
16471 /*
16472 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16473 * Since this is generally used to protect other memory information, we
16474 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16475 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16476 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16477
16478 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16479 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16480 +
16481 #define __add(ptr, inc, lock) \
16482 ({ \
16483 __typeof__ (*(ptr)) __ret = (inc); \
16484 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16485 index 59c6c40..5e0b22c 100644
16486 --- a/arch/x86/include/asm/compat.h
16487 +++ b/arch/x86/include/asm/compat.h
16488 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16489 typedef u32 compat_uint_t;
16490 typedef u32 compat_ulong_t;
16491 typedef u64 __attribute__((aligned(4))) compat_u64;
16492 -typedef u32 compat_uptr_t;
16493 +typedef u32 __user compat_uptr_t;
16494
16495 struct compat_timespec {
16496 compat_time_t tv_sec;
16497 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16498 index 0bb1335..8f1aec7 100644
16499 --- a/arch/x86/include/asm/cpufeature.h
16500 +++ b/arch/x86/include/asm/cpufeature.h
16501 @@ -207,7 +207,7 @@
16502 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16503 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16504 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16505 -
16506 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16507
16508 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16509 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16510 @@ -215,7 +215,7 @@
16511 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16512 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16513 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16514 -#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16515 +#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16516 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16517 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16518 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16519 @@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16520 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16521 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16522 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16523 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16524
16525 #if __GNUC__ >= 4
16526 extern void warn_pre_alternatives(void);
16527 @@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16528
16529 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16530 t_warn:
16531 - warn_pre_alternatives();
16532 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16533 + warn_pre_alternatives();
16534 return false;
16535 #endif
16536
16537 @@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16538 ".section .discard,\"aw\",@progbits\n"
16539 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16540 ".previous\n"
16541 - ".section .altinstr_replacement,\"ax\"\n"
16542 + ".section .altinstr_replacement,\"a\"\n"
16543 "3: movb $1,%0\n"
16544 "4:\n"
16545 ".previous\n"
16546 @@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16547 " .byte 2b - 1b\n" /* src len */
16548 " .byte 4f - 3f\n" /* repl len */
16549 ".previous\n"
16550 - ".section .altinstr_replacement,\"ax\"\n"
16551 + ".section .altinstr_replacement,\"a\"\n"
16552 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16553 "4:\n"
16554 ".previous\n"
16555 @@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16556 ".section .discard,\"aw\",@progbits\n"
16557 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16558 ".previous\n"
16559 - ".section .altinstr_replacement,\"ax\"\n"
16560 + ".section .altinstr_replacement,\"a\"\n"
16561 "3: movb $0,%0\n"
16562 "4:\n"
16563 ".previous\n"
16564 @@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16565 ".section .discard,\"aw\",@progbits\n"
16566 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16567 ".previous\n"
16568 - ".section .altinstr_replacement,\"ax\"\n"
16569 + ".section .altinstr_replacement,\"a\"\n"
16570 "5: movb $1,%0\n"
16571 "6:\n"
16572 ".previous\n"
16573 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16574 index a94b82e..59ecefa 100644
16575 --- a/arch/x86/include/asm/desc.h
16576 +++ b/arch/x86/include/asm/desc.h
16577 @@ -4,6 +4,7 @@
16578 #include <asm/desc_defs.h>
16579 #include <asm/ldt.h>
16580 #include <asm/mmu.h>
16581 +#include <asm/pgtable.h>
16582
16583 #include <linux/smp.h>
16584 #include <linux/percpu.h>
16585 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16586
16587 desc->type = (info->read_exec_only ^ 1) << 1;
16588 desc->type |= info->contents << 2;
16589 + desc->type |= info->seg_not_present ^ 1;
16590
16591 desc->s = 1;
16592 desc->dpl = 0x3;
16593 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16594 }
16595
16596 extern struct desc_ptr idt_descr;
16597 -extern gate_desc idt_table[];
16598 -extern struct desc_ptr debug_idt_descr;
16599 -extern gate_desc debug_idt_table[];
16600 -
16601 -struct gdt_page {
16602 - struct desc_struct gdt[GDT_ENTRIES];
16603 -} __attribute__((aligned(PAGE_SIZE)));
16604 -
16605 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16606 +extern gate_desc idt_table[IDT_ENTRIES];
16607 +extern const struct desc_ptr debug_idt_descr;
16608 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16609
16610 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16611 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16612 {
16613 - return per_cpu(gdt_page, cpu).gdt;
16614 + return cpu_gdt_table[cpu];
16615 }
16616
16617 #ifdef CONFIG_X86_64
16618 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16619 unsigned long base, unsigned dpl, unsigned flags,
16620 unsigned short seg)
16621 {
16622 - gate->a = (seg << 16) | (base & 0xffff);
16623 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16624 + gate->gate.offset_low = base;
16625 + gate->gate.seg = seg;
16626 + gate->gate.reserved = 0;
16627 + gate->gate.type = type;
16628 + gate->gate.s = 0;
16629 + gate->gate.dpl = dpl;
16630 + gate->gate.p = 1;
16631 + gate->gate.offset_high = base >> 16;
16632 }
16633
16634 #endif
16635 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16636
16637 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16638 {
16639 + pax_open_kernel();
16640 memcpy(&idt[entry], gate, sizeof(*gate));
16641 + pax_close_kernel();
16642 }
16643
16644 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16645 {
16646 + pax_open_kernel();
16647 memcpy(&ldt[entry], desc, 8);
16648 + pax_close_kernel();
16649 }
16650
16651 static inline void
16652 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16653 default: size = sizeof(*gdt); break;
16654 }
16655
16656 + pax_open_kernel();
16657 memcpy(&gdt[entry], desc, size);
16658 + pax_close_kernel();
16659 }
16660
16661 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16662 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16663
16664 static inline void native_load_tr_desc(void)
16665 {
16666 + pax_open_kernel();
16667 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16668 + pax_close_kernel();
16669 }
16670
16671 static inline void native_load_gdt(const struct desc_ptr *dtr)
16672 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16673 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16674 unsigned int i;
16675
16676 + pax_open_kernel();
16677 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16678 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16679 + pax_close_kernel();
16680 }
16681
16682 /* This intentionally ignores lm, since 32-bit apps don't have that field. */
16683 @@ -295,7 +308,7 @@ static inline void load_LDT(mm_context_t *pc)
16684 preempt_enable();
16685 }
16686
16687 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16688 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16689 {
16690 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16691 }
16692 @@ -319,7 +332,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16693 }
16694
16695 #ifdef CONFIG_X86_64
16696 -static inline void set_nmi_gate(int gate, void *addr)
16697 +static inline void set_nmi_gate(int gate, const void *addr)
16698 {
16699 gate_desc s;
16700
16701 @@ -329,14 +342,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16702 #endif
16703
16704 #ifdef CONFIG_TRACING
16705 -extern struct desc_ptr trace_idt_descr;
16706 -extern gate_desc trace_idt_table[];
16707 +extern const struct desc_ptr trace_idt_descr;
16708 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16709 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16710 {
16711 write_idt_entry(trace_idt_table, entry, gate);
16712 }
16713
16714 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16715 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16716 unsigned dpl, unsigned ist, unsigned seg)
16717 {
16718 gate_desc s;
16719 @@ -356,7 +369,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16720 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16721 #endif
16722
16723 -static inline void _set_gate(int gate, unsigned type, void *addr,
16724 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16725 unsigned dpl, unsigned ist, unsigned seg)
16726 {
16727 gate_desc s;
16728 @@ -379,9 +392,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16729 #define set_intr_gate(n, addr) \
16730 do { \
16731 BUG_ON((unsigned)n > 0xFF); \
16732 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16733 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16734 __KERNEL_CS); \
16735 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16736 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16737 0, 0, __KERNEL_CS); \
16738 } while (0)
16739
16740 @@ -409,19 +422,19 @@ static inline void alloc_system_vector(int vector)
16741 /*
16742 * This routine sets up an interrupt gate at directory privilege level 3.
16743 */
16744 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16745 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16746 {
16747 BUG_ON((unsigned)n > 0xFF);
16748 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16749 }
16750
16751 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16752 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16753 {
16754 BUG_ON((unsigned)n > 0xFF);
16755 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16756 }
16757
16758 -static inline void set_trap_gate(unsigned int n, void *addr)
16759 +static inline void set_trap_gate(unsigned int n, const void *addr)
16760 {
16761 BUG_ON((unsigned)n > 0xFF);
16762 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16763 @@ -430,16 +443,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16764 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16765 {
16766 BUG_ON((unsigned)n > 0xFF);
16767 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16768 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16769 }
16770
16771 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16772 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16773 {
16774 BUG_ON((unsigned)n > 0xFF);
16775 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16776 }
16777
16778 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16779 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16780 {
16781 BUG_ON((unsigned)n > 0xFF);
16782 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16783 @@ -511,4 +524,17 @@ static inline void load_current_idt(void)
16784 else
16785 load_idt((const struct desc_ptr *)&idt_descr);
16786 }
16787 +
16788 +#ifdef CONFIG_X86_32
16789 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16790 +{
16791 + struct desc_struct d;
16792 +
16793 + if (likely(limit))
16794 + limit = (limit - 1UL) >> PAGE_SHIFT;
16795 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16796 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16797 +}
16798 +#endif
16799 +
16800 #endif /* _ASM_X86_DESC_H */
16801 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16802 index 278441f..b95a174 100644
16803 --- a/arch/x86/include/asm/desc_defs.h
16804 +++ b/arch/x86/include/asm/desc_defs.h
16805 @@ -31,6 +31,12 @@ struct desc_struct {
16806 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16807 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16808 };
16809 + struct {
16810 + u16 offset_low;
16811 + u16 seg;
16812 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16813 + unsigned offset_high: 16;
16814 + } gate;
16815 };
16816 } __attribute__((packed));
16817
16818 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16819 index ced283a..ffe04cc 100644
16820 --- a/arch/x86/include/asm/div64.h
16821 +++ b/arch/x86/include/asm/div64.h
16822 @@ -39,7 +39,7 @@
16823 __mod; \
16824 })
16825
16826 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16827 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16828 {
16829 union {
16830 u64 v64;
16831 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16832 index ca3347a..1a5082a 100644
16833 --- a/arch/x86/include/asm/elf.h
16834 +++ b/arch/x86/include/asm/elf.h
16835 @@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16836
16837 #include <asm/vdso.h>
16838
16839 -#ifdef CONFIG_X86_64
16840 -extern unsigned int vdso64_enabled;
16841 -#endif
16842 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16843 extern unsigned int vdso32_enabled;
16844 #endif
16845 @@ -249,7 +246,25 @@ extern int force_personality32;
16846 the loader. We need to make sure that it is out of the way of the program
16847 that it will "exec", and that there is sufficient room for the brk. */
16848
16849 +#ifdef CONFIG_PAX_SEGMEXEC
16850 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16851 +#else
16852 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16853 +#endif
16854 +
16855 +#ifdef CONFIG_PAX_ASLR
16856 +#ifdef CONFIG_X86_32
16857 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16858 +
16859 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16860 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16861 +#else
16862 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16863 +
16864 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16865 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16866 +#endif
16867 +#endif
16868
16869 /* This yields a mask that user programs can use to figure out what
16870 instruction set this CPU supports. This could be done in user space,
16871 @@ -298,17 +313,13 @@ do { \
16872
16873 #define ARCH_DLINFO \
16874 do { \
16875 - if (vdso64_enabled) \
16876 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16877 - (unsigned long __force)current->mm->context.vdso); \
16878 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16879 } while (0)
16880
16881 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16882 #define ARCH_DLINFO_X32 \
16883 do { \
16884 - if (vdso64_enabled) \
16885 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16886 - (unsigned long __force)current->mm->context.vdso); \
16887 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16888 } while (0)
16889
16890 #define AT_SYSINFO 32
16891 @@ -323,10 +334,10 @@ else \
16892
16893 #endif /* !CONFIG_X86_32 */
16894
16895 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16896 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16897
16898 #define VDSO_ENTRY \
16899 - ((unsigned long)current->mm->context.vdso + \
16900 + (current->mm->context.vdso + \
16901 selected_vdso32->sym___kernel_vsyscall)
16902
16903 struct linux_binprm;
16904 @@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16905 int uses_interp);
16906 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16907
16908 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16909 -#define arch_randomize_brk arch_randomize_brk
16910 -
16911 /*
16912 * True on X86_32 or when emulating IA32 on X86_64
16913 */
16914 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16915 index 77a99ac..39ff7f5 100644
16916 --- a/arch/x86/include/asm/emergency-restart.h
16917 +++ b/arch/x86/include/asm/emergency-restart.h
16918 @@ -1,6 +1,6 @@
16919 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16920 #define _ASM_X86_EMERGENCY_RESTART_H
16921
16922 -extern void machine_emergency_restart(void);
16923 +extern void machine_emergency_restart(void) __noreturn;
16924
16925 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16926 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16927 index 1c7eefe..d0e4702 100644
16928 --- a/arch/x86/include/asm/floppy.h
16929 +++ b/arch/x86/include/asm/floppy.h
16930 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16931 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16932 } fd_routine[] = {
16933 {
16934 - request_dma,
16935 - free_dma,
16936 - get_dma_residue,
16937 - dma_mem_alloc,
16938 - hard_dma_setup
16939 + ._request_dma = request_dma,
16940 + ._free_dma = free_dma,
16941 + ._get_dma_residue = get_dma_residue,
16942 + ._dma_mem_alloc = dma_mem_alloc,
16943 + ._dma_setup = hard_dma_setup
16944 },
16945 {
16946 - vdma_request_dma,
16947 - vdma_nop,
16948 - vdma_get_dma_residue,
16949 - vdma_mem_alloc,
16950 - vdma_dma_setup
16951 + ._request_dma = vdma_request_dma,
16952 + ._free_dma = vdma_nop,
16953 + ._get_dma_residue = vdma_get_dma_residue,
16954 + ._dma_mem_alloc = vdma_mem_alloc,
16955 + ._dma_setup = vdma_dma_setup
16956 }
16957 };
16958
16959 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16960 index e97622f..d0ba77a 100644
16961 --- a/arch/x86/include/asm/fpu-internal.h
16962 +++ b/arch/x86/include/asm/fpu-internal.h
16963 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16964 #define user_insn(insn, output, input...) \
16965 ({ \
16966 int err; \
16967 + pax_open_userland(); \
16968 asm volatile(ASM_STAC "\n" \
16969 - "1:" #insn "\n\t" \
16970 + "1:" \
16971 + __copyuser_seg \
16972 + #insn "\n\t" \
16973 "2: " ASM_CLAC "\n" \
16974 ".section .fixup,\"ax\"\n" \
16975 "3: movl $-1,%[err]\n" \
16976 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16977 _ASM_EXTABLE(1b, 3b) \
16978 : [err] "=r" (err), output \
16979 : "0"(0), input); \
16980 + pax_close_userland(); \
16981 err; \
16982 })
16983
16984 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16985 "fnclex\n\t"
16986 "emms\n\t"
16987 "fildl %P[addr]" /* set F?P to defined value */
16988 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16989 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16990 }
16991
16992 return fpu_restore_checking(&tsk->thread.fpu);
16993 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16994 index b4c1f54..e290c08 100644
16995 --- a/arch/x86/include/asm/futex.h
16996 +++ b/arch/x86/include/asm/futex.h
16997 @@ -12,6 +12,7 @@
16998 #include <asm/smap.h>
16999
17000 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17001 + typecheck(u32 __user *, uaddr); \
17002 asm volatile("\t" ASM_STAC "\n" \
17003 "1:\t" insn "\n" \
17004 "2:\t" ASM_CLAC "\n" \
17005 @@ -20,15 +21,16 @@
17006 "\tjmp\t2b\n" \
17007 "\t.previous\n" \
17008 _ASM_EXTABLE(1b, 3b) \
17009 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17010 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17011 : "i" (-EFAULT), "0" (oparg), "1" (0))
17012
17013 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17014 + typecheck(u32 __user *, uaddr); \
17015 asm volatile("\t" ASM_STAC "\n" \
17016 "1:\tmovl %2, %0\n" \
17017 "\tmovl\t%0, %3\n" \
17018 "\t" insn "\n" \
17019 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17020 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17021 "\tjnz\t1b\n" \
17022 "3:\t" ASM_CLAC "\n" \
17023 "\t.section .fixup,\"ax\"\n" \
17024 @@ -38,7 +40,7 @@
17025 _ASM_EXTABLE(1b, 4b) \
17026 _ASM_EXTABLE(2b, 4b) \
17027 : "=&a" (oldval), "=&r" (ret), \
17028 - "+m" (*uaddr), "=&r" (tem) \
17029 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17030 : "r" (oparg), "i" (-EFAULT), "1" (0))
17031
17032 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17033 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17034
17035 pagefault_disable();
17036
17037 + pax_open_userland();
17038 switch (op) {
17039 case FUTEX_OP_SET:
17040 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17041 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17042 break;
17043 case FUTEX_OP_ADD:
17044 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17045 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17046 uaddr, oparg);
17047 break;
17048 case FUTEX_OP_OR:
17049 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17050 default:
17051 ret = -ENOSYS;
17052 }
17053 + pax_close_userland();
17054
17055 pagefault_enable();
17056
17057 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17058 index 4615906..788c817 100644
17059 --- a/arch/x86/include/asm/hw_irq.h
17060 +++ b/arch/x86/include/asm/hw_irq.h
17061 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17062 extern void enable_IO_APIC(void);
17063
17064 /* Statistics */
17065 -extern atomic_t irq_err_count;
17066 -extern atomic_t irq_mis_count;
17067 +extern atomic_unchecked_t irq_err_count;
17068 +extern atomic_unchecked_t irq_mis_count;
17069
17070 /* EISA */
17071 extern void eisa_set_level_irq(unsigned int irq);
17072 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17073 index ccffa53..3c90c87 100644
17074 --- a/arch/x86/include/asm/i8259.h
17075 +++ b/arch/x86/include/asm/i8259.h
17076 @@ -62,7 +62,7 @@ struct legacy_pic {
17077 void (*init)(int auto_eoi);
17078 int (*irq_pending)(unsigned int irq);
17079 void (*make_irq)(unsigned int irq);
17080 -};
17081 +} __do_const;
17082
17083 extern struct legacy_pic *legacy_pic;
17084 extern struct legacy_pic null_legacy_pic;
17085 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17086 index b8237d8..3e8864e 100644
17087 --- a/arch/x86/include/asm/io.h
17088 +++ b/arch/x86/include/asm/io.h
17089 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17090 "m" (*(volatile type __force *)addr) barrier); }
17091
17092 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17093 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17094 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17095 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17096 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17097
17098 build_mmio_read(__readb, "b", unsigned char, "=q", )
17099 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17100 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17101 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17102 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17103
17104 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17105 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17106 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17107 * this function
17108 */
17109
17110 -static inline phys_addr_t virt_to_phys(volatile void *address)
17111 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17112 {
17113 return __pa(address);
17114 }
17115 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17116 return ioremap_nocache(offset, size);
17117 }
17118
17119 -extern void iounmap(volatile void __iomem *addr);
17120 +extern void iounmap(const volatile void __iomem *addr);
17121
17122 extern void set_iounmap_nonlazy(void);
17123
17124 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17125
17126 #include <linux/vmalloc.h>
17127
17128 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17129 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17130 +{
17131 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17132 +}
17133 +
17134 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17135 +{
17136 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17137 +}
17138 +
17139 /*
17140 * Convert a virtual cached pointer to an uncached pointer
17141 */
17142 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17143 index 0a8b519..80e7d5b 100644
17144 --- a/arch/x86/include/asm/irqflags.h
17145 +++ b/arch/x86/include/asm/irqflags.h
17146 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17147 sti; \
17148 sysexit
17149
17150 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17151 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17152 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17153 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17154 +
17155 #else
17156 #define INTERRUPT_RETURN iret
17157 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17158 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17159 index 4421b5d..8543006 100644
17160 --- a/arch/x86/include/asm/kprobes.h
17161 +++ b/arch/x86/include/asm/kprobes.h
17162 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17163 #define RELATIVEJUMP_SIZE 5
17164 #define RELATIVECALL_OPCODE 0xe8
17165 #define RELATIVE_ADDR_SIZE 4
17166 -#define MAX_STACK_SIZE 64
17167 -#define MIN_STACK_SIZE(ADDR) \
17168 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17169 - THREAD_SIZE - (unsigned long)(ADDR))) \
17170 - ? (MAX_STACK_SIZE) \
17171 - : (((unsigned long)current_thread_info()) + \
17172 - THREAD_SIZE - (unsigned long)(ADDR)))
17173 +#define MAX_STACK_SIZE 64UL
17174 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17175
17176 #define flush_insn_slot(p) do { } while (0)
17177
17178 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17179 index 6ed0c30..74fb6c3 100644
17180 --- a/arch/x86/include/asm/kvm_host.h
17181 +++ b/arch/x86/include/asm/kvm_host.h
17182 @@ -51,6 +51,7 @@
17183 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17184
17185 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17186 +#define CR3_PCID_INVD (1UL << 63)
17187 #define CR4_RESERVED_BITS \
17188 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17189 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17190 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17191 index 4ad6560..75c7bdd 100644
17192 --- a/arch/x86/include/asm/local.h
17193 +++ b/arch/x86/include/asm/local.h
17194 @@ -10,33 +10,97 @@ typedef struct {
17195 atomic_long_t a;
17196 } local_t;
17197
17198 +typedef struct {
17199 + atomic_long_unchecked_t a;
17200 +} local_unchecked_t;
17201 +
17202 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17203
17204 #define local_read(l) atomic_long_read(&(l)->a)
17205 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17206 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17207 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17208
17209 static inline void local_inc(local_t *l)
17210 {
17211 - asm volatile(_ASM_INC "%0"
17212 + asm volatile(_ASM_INC "%0\n"
17213 +
17214 +#ifdef CONFIG_PAX_REFCOUNT
17215 + "jno 0f\n"
17216 + _ASM_DEC "%0\n"
17217 + "int $4\n0:\n"
17218 + _ASM_EXTABLE(0b, 0b)
17219 +#endif
17220 +
17221 + : "+m" (l->a.counter));
17222 +}
17223 +
17224 +static inline void local_inc_unchecked(local_unchecked_t *l)
17225 +{
17226 + asm volatile(_ASM_INC "%0\n"
17227 : "+m" (l->a.counter));
17228 }
17229
17230 static inline void local_dec(local_t *l)
17231 {
17232 - asm volatile(_ASM_DEC "%0"
17233 + asm volatile(_ASM_DEC "%0\n"
17234 +
17235 +#ifdef CONFIG_PAX_REFCOUNT
17236 + "jno 0f\n"
17237 + _ASM_INC "%0\n"
17238 + "int $4\n0:\n"
17239 + _ASM_EXTABLE(0b, 0b)
17240 +#endif
17241 +
17242 + : "+m" (l->a.counter));
17243 +}
17244 +
17245 +static inline void local_dec_unchecked(local_unchecked_t *l)
17246 +{
17247 + asm volatile(_ASM_DEC "%0\n"
17248 : "+m" (l->a.counter));
17249 }
17250
17251 static inline void local_add(long i, local_t *l)
17252 {
17253 - asm volatile(_ASM_ADD "%1,%0"
17254 + asm volatile(_ASM_ADD "%1,%0\n"
17255 +
17256 +#ifdef CONFIG_PAX_REFCOUNT
17257 + "jno 0f\n"
17258 + _ASM_SUB "%1,%0\n"
17259 + "int $4\n0:\n"
17260 + _ASM_EXTABLE(0b, 0b)
17261 +#endif
17262 +
17263 + : "+m" (l->a.counter)
17264 + : "ir" (i));
17265 +}
17266 +
17267 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17268 +{
17269 + asm volatile(_ASM_ADD "%1,%0\n"
17270 : "+m" (l->a.counter)
17271 : "ir" (i));
17272 }
17273
17274 static inline void local_sub(long i, local_t *l)
17275 {
17276 - asm volatile(_ASM_SUB "%1,%0"
17277 + asm volatile(_ASM_SUB "%1,%0\n"
17278 +
17279 +#ifdef CONFIG_PAX_REFCOUNT
17280 + "jno 0f\n"
17281 + _ASM_ADD "%1,%0\n"
17282 + "int $4\n0:\n"
17283 + _ASM_EXTABLE(0b, 0b)
17284 +#endif
17285 +
17286 + : "+m" (l->a.counter)
17287 + : "ir" (i));
17288 +}
17289 +
17290 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17291 +{
17292 + asm volatile(_ASM_SUB "%1,%0\n"
17293 : "+m" (l->a.counter)
17294 : "ir" (i));
17295 }
17296 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17297 */
17298 static inline int local_sub_and_test(long i, local_t *l)
17299 {
17300 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17301 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17302 }
17303
17304 /**
17305 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17306 */
17307 static inline int local_dec_and_test(local_t *l)
17308 {
17309 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17310 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17311 }
17312
17313 /**
17314 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17315 */
17316 static inline int local_inc_and_test(local_t *l)
17317 {
17318 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17319 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17320 }
17321
17322 /**
17323 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17324 */
17325 static inline int local_add_negative(long i, local_t *l)
17326 {
17327 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17328 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17329 }
17330
17331 /**
17332 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17333 static inline long local_add_return(long i, local_t *l)
17334 {
17335 long __i = i;
17336 + asm volatile(_ASM_XADD "%0, %1\n"
17337 +
17338 +#ifdef CONFIG_PAX_REFCOUNT
17339 + "jno 0f\n"
17340 + _ASM_MOV "%0,%1\n"
17341 + "int $4\n0:\n"
17342 + _ASM_EXTABLE(0b, 0b)
17343 +#endif
17344 +
17345 + : "+r" (i), "+m" (l->a.counter)
17346 + : : "memory");
17347 + return i + __i;
17348 +}
17349 +
17350 +/**
17351 + * local_add_return_unchecked - add and return
17352 + * @i: integer value to add
17353 + * @l: pointer to type local_unchecked_t
17354 + *
17355 + * Atomically adds @i to @l and returns @i + @l
17356 + */
17357 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17358 +{
17359 + long __i = i;
17360 asm volatile(_ASM_XADD "%0, %1;"
17361 : "+r" (i), "+m" (l->a.counter)
17362 : : "memory");
17363 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17364
17365 #define local_cmpxchg(l, o, n) \
17366 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17367 +#define local_cmpxchg_unchecked(l, o, n) \
17368 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17369 /* Always has a lock prefix */
17370 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17371
17372 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17373 new file mode 100644
17374 index 0000000..2bfd3ba
17375 --- /dev/null
17376 +++ b/arch/x86/include/asm/mman.h
17377 @@ -0,0 +1,15 @@
17378 +#ifndef _X86_MMAN_H
17379 +#define _X86_MMAN_H
17380 +
17381 +#include <uapi/asm/mman.h>
17382 +
17383 +#ifdef __KERNEL__
17384 +#ifndef __ASSEMBLY__
17385 +#ifdef CONFIG_X86_32
17386 +#define arch_mmap_check i386_mmap_check
17387 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17388 +#endif
17389 +#endif
17390 +#endif
17391 +
17392 +#endif /* X86_MMAN_H */
17393 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17394 index 876e74e..e20bfb1 100644
17395 --- a/arch/x86/include/asm/mmu.h
17396 +++ b/arch/x86/include/asm/mmu.h
17397 @@ -9,7 +9,7 @@
17398 * we put the segment information here.
17399 */
17400 typedef struct {
17401 - void *ldt;
17402 + struct desc_struct *ldt;
17403 int size;
17404
17405 #ifdef CONFIG_X86_64
17406 @@ -18,7 +18,19 @@ typedef struct {
17407 #endif
17408
17409 struct mutex lock;
17410 - void __user *vdso;
17411 + unsigned long vdso;
17412 +
17413 +#ifdef CONFIG_X86_32
17414 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17415 + unsigned long user_cs_base;
17416 + unsigned long user_cs_limit;
17417 +
17418 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17419 + cpumask_t cpu_user_cs_mask;
17420 +#endif
17421 +
17422 +#endif
17423 +#endif
17424 } mm_context_t;
17425
17426 #ifdef CONFIG_SMP
17427 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17428 index 166af2a..648c200 100644
17429 --- a/arch/x86/include/asm/mmu_context.h
17430 +++ b/arch/x86/include/asm/mmu_context.h
17431 @@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17432
17433 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17434 {
17435 +
17436 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17437 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17438 + unsigned int i;
17439 + pgd_t *pgd;
17440 +
17441 + pax_open_kernel();
17442 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17443 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17444 + set_pgd_batched(pgd+i, native_make_pgd(0));
17445 + pax_close_kernel();
17446 + }
17447 +#endif
17448 +
17449 #ifdef CONFIG_SMP
17450 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17451 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17452 @@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17453 struct task_struct *tsk)
17454 {
17455 unsigned cpu = smp_processor_id();
17456 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17457 + int tlbstate = TLBSTATE_OK;
17458 +#endif
17459
17460 if (likely(prev != next)) {
17461 #ifdef CONFIG_SMP
17462 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17463 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17464 +#endif
17465 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17466 this_cpu_write(cpu_tlbstate.active_mm, next);
17467 #endif
17468 cpumask_set_cpu(cpu, mm_cpumask(next));
17469
17470 /* Re-load page tables */
17471 +#ifdef CONFIG_PAX_PER_CPU_PGD
17472 + pax_open_kernel();
17473 +
17474 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17475 + if (static_cpu_has(X86_FEATURE_PCID))
17476 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17477 + else
17478 +#endif
17479 +
17480 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17481 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17482 + pax_close_kernel();
17483 + 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));
17484 +
17485 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17486 + if (static_cpu_has(X86_FEATURE_PCID)) {
17487 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17488 + u64 descriptor[2];
17489 + descriptor[0] = PCID_USER;
17490 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17491 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17492 + descriptor[0] = PCID_KERNEL;
17493 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17494 + }
17495 + } else {
17496 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17497 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17498 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17499 + else
17500 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17501 + }
17502 + } else
17503 +#endif
17504 +
17505 + load_cr3(get_cpu_pgd(cpu, kernel));
17506 +#else
17507 load_cr3(next->pgd);
17508 +#endif
17509 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17510
17511 /* Stop flush ipis for the previous mm */
17512 @@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17513 /* Load the LDT, if the LDT is different: */
17514 if (unlikely(prev->context.ldt != next->context.ldt))
17515 load_LDT_nolock(&next->context);
17516 +
17517 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17518 + if (!(__supported_pte_mask & _PAGE_NX)) {
17519 + smp_mb__before_atomic();
17520 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17521 + smp_mb__after_atomic();
17522 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17523 + }
17524 +#endif
17525 +
17526 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17527 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17528 + prev->context.user_cs_limit != next->context.user_cs_limit))
17529 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17530 +#ifdef CONFIG_SMP
17531 + else if (unlikely(tlbstate != TLBSTATE_OK))
17532 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17533 +#endif
17534 +#endif
17535 +
17536 }
17537 + else {
17538 +
17539 +#ifdef CONFIG_PAX_PER_CPU_PGD
17540 + pax_open_kernel();
17541 +
17542 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17543 + if (static_cpu_has(X86_FEATURE_PCID))
17544 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17545 + else
17546 +#endif
17547 +
17548 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17549 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17550 + pax_close_kernel();
17551 + 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));
17552 +
17553 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17554 + if (static_cpu_has(X86_FEATURE_PCID)) {
17555 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17556 + u64 descriptor[2];
17557 + descriptor[0] = PCID_USER;
17558 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17559 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17560 + descriptor[0] = PCID_KERNEL;
17561 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17562 + }
17563 + } else {
17564 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17565 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17566 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17567 + else
17568 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17569 + }
17570 + } else
17571 +#endif
17572 +
17573 + load_cr3(get_cpu_pgd(cpu, kernel));
17574 +#endif
17575 +
17576 #ifdef CONFIG_SMP
17577 - else {
17578 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17579 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17580
17581 @@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17582 * tlb flush IPI delivery. We must reload CR3
17583 * to make sure to use no freed page tables.
17584 */
17585 +
17586 +#ifndef CONFIG_PAX_PER_CPU_PGD
17587 load_cr3(next->pgd);
17588 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17589 +#endif
17590 +
17591 load_LDT_nolock(&next->context);
17592 +
17593 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17594 + if (!(__supported_pte_mask & _PAGE_NX))
17595 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17596 +#endif
17597 +
17598 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17599 +#ifdef CONFIG_PAX_PAGEEXEC
17600 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17601 +#endif
17602 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17603 +#endif
17604 +
17605 }
17606 +#endif
17607 }
17608 -#endif
17609 }
17610
17611 #define activate_mm(prev, next) \
17612 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17613 index e3b7819..b257c64 100644
17614 --- a/arch/x86/include/asm/module.h
17615 +++ b/arch/x86/include/asm/module.h
17616 @@ -5,6 +5,7 @@
17617
17618 #ifdef CONFIG_X86_64
17619 /* X86_64 does not define MODULE_PROC_FAMILY */
17620 +#define MODULE_PROC_FAMILY ""
17621 #elif defined CONFIG_M486
17622 #define MODULE_PROC_FAMILY "486 "
17623 #elif defined CONFIG_M586
17624 @@ -57,8 +58,20 @@
17625 #error unknown processor family
17626 #endif
17627
17628 -#ifdef CONFIG_X86_32
17629 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17630 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17631 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17632 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17633 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17634 +#else
17635 +#define MODULE_PAX_KERNEXEC ""
17636 #endif
17637
17638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17639 +#define MODULE_PAX_UDEREF "UDEREF "
17640 +#else
17641 +#define MODULE_PAX_UDEREF ""
17642 +#endif
17643 +
17644 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17645 +
17646 #endif /* _ASM_X86_MODULE_H */
17647 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17648 index 5f2fc44..106caa6 100644
17649 --- a/arch/x86/include/asm/nmi.h
17650 +++ b/arch/x86/include/asm/nmi.h
17651 @@ -36,26 +36,35 @@ enum {
17652
17653 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17654
17655 +struct nmiaction;
17656 +
17657 +struct nmiwork {
17658 + const struct nmiaction *action;
17659 + u64 max_duration;
17660 + struct irq_work irq_work;
17661 +};
17662 +
17663 struct nmiaction {
17664 struct list_head list;
17665 nmi_handler_t handler;
17666 - u64 max_duration;
17667 - struct irq_work irq_work;
17668 unsigned long flags;
17669 const char *name;
17670 -};
17671 + struct nmiwork *work;
17672 +} __do_const;
17673
17674 #define register_nmi_handler(t, fn, fg, n, init...) \
17675 ({ \
17676 - static struct nmiaction init fn##_na = { \
17677 + static struct nmiwork fn##_nw; \
17678 + static const struct nmiaction init fn##_na = { \
17679 .handler = (fn), \
17680 .name = (n), \
17681 .flags = (fg), \
17682 + .work = &fn##_nw, \
17683 }; \
17684 __register_nmi_handler((t), &fn##_na); \
17685 })
17686
17687 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17688 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17689
17690 void unregister_nmi_handler(unsigned int, const char *);
17691
17692 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17693 index 802dde3..9183e68 100644
17694 --- a/arch/x86/include/asm/page.h
17695 +++ b/arch/x86/include/asm/page.h
17696 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17697 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17698
17699 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17700 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17701
17702 #define __boot_va(x) __va(x)
17703 #define __boot_pa(x) __pa(x)
17704 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17705 * virt_to_page(kaddr) returns a valid pointer if and only if
17706 * virt_addr_valid(kaddr) returns true.
17707 */
17708 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17709 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17710 extern bool __virt_addr_valid(unsigned long kaddr);
17711 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17712
17713 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17714 +#define virt_to_page(kaddr) \
17715 + ({ \
17716 + const void *__kaddr = (const void *)(kaddr); \
17717 + BUG_ON(!virt_addr_valid(__kaddr)); \
17718 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17719 + })
17720 +#else
17721 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17722 +#endif
17723 +
17724 #endif /* __ASSEMBLY__ */
17725
17726 #include <asm-generic/memory_model.h>
17727 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17728 index f408caf..4a0455e 100644
17729 --- a/arch/x86/include/asm/page_64.h
17730 +++ b/arch/x86/include/asm/page_64.h
17731 @@ -7,9 +7,9 @@
17732
17733 /* duplicated to the one in bootmem.h */
17734 extern unsigned long max_pfn;
17735 -extern unsigned long phys_base;
17736 +extern const unsigned long phys_base;
17737
17738 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17739 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17740 {
17741 unsigned long y = x - __START_KERNEL_map;
17742
17743 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17744 index cd6e1610..70f4418 100644
17745 --- a/arch/x86/include/asm/paravirt.h
17746 +++ b/arch/x86/include/asm/paravirt.h
17747 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17748 return (pmd_t) { ret };
17749 }
17750
17751 -static inline pmdval_t pmd_val(pmd_t pmd)
17752 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17753 {
17754 pmdval_t ret;
17755
17756 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17757 val);
17758 }
17759
17760 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17761 +{
17762 + pgdval_t val = native_pgd_val(pgd);
17763 +
17764 + if (sizeof(pgdval_t) > sizeof(long))
17765 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17766 + val, (u64)val >> 32);
17767 + else
17768 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17769 + val);
17770 +}
17771 +
17772 static inline void pgd_clear(pgd_t *pgdp)
17773 {
17774 set_pgd(pgdp, __pgd(0));
17775 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17776 pv_mmu_ops.set_fixmap(idx, phys, flags);
17777 }
17778
17779 +#ifdef CONFIG_PAX_KERNEXEC
17780 +static inline unsigned long pax_open_kernel(void)
17781 +{
17782 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17783 +}
17784 +
17785 +static inline unsigned long pax_close_kernel(void)
17786 +{
17787 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17788 +}
17789 +#else
17790 +static inline unsigned long pax_open_kernel(void) { return 0; }
17791 +static inline unsigned long pax_close_kernel(void) { return 0; }
17792 +#endif
17793 +
17794 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17795
17796 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17797 @@ -906,7 +933,7 @@ extern void default_banner(void);
17798
17799 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17800 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17801 -#define PARA_INDIRECT(addr) *%cs:addr
17802 +#define PARA_INDIRECT(addr) *%ss:addr
17803 #endif
17804
17805 #define INTERRUPT_RETURN \
17806 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17807 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17808 CLBR_NONE, \
17809 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17810 +
17811 +#define GET_CR0_INTO_RDI \
17812 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17813 + mov %rax,%rdi
17814 +
17815 +#define SET_RDI_INTO_CR0 \
17816 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17817 +
17818 +#define GET_CR3_INTO_RDI \
17819 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17820 + mov %rax,%rdi
17821 +
17822 +#define SET_RDI_INTO_CR3 \
17823 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17824 +
17825 #endif /* CONFIG_X86_32 */
17826
17827 #endif /* __ASSEMBLY__ */
17828 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17829 index 7549b8b..f0edfda 100644
17830 --- a/arch/x86/include/asm/paravirt_types.h
17831 +++ b/arch/x86/include/asm/paravirt_types.h
17832 @@ -84,7 +84,7 @@ struct pv_init_ops {
17833 */
17834 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17835 unsigned long addr, unsigned len);
17836 -};
17837 +} __no_const __no_randomize_layout;
17838
17839
17840 struct pv_lazy_ops {
17841 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17842 void (*enter)(void);
17843 void (*leave)(void);
17844 void (*flush)(void);
17845 -};
17846 +} __no_randomize_layout;
17847
17848 struct pv_time_ops {
17849 unsigned long long (*sched_clock)(void);
17850 unsigned long long (*steal_clock)(int cpu);
17851 unsigned long (*get_tsc_khz)(void);
17852 -};
17853 +} __no_const __no_randomize_layout;
17854
17855 struct pv_cpu_ops {
17856 /* hooks for various privileged instructions */
17857 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17858
17859 void (*start_context_switch)(struct task_struct *prev);
17860 void (*end_context_switch)(struct task_struct *next);
17861 -};
17862 +} __no_const __no_randomize_layout;
17863
17864 struct pv_irq_ops {
17865 /*
17866 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17867 #ifdef CONFIG_X86_64
17868 void (*adjust_exception_frame)(void);
17869 #endif
17870 -};
17871 +} __no_randomize_layout;
17872
17873 struct pv_apic_ops {
17874 #ifdef CONFIG_X86_LOCAL_APIC
17875 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17876 unsigned long start_eip,
17877 unsigned long start_esp);
17878 #endif
17879 -};
17880 +} __no_const __no_randomize_layout;
17881
17882 struct pv_mmu_ops {
17883 unsigned long (*read_cr2)(void);
17884 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17885 struct paravirt_callee_save make_pud;
17886
17887 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17888 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17889 #endif /* PAGETABLE_LEVELS == 4 */
17890 #endif /* PAGETABLE_LEVELS >= 3 */
17891
17892 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17893 an mfn. We can tell which is which from the index. */
17894 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17895 phys_addr_t phys, pgprot_t flags);
17896 -};
17897 +
17898 +#ifdef CONFIG_PAX_KERNEXEC
17899 + unsigned long (*pax_open_kernel)(void);
17900 + unsigned long (*pax_close_kernel)(void);
17901 +#endif
17902 +
17903 +} __no_randomize_layout;
17904
17905 struct arch_spinlock;
17906 #ifdef CONFIG_SMP
17907 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17908 struct pv_lock_ops {
17909 struct paravirt_callee_save lock_spinning;
17910 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17911 -};
17912 +} __no_randomize_layout;
17913
17914 /* This contains all the paravirt structures: we get a convenient
17915 * number for each function using the offset which we use to indicate
17916 - * what to patch. */
17917 + * what to patch.
17918 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17919 + */
17920 +
17921 struct paravirt_patch_template {
17922 struct pv_init_ops pv_init_ops;
17923 struct pv_time_ops pv_time_ops;
17924 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17925 struct pv_apic_ops pv_apic_ops;
17926 struct pv_mmu_ops pv_mmu_ops;
17927 struct pv_lock_ops pv_lock_ops;
17928 -};
17929 +} __no_randomize_layout;
17930
17931 extern struct pv_info pv_info;
17932 extern struct pv_init_ops pv_init_ops;
17933 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17934 index c4412e9..90e88c5 100644
17935 --- a/arch/x86/include/asm/pgalloc.h
17936 +++ b/arch/x86/include/asm/pgalloc.h
17937 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17938 pmd_t *pmd, pte_t *pte)
17939 {
17940 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17941 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17942 +}
17943 +
17944 +static inline void pmd_populate_user(struct mm_struct *mm,
17945 + pmd_t *pmd, pte_t *pte)
17946 +{
17947 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17948 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17949 }
17950
17951 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17952
17953 #ifdef CONFIG_X86_PAE
17954 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17955 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17956 +{
17957 + pud_populate(mm, pudp, pmd);
17958 +}
17959 #else /* !CONFIG_X86_PAE */
17960 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17961 {
17962 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17963 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17964 }
17965 +
17966 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17967 +{
17968 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17969 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17970 +}
17971 #endif /* CONFIG_X86_PAE */
17972
17973 #if PAGETABLE_LEVELS > 3
17974 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17975 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17976 }
17977
17978 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17979 +{
17980 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17981 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17982 +}
17983 +
17984 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17985 {
17986 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17987 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17988 index 206a87f..1623b06 100644
17989 --- a/arch/x86/include/asm/pgtable-2level.h
17990 +++ b/arch/x86/include/asm/pgtable-2level.h
17991 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17992
17993 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17994 {
17995 + pax_open_kernel();
17996 *pmdp = pmd;
17997 + pax_close_kernel();
17998 }
17999
18000 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18001 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18002 index 81bb91b..9392125 100644
18003 --- a/arch/x86/include/asm/pgtable-3level.h
18004 +++ b/arch/x86/include/asm/pgtable-3level.h
18005 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18006
18007 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18008 {
18009 + pax_open_kernel();
18010 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18011 + pax_close_kernel();
18012 }
18013
18014 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18015 {
18016 + pax_open_kernel();
18017 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18018 + pax_close_kernel();
18019 }
18020
18021 /*
18022 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18023 index aa97a07..5c53c32 100644
18024 --- a/arch/x86/include/asm/pgtable.h
18025 +++ b/arch/x86/include/asm/pgtable.h
18026 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18027
18028 #ifndef __PAGETABLE_PUD_FOLDED
18029 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18030 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18031 #define pgd_clear(pgd) native_pgd_clear(pgd)
18032 #endif
18033
18034 @@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18035
18036 #define arch_end_context_switch(prev) do {} while(0)
18037
18038 +#define pax_open_kernel() native_pax_open_kernel()
18039 +#define pax_close_kernel() native_pax_close_kernel()
18040 #endif /* CONFIG_PARAVIRT */
18041
18042 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
18043 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18044 +
18045 +#ifdef CONFIG_PAX_KERNEXEC
18046 +static inline unsigned long native_pax_open_kernel(void)
18047 +{
18048 + unsigned long cr0;
18049 +
18050 + preempt_disable();
18051 + barrier();
18052 + cr0 = read_cr0() ^ X86_CR0_WP;
18053 + BUG_ON(cr0 & X86_CR0_WP);
18054 + write_cr0(cr0);
18055 + barrier();
18056 + return cr0 ^ X86_CR0_WP;
18057 +}
18058 +
18059 +static inline unsigned long native_pax_close_kernel(void)
18060 +{
18061 + unsigned long cr0;
18062 +
18063 + barrier();
18064 + cr0 = read_cr0() ^ X86_CR0_WP;
18065 + BUG_ON(!(cr0 & X86_CR0_WP));
18066 + write_cr0(cr0);
18067 + barrier();
18068 + preempt_enable_no_resched();
18069 + return cr0 ^ X86_CR0_WP;
18070 +}
18071 +#else
18072 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
18073 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
18074 +#endif
18075 +
18076 /*
18077 * The following only work if pte_present() is true.
18078 * Undefined behaviour if not..
18079 */
18080 +static inline int pte_user(pte_t pte)
18081 +{
18082 + return pte_val(pte) & _PAGE_USER;
18083 +}
18084 +
18085 static inline int pte_dirty(pte_t pte)
18086 {
18087 return pte_flags(pte) & _PAGE_DIRTY;
18088 @@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18089 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18090 }
18091
18092 +static inline unsigned long pgd_pfn(pgd_t pgd)
18093 +{
18094 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18095 +}
18096 +
18097 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18098
18099 static inline int pmd_large(pmd_t pte)
18100 @@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18101 return pte_clear_flags(pte, _PAGE_RW);
18102 }
18103
18104 +static inline pte_t pte_mkread(pte_t pte)
18105 +{
18106 + return __pte(pte_val(pte) | _PAGE_USER);
18107 +}
18108 +
18109 static inline pte_t pte_mkexec(pte_t pte)
18110 {
18111 - return pte_clear_flags(pte, _PAGE_NX);
18112 +#ifdef CONFIG_X86_PAE
18113 + if (__supported_pte_mask & _PAGE_NX)
18114 + return pte_clear_flags(pte, _PAGE_NX);
18115 + else
18116 +#endif
18117 + return pte_set_flags(pte, _PAGE_USER);
18118 +}
18119 +
18120 +static inline pte_t pte_exprotect(pte_t pte)
18121 +{
18122 +#ifdef CONFIG_X86_PAE
18123 + if (__supported_pte_mask & _PAGE_NX)
18124 + return pte_set_flags(pte, _PAGE_NX);
18125 + else
18126 +#endif
18127 + return pte_clear_flags(pte, _PAGE_USER);
18128 }
18129
18130 static inline pte_t pte_mkdirty(pte_t pte)
18131 @@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18132 #endif
18133
18134 #ifndef __ASSEMBLY__
18135 +
18136 +#ifdef CONFIG_PAX_PER_CPU_PGD
18137 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18138 +enum cpu_pgd_type {kernel = 0, user = 1};
18139 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18140 +{
18141 + return cpu_pgd[cpu][type];
18142 +}
18143 +#endif
18144 +
18145 #include <linux/mm_types.h>
18146 #include <linux/mmdebug.h>
18147 #include <linux/log2.h>
18148 @@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18149 * Currently stuck as a macro due to indirect forward reference to
18150 * linux/mmzone.h's __section_mem_map_addr() definition:
18151 */
18152 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18153 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18154
18155 /* Find an entry in the second-level page table.. */
18156 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18157 @@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18158 * Currently stuck as a macro due to indirect forward reference to
18159 * linux/mmzone.h's __section_mem_map_addr() definition:
18160 */
18161 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18162 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18163
18164 /* to find an entry in a page-table-directory. */
18165 static inline unsigned long pud_index(unsigned long address)
18166 @@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18167
18168 static inline int pgd_bad(pgd_t pgd)
18169 {
18170 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18171 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18172 }
18173
18174 static inline int pgd_none(pgd_t pgd)
18175 @@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18176 * pgd_offset() returns a (pgd_t *)
18177 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18178 */
18179 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18180 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18181 +
18182 +#ifdef CONFIG_PAX_PER_CPU_PGD
18183 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18184 +#endif
18185 +
18186 /*
18187 * a shortcut which implies the use of the kernel's pgd, instead
18188 * of a process's
18189 @@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18190 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18191 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18192
18193 +#ifdef CONFIG_X86_32
18194 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18195 +#else
18196 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18197 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18198 +
18199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18200 +#ifdef __ASSEMBLY__
18201 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18202 +#else
18203 +extern unsigned long pax_user_shadow_base;
18204 +extern pgdval_t clone_pgd_mask;
18205 +#endif
18206 +#endif
18207 +
18208 +#endif
18209 +
18210 #ifndef __ASSEMBLY__
18211
18212 extern int direct_gbpages;
18213 @@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18214 * dst and src can be on the same page, but the range must not overlap,
18215 * and must not cross a page boundary.
18216 */
18217 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18218 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18219 {
18220 - memcpy(dst, src, count * sizeof(pgd_t));
18221 + pax_open_kernel();
18222 + while (count--)
18223 + *dst++ = *src++;
18224 + pax_close_kernel();
18225 }
18226
18227 +#ifdef CONFIG_PAX_PER_CPU_PGD
18228 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18229 +#endif
18230 +
18231 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18232 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18233 +#else
18234 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18235 +#endif
18236 +
18237 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18238 static inline int page_level_shift(enum pg_level level)
18239 {
18240 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18241 index b6c0b40..3535d47 100644
18242 --- a/arch/x86/include/asm/pgtable_32.h
18243 +++ b/arch/x86/include/asm/pgtable_32.h
18244 @@ -25,9 +25,6 @@
18245 struct mm_struct;
18246 struct vm_area_struct;
18247
18248 -extern pgd_t swapper_pg_dir[1024];
18249 -extern pgd_t initial_page_table[1024];
18250 -
18251 static inline void pgtable_cache_init(void) { }
18252 static inline void check_pgt_cache(void) { }
18253 void paging_init(void);
18254 @@ -45,6 +42,12 @@ void paging_init(void);
18255 # include <asm/pgtable-2level.h>
18256 #endif
18257
18258 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18259 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18260 +#ifdef CONFIG_X86_PAE
18261 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18262 +#endif
18263 +
18264 #if defined(CONFIG_HIGHPTE)
18265 #define pte_offset_map(dir, address) \
18266 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18267 @@ -59,12 +62,17 @@ void paging_init(void);
18268 /* Clear a kernel PTE and flush it from the TLB */
18269 #define kpte_clear_flush(ptep, vaddr) \
18270 do { \
18271 + pax_open_kernel(); \
18272 pte_clear(&init_mm, (vaddr), (ptep)); \
18273 + pax_close_kernel(); \
18274 __flush_tlb_one((vaddr)); \
18275 } while (0)
18276
18277 #endif /* !__ASSEMBLY__ */
18278
18279 +#define HAVE_ARCH_UNMAPPED_AREA
18280 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18281 +
18282 /*
18283 * kern_addr_valid() is (1) for FLATMEM and (0) for
18284 * SPARSEMEM and DISCONTIGMEM
18285 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18286 index ed5903b..c7fe163 100644
18287 --- a/arch/x86/include/asm/pgtable_32_types.h
18288 +++ b/arch/x86/include/asm/pgtable_32_types.h
18289 @@ -8,7 +8,7 @@
18290 */
18291 #ifdef CONFIG_X86_PAE
18292 # include <asm/pgtable-3level_types.h>
18293 -# define PMD_SIZE (1UL << PMD_SHIFT)
18294 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18295 # define PMD_MASK (~(PMD_SIZE - 1))
18296 #else
18297 # include <asm/pgtable-2level_types.h>
18298 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18299 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18300 #endif
18301
18302 +#ifdef CONFIG_PAX_KERNEXEC
18303 +#ifndef __ASSEMBLY__
18304 +extern unsigned char MODULES_EXEC_VADDR[];
18305 +extern unsigned char MODULES_EXEC_END[];
18306 +#endif
18307 +#include <asm/boot.h>
18308 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18309 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18310 +#else
18311 +#define ktla_ktva(addr) (addr)
18312 +#define ktva_ktla(addr) (addr)
18313 +#endif
18314 +
18315 #define MODULES_VADDR VMALLOC_START
18316 #define MODULES_END VMALLOC_END
18317 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18318 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18319 index 4572b2f..4430113 100644
18320 --- a/arch/x86/include/asm/pgtable_64.h
18321 +++ b/arch/x86/include/asm/pgtable_64.h
18322 @@ -16,11 +16,16 @@
18323
18324 extern pud_t level3_kernel_pgt[512];
18325 extern pud_t level3_ident_pgt[512];
18326 +extern pud_t level3_vmalloc_start_pgt[512];
18327 +extern pud_t level3_vmalloc_end_pgt[512];
18328 +extern pud_t level3_vmemmap_pgt[512];
18329 +extern pud_t level2_vmemmap_pgt[512];
18330 extern pmd_t level2_kernel_pgt[512];
18331 extern pmd_t level2_fixmap_pgt[512];
18332 -extern pmd_t level2_ident_pgt[512];
18333 +extern pmd_t level2_ident_pgt[512*2];
18334 extern pte_t level1_fixmap_pgt[512];
18335 -extern pgd_t init_level4_pgt[];
18336 +extern pte_t level1_vsyscall_pgt[512];
18337 +extern pgd_t init_level4_pgt[512];
18338
18339 #define swapper_pg_dir init_level4_pgt
18340
18341 @@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18342
18343 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18344 {
18345 + pax_open_kernel();
18346 *pmdp = pmd;
18347 + pax_close_kernel();
18348 }
18349
18350 static inline void native_pmd_clear(pmd_t *pmd)
18351 @@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18352
18353 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18354 {
18355 + pax_open_kernel();
18356 *pudp = pud;
18357 + pax_close_kernel();
18358 }
18359
18360 static inline void native_pud_clear(pud_t *pud)
18361 @@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18362
18363 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18364 {
18365 + pax_open_kernel();
18366 + *pgdp = pgd;
18367 + pax_close_kernel();
18368 +}
18369 +
18370 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18371 +{
18372 *pgdp = pgd;
18373 }
18374
18375 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18376 index 7166e25..baaa6fe 100644
18377 --- a/arch/x86/include/asm/pgtable_64_types.h
18378 +++ b/arch/x86/include/asm/pgtable_64_types.h
18379 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18380 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18381 #define MODULES_END _AC(0xffffffffff000000, UL)
18382 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18383 +#define MODULES_EXEC_VADDR MODULES_VADDR
18384 +#define MODULES_EXEC_END MODULES_END
18385 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18386 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18387
18388 +#define ktla_ktva(addr) (addr)
18389 +#define ktva_ktla(addr) (addr)
18390 +
18391 #define EARLY_DYNAMIC_PAGE_TABLES 64
18392
18393 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18394 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18395 index 0778964..0e94758 100644
18396 --- a/arch/x86/include/asm/pgtable_types.h
18397 +++ b/arch/x86/include/asm/pgtable_types.h
18398 @@ -110,8 +110,10 @@
18399
18400 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18401 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18402 -#else
18403 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18404 #define _PAGE_NX (_AT(pteval_t, 0))
18405 +#else
18406 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18407 #endif
18408
18409 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18410 @@ -150,6 +152,9 @@
18411 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18412 _PAGE_ACCESSED)
18413
18414 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18415 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18416 +
18417 #define __PAGE_KERNEL_EXEC \
18418 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18419 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18420 @@ -160,7 +165,7 @@
18421 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18422 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18423 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18424 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18425 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18426 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18427 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18428 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18429 @@ -217,7 +222,7 @@
18430 #ifdef CONFIG_X86_64
18431 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18432 #else
18433 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18434 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18435 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18436 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18437 #endif
18438 @@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18439 {
18440 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18441 }
18442 +#endif
18443
18444 +#if PAGETABLE_LEVELS == 3
18445 +#include <asm-generic/pgtable-nopud.h>
18446 +#endif
18447 +
18448 +#if PAGETABLE_LEVELS == 2
18449 +#include <asm-generic/pgtable-nopmd.h>
18450 +#endif
18451 +
18452 +#ifndef __ASSEMBLY__
18453 #if PAGETABLE_LEVELS > 3
18454 typedef struct { pudval_t pud; } pud_t;
18455
18456 @@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18457 return pud.pud;
18458 }
18459 #else
18460 -#include <asm-generic/pgtable-nopud.h>
18461 -
18462 static inline pudval_t native_pud_val(pud_t pud)
18463 {
18464 return native_pgd_val(pud.pgd);
18465 @@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18466 return pmd.pmd;
18467 }
18468 #else
18469 -#include <asm-generic/pgtable-nopmd.h>
18470 -
18471 static inline pmdval_t native_pmd_val(pmd_t pmd)
18472 {
18473 return native_pgd_val(pmd.pud.pgd);
18474 @@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18475
18476 extern pteval_t __supported_pte_mask;
18477 extern void set_nx(void);
18478 -extern int nx_enabled;
18479
18480 #define pgprot_writecombine pgprot_writecombine
18481 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18482 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18483 index 4008734..48f0d81 100644
18484 --- a/arch/x86/include/asm/preempt.h
18485 +++ b/arch/x86/include/asm/preempt.h
18486 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18487 */
18488 static __always_inline bool __preempt_count_dec_and_test(void)
18489 {
18490 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18491 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18492 }
18493
18494 /*
18495 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18496 index eb71ec7..f06532a 100644
18497 --- a/arch/x86/include/asm/processor.h
18498 +++ b/arch/x86/include/asm/processor.h
18499 @@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18500 /* Index into per_cpu list: */
18501 u16 cpu_index;
18502 u32 microcode;
18503 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18504 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18505
18506 #define X86_VENDOR_INTEL 0
18507 #define X86_VENDOR_CYRIX 1
18508 @@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18509 : "memory");
18510 }
18511
18512 +/* invpcid (%rdx),%rax */
18513 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18514 +
18515 +#define INVPCID_SINGLE_ADDRESS 0UL
18516 +#define INVPCID_SINGLE_CONTEXT 1UL
18517 +#define INVPCID_ALL_GLOBAL 2UL
18518 +#define INVPCID_ALL_NONGLOBAL 3UL
18519 +
18520 +#define PCID_KERNEL 0UL
18521 +#define PCID_USER 1UL
18522 +#define PCID_NOFLUSH (1UL << 63)
18523 +
18524 static inline void load_cr3(pgd_t *pgdir)
18525 {
18526 - write_cr3(__pa(pgdir));
18527 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18528 }
18529
18530 #ifdef CONFIG_X86_32
18531 @@ -282,7 +294,7 @@ struct tss_struct {
18532
18533 } ____cacheline_aligned;
18534
18535 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18536 +extern struct tss_struct init_tss[NR_CPUS];
18537
18538 /*
18539 * Save the original ist values for checking stack pointers during debugging
18540 @@ -478,6 +490,7 @@ struct thread_struct {
18541 unsigned short ds;
18542 unsigned short fsindex;
18543 unsigned short gsindex;
18544 + unsigned short ss;
18545 #endif
18546 #ifdef CONFIG_X86_32
18547 unsigned long ip;
18548 @@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18549 extern unsigned long mmu_cr4_features;
18550 extern u32 *trampoline_cr4_features;
18551
18552 -static inline void set_in_cr4(unsigned long mask)
18553 -{
18554 - unsigned long cr4;
18555 -
18556 - mmu_cr4_features |= mask;
18557 - if (trampoline_cr4_features)
18558 - *trampoline_cr4_features = mmu_cr4_features;
18559 - cr4 = read_cr4();
18560 - cr4 |= mask;
18561 - write_cr4(cr4);
18562 -}
18563 -
18564 -static inline void clear_in_cr4(unsigned long mask)
18565 -{
18566 - unsigned long cr4;
18567 -
18568 - mmu_cr4_features &= ~mask;
18569 - if (trampoline_cr4_features)
18570 - *trampoline_cr4_features = mmu_cr4_features;
18571 - cr4 = read_cr4();
18572 - cr4 &= ~mask;
18573 - write_cr4(cr4);
18574 -}
18575 +extern void set_in_cr4(unsigned long mask);
18576 +extern void clear_in_cr4(unsigned long mask);
18577
18578 typedef struct {
18579 unsigned long seg;
18580 @@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18581 */
18582 #define TASK_SIZE PAGE_OFFSET
18583 #define TASK_SIZE_MAX TASK_SIZE
18584 +
18585 +#ifdef CONFIG_PAX_SEGMEXEC
18586 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18587 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18588 +#else
18589 #define STACK_TOP TASK_SIZE
18590 -#define STACK_TOP_MAX STACK_TOP
18591 +#endif
18592 +
18593 +#define STACK_TOP_MAX TASK_SIZE
18594
18595 #define INIT_THREAD { \
18596 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18597 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18598 .vm86_info = NULL, \
18599 .sysenter_cs = __KERNEL_CS, \
18600 .io_bitmap_ptr = NULL, \
18601 @@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18602 */
18603 #define INIT_TSS { \
18604 .x86_tss = { \
18605 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18606 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18607 .ss0 = __KERNEL_DS, \
18608 .ss1 = __KERNEL_CS, \
18609 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18610 @@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18611 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18612
18613 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18614 -#define KSTK_TOP(info) \
18615 -({ \
18616 - unsigned long *__ptr = (unsigned long *)(info); \
18617 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18618 -})
18619 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18620
18621 /*
18622 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18623 @@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18624 #define task_pt_regs(task) \
18625 ({ \
18626 struct pt_regs *__regs__; \
18627 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18628 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18629 __regs__ - 1; \
18630 })
18631
18632 @@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18633 /*
18634 * User space process size. 47bits minus one guard page.
18635 */
18636 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18637 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18638
18639 /* This decides where the kernel will search for a free chunk of vm
18640 * space during mmap's.
18641 */
18642 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18643 - 0xc0000000 : 0xFFFFe000)
18644 + 0xc0000000 : 0xFFFFf000)
18645
18646 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18647 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18648 @@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18649 #define STACK_TOP_MAX TASK_SIZE_MAX
18650
18651 #define INIT_THREAD { \
18652 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18653 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18654 }
18655
18656 #define INIT_TSS { \
18657 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18658 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18659 }
18660
18661 /*
18662 @@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18663 */
18664 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18665
18666 +#ifdef CONFIG_PAX_SEGMEXEC
18667 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18668 +#endif
18669 +
18670 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18671
18672 /* Get/set a process' ability to use the timestamp counter instruction */
18673 @@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18674 return 0;
18675 }
18676
18677 -extern unsigned long arch_align_stack(unsigned long sp);
18678 +#define arch_align_stack(x) ((x) & ~0xfUL)
18679 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18680
18681 void default_idle(void);
18682 @@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18683 #define xen_set_default_idle 0
18684 #endif
18685
18686 -void stop_this_cpu(void *dummy);
18687 +void stop_this_cpu(void *dummy) __noreturn;
18688 void df_debug(struct pt_regs *regs, long error_code);
18689 #endif /* _ASM_X86_PROCESSOR_H */
18690 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18691 index 86fc2bb..bd5049a 100644
18692 --- a/arch/x86/include/asm/ptrace.h
18693 +++ b/arch/x86/include/asm/ptrace.h
18694 @@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18695 }
18696
18697 /*
18698 - * user_mode_vm(regs) determines whether a register set came from user mode.
18699 + * user_mode(regs) determines whether a register set came from user mode.
18700 * This is true if V8086 mode was enabled OR if the register set was from
18701 * protected mode with RPL-3 CS value. This tricky test checks that with
18702 * one comparison. Many places in the kernel can bypass this full check
18703 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18704 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18705 + * be used.
18706 */
18707 -static inline int user_mode(struct pt_regs *regs)
18708 +static inline int user_mode_novm(struct pt_regs *regs)
18709 {
18710 #ifdef CONFIG_X86_32
18711 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18712 #else
18713 - return !!(regs->cs & 3);
18714 + return !!(regs->cs & SEGMENT_RPL_MASK);
18715 #endif
18716 }
18717
18718 -static inline int user_mode_vm(struct pt_regs *regs)
18719 +static inline int user_mode(struct pt_regs *regs)
18720 {
18721 #ifdef CONFIG_X86_32
18722 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18723 USER_RPL;
18724 #else
18725 - return user_mode(regs);
18726 + return user_mode_novm(regs);
18727 #endif
18728 }
18729
18730 @@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18731 #ifdef CONFIG_X86_64
18732 static inline bool user_64bit_mode(struct pt_regs *regs)
18733 {
18734 + unsigned long cs = regs->cs & 0xffff;
18735 #ifndef CONFIG_PARAVIRT
18736 /*
18737 * On non-paravirt systems, this is the only long mode CPL 3
18738 * selector. We do not allow long mode selectors in the LDT.
18739 */
18740 - return regs->cs == __USER_CS;
18741 + return cs == __USER_CS;
18742 #else
18743 /* Headers are too twisted for this to go in paravirt.h. */
18744 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18745 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18746 #endif
18747 }
18748
18749 @@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18750 * Traps from the kernel do not save sp and ss.
18751 * Use the helper function to retrieve sp.
18752 */
18753 - if (offset == offsetof(struct pt_regs, sp) &&
18754 - regs->cs == __KERNEL_CS)
18755 - return kernel_stack_pointer(regs);
18756 + if (offset == offsetof(struct pt_regs, sp)) {
18757 + unsigned long cs = regs->cs & 0xffff;
18758 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18759 + return kernel_stack_pointer(regs);
18760 + }
18761 #endif
18762 return *(unsigned long *)((unsigned long)regs + offset);
18763 }
18764 diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18765 index ae0e241..e80b10b 100644
18766 --- a/arch/x86/include/asm/qrwlock.h
18767 +++ b/arch/x86/include/asm/qrwlock.h
18768 @@ -7,8 +7,8 @@
18769 #define queue_write_unlock queue_write_unlock
18770 static inline void queue_write_unlock(struct qrwlock *lock)
18771 {
18772 - barrier();
18773 - ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18774 + barrier();
18775 + ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18776 }
18777 #endif
18778
18779 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18780 index 9c6b890..5305f53 100644
18781 --- a/arch/x86/include/asm/realmode.h
18782 +++ b/arch/x86/include/asm/realmode.h
18783 @@ -22,16 +22,14 @@ struct real_mode_header {
18784 #endif
18785 /* APM/BIOS reboot */
18786 u32 machine_real_restart_asm;
18787 -#ifdef CONFIG_X86_64
18788 u32 machine_real_restart_seg;
18789 -#endif
18790 };
18791
18792 /* This must match data at trampoline_32/64.S */
18793 struct trampoline_header {
18794 #ifdef CONFIG_X86_32
18795 u32 start;
18796 - u16 gdt_pad;
18797 + u16 boot_cs;
18798 u16 gdt_limit;
18799 u32 gdt_base;
18800 #else
18801 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18802 index a82c4f1..ac45053 100644
18803 --- a/arch/x86/include/asm/reboot.h
18804 +++ b/arch/x86/include/asm/reboot.h
18805 @@ -6,13 +6,13 @@
18806 struct pt_regs;
18807
18808 struct machine_ops {
18809 - void (*restart)(char *cmd);
18810 - void (*halt)(void);
18811 - void (*power_off)(void);
18812 + void (* __noreturn restart)(char *cmd);
18813 + void (* __noreturn halt)(void);
18814 + void (* __noreturn power_off)(void);
18815 void (*shutdown)(void);
18816 void (*crash_shutdown)(struct pt_regs *);
18817 - void (*emergency_restart)(void);
18818 -};
18819 + void (* __noreturn emergency_restart)(void);
18820 +} __no_const;
18821
18822 extern struct machine_ops machine_ops;
18823
18824 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18825 index 8f7866a..e442f20 100644
18826 --- a/arch/x86/include/asm/rmwcc.h
18827 +++ b/arch/x86/include/asm/rmwcc.h
18828 @@ -3,7 +3,34 @@
18829
18830 #ifdef CC_HAVE_ASM_GOTO
18831
18832 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18833 +#ifdef CONFIG_PAX_REFCOUNT
18834 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18835 +do { \
18836 + asm_volatile_goto (fullop \
18837 + ";jno 0f\n" \
18838 + fullantiop \
18839 + ";int $4\n0:\n" \
18840 + _ASM_EXTABLE(0b, 0b) \
18841 + ";j" cc " %l[cc_label]" \
18842 + : : "m" (var), ## __VA_ARGS__ \
18843 + : "memory" : cc_label); \
18844 + return 0; \
18845 +cc_label: \
18846 + return 1; \
18847 +} while (0)
18848 +#else
18849 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18850 +do { \
18851 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18852 + : : "m" (var), ## __VA_ARGS__ \
18853 + : "memory" : cc_label); \
18854 + return 0; \
18855 +cc_label: \
18856 + return 1; \
18857 +} while (0)
18858 +#endif
18859 +
18860 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18861 do { \
18862 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18863 : : "m" (var), ## __VA_ARGS__ \
18864 @@ -13,15 +40,46 @@ cc_label: \
18865 return 1; \
18866 } while (0)
18867
18868 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18869 - __GEN_RMWcc(op " " arg0, var, cc)
18870 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18871 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18872
18873 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18874 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18875 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18876 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18877 +
18878 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18879 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18880 +
18881 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18882 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18883
18884 #else /* !CC_HAVE_ASM_GOTO */
18885
18886 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18887 +#ifdef CONFIG_PAX_REFCOUNT
18888 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18889 +do { \
18890 + char c; \
18891 + asm volatile (fullop \
18892 + ";jno 0f\n" \
18893 + fullantiop \
18894 + ";int $4\n0:\n" \
18895 + _ASM_EXTABLE(0b, 0b) \
18896 + "; set" cc " %1" \
18897 + : "+m" (var), "=qm" (c) \
18898 + : __VA_ARGS__ : "memory"); \
18899 + return c != 0; \
18900 +} while (0)
18901 +#else
18902 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18903 +do { \
18904 + char c; \
18905 + asm volatile (fullop "; set" cc " %1" \
18906 + : "+m" (var), "=qm" (c) \
18907 + : __VA_ARGS__ : "memory"); \
18908 + return c != 0; \
18909 +} while (0)
18910 +#endif
18911 +
18912 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18913 do { \
18914 char c; \
18915 asm volatile (fullop "; set" cc " %1" \
18916 @@ -30,11 +88,17 @@ do { \
18917 return c != 0; \
18918 } while (0)
18919
18920 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18921 - __GEN_RMWcc(op " " arg0, var, cc)
18922 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18923 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18924 +
18925 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18926 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18927 +
18928 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18929 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18930
18931 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18932 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18933 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18934 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18935
18936 #endif /* CC_HAVE_ASM_GOTO */
18937
18938 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18939 index cad82c9..2e5c5c1 100644
18940 --- a/arch/x86/include/asm/rwsem.h
18941 +++ b/arch/x86/include/asm/rwsem.h
18942 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18943 {
18944 asm volatile("# beginning down_read\n\t"
18945 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18946 +
18947 +#ifdef CONFIG_PAX_REFCOUNT
18948 + "jno 0f\n"
18949 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18950 + "int $4\n0:\n"
18951 + _ASM_EXTABLE(0b, 0b)
18952 +#endif
18953 +
18954 /* adds 0x00000001 */
18955 " jns 1f\n"
18956 " call call_rwsem_down_read_failed\n"
18957 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18958 "1:\n\t"
18959 " mov %1,%2\n\t"
18960 " add %3,%2\n\t"
18961 +
18962 +#ifdef CONFIG_PAX_REFCOUNT
18963 + "jno 0f\n"
18964 + "sub %3,%2\n"
18965 + "int $4\n0:\n"
18966 + _ASM_EXTABLE(0b, 0b)
18967 +#endif
18968 +
18969 " jle 2f\n\t"
18970 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18971 " jnz 1b\n\t"
18972 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18973 long tmp;
18974 asm volatile("# beginning down_write\n\t"
18975 LOCK_PREFIX " xadd %1,(%2)\n\t"
18976 +
18977 +#ifdef CONFIG_PAX_REFCOUNT
18978 + "jno 0f\n"
18979 + "mov %1,(%2)\n"
18980 + "int $4\n0:\n"
18981 + _ASM_EXTABLE(0b, 0b)
18982 +#endif
18983 +
18984 /* adds 0xffff0001, returns the old value */
18985 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18986 /* was the active mask 0 before? */
18987 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18988 long tmp;
18989 asm volatile("# beginning __up_read\n\t"
18990 LOCK_PREFIX " xadd %1,(%2)\n\t"
18991 +
18992 +#ifdef CONFIG_PAX_REFCOUNT
18993 + "jno 0f\n"
18994 + "mov %1,(%2)\n"
18995 + "int $4\n0:\n"
18996 + _ASM_EXTABLE(0b, 0b)
18997 +#endif
18998 +
18999 /* subtracts 1, returns the old value */
19000 " jns 1f\n\t"
19001 " call call_rwsem_wake\n" /* expects old value in %edx */
19002 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19003 long tmp;
19004 asm volatile("# beginning __up_write\n\t"
19005 LOCK_PREFIX " xadd %1,(%2)\n\t"
19006 +
19007 +#ifdef CONFIG_PAX_REFCOUNT
19008 + "jno 0f\n"
19009 + "mov %1,(%2)\n"
19010 + "int $4\n0:\n"
19011 + _ASM_EXTABLE(0b, 0b)
19012 +#endif
19013 +
19014 /* subtracts 0xffff0001, returns the old value */
19015 " jns 1f\n\t"
19016 " call call_rwsem_wake\n" /* expects old value in %edx */
19017 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19018 {
19019 asm volatile("# beginning __downgrade_write\n\t"
19020 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19021 +
19022 +#ifdef CONFIG_PAX_REFCOUNT
19023 + "jno 0f\n"
19024 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19025 + "int $4\n0:\n"
19026 + _ASM_EXTABLE(0b, 0b)
19027 +#endif
19028 +
19029 /*
19030 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19031 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19032 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19033 */
19034 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19035 {
19036 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19037 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19038 +
19039 +#ifdef CONFIG_PAX_REFCOUNT
19040 + "jno 0f\n"
19041 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
19042 + "int $4\n0:\n"
19043 + _ASM_EXTABLE(0b, 0b)
19044 +#endif
19045 +
19046 : "+m" (sem->count)
19047 : "er" (delta));
19048 }
19049 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19050 */
19051 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19052 {
19053 - return delta + xadd(&sem->count, delta);
19054 + return delta + xadd_check_overflow(&sem->count, delta);
19055 }
19056
19057 #endif /* __KERNEL__ */
19058 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19059 index 6f1c3a8..7744f19 100644
19060 --- a/arch/x86/include/asm/segment.h
19061 +++ b/arch/x86/include/asm/segment.h
19062 @@ -64,10 +64,15 @@
19063 * 26 - ESPFIX small SS
19064 * 27 - per-cpu [ offset to per-cpu data area ]
19065 * 28 - stack_canary-20 [ for stack protector ]
19066 - * 29 - unused
19067 - * 30 - unused
19068 + * 29 - PCI BIOS CS
19069 + * 30 - PCI BIOS DS
19070 * 31 - TSS for double fault handler
19071 */
19072 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19073 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19074 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19075 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19076 +
19077 #define GDT_ENTRY_TLS_MIN 6
19078 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19079
19080 @@ -79,6 +84,8 @@
19081
19082 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19083
19084 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19085 +
19086 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19087
19088 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19089 @@ -104,6 +111,12 @@
19090 #define __KERNEL_STACK_CANARY 0
19091 #endif
19092
19093 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19094 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19095 +
19096 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19097 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19098 +
19099 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19100
19101 /*
19102 @@ -141,7 +154,7 @@
19103 */
19104
19105 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19106 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19107 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19108
19109
19110 #else
19111 @@ -165,6 +178,8 @@
19112 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19113 #define __USER32_DS __USER_DS
19114
19115 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19116 +
19117 #define GDT_ENTRY_TSS 8 /* needs two entries */
19118 #define GDT_ENTRY_LDT 10 /* needs two entries */
19119 #define GDT_ENTRY_TLS_MIN 12
19120 @@ -173,6 +188,8 @@
19121 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19122 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19123
19124 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19125 +
19126 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19127 #define FS_TLS 0
19128 #define GS_TLS 1
19129 @@ -180,12 +197,14 @@
19130 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19131 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19132
19133 -#define GDT_ENTRIES 16
19134 +#define GDT_ENTRIES 17
19135
19136 #endif
19137
19138 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19139 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19140 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19141 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19142 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19143 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19144 #ifndef CONFIG_PARAVIRT
19145 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19146 {
19147 unsigned long __limit;
19148 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19149 - return __limit + 1;
19150 + return __limit;
19151 }
19152
19153 #endif /* !__ASSEMBLY__ */
19154 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19155 index 8d3120f..352b440 100644
19156 --- a/arch/x86/include/asm/smap.h
19157 +++ b/arch/x86/include/asm/smap.h
19158 @@ -25,11 +25,40 @@
19159
19160 #include <asm/alternative-asm.h>
19161
19162 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19163 +#define ASM_PAX_OPEN_USERLAND \
19164 + 661: jmp 663f; \
19165 + .pushsection .altinstr_replacement, "a" ; \
19166 + 662: pushq %rax; nop; \
19167 + .popsection ; \
19168 + .pushsection .altinstructions, "a" ; \
19169 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19170 + .popsection ; \
19171 + call __pax_open_userland; \
19172 + popq %rax; \
19173 + 663:
19174 +
19175 +#define ASM_PAX_CLOSE_USERLAND \
19176 + 661: jmp 663f; \
19177 + .pushsection .altinstr_replacement, "a" ; \
19178 + 662: pushq %rax; nop; \
19179 + .popsection; \
19180 + .pushsection .altinstructions, "a" ; \
19181 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19182 + .popsection; \
19183 + call __pax_close_userland; \
19184 + popq %rax; \
19185 + 663:
19186 +#else
19187 +#define ASM_PAX_OPEN_USERLAND
19188 +#define ASM_PAX_CLOSE_USERLAND
19189 +#endif
19190 +
19191 #ifdef CONFIG_X86_SMAP
19192
19193 #define ASM_CLAC \
19194 661: ASM_NOP3 ; \
19195 - .pushsection .altinstr_replacement, "ax" ; \
19196 + .pushsection .altinstr_replacement, "a" ; \
19197 662: __ASM_CLAC ; \
19198 .popsection ; \
19199 .pushsection .altinstructions, "a" ; \
19200 @@ -38,7 +67,7 @@
19201
19202 #define ASM_STAC \
19203 661: ASM_NOP3 ; \
19204 - .pushsection .altinstr_replacement, "ax" ; \
19205 + .pushsection .altinstr_replacement, "a" ; \
19206 662: __ASM_STAC ; \
19207 .popsection ; \
19208 .pushsection .altinstructions, "a" ; \
19209 @@ -56,6 +85,37 @@
19210
19211 #include <asm/alternative.h>
19212
19213 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19214 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19215 +
19216 +extern void __pax_open_userland(void);
19217 +static __always_inline unsigned long pax_open_userland(void)
19218 +{
19219 +
19220 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19221 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19222 + :
19223 + : [open] "i" (__pax_open_userland)
19224 + : "memory", "rax");
19225 +#endif
19226 +
19227 + return 0;
19228 +}
19229 +
19230 +extern void __pax_close_userland(void);
19231 +static __always_inline unsigned long pax_close_userland(void)
19232 +{
19233 +
19234 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19235 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19236 + :
19237 + : [close] "i" (__pax_close_userland)
19238 + : "memory", "rax");
19239 +#endif
19240 +
19241 + return 0;
19242 +}
19243 +
19244 #ifdef CONFIG_X86_SMAP
19245
19246 static __always_inline void clac(void)
19247 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19248 index 8cd1cc3..827e09e 100644
19249 --- a/arch/x86/include/asm/smp.h
19250 +++ b/arch/x86/include/asm/smp.h
19251 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19252 /* cpus sharing the last level cache: */
19253 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19254 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19255 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19256 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19257
19258 static inline struct cpumask *cpu_sibling_mask(int cpu)
19259 {
19260 @@ -78,7 +78,7 @@ struct smp_ops {
19261
19262 void (*send_call_func_ipi)(const struct cpumask *mask);
19263 void (*send_call_func_single_ipi)(int cpu);
19264 -};
19265 +} __no_const;
19266
19267 /* Globals due to paravirt */
19268 extern void set_cpu_sibling_map(int cpu);
19269 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19270 extern int safe_smp_processor_id(void);
19271
19272 #elif defined(CONFIG_X86_64_SMP)
19273 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19274 -
19275 -#define stack_smp_processor_id() \
19276 -({ \
19277 - struct thread_info *ti; \
19278 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19279 - ti->cpu; \
19280 -})
19281 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19282 +#define stack_smp_processor_id() raw_smp_processor_id()
19283 #define safe_smp_processor_id() smp_processor_id()
19284
19285 #endif
19286 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19287 index 6a99859..03cb807 100644
19288 --- a/arch/x86/include/asm/stackprotector.h
19289 +++ b/arch/x86/include/asm/stackprotector.h
19290 @@ -47,7 +47,7 @@
19291 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19292 */
19293 #define GDT_STACK_CANARY_INIT \
19294 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19295 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19296
19297 /*
19298 * Initialize the stackprotector canary value.
19299 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19300
19301 static inline void load_stack_canary_segment(void)
19302 {
19303 -#ifdef CONFIG_X86_32
19304 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19305 asm volatile ("mov %0, %%gs" : : "r" (0));
19306 #endif
19307 }
19308 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19309 index 70bbe39..4ae2bd4 100644
19310 --- a/arch/x86/include/asm/stacktrace.h
19311 +++ b/arch/x86/include/asm/stacktrace.h
19312 @@ -11,28 +11,20 @@
19313
19314 extern int kstack_depth_to_print;
19315
19316 -struct thread_info;
19317 +struct task_struct;
19318 struct stacktrace_ops;
19319
19320 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19321 - unsigned long *stack,
19322 - unsigned long bp,
19323 - const struct stacktrace_ops *ops,
19324 - void *data,
19325 - unsigned long *end,
19326 - int *graph);
19327 +typedef unsigned long walk_stack_t(struct task_struct *task,
19328 + void *stack_start,
19329 + unsigned long *stack,
19330 + unsigned long bp,
19331 + const struct stacktrace_ops *ops,
19332 + void *data,
19333 + unsigned long *end,
19334 + int *graph);
19335
19336 -extern unsigned long
19337 -print_context_stack(struct thread_info *tinfo,
19338 - unsigned long *stack, unsigned long bp,
19339 - const struct stacktrace_ops *ops, void *data,
19340 - unsigned long *end, int *graph);
19341 -
19342 -extern unsigned long
19343 -print_context_stack_bp(struct thread_info *tinfo,
19344 - unsigned long *stack, unsigned long bp,
19345 - const struct stacktrace_ops *ops, void *data,
19346 - unsigned long *end, int *graph);
19347 +extern walk_stack_t print_context_stack;
19348 +extern walk_stack_t print_context_stack_bp;
19349
19350 /* Generic stack tracer with callbacks */
19351
19352 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19353 void (*address)(void *data, unsigned long address, int reliable);
19354 /* On negative return stop dumping */
19355 int (*stack)(void *data, char *name);
19356 - walk_stack_t walk_stack;
19357 + walk_stack_t *walk_stack;
19358 };
19359
19360 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19361 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19362 index d7f3b3b..3cc39f1 100644
19363 --- a/arch/x86/include/asm/switch_to.h
19364 +++ b/arch/x86/include/asm/switch_to.h
19365 @@ -108,7 +108,7 @@ do { \
19366 "call __switch_to\n\t" \
19367 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19368 __switch_canary \
19369 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19370 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19371 "movq %%rax,%%rdi\n\t" \
19372 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19373 "jnz ret_from_fork\n\t" \
19374 @@ -119,7 +119,7 @@ do { \
19375 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19376 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19377 [_tif_fork] "i" (_TIF_FORK), \
19378 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19379 + [thread_info] "m" (current_tinfo), \
19380 [current_task] "m" (current_task) \
19381 __switch_canary_iparam \
19382 : "memory", "cc" __EXTRA_CLOBBER)
19383 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19384 index 547e344..6be1175 100644
19385 --- a/arch/x86/include/asm/thread_info.h
19386 +++ b/arch/x86/include/asm/thread_info.h
19387 @@ -24,7 +24,6 @@ struct exec_domain;
19388 #include <linux/atomic.h>
19389
19390 struct thread_info {
19391 - struct task_struct *task; /* main task structure */
19392 struct exec_domain *exec_domain; /* execution domain */
19393 __u32 flags; /* low level flags */
19394 __u32 status; /* thread synchronous flags */
19395 @@ -33,13 +32,13 @@ struct thread_info {
19396 mm_segment_t addr_limit;
19397 struct restart_block restart_block;
19398 void __user *sysenter_return;
19399 + unsigned long lowest_stack;
19400 unsigned int sig_on_uaccess_error:1;
19401 unsigned int uaccess_err:1; /* uaccess failed */
19402 };
19403
19404 -#define INIT_THREAD_INFO(tsk) \
19405 +#define INIT_THREAD_INFO \
19406 { \
19407 - .task = &tsk, \
19408 .exec_domain = &default_exec_domain, \
19409 .flags = 0, \
19410 .cpu = 0, \
19411 @@ -50,7 +49,7 @@ struct thread_info {
19412 }, \
19413 }
19414
19415 -#define init_thread_info (init_thread_union.thread_info)
19416 +#define init_thread_info (init_thread_union.stack)
19417 #define init_stack (init_thread_union.stack)
19418
19419 #else /* !__ASSEMBLY__ */
19420 @@ -91,6 +90,7 @@ struct thread_info {
19421 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19422 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19423 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19424 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19425
19426 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19427 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19428 @@ -115,17 +115,18 @@ struct thread_info {
19429 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19430 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19431 #define _TIF_X32 (1 << TIF_X32)
19432 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19433
19434 /* work to do in syscall_trace_enter() */
19435 #define _TIF_WORK_SYSCALL_ENTRY \
19436 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19437 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19438 - _TIF_NOHZ)
19439 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19440
19441 /* work to do in syscall_trace_leave() */
19442 #define _TIF_WORK_SYSCALL_EXIT \
19443 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19444 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19445 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19446
19447 /* work to do on interrupt/exception return */
19448 #define _TIF_WORK_MASK \
19449 @@ -136,7 +137,7 @@ struct thread_info {
19450 /* work to do on any return to user space */
19451 #define _TIF_ALLWORK_MASK \
19452 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19453 - _TIF_NOHZ)
19454 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19455
19456 /* Only used for 64 bit */
19457 #define _TIF_DO_NOTIFY_MASK \
19458 @@ -151,7 +152,6 @@ struct thread_info {
19459 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19460
19461 #define STACK_WARN (THREAD_SIZE/8)
19462 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19463
19464 /*
19465 * macros/functions for gaining access to the thread information structure
19466 @@ -162,26 +162,18 @@ struct thread_info {
19467
19468 DECLARE_PER_CPU(unsigned long, kernel_stack);
19469
19470 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19471 +
19472 static inline struct thread_info *current_thread_info(void)
19473 {
19474 - struct thread_info *ti;
19475 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19476 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19477 - return ti;
19478 + return this_cpu_read_stable(current_tinfo);
19479 }
19480
19481 #else /* !__ASSEMBLY__ */
19482
19483 /* how to get the thread information struct from ASM */
19484 #define GET_THREAD_INFO(reg) \
19485 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19486 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19487 -
19488 -/*
19489 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19490 - * a certain register (to be used in assembler memory operands).
19491 - */
19492 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19493 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19494
19495 #endif
19496
19497 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19498 extern void arch_task_cache_init(void);
19499 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19500 extern void arch_release_task_struct(struct task_struct *tsk);
19501 +
19502 +#define __HAVE_THREAD_FUNCTIONS
19503 +#define task_thread_info(task) (&(task)->tinfo)
19504 +#define task_stack_page(task) ((task)->stack)
19505 +#define setup_thread_stack(p, org) do {} while (0)
19506 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19507 +
19508 #endif
19509 #endif /* _ASM_X86_THREAD_INFO_H */
19510 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19511 index 04905bf..1178cdf 100644
19512 --- a/arch/x86/include/asm/tlbflush.h
19513 +++ b/arch/x86/include/asm/tlbflush.h
19514 @@ -17,18 +17,44 @@
19515
19516 static inline void __native_flush_tlb(void)
19517 {
19518 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19519 + u64 descriptor[2];
19520 +
19521 + descriptor[0] = PCID_KERNEL;
19522 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19523 + return;
19524 + }
19525 +
19526 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19527 + if (static_cpu_has(X86_FEATURE_PCID)) {
19528 + unsigned int cpu = raw_get_cpu();
19529 +
19530 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19531 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19532 + raw_put_cpu_no_resched();
19533 + return;
19534 + }
19535 +#endif
19536 +
19537 native_write_cr3(native_read_cr3());
19538 }
19539
19540 static inline void __native_flush_tlb_global_irq_disabled(void)
19541 {
19542 - unsigned long cr4;
19543 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19544 + u64 descriptor[2];
19545
19546 - cr4 = native_read_cr4();
19547 - /* clear PGE */
19548 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19549 - /* write old PGE again and flush TLBs */
19550 - native_write_cr4(cr4);
19551 + descriptor[0] = PCID_KERNEL;
19552 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19553 + } else {
19554 + unsigned long cr4;
19555 +
19556 + cr4 = native_read_cr4();
19557 + /* clear PGE */
19558 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19559 + /* write old PGE again and flush TLBs */
19560 + native_write_cr4(cr4);
19561 + }
19562 }
19563
19564 static inline void __native_flush_tlb_global(void)
19565 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19566
19567 static inline void __native_flush_tlb_single(unsigned long addr)
19568 {
19569 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19570 + u64 descriptor[2];
19571 +
19572 + descriptor[0] = PCID_KERNEL;
19573 + descriptor[1] = addr;
19574 +
19575 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19576 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19577 + if (addr < TASK_SIZE_MAX)
19578 + descriptor[1] += pax_user_shadow_base;
19579 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19580 + }
19581 +
19582 + descriptor[0] = PCID_USER;
19583 + descriptor[1] = addr;
19584 +#endif
19585 +
19586 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19587 + return;
19588 + }
19589 +
19590 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19591 + if (static_cpu_has(X86_FEATURE_PCID)) {
19592 + unsigned int cpu = raw_get_cpu();
19593 +
19594 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19595 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19596 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19597 + raw_put_cpu_no_resched();
19598 +
19599 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19600 + addr += pax_user_shadow_base;
19601 + }
19602 +#endif
19603 +
19604 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19605 }
19606
19607 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19608 index 0d592e0..526f797 100644
19609 --- a/arch/x86/include/asm/uaccess.h
19610 +++ b/arch/x86/include/asm/uaccess.h
19611 @@ -7,6 +7,7 @@
19612 #include <linux/compiler.h>
19613 #include <linux/thread_info.h>
19614 #include <linux/string.h>
19615 +#include <linux/spinlock.h>
19616 #include <asm/asm.h>
19617 #include <asm/page.h>
19618 #include <asm/smap.h>
19619 @@ -29,7 +30,12 @@
19620
19621 #define get_ds() (KERNEL_DS)
19622 #define get_fs() (current_thread_info()->addr_limit)
19623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19624 +void __set_fs(mm_segment_t x);
19625 +void set_fs(mm_segment_t x);
19626 +#else
19627 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19628 +#endif
19629
19630 #define segment_eq(a, b) ((a).seg == (b).seg)
19631
19632 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19633 * checks that the pointer is in the user space range - after calling
19634 * this function, memory access functions may still return -EFAULT.
19635 */
19636 -#define access_ok(type, addr, size) \
19637 - likely(!__range_not_ok(addr, size, user_addr_max()))
19638 +extern int _cond_resched(void);
19639 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19640 +#define access_ok(type, addr, size) \
19641 +({ \
19642 + unsigned long __size = size; \
19643 + unsigned long __addr = (unsigned long)addr; \
19644 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19645 + if (__ret_ao && __size) { \
19646 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19647 + unsigned long __end_ao = __addr + __size - 1; \
19648 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19649 + while (__addr_ao <= __end_ao) { \
19650 + char __c_ao; \
19651 + __addr_ao += PAGE_SIZE; \
19652 + if (__size > PAGE_SIZE) \
19653 + _cond_resched(); \
19654 + if (__get_user(__c_ao, (char __user *)__addr)) \
19655 + break; \
19656 + if (type != VERIFY_WRITE) { \
19657 + __addr = __addr_ao; \
19658 + continue; \
19659 + } \
19660 + if (__put_user(__c_ao, (char __user *)__addr)) \
19661 + break; \
19662 + __addr = __addr_ao; \
19663 + } \
19664 + } \
19665 + } \
19666 + __ret_ao; \
19667 +})
19668
19669 /*
19670 * The exception table consists of pairs of addresses relative to the
19671 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19672 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19673 __chk_user_ptr(ptr); \
19674 might_fault(); \
19675 + pax_open_userland(); \
19676 asm volatile("call __get_user_%P3" \
19677 : "=a" (__ret_gu), "=r" (__val_gu) \
19678 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19679 (x) = (__typeof__(*(ptr))) __val_gu; \
19680 + pax_close_userland(); \
19681 __ret_gu; \
19682 })
19683
19684 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19685 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19686 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19687
19688 -
19689 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19690 +#define __copyuser_seg "gs;"
19691 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19692 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19693 +#else
19694 +#define __copyuser_seg
19695 +#define __COPYUSER_SET_ES
19696 +#define __COPYUSER_RESTORE_ES
19697 +#endif
19698
19699 #ifdef CONFIG_X86_32
19700 #define __put_user_asm_u64(x, addr, err, errret) \
19701 asm volatile(ASM_STAC "\n" \
19702 - "1: movl %%eax,0(%2)\n" \
19703 - "2: movl %%edx,4(%2)\n" \
19704 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19705 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19706 "3: " ASM_CLAC "\n" \
19707 ".section .fixup,\"ax\"\n" \
19708 "4: movl %3,%0\n" \
19709 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19710
19711 #define __put_user_asm_ex_u64(x, addr) \
19712 asm volatile(ASM_STAC "\n" \
19713 - "1: movl %%eax,0(%1)\n" \
19714 - "2: movl %%edx,4(%1)\n" \
19715 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19716 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19717 "3: " ASM_CLAC "\n" \
19718 _ASM_EXTABLE_EX(1b, 2b) \
19719 _ASM_EXTABLE_EX(2b, 3b) \
19720 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19721 __typeof__(*(ptr)) __pu_val; \
19722 __chk_user_ptr(ptr); \
19723 might_fault(); \
19724 - __pu_val = x; \
19725 + __pu_val = (x); \
19726 + pax_open_userland(); \
19727 switch (sizeof(*(ptr))) { \
19728 case 1: \
19729 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19730 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19731 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19732 break; \
19733 } \
19734 + pax_close_userland(); \
19735 __ret_pu; \
19736 })
19737
19738 @@ -355,8 +401,10 @@ do { \
19739 } while (0)
19740
19741 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19742 +do { \
19743 + pax_open_userland(); \
19744 asm volatile(ASM_STAC "\n" \
19745 - "1: mov"itype" %2,%"rtype"1\n" \
19746 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19747 "2: " ASM_CLAC "\n" \
19748 ".section .fixup,\"ax\"\n" \
19749 "3: mov %3,%0\n" \
19750 @@ -364,8 +412,10 @@ do { \
19751 " jmp 2b\n" \
19752 ".previous\n" \
19753 _ASM_EXTABLE(1b, 3b) \
19754 - : "=r" (err), ltype(x) \
19755 - : "m" (__m(addr)), "i" (errret), "0" (err))
19756 + : "=r" (err), ltype (x) \
19757 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19758 + pax_close_userland(); \
19759 +} while (0)
19760
19761 #define __get_user_size_ex(x, ptr, size) \
19762 do { \
19763 @@ -389,7 +439,7 @@ do { \
19764 } while (0)
19765
19766 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19767 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19768 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19769 "2:\n" \
19770 _ASM_EXTABLE_EX(1b, 2b) \
19771 : ltype(x) : "m" (__m(addr)))
19772 @@ -406,13 +456,24 @@ do { \
19773 int __gu_err; \
19774 unsigned long __gu_val; \
19775 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19776 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19777 + (x) = (__typeof__(*(ptr)))__gu_val; \
19778 __gu_err; \
19779 })
19780
19781 /* FIXME: this hack is definitely wrong -AK */
19782 struct __large_struct { unsigned long buf[100]; };
19783 -#define __m(x) (*(struct __large_struct __user *)(x))
19784 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19785 +#define ____m(x) \
19786 +({ \
19787 + unsigned long ____x = (unsigned long)(x); \
19788 + if (____x < pax_user_shadow_base) \
19789 + ____x += pax_user_shadow_base; \
19790 + (typeof(x))____x; \
19791 +})
19792 +#else
19793 +#define ____m(x) (x)
19794 +#endif
19795 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19796
19797 /*
19798 * Tell gcc we read from memory instead of writing: this is because
19799 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19800 * aliasing issues.
19801 */
19802 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19803 +do { \
19804 + pax_open_userland(); \
19805 asm volatile(ASM_STAC "\n" \
19806 - "1: mov"itype" %"rtype"1,%2\n" \
19807 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19808 "2: " ASM_CLAC "\n" \
19809 ".section .fixup,\"ax\"\n" \
19810 "3: mov %3,%0\n" \
19811 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19812 ".previous\n" \
19813 _ASM_EXTABLE(1b, 3b) \
19814 : "=r"(err) \
19815 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19816 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19817 + pax_close_userland(); \
19818 +} while (0)
19819
19820 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19821 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19822 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19823 "2:\n" \
19824 _ASM_EXTABLE_EX(1b, 2b) \
19825 : : ltype(x), "m" (__m(addr)))
19826 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19827 */
19828 #define uaccess_try do { \
19829 current_thread_info()->uaccess_err = 0; \
19830 + pax_open_userland(); \
19831 stac(); \
19832 barrier();
19833
19834 #define uaccess_catch(err) \
19835 clac(); \
19836 + pax_close_userland(); \
19837 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19838 } while (0)
19839
19840 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19841 * On error, the variable @x is set to zero.
19842 */
19843
19844 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19845 +#define __get_user(x, ptr) get_user((x), (ptr))
19846 +#else
19847 #define __get_user(x, ptr) \
19848 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19849 +#endif
19850
19851 /**
19852 * __put_user: - Write a simple value into user space, with less checking.
19853 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19854 * Returns zero on success, or -EFAULT on error.
19855 */
19856
19857 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19858 +#define __put_user(x, ptr) put_user((x), (ptr))
19859 +#else
19860 #define __put_user(x, ptr) \
19861 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19862 +#endif
19863
19864 #define __get_user_unaligned __get_user
19865 #define __put_user_unaligned __put_user
19866 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19867 #define get_user_ex(x, ptr) do { \
19868 unsigned long __gue_val; \
19869 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19870 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19871 + (x) = (__typeof__(*(ptr)))__gue_val; \
19872 } while (0)
19873
19874 #define put_user_try uaccess_try
19875 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19876 __typeof__(ptr) __uval = (uval); \
19877 __typeof__(*(ptr)) __old = (old); \
19878 __typeof__(*(ptr)) __new = (new); \
19879 + pax_open_userland(); \
19880 switch (size) { \
19881 case 1: \
19882 { \
19883 asm volatile("\t" ASM_STAC "\n" \
19884 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19885 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19886 "2:\t" ASM_CLAC "\n" \
19887 "\t.section .fixup, \"ax\"\n" \
19888 "3:\tmov %3, %0\n" \
19889 "\tjmp 2b\n" \
19890 "\t.previous\n" \
19891 _ASM_EXTABLE(1b, 3b) \
19892 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19893 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19894 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19895 : "memory" \
19896 ); \
19897 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19898 case 2: \
19899 { \
19900 asm volatile("\t" ASM_STAC "\n" \
19901 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19902 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19903 "2:\t" ASM_CLAC "\n" \
19904 "\t.section .fixup, \"ax\"\n" \
19905 "3:\tmov %3, %0\n" \
19906 "\tjmp 2b\n" \
19907 "\t.previous\n" \
19908 _ASM_EXTABLE(1b, 3b) \
19909 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19910 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19911 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19912 : "memory" \
19913 ); \
19914 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19915 case 4: \
19916 { \
19917 asm volatile("\t" ASM_STAC "\n" \
19918 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19919 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19920 "2:\t" ASM_CLAC "\n" \
19921 "\t.section .fixup, \"ax\"\n" \
19922 "3:\tmov %3, %0\n" \
19923 "\tjmp 2b\n" \
19924 "\t.previous\n" \
19925 _ASM_EXTABLE(1b, 3b) \
19926 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19927 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19928 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19929 : "memory" \
19930 ); \
19931 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19932 __cmpxchg_wrong_size(); \
19933 \
19934 asm volatile("\t" ASM_STAC "\n" \
19935 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19936 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19937 "2:\t" ASM_CLAC "\n" \
19938 "\t.section .fixup, \"ax\"\n" \
19939 "3:\tmov %3, %0\n" \
19940 "\tjmp 2b\n" \
19941 "\t.previous\n" \
19942 _ASM_EXTABLE(1b, 3b) \
19943 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19944 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19945 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19946 : "memory" \
19947 ); \
19948 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19949 default: \
19950 __cmpxchg_wrong_size(); \
19951 } \
19952 + pax_close_userland(); \
19953 *__uval = __old; \
19954 __ret; \
19955 })
19956 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19957
19958 #define ARCH_HAS_NOCACHE_UACCESS 1
19959
19960 -#ifdef CONFIG_X86_32
19961 -# include <asm/uaccess_32.h>
19962 -#else
19963 -# include <asm/uaccess_64.h>
19964 -#endif
19965 -
19966 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19967 - unsigned n);
19968 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19969 - unsigned n);
19970 -
19971 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19972 # define copy_user_diag __compiletime_error
19973 #else
19974 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19975 extern void copy_user_diag("copy_from_user() buffer size is too small")
19976 copy_from_user_overflow(void);
19977 extern void copy_user_diag("copy_to_user() buffer size is too small")
19978 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19979 +copy_to_user_overflow(void);
19980
19981 #undef copy_user_diag
19982
19983 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19984
19985 extern void
19986 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19987 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19988 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19989 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19990
19991 #else
19992 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19993
19994 #endif
19995
19996 +#ifdef CONFIG_X86_32
19997 +# include <asm/uaccess_32.h>
19998 +#else
19999 +# include <asm/uaccess_64.h>
20000 +#endif
20001 +
20002 static inline unsigned long __must_check
20003 copy_from_user(void *to, const void __user *from, unsigned long n)
20004 {
20005 - int sz = __compiletime_object_size(to);
20006 + size_t sz = __compiletime_object_size(to);
20007
20008 might_fault();
20009
20010 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20011 * case, and do only runtime checking for non-constant sizes.
20012 */
20013
20014 - if (likely(sz < 0 || sz >= n))
20015 - n = _copy_from_user(to, from, n);
20016 - else if(__builtin_constant_p(n))
20017 - copy_from_user_overflow();
20018 - else
20019 - __copy_from_user_overflow(sz, n);
20020 + if (likely(sz != (size_t)-1 && sz < n)) {
20021 + if(__builtin_constant_p(n))
20022 + copy_from_user_overflow();
20023 + else
20024 + __copy_from_user_overflow(sz, n);
20025 + } else if (access_ok(VERIFY_READ, from, n))
20026 + n = __copy_from_user(to, from, n);
20027 + else if ((long)n > 0)
20028 + memset(to, 0, n);
20029
20030 return n;
20031 }
20032 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20033 static inline unsigned long __must_check
20034 copy_to_user(void __user *to, const void *from, unsigned long n)
20035 {
20036 - int sz = __compiletime_object_size(from);
20037 + size_t sz = __compiletime_object_size(from);
20038
20039 might_fault();
20040
20041 /* See the comment in copy_from_user() above. */
20042 - if (likely(sz < 0 || sz >= n))
20043 - n = _copy_to_user(to, from, n);
20044 - else if(__builtin_constant_p(n))
20045 - copy_to_user_overflow();
20046 - else
20047 - __copy_to_user_overflow(sz, n);
20048 + if (likely(sz != (size_t)-1 && sz < n)) {
20049 + if(__builtin_constant_p(n))
20050 + copy_to_user_overflow();
20051 + else
20052 + __copy_to_user_overflow(sz, n);
20053 + } else if (access_ok(VERIFY_WRITE, to, n))
20054 + n = __copy_to_user(to, from, n);
20055
20056 return n;
20057 }
20058 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20059 index 3c03a5d..1071638 100644
20060 --- a/arch/x86/include/asm/uaccess_32.h
20061 +++ b/arch/x86/include/asm/uaccess_32.h
20062 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20063 static __always_inline unsigned long __must_check
20064 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20065 {
20066 + if ((long)n < 0)
20067 + return n;
20068 +
20069 + check_object_size(from, n, true);
20070 +
20071 if (__builtin_constant_p(n)) {
20072 unsigned long ret;
20073
20074 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20075 __copy_to_user(void __user *to, const void *from, unsigned long n)
20076 {
20077 might_fault();
20078 +
20079 return __copy_to_user_inatomic(to, from, n);
20080 }
20081
20082 static __always_inline unsigned long
20083 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20084 {
20085 + if ((long)n < 0)
20086 + return n;
20087 +
20088 /* Avoid zeroing the tail if the copy fails..
20089 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20090 * but as the zeroing behaviour is only significant when n is not
20091 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20092 __copy_from_user(void *to, const void __user *from, unsigned long n)
20093 {
20094 might_fault();
20095 +
20096 + if ((long)n < 0)
20097 + return n;
20098 +
20099 + check_object_size(to, n, false);
20100 +
20101 if (__builtin_constant_p(n)) {
20102 unsigned long ret;
20103
20104 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20105 const void __user *from, unsigned long n)
20106 {
20107 might_fault();
20108 +
20109 + if ((long)n < 0)
20110 + return n;
20111 +
20112 if (__builtin_constant_p(n)) {
20113 unsigned long ret;
20114
20115 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20116 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20117 unsigned long n)
20118 {
20119 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20120 + if ((long)n < 0)
20121 + return n;
20122 +
20123 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20124 }
20125
20126 #endif /* _ASM_X86_UACCESS_32_H */
20127 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20128 index 12a26b9..206c200 100644
20129 --- a/arch/x86/include/asm/uaccess_64.h
20130 +++ b/arch/x86/include/asm/uaccess_64.h
20131 @@ -10,6 +10,9 @@
20132 #include <asm/alternative.h>
20133 #include <asm/cpufeature.h>
20134 #include <asm/page.h>
20135 +#include <asm/pgtable.h>
20136 +
20137 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20138
20139 /*
20140 * Copy To/From Userspace
20141 @@ -17,14 +20,14 @@
20142
20143 /* Handles exceptions in both to and from, but doesn't do access_ok */
20144 __must_check unsigned long
20145 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20146 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20147 __must_check unsigned long
20148 -copy_user_generic_string(void *to, const void *from, unsigned len);
20149 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20150 __must_check unsigned long
20151 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20152 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20153
20154 static __always_inline __must_check unsigned long
20155 -copy_user_generic(void *to, const void *from, unsigned len)
20156 +copy_user_generic(void *to, const void *from, unsigned long len)
20157 {
20158 unsigned ret;
20159
20160 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20161 }
20162
20163 __must_check unsigned long
20164 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20165 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20166
20167 static __always_inline __must_check
20168 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20169 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20170 {
20171 - int ret = 0;
20172 + size_t sz = __compiletime_object_size(dst);
20173 + unsigned ret = 0;
20174 +
20175 + if (size > INT_MAX)
20176 + return size;
20177 +
20178 + check_object_size(dst, size, false);
20179 +
20180 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20181 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20182 + return size;
20183 +#endif
20184 +
20185 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20186 + if(__builtin_constant_p(size))
20187 + copy_from_user_overflow();
20188 + else
20189 + __copy_from_user_overflow(sz, size);
20190 + return size;
20191 + }
20192
20193 if (!__builtin_constant_p(size))
20194 - return copy_user_generic(dst, (__force void *)src, size);
20195 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20196 switch (size) {
20197 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20198 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20199 ret, "b", "b", "=q", 1);
20200 return ret;
20201 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20202 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20203 ret, "w", "w", "=r", 2);
20204 return ret;
20205 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20206 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20207 ret, "l", "k", "=r", 4);
20208 return ret;
20209 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20210 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20211 ret, "q", "", "=r", 8);
20212 return ret;
20213 case 10:
20214 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20215 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20216 ret, "q", "", "=r", 10);
20217 if (unlikely(ret))
20218 return ret;
20219 __get_user_asm(*(u16 *)(8 + (char *)dst),
20220 - (u16 __user *)(8 + (char __user *)src),
20221 + (const u16 __user *)(8 + (const char __user *)src),
20222 ret, "w", "w", "=r", 2);
20223 return ret;
20224 case 16:
20225 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20226 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20227 ret, "q", "", "=r", 16);
20228 if (unlikely(ret))
20229 return ret;
20230 __get_user_asm(*(u64 *)(8 + (char *)dst),
20231 - (u64 __user *)(8 + (char __user *)src),
20232 + (const u64 __user *)(8 + (const char __user *)src),
20233 ret, "q", "", "=r", 8);
20234 return ret;
20235 default:
20236 - return copy_user_generic(dst, (__force void *)src, size);
20237 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20238 }
20239 }
20240
20241 static __always_inline __must_check
20242 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20243 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20244 {
20245 might_fault();
20246 return __copy_from_user_nocheck(dst, src, size);
20247 }
20248
20249 static __always_inline __must_check
20250 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20251 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20252 {
20253 - int ret = 0;
20254 + size_t sz = __compiletime_object_size(src);
20255 + unsigned ret = 0;
20256 +
20257 + if (size > INT_MAX)
20258 + return size;
20259 +
20260 + check_object_size(src, size, true);
20261 +
20262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20263 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20264 + return size;
20265 +#endif
20266 +
20267 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20268 + if(__builtin_constant_p(size))
20269 + copy_to_user_overflow();
20270 + else
20271 + __copy_to_user_overflow(sz, size);
20272 + return size;
20273 + }
20274
20275 if (!__builtin_constant_p(size))
20276 - return copy_user_generic((__force void *)dst, src, size);
20277 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20278 switch (size) {
20279 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20280 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20281 ret, "b", "b", "iq", 1);
20282 return ret;
20283 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20284 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20285 ret, "w", "w", "ir", 2);
20286 return ret;
20287 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20288 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20289 ret, "l", "k", "ir", 4);
20290 return ret;
20291 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20292 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20293 ret, "q", "", "er", 8);
20294 return ret;
20295 case 10:
20296 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20297 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20298 ret, "q", "", "er", 10);
20299 if (unlikely(ret))
20300 return ret;
20301 asm("":::"memory");
20302 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20303 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20304 ret, "w", "w", "ir", 2);
20305 return ret;
20306 case 16:
20307 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20308 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20309 ret, "q", "", "er", 16);
20310 if (unlikely(ret))
20311 return ret;
20312 asm("":::"memory");
20313 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20314 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20315 ret, "q", "", "er", 8);
20316 return ret;
20317 default:
20318 - return copy_user_generic((__force void *)dst, src, size);
20319 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20320 }
20321 }
20322
20323 static __always_inline __must_check
20324 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20325 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20326 {
20327 might_fault();
20328 return __copy_to_user_nocheck(dst, src, size);
20329 }
20330
20331 static __always_inline __must_check
20332 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20333 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20334 {
20335 - int ret = 0;
20336 + unsigned ret = 0;
20337
20338 might_fault();
20339 +
20340 + if (size > INT_MAX)
20341 + return size;
20342 +
20343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20344 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20345 + return size;
20346 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20347 + return size;
20348 +#endif
20349 +
20350 if (!__builtin_constant_p(size))
20351 - return copy_user_generic((__force void *)dst,
20352 - (__force void *)src, size);
20353 + return copy_user_generic((__force_kernel void *)____m(dst),
20354 + (__force_kernel const void *)____m(src), size);
20355 switch (size) {
20356 case 1: {
20357 u8 tmp;
20358 - __get_user_asm(tmp, (u8 __user *)src,
20359 + __get_user_asm(tmp, (const u8 __user *)src,
20360 ret, "b", "b", "=q", 1);
20361 if (likely(!ret))
20362 __put_user_asm(tmp, (u8 __user *)dst,
20363 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20364 }
20365 case 2: {
20366 u16 tmp;
20367 - __get_user_asm(tmp, (u16 __user *)src,
20368 + __get_user_asm(tmp, (const u16 __user *)src,
20369 ret, "w", "w", "=r", 2);
20370 if (likely(!ret))
20371 __put_user_asm(tmp, (u16 __user *)dst,
20372 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20373
20374 case 4: {
20375 u32 tmp;
20376 - __get_user_asm(tmp, (u32 __user *)src,
20377 + __get_user_asm(tmp, (const u32 __user *)src,
20378 ret, "l", "k", "=r", 4);
20379 if (likely(!ret))
20380 __put_user_asm(tmp, (u32 __user *)dst,
20381 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20382 }
20383 case 8: {
20384 u64 tmp;
20385 - __get_user_asm(tmp, (u64 __user *)src,
20386 + __get_user_asm(tmp, (const u64 __user *)src,
20387 ret, "q", "", "=r", 8);
20388 if (likely(!ret))
20389 __put_user_asm(tmp, (u64 __user *)dst,
20390 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20391 return ret;
20392 }
20393 default:
20394 - return copy_user_generic((__force void *)dst,
20395 - (__force void *)src, size);
20396 + return copy_user_generic((__force_kernel void *)____m(dst),
20397 + (__force_kernel const void *)____m(src), size);
20398 }
20399 }
20400
20401 -static __must_check __always_inline int
20402 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20403 +static __must_check __always_inline unsigned long
20404 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20405 {
20406 return __copy_from_user_nocheck(dst, src, size);
20407 }
20408
20409 -static __must_check __always_inline int
20410 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20411 +static __must_check __always_inline unsigned long
20412 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20413 {
20414 return __copy_to_user_nocheck(dst, src, size);
20415 }
20416
20417 -extern long __copy_user_nocache(void *dst, const void __user *src,
20418 - unsigned size, int zerorest);
20419 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20420 + unsigned long size, int zerorest);
20421
20422 -static inline int
20423 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20424 +static inline unsigned long
20425 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20426 {
20427 might_fault();
20428 +
20429 + if (size > INT_MAX)
20430 + return size;
20431 +
20432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20433 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20434 + return size;
20435 +#endif
20436 +
20437 return __copy_user_nocache(dst, src, size, 1);
20438 }
20439
20440 -static inline int
20441 +static inline unsigned long
20442 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20443 - unsigned size)
20444 + unsigned long size)
20445 {
20446 + if (size > INT_MAX)
20447 + return size;
20448 +
20449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20450 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20451 + return size;
20452 +#endif
20453 +
20454 return __copy_user_nocache(dst, src, size, 0);
20455 }
20456
20457 unsigned long
20458 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20459 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20460
20461 #endif /* _ASM_X86_UACCESS_64_H */
20462 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20463 index 5b238981..77fdd78 100644
20464 --- a/arch/x86/include/asm/word-at-a-time.h
20465 +++ b/arch/x86/include/asm/word-at-a-time.h
20466 @@ -11,7 +11,7 @@
20467 * and shift, for example.
20468 */
20469 struct word_at_a_time {
20470 - const unsigned long one_bits, high_bits;
20471 + unsigned long one_bits, high_bits;
20472 };
20473
20474 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20475 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20476 index e45e4da..44e8572 100644
20477 --- a/arch/x86/include/asm/x86_init.h
20478 +++ b/arch/x86/include/asm/x86_init.h
20479 @@ -129,7 +129,7 @@ struct x86_init_ops {
20480 struct x86_init_timers timers;
20481 struct x86_init_iommu iommu;
20482 struct x86_init_pci pci;
20483 -};
20484 +} __no_const;
20485
20486 /**
20487 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20488 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20489 void (*setup_percpu_clockev)(void);
20490 void (*early_percpu_clock_init)(void);
20491 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20492 -};
20493 +} __no_const;
20494
20495 struct timespec;
20496
20497 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20498 void (*save_sched_clock_state)(void);
20499 void (*restore_sched_clock_state)(void);
20500 void (*apic_post_init)(void);
20501 -};
20502 +} __no_const;
20503
20504 struct pci_dev;
20505 struct msi_msg;
20506 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20507 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20508 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20509 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20510 -};
20511 +} __no_const;
20512
20513 struct IO_APIC_route_entry;
20514 struct io_apic_irq_attr;
20515 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20516 unsigned int destination, int vector,
20517 struct io_apic_irq_attr *attr);
20518 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20519 -};
20520 +} __no_const;
20521
20522 extern struct x86_init_ops x86_init;
20523 extern struct x86_cpuinit_ops x86_cpuinit;
20524 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20525 index f58ef6c..a2abc78 100644
20526 --- a/arch/x86/include/asm/xen/page.h
20527 +++ b/arch/x86/include/asm/xen/page.h
20528 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20529 extern struct page *m2p_find_override(unsigned long mfn);
20530 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20531
20532 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20533 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20534 {
20535 unsigned long mfn;
20536
20537 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20538 index 7e7a79a..0824666 100644
20539 --- a/arch/x86/include/asm/xsave.h
20540 +++ b/arch/x86/include/asm/xsave.h
20541 @@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20542 if (unlikely(err))
20543 return -EFAULT;
20544
20545 + pax_open_userland();
20546 __asm__ __volatile__(ASM_STAC "\n"
20547 - "1:"XSAVE"\n"
20548 + "1:"
20549 + __copyuser_seg
20550 + XSAVE"\n"
20551 "2: " ASM_CLAC "\n"
20552 xstate_fault
20553 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20554 : "memory");
20555 + pax_close_userland();
20556 return err;
20557 }
20558
20559 @@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20560 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20561 {
20562 int err = 0;
20563 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20564 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20565 u32 lmask = mask;
20566 u32 hmask = mask >> 32;
20567
20568 + pax_open_userland();
20569 __asm__ __volatile__(ASM_STAC "\n"
20570 - "1:"XRSTOR"\n"
20571 + "1:"
20572 + __copyuser_seg
20573 + XRSTOR"\n"
20574 "2: " ASM_CLAC "\n"
20575 xstate_fault
20576 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20577 : "memory"); /* memory required? */
20578 + pax_close_userland();
20579 return err;
20580 }
20581
20582 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20583 index d993e33..8db1b18 100644
20584 --- a/arch/x86/include/uapi/asm/e820.h
20585 +++ b/arch/x86/include/uapi/asm/e820.h
20586 @@ -58,7 +58,7 @@ struct e820map {
20587 #define ISA_START_ADDRESS 0xa0000
20588 #define ISA_END_ADDRESS 0x100000
20589
20590 -#define BIOS_BEGIN 0x000a0000
20591 +#define BIOS_BEGIN 0x000c0000
20592 #define BIOS_END 0x00100000
20593
20594 #define BIOS_ROM_BASE 0xffe00000
20595 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20596 index 7b0a55a..ad115bf 100644
20597 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20598 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20599 @@ -49,7 +49,6 @@
20600 #define EFLAGS 144
20601 #define RSP 152
20602 #define SS 160
20603 -#define ARGOFFSET R11
20604 #endif /* __ASSEMBLY__ */
20605
20606 /* top of stack page */
20607 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20608 index 8f1e774..9b4c381 100644
20609 --- a/arch/x86/kernel/Makefile
20610 +++ b/arch/x86/kernel/Makefile
20611 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20612 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20613 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20614 obj-y += probe_roms.o
20615 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20616 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20617 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20618 obj-$(CONFIG_X86_64) += mcount_64.o
20619 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20620 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20621 index a3eadfd..56fdd27 100644
20622 --- a/arch/x86/kernel/acpi/boot.c
20623 +++ b/arch/x86/kernel/acpi/boot.c
20624 @@ -1282,7 +1282,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20625 * If your system is blacklisted here, but you find that acpi=force
20626 * works for you, please contact linux-acpi@vger.kernel.org
20627 */
20628 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20629 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20630 /*
20631 * Boxes that need ACPI disabled
20632 */
20633 @@ -1357,7 +1357,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20634 };
20635
20636 /* second table for DMI checks that should run after early-quirks */
20637 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20638 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20639 /*
20640 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20641 * which includes some code which overrides all temperature
20642 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20643 index 3136820..e2c6577 100644
20644 --- a/arch/x86/kernel/acpi/sleep.c
20645 +++ b/arch/x86/kernel/acpi/sleep.c
20646 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20647 #else /* CONFIG_64BIT */
20648 #ifdef CONFIG_SMP
20649 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20650 +
20651 + pax_open_kernel();
20652 early_gdt_descr.address =
20653 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20654 + pax_close_kernel();
20655 +
20656 initial_gs = per_cpu_offset(smp_processor_id());
20657 #endif
20658 initial_code = (unsigned long)wakeup_long64;
20659 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20660 index 665c6b7..eae4d56 100644
20661 --- a/arch/x86/kernel/acpi/wakeup_32.S
20662 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20663 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20664 # and restore the stack ... but you need gdt for this to work
20665 movl saved_context_esp, %esp
20666
20667 - movl %cs:saved_magic, %eax
20668 - cmpl $0x12345678, %eax
20669 + cmpl $0x12345678, saved_magic
20670 jne bogus_magic
20671
20672 # jump to place where we left off
20673 - movl saved_eip, %eax
20674 - jmp *%eax
20675 + jmp *(saved_eip)
20676
20677 bogus_magic:
20678 jmp bogus_magic
20679 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20680 index 703130f..27a155d 100644
20681 --- a/arch/x86/kernel/alternative.c
20682 +++ b/arch/x86/kernel/alternative.c
20683 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20684 */
20685 for (a = start; a < end; a++) {
20686 instr = (u8 *)&a->instr_offset + a->instr_offset;
20687 +
20688 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20689 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20691 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20692 +#endif
20693 +
20694 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20695 BUG_ON(a->replacementlen > a->instrlen);
20696 BUG_ON(a->instrlen > sizeof(insnbuf));
20697 @@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20698 add_nops(insnbuf + a->replacementlen,
20699 a->instrlen - a->replacementlen);
20700
20701 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20702 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20703 + instr = ktva_ktla(instr);
20704 +#endif
20705 +
20706 text_poke_early(instr, insnbuf, a->instrlen);
20707 }
20708 }
20709 @@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20710 for (poff = start; poff < end; poff++) {
20711 u8 *ptr = (u8 *)poff + *poff;
20712
20713 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20714 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20715 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20716 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20717 +#endif
20718 +
20719 if (!*poff || ptr < text || ptr >= text_end)
20720 continue;
20721 /* turn DS segment override prefix into lock prefix */
20722 - if (*ptr == 0x3e)
20723 + if (*ktla_ktva(ptr) == 0x3e)
20724 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20725 }
20726 mutex_unlock(&text_mutex);
20727 @@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20728 for (poff = start; poff < end; poff++) {
20729 u8 *ptr = (u8 *)poff + *poff;
20730
20731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20732 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20733 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20734 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20735 +#endif
20736 +
20737 if (!*poff || ptr < text || ptr >= text_end)
20738 continue;
20739 /* turn lock prefix into DS segment override prefix */
20740 - if (*ptr == 0xf0)
20741 + if (*ktla_ktva(ptr) == 0xf0)
20742 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20743 }
20744 mutex_unlock(&text_mutex);
20745 @@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20746
20747 BUG_ON(p->len > MAX_PATCH_LEN);
20748 /* prep the buffer with the original instructions */
20749 - memcpy(insnbuf, p->instr, p->len);
20750 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20751 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20752 (unsigned long)p->instr, p->len);
20753
20754 @@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20755 if (!uniproc_patched || num_possible_cpus() == 1)
20756 free_init_pages("SMP alternatives",
20757 (unsigned long)__smp_locks,
20758 - (unsigned long)__smp_locks_end);
20759 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20760 #endif
20761
20762 apply_paravirt(__parainstructions, __parainstructions_end);
20763 @@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20764 * instructions. And on the local CPU you need to be protected again NMI or MCE
20765 * handlers seeing an inconsistent instruction while you patch.
20766 */
20767 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20768 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20769 size_t len)
20770 {
20771 unsigned long flags;
20772 local_irq_save(flags);
20773 - memcpy(addr, opcode, len);
20774 +
20775 + pax_open_kernel();
20776 + memcpy(ktla_ktva(addr), opcode, len);
20777 sync_core();
20778 + pax_close_kernel();
20779 +
20780 local_irq_restore(flags);
20781 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20782 that causes hangs on some VIA CPUs. */
20783 @@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20784 */
20785 void *text_poke(void *addr, const void *opcode, size_t len)
20786 {
20787 - unsigned long flags;
20788 - char *vaddr;
20789 + unsigned char *vaddr = ktla_ktva(addr);
20790 struct page *pages[2];
20791 - int i;
20792 + size_t i;
20793
20794 if (!core_kernel_text((unsigned long)addr)) {
20795 - pages[0] = vmalloc_to_page(addr);
20796 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20797 + pages[0] = vmalloc_to_page(vaddr);
20798 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20799 } else {
20800 - pages[0] = virt_to_page(addr);
20801 + pages[0] = virt_to_page(vaddr);
20802 WARN_ON(!PageReserved(pages[0]));
20803 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20804 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20805 }
20806 BUG_ON(!pages[0]);
20807 - local_irq_save(flags);
20808 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20809 - if (pages[1])
20810 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20811 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20812 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20813 - clear_fixmap(FIX_TEXT_POKE0);
20814 - if (pages[1])
20815 - clear_fixmap(FIX_TEXT_POKE1);
20816 - local_flush_tlb();
20817 - sync_core();
20818 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20819 - that causes hangs on some VIA CPUs. */
20820 + text_poke_early(addr, opcode, len);
20821 for (i = 0; i < len; i++)
20822 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20823 - local_irq_restore(flags);
20824 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20825 return addr;
20826 }
20827
20828 @@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20829 if (likely(!bp_patching_in_progress))
20830 return 0;
20831
20832 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20833 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20834 return 0;
20835
20836 /* set up the specified breakpoint handler */
20837 @@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20838 */
20839 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20840 {
20841 - unsigned char int3 = 0xcc;
20842 + const unsigned char int3 = 0xcc;
20843
20844 bp_int3_handler = handler;
20845 bp_int3_addr = (u8 *)addr + sizeof(int3);
20846 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20847 index ba6cc04..06fd971 100644
20848 --- a/arch/x86/kernel/apic/apic.c
20849 +++ b/arch/x86/kernel/apic/apic.c
20850 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20851 /*
20852 * Debug level, exported for io_apic.c
20853 */
20854 -unsigned int apic_verbosity;
20855 +int apic_verbosity;
20856
20857 int pic_mode;
20858
20859 @@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20860 apic_write(APIC_ESR, 0);
20861 v = apic_read(APIC_ESR);
20862 ack_APIC_irq();
20863 - atomic_inc(&irq_err_count);
20864 + atomic_inc_unchecked(&irq_err_count);
20865
20866 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20867 smp_processor_id(), v);
20868 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20869 index de918c4..32eed23 100644
20870 --- a/arch/x86/kernel/apic/apic_flat_64.c
20871 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20872 @@ -154,7 +154,7 @@ static int flat_probe(void)
20873 return 1;
20874 }
20875
20876 -static struct apic apic_flat = {
20877 +static struct apic apic_flat __read_only = {
20878 .name = "flat",
20879 .probe = flat_probe,
20880 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20881 @@ -260,7 +260,7 @@ static int physflat_probe(void)
20882 return 0;
20883 }
20884
20885 -static struct apic apic_physflat = {
20886 +static struct apic apic_physflat __read_only = {
20887
20888 .name = "physical flat",
20889 .probe = physflat_probe,
20890 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20891 index b205cdb..d8503ff 100644
20892 --- a/arch/x86/kernel/apic/apic_noop.c
20893 +++ b/arch/x86/kernel/apic/apic_noop.c
20894 @@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20895 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20896 }
20897
20898 -struct apic apic_noop = {
20899 +struct apic apic_noop __read_only = {
20900 .name = "noop",
20901 .probe = noop_probe,
20902 .acpi_madt_oem_check = NULL,
20903 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20904 index c4a8d63..fe893ac 100644
20905 --- a/arch/x86/kernel/apic/bigsmp_32.c
20906 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20907 @@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20908 return dmi_bigsmp;
20909 }
20910
20911 -static struct apic apic_bigsmp = {
20912 +static struct apic apic_bigsmp __read_only = {
20913
20914 .name = "bigsmp",
20915 .probe = probe_bigsmp,
20916 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20917 index 1183d54..6158e47 100644
20918 --- a/arch/x86/kernel/apic/io_apic.c
20919 +++ b/arch/x86/kernel/apic/io_apic.c
20920 @@ -1230,7 +1230,7 @@ out:
20921 }
20922 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20923
20924 -void lock_vector_lock(void)
20925 +void lock_vector_lock(void) __acquires(vector_lock)
20926 {
20927 /* Used to the online set of cpus does not change
20928 * during assign_irq_vector.
20929 @@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20930 raw_spin_lock(&vector_lock);
20931 }
20932
20933 -void unlock_vector_lock(void)
20934 +void unlock_vector_lock(void) __releases(vector_lock)
20935 {
20936 raw_spin_unlock(&vector_lock);
20937 }
20938 @@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20939 ack_APIC_irq();
20940 }
20941
20942 -atomic_t irq_mis_count;
20943 +atomic_unchecked_t irq_mis_count;
20944
20945 #ifdef CONFIG_GENERIC_PENDING_IRQ
20946 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20947 @@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20948 * at the cpu.
20949 */
20950 if (!(v & (1 << (i & 0x1f)))) {
20951 - atomic_inc(&irq_mis_count);
20952 + atomic_inc_unchecked(&irq_mis_count);
20953
20954 eoi_ioapic_irq(irq, cfg);
20955 }
20956 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20957 index bda4886..f9c7195 100644
20958 --- a/arch/x86/kernel/apic/probe_32.c
20959 +++ b/arch/x86/kernel/apic/probe_32.c
20960 @@ -72,7 +72,7 @@ static int probe_default(void)
20961 return 1;
20962 }
20963
20964 -static struct apic apic_default = {
20965 +static struct apic apic_default __read_only = {
20966
20967 .name = "default",
20968 .probe = probe_default,
20969 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20970 index e658f21..b695a1a 100644
20971 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20972 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20973 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20974 return notifier_from_errno(err);
20975 }
20976
20977 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20978 +static struct notifier_block x2apic_cpu_notifier = {
20979 .notifier_call = update_clusterinfo,
20980 };
20981
20982 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20983 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20984 }
20985
20986 -static struct apic apic_x2apic_cluster = {
20987 +static struct apic apic_x2apic_cluster __read_only = {
20988
20989 .name = "cluster x2apic",
20990 .probe = x2apic_cluster_probe,
20991 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20992 index 6fae733..5ca17af 100644
20993 --- a/arch/x86/kernel/apic/x2apic_phys.c
20994 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20995 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20996 return apic == &apic_x2apic_phys;
20997 }
20998
20999 -static struct apic apic_x2apic_phys = {
21000 +static struct apic apic_x2apic_phys __read_only = {
21001
21002 .name = "physical x2apic",
21003 .probe = x2apic_phys_probe,
21004 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21005 index 8e9dcfd..c61b3e4 100644
21006 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21007 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21008 @@ -348,7 +348,7 @@ static int uv_probe(void)
21009 return apic == &apic_x2apic_uv_x;
21010 }
21011
21012 -static struct apic __refdata apic_x2apic_uv_x = {
21013 +static struct apic apic_x2apic_uv_x __read_only = {
21014
21015 .name = "UV large system",
21016 .probe = uv_probe,
21017 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21018 index 5848744..56cb598 100644
21019 --- a/arch/x86/kernel/apm_32.c
21020 +++ b/arch/x86/kernel/apm_32.c
21021 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21022 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21023 * even though they are called in protected mode.
21024 */
21025 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21026 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21027 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21028
21029 static const char driver_version[] = "1.16ac"; /* no spaces */
21030 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21031 BUG_ON(cpu != 0);
21032 gdt = get_cpu_gdt_table(cpu);
21033 save_desc_40 = gdt[0x40 / 8];
21034 +
21035 + pax_open_kernel();
21036 gdt[0x40 / 8] = bad_bios_desc;
21037 + pax_close_kernel();
21038
21039 apm_irq_save(flags);
21040 APM_DO_SAVE_SEGS;
21041 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21042 &call->esi);
21043 APM_DO_RESTORE_SEGS;
21044 apm_irq_restore(flags);
21045 +
21046 + pax_open_kernel();
21047 gdt[0x40 / 8] = save_desc_40;
21048 + pax_close_kernel();
21049 +
21050 put_cpu();
21051
21052 return call->eax & 0xff;
21053 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21054 BUG_ON(cpu != 0);
21055 gdt = get_cpu_gdt_table(cpu);
21056 save_desc_40 = gdt[0x40 / 8];
21057 +
21058 + pax_open_kernel();
21059 gdt[0x40 / 8] = bad_bios_desc;
21060 + pax_close_kernel();
21061
21062 apm_irq_save(flags);
21063 APM_DO_SAVE_SEGS;
21064 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21065 &call->eax);
21066 APM_DO_RESTORE_SEGS;
21067 apm_irq_restore(flags);
21068 +
21069 + pax_open_kernel();
21070 gdt[0x40 / 8] = save_desc_40;
21071 + pax_close_kernel();
21072 +
21073 put_cpu();
21074 return error;
21075 }
21076 @@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21077 * code to that CPU.
21078 */
21079 gdt = get_cpu_gdt_table(0);
21080 +
21081 + pax_open_kernel();
21082 set_desc_base(&gdt[APM_CS >> 3],
21083 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21084 set_desc_base(&gdt[APM_CS_16 >> 3],
21085 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21086 set_desc_base(&gdt[APM_DS >> 3],
21087 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21088 + pax_close_kernel();
21089
21090 proc_create("apm", 0, NULL, &apm_file_ops);
21091
21092 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21093 index 9f6b934..cf5ffb3 100644
21094 --- a/arch/x86/kernel/asm-offsets.c
21095 +++ b/arch/x86/kernel/asm-offsets.c
21096 @@ -32,6 +32,8 @@ void common(void) {
21097 OFFSET(TI_flags, thread_info, flags);
21098 OFFSET(TI_status, thread_info, status);
21099 OFFSET(TI_addr_limit, thread_info, addr_limit);
21100 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21101 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21102
21103 BLANK();
21104 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21105 @@ -52,8 +54,26 @@ void common(void) {
21106 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21107 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21108 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21109 +
21110 +#ifdef CONFIG_PAX_KERNEXEC
21111 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21112 #endif
21113
21114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21115 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21116 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21117 +#ifdef CONFIG_X86_64
21118 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21119 +#endif
21120 +#endif
21121 +
21122 +#endif
21123 +
21124 + BLANK();
21125 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21126 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21127 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21128 +
21129 #ifdef CONFIG_XEN
21130 BLANK();
21131 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21132 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21133 index e7c798b..2b2019b 100644
21134 --- a/arch/x86/kernel/asm-offsets_64.c
21135 +++ b/arch/x86/kernel/asm-offsets_64.c
21136 @@ -77,6 +77,7 @@ int main(void)
21137 BLANK();
21138 #undef ENTRY
21139
21140 + DEFINE(TSS_size, sizeof(struct tss_struct));
21141 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21142 BLANK();
21143
21144 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21145 index 80091ae..0c5184f 100644
21146 --- a/arch/x86/kernel/cpu/Makefile
21147 +++ b/arch/x86/kernel/cpu/Makefile
21148 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21149 CFLAGS_REMOVE_perf_event.o = -pg
21150 endif
21151
21152 -# Make sure load_percpu_segment has no stackprotector
21153 -nostackp := $(call cc-option, -fno-stack-protector)
21154 -CFLAGS_common.o := $(nostackp)
21155 -
21156 obj-y := intel_cacheinfo.o scattered.o topology.o
21157 obj-y += common.o
21158 obj-y += rdrand.o
21159 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21160 index 813d29d..6e542d4 100644
21161 --- a/arch/x86/kernel/cpu/amd.c
21162 +++ b/arch/x86/kernel/cpu/amd.c
21163 @@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21164 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21165 {
21166 /* AMD errata T13 (order #21922) */
21167 - if ((c->x86 == 6)) {
21168 + if (c->x86 == 6) {
21169 /* Duron Rev A0 */
21170 if (c->x86_model == 3 && c->x86_mask == 0)
21171 size = 64;
21172 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21173 index cfa9b5b..19b5084 100644
21174 --- a/arch/x86/kernel/cpu/common.c
21175 +++ b/arch/x86/kernel/cpu/common.c
21176 @@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21177
21178 static const struct cpu_dev *this_cpu = &default_cpu;
21179
21180 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21181 -#ifdef CONFIG_X86_64
21182 - /*
21183 - * We need valid kernel segments for data and code in long mode too
21184 - * IRET will check the segment types kkeil 2000/10/28
21185 - * Also sysret mandates a special GDT layout
21186 - *
21187 - * TLS descriptors are currently at a different place compared to i386.
21188 - * Hopefully nobody expects them at a fixed place (Wine?)
21189 - */
21190 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21191 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21192 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21193 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21194 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21195 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21196 -#else
21197 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21198 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21199 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21200 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21201 - /*
21202 - * Segments used for calling PnP BIOS have byte granularity.
21203 - * They code segments and data segments have fixed 64k limits,
21204 - * the transfer segment sizes are set at run time.
21205 - */
21206 - /* 32-bit code */
21207 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21208 - /* 16-bit code */
21209 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21210 - /* 16-bit data */
21211 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21212 - /* 16-bit data */
21213 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21214 - /* 16-bit data */
21215 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21216 - /*
21217 - * The APM segments have byte granularity and their bases
21218 - * are set at run time. All have 64k limits.
21219 - */
21220 - /* 32-bit code */
21221 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21222 - /* 16-bit code */
21223 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21224 - /* data */
21225 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21226 -
21227 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21228 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21229 - GDT_STACK_CANARY_INIT
21230 -#endif
21231 -} };
21232 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21233 -
21234 static int __init x86_xsave_setup(char *s)
21235 {
21236 if (strlen(s))
21237 @@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21238 }
21239 }
21240
21241 +#ifdef CONFIG_X86_64
21242 +static __init int setup_disable_pcid(char *arg)
21243 +{
21244 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21245 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21246 +
21247 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21248 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21249 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21250 +#endif
21251 +
21252 + return 1;
21253 +}
21254 +__setup("nopcid", setup_disable_pcid);
21255 +
21256 +static void setup_pcid(struct cpuinfo_x86 *c)
21257 +{
21258 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21259 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21260 +
21261 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21262 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21263 + pax_open_kernel();
21264 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21265 + pax_close_kernel();
21266 + printk("PAX: slow and weak UDEREF enabled\n");
21267 + } else
21268 + printk("PAX: UDEREF disabled\n");
21269 +#endif
21270 +
21271 + return;
21272 + }
21273 +
21274 + printk("PAX: PCID detected\n");
21275 + set_in_cr4(X86_CR4_PCIDE);
21276 +
21277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21278 + pax_open_kernel();
21279 + clone_pgd_mask = ~(pgdval_t)0UL;
21280 + pax_close_kernel();
21281 + if (pax_user_shadow_base)
21282 + printk("PAX: weak UDEREF enabled\n");
21283 + else {
21284 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21285 + printk("PAX: strong UDEREF enabled\n");
21286 + }
21287 +#endif
21288 +
21289 + if (cpu_has(c, X86_FEATURE_INVPCID))
21290 + printk("PAX: INVPCID detected\n");
21291 +}
21292 +#endif
21293 +
21294 /*
21295 * Some CPU features depend on higher CPUID levels, which may not always
21296 * be available due to CPUID level capping or broken virtualization
21297 @@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21298 {
21299 struct desc_ptr gdt_descr;
21300
21301 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21302 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21303 gdt_descr.size = GDT_SIZE - 1;
21304 load_gdt(&gdt_descr);
21305 /* Reload the per-cpu base */
21306 @@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21307 setup_smep(c);
21308 setup_smap(c);
21309
21310 +#ifdef CONFIG_X86_64
21311 + setup_pcid(c);
21312 +#endif
21313 +
21314 /*
21315 * The vendor-specific functions might have changed features.
21316 * Now we do "generic changes."
21317 @@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21318 /* Filter out anything that depends on CPUID levels we don't have */
21319 filter_cpuid_features(c, true);
21320
21321 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21322 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21323 +#endif
21324 +
21325 /* If the model name is still unset, do table lookup. */
21326 if (!c->x86_model_id[0]) {
21327 const char *p;
21328 @@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21329 void enable_sep_cpu(void)
21330 {
21331 int cpu = get_cpu();
21332 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21333 + struct tss_struct *tss = init_tss + cpu;
21334
21335 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21336 put_cpu();
21337 @@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21338 }
21339 __setup("clearcpuid=", setup_disablecpuid);
21340
21341 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21342 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21343 +
21344 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21345 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21346 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21347 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21348
21349 #ifdef CONFIG_X86_64
21350 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21351 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21352 - (unsigned long) debug_idt_table };
21353 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21354 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21355
21356 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21357 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21358 @@ -1309,7 +1318,7 @@ void cpu_init(void)
21359 */
21360 load_ucode_ap();
21361
21362 - t = &per_cpu(init_tss, cpu);
21363 + t = init_tss + cpu;
21364 oist = &per_cpu(orig_ist, cpu);
21365
21366 #ifdef CONFIG_NUMA
21367 @@ -1341,7 +1350,6 @@ void cpu_init(void)
21368 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21369 barrier();
21370
21371 - x86_configure_nx();
21372 enable_x2apic();
21373
21374 /*
21375 @@ -1393,7 +1401,7 @@ void cpu_init(void)
21376 {
21377 int cpu = smp_processor_id();
21378 struct task_struct *curr = current;
21379 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21380 + struct tss_struct *t = init_tss + cpu;
21381 struct thread_struct *thread = &curr->thread;
21382
21383 wait_for_master_cpu(cpu);
21384 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21385 index c703507..28535e3 100644
21386 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21387 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21388 @@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21389 };
21390
21391 #ifdef CONFIG_AMD_NB
21392 +static struct attribute *default_attrs_amd_nb[] = {
21393 + &type.attr,
21394 + &level.attr,
21395 + &coherency_line_size.attr,
21396 + &physical_line_partition.attr,
21397 + &ways_of_associativity.attr,
21398 + &number_of_sets.attr,
21399 + &size.attr,
21400 + &shared_cpu_map.attr,
21401 + &shared_cpu_list.attr,
21402 + NULL,
21403 + NULL,
21404 + NULL,
21405 + NULL
21406 +};
21407 +
21408 static struct attribute **amd_l3_attrs(void)
21409 {
21410 static struct attribute **attrs;
21411 @@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21412
21413 n = ARRAY_SIZE(default_attrs);
21414
21415 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21416 - n += 2;
21417 -
21418 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21419 - n += 1;
21420 -
21421 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21422 - if (attrs == NULL)
21423 - return attrs = default_attrs;
21424 -
21425 - for (n = 0; default_attrs[n]; n++)
21426 - attrs[n] = default_attrs[n];
21427 + attrs = default_attrs_amd_nb;
21428
21429 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21430 attrs[n++] = &cache_disable_0.attr;
21431 @@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21432 .default_attrs = default_attrs,
21433 };
21434
21435 +#ifdef CONFIG_AMD_NB
21436 +static struct kobj_type ktype_cache_amd_nb = {
21437 + .sysfs_ops = &sysfs_ops,
21438 + .default_attrs = default_attrs_amd_nb,
21439 +};
21440 +#endif
21441 +
21442 static struct kobj_type ktype_percpu_entry = {
21443 .sysfs_ops = &sysfs_ops,
21444 };
21445 @@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21446 return retval;
21447 }
21448
21449 +#ifdef CONFIG_AMD_NB
21450 + amd_l3_attrs();
21451 +#endif
21452 +
21453 for (i = 0; i < num_cache_leaves; i++) {
21454 + struct kobj_type *ktype;
21455 +
21456 this_object = INDEX_KOBJECT_PTR(cpu, i);
21457 this_object->cpu = cpu;
21458 this_object->index = i;
21459
21460 this_leaf = CPUID4_INFO_IDX(cpu, i);
21461
21462 - ktype_cache.default_attrs = default_attrs;
21463 + ktype = &ktype_cache;
21464 #ifdef CONFIG_AMD_NB
21465 if (this_leaf->base.nb)
21466 - ktype_cache.default_attrs = amd_l3_attrs();
21467 + ktype = &ktype_cache_amd_nb;
21468 #endif
21469 retval = kobject_init_and_add(&(this_object->kobj),
21470 - &ktype_cache,
21471 + ktype,
21472 per_cpu(ici_cache_kobject, cpu),
21473 "index%1lu", i);
21474 if (unlikely(retval)) {
21475 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21476 index 61a9668ce..b446a37 100644
21477 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21478 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21479 @@ -45,6 +45,7 @@
21480 #include <asm/processor.h>
21481 #include <asm/mce.h>
21482 #include <asm/msr.h>
21483 +#include <asm/local.h>
21484
21485 #include "mce-internal.h"
21486
21487 @@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21488 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21489 m->cs, m->ip);
21490
21491 - if (m->cs == __KERNEL_CS)
21492 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21493 print_symbol("{%s}", m->ip);
21494 pr_cont("\n");
21495 }
21496 @@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21497
21498 #define PANIC_TIMEOUT 5 /* 5 seconds */
21499
21500 -static atomic_t mce_paniced;
21501 +static atomic_unchecked_t mce_paniced;
21502
21503 static int fake_panic;
21504 -static atomic_t mce_fake_paniced;
21505 +static atomic_unchecked_t mce_fake_paniced;
21506
21507 /* Panic in progress. Enable interrupts and wait for final IPI */
21508 static void wait_for_panic(void)
21509 @@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21510 /*
21511 * Make sure only one CPU runs in machine check panic
21512 */
21513 - if (atomic_inc_return(&mce_paniced) > 1)
21514 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21515 wait_for_panic();
21516 barrier();
21517
21518 @@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21519 console_verbose();
21520 } else {
21521 /* Don't log too much for fake panic */
21522 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21523 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21524 return;
21525 }
21526 /* First print corrected ones that are still unlogged */
21527 @@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21528 if (!fake_panic) {
21529 if (panic_timeout == 0)
21530 panic_timeout = mca_cfg.panic_timeout;
21531 - panic(msg);
21532 + panic("%s", msg);
21533 } else
21534 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21535 }
21536 @@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21537 * might have been modified by someone else.
21538 */
21539 rmb();
21540 - if (atomic_read(&mce_paniced))
21541 + if (atomic_read_unchecked(&mce_paniced))
21542 wait_for_panic();
21543 if (!mca_cfg.monarch_timeout)
21544 goto out;
21545 @@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21546 }
21547
21548 /* Call the installed machine check handler for this CPU setup. */
21549 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21550 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21551 unexpected_machine_check;
21552
21553 /*
21554 @@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21555 return;
21556 }
21557
21558 + pax_open_kernel();
21559 machine_check_vector = do_machine_check;
21560 + pax_close_kernel();
21561
21562 __mcheck_cpu_init_generic();
21563 __mcheck_cpu_init_vendor(c);
21564 @@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21565 */
21566
21567 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21568 -static int mce_chrdev_open_count; /* #times opened */
21569 +static local_t mce_chrdev_open_count; /* #times opened */
21570 static int mce_chrdev_open_exclu; /* already open exclusive? */
21571
21572 static int mce_chrdev_open(struct inode *inode, struct file *file)
21573 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21574 spin_lock(&mce_chrdev_state_lock);
21575
21576 if (mce_chrdev_open_exclu ||
21577 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21578 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21579 spin_unlock(&mce_chrdev_state_lock);
21580
21581 return -EBUSY;
21582 @@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21583
21584 if (file->f_flags & O_EXCL)
21585 mce_chrdev_open_exclu = 1;
21586 - mce_chrdev_open_count++;
21587 + local_inc(&mce_chrdev_open_count);
21588
21589 spin_unlock(&mce_chrdev_state_lock);
21590
21591 @@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21592 {
21593 spin_lock(&mce_chrdev_state_lock);
21594
21595 - mce_chrdev_open_count--;
21596 + local_dec(&mce_chrdev_open_count);
21597 mce_chrdev_open_exclu = 0;
21598
21599 spin_unlock(&mce_chrdev_state_lock);
21600 @@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21601
21602 for (i = 0; i < mca_cfg.banks; i++) {
21603 struct mce_bank *b = &mce_banks[i];
21604 - struct device_attribute *a = &b->attr;
21605 + device_attribute_no_const *a = &b->attr;
21606
21607 sysfs_attr_init(&a->attr);
21608 a->attr.name = b->attrname;
21609 @@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21610 static void mce_reset(void)
21611 {
21612 cpu_missing = 0;
21613 - atomic_set(&mce_fake_paniced, 0);
21614 + atomic_set_unchecked(&mce_fake_paniced, 0);
21615 atomic_set(&mce_executing, 0);
21616 atomic_set(&mce_callin, 0);
21617 atomic_set(&global_nwo, 0);
21618 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21619 index a304298..49b6d06 100644
21620 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21621 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21622 @@ -10,6 +10,7 @@
21623 #include <asm/processor.h>
21624 #include <asm/mce.h>
21625 #include <asm/msr.h>
21626 +#include <asm/pgtable.h>
21627
21628 /* By default disabled */
21629 int mce_p5_enabled __read_mostly;
21630 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21631 if (!cpu_has(c, X86_FEATURE_MCE))
21632 return;
21633
21634 + pax_open_kernel();
21635 machine_check_vector = pentium_machine_check;
21636 + pax_close_kernel();
21637 /* Make sure the vector pointer is visible before we enable MCEs: */
21638 wmb();
21639
21640 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21641 index 7dc5564..1273569 100644
21642 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21643 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21644 @@ -9,6 +9,7 @@
21645 #include <asm/processor.h>
21646 #include <asm/mce.h>
21647 #include <asm/msr.h>
21648 +#include <asm/pgtable.h>
21649
21650 /* Machine check handler for WinChip C6: */
21651 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21652 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21653 {
21654 u32 lo, hi;
21655
21656 + pax_open_kernel();
21657 machine_check_vector = winchip_machine_check;
21658 + pax_close_kernel();
21659 /* Make sure the vector pointer is visible before we enable MCEs: */
21660 wmb();
21661
21662 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21663 index 36a8361..e7058c2 100644
21664 --- a/arch/x86/kernel/cpu/microcode/core.c
21665 +++ b/arch/x86/kernel/cpu/microcode/core.c
21666 @@ -518,7 +518,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21667 return NOTIFY_OK;
21668 }
21669
21670 -static struct notifier_block __refdata mc_cpu_notifier = {
21671 +static struct notifier_block mc_cpu_notifier = {
21672 .notifier_call = mc_cpu_callback,
21673 };
21674
21675 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21676 index c6826d1..8dc677e 100644
21677 --- a/arch/x86/kernel/cpu/microcode/intel.c
21678 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21679 @@ -196,6 +196,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
21680 struct microcode_header_intel mc_header;
21681 unsigned int mc_size;
21682
21683 + if (leftover < sizeof(mc_header)) {
21684 + pr_err("error! Truncated header in microcode data file\n");
21685 + break;
21686 + }
21687 +
21688 if (get_ucode_data(&mc_header, ucode_ptr, sizeof(mc_header)))
21689 break;
21690
21691 @@ -293,13 +298,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21692
21693 static int get_ucode_user(void *to, const void *from, size_t n)
21694 {
21695 - return copy_from_user(to, from, n);
21696 + return copy_from_user(to, (const void __force_user *)from, n);
21697 }
21698
21699 static enum ucode_state
21700 request_microcode_user(int cpu, const void __user *buf, size_t size)
21701 {
21702 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21703 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21704 }
21705
21706 static void microcode_fini_cpu(int cpu)
21707 diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
21708 index ec9df6f..420eb93 100644
21709 --- a/arch/x86/kernel/cpu/microcode/intel_early.c
21710 +++ b/arch/x86/kernel/cpu/microcode/intel_early.c
21711 @@ -321,7 +321,11 @@ get_matching_model_microcode(int cpu, unsigned long start,
21712 unsigned int mc_saved_count = mc_saved_data->mc_saved_count;
21713 int i;
21714
21715 - while (leftover) {
21716 + while (leftover && mc_saved_count < ARRAY_SIZE(mc_saved_tmp)) {
21717 +
21718 + if (leftover < sizeof(mc_header))
21719 + break;
21720 +
21721 mc_header = (struct microcode_header_intel *)ucode_ptr;
21722
21723 mc_size = get_totalsize(mc_header);
21724 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21725 index ea5f363..cb0e905 100644
21726 --- a/arch/x86/kernel/cpu/mtrr/main.c
21727 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21728 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21729 u64 size_or_mask, size_and_mask;
21730 static bool mtrr_aps_delayed_init;
21731
21732 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21733 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21734
21735 const struct mtrr_ops *mtrr_if;
21736
21737 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21738 index df5e41f..816c719 100644
21739 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21740 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21741 @@ -25,7 +25,7 @@ struct mtrr_ops {
21742 int (*validate_add_page)(unsigned long base, unsigned long size,
21743 unsigned int type);
21744 int (*have_wrcomb)(void);
21745 -};
21746 +} __do_const;
21747
21748 extern int generic_get_free_region(unsigned long base, unsigned long size,
21749 int replace_reg);
21750 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21751 index 143e5f5..5825081 100644
21752 --- a/arch/x86/kernel/cpu/perf_event.c
21753 +++ b/arch/x86/kernel/cpu/perf_event.c
21754 @@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21755
21756 }
21757
21758 -static struct attribute_group x86_pmu_format_group = {
21759 +static attribute_group_no_const x86_pmu_format_group = {
21760 .name = "format",
21761 .attrs = NULL,
21762 };
21763 @@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21764 NULL,
21765 };
21766
21767 -static struct attribute_group x86_pmu_events_group = {
21768 +static attribute_group_no_const x86_pmu_events_group = {
21769 .name = "events",
21770 .attrs = events_attr,
21771 };
21772 @@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21773 if (idx > GDT_ENTRIES)
21774 return 0;
21775
21776 - desc = raw_cpu_ptr(gdt_page.gdt);
21777 + desc = get_cpu_gdt_table(smp_processor_id());
21778 }
21779
21780 return get_desc_base(desc + idx);
21781 @@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21782 break;
21783
21784 perf_callchain_store(entry, frame.return_address);
21785 - fp = frame.next_frame;
21786 + fp = (const void __force_user *)frame.next_frame;
21787 }
21788 }
21789
21790 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21791 index 639d128..e92d7e5 100644
21792 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21793 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21794 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21795 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21796 {
21797 struct attribute **attrs;
21798 - struct attribute_group *attr_group;
21799 + attribute_group_no_const *attr_group;
21800 int i = 0, j;
21801
21802 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21803 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21804 index 498b6d9..4126515 100644
21805 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21806 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21807 @@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21808 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21809
21810 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21811 - u64 capabilities;
21812 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21813
21814 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21815 - x86_pmu.intel_cap.capabilities = capabilities;
21816 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21817 + x86_pmu.intel_cap.capabilities = capabilities;
21818 }
21819
21820 intel_ds_init();
21821 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21822 index 8c25674..30aa32e 100644
21823 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21824 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21825 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21826 NULL,
21827 };
21828
21829 -static struct attribute_group rapl_pmu_events_group = {
21830 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21831 .name = "events",
21832 .attrs = NULL, /* patched at runtime */
21833 };
21834 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21835 index e98f68c..1992b15 100644
21836 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21837 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21838 @@ -737,7 +737,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21839 static int __init uncore_type_init(struct intel_uncore_type *type)
21840 {
21841 struct intel_uncore_pmu *pmus;
21842 - struct attribute_group *attr_group;
21843 + attribute_group_no_const *attr_group;
21844 struct attribute **attrs;
21845 int i, j;
21846
21847 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21848 index 863d9b0..6289b63 100644
21849 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21850 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21851 @@ -114,7 +114,7 @@ struct intel_uncore_box {
21852 struct uncore_event_desc {
21853 struct kobj_attribute attr;
21854 const char *config;
21855 -};
21856 +} __do_const;
21857
21858 ssize_t uncore_event_show(struct kobject *kobj,
21859 struct kobj_attribute *attr, char *buf);
21860 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21861 index 3225ae6c..ee3c6db 100644
21862 --- a/arch/x86/kernel/cpuid.c
21863 +++ b/arch/x86/kernel/cpuid.c
21864 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21865 return notifier_from_errno(err);
21866 }
21867
21868 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21869 +static struct notifier_block cpuid_class_cpu_notifier =
21870 {
21871 .notifier_call = cpuid_class_cpu_callback,
21872 };
21873 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21874 index f5ab56d..d3b201a 100644
21875 --- a/arch/x86/kernel/crash.c
21876 +++ b/arch/x86/kernel/crash.c
21877 @@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21878 #ifdef CONFIG_X86_32
21879 struct pt_regs fixed_regs;
21880
21881 - if (!user_mode_vm(regs)) {
21882 + if (!user_mode(regs)) {
21883 crash_fixup_ss_esp(&fixed_regs, regs);
21884 regs = &fixed_regs;
21885 }
21886 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21887 index afa64ad..dce67dd 100644
21888 --- a/arch/x86/kernel/crash_dump_64.c
21889 +++ b/arch/x86/kernel/crash_dump_64.c
21890 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21891 return -ENOMEM;
21892
21893 if (userbuf) {
21894 - if (copy_to_user(buf, vaddr + offset, csize)) {
21895 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21896 iounmap(vaddr);
21897 return -EFAULT;
21898 }
21899 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21900 index f6dfd93..892ade4 100644
21901 --- a/arch/x86/kernel/doublefault.c
21902 +++ b/arch/x86/kernel/doublefault.c
21903 @@ -12,7 +12,7 @@
21904
21905 #define DOUBLEFAULT_STACKSIZE (1024)
21906 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21907 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21908 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21909
21910 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21911
21912 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21913 unsigned long gdt, tss;
21914
21915 native_store_gdt(&gdt_desc);
21916 - gdt = gdt_desc.address;
21917 + gdt = (unsigned long)gdt_desc.address;
21918
21919 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21920
21921 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21922 /* 0x2 bit is always set */
21923 .flags = X86_EFLAGS_SF | 0x2,
21924 .sp = STACK_START,
21925 - .es = __USER_DS,
21926 + .es = __KERNEL_DS,
21927 .cs = __KERNEL_CS,
21928 .ss = __KERNEL_DS,
21929 - .ds = __USER_DS,
21930 + .ds = __KERNEL_DS,
21931 .fs = __KERNEL_PERCPU,
21932
21933 .__cr3 = __pa_nodebug(swapper_pg_dir),
21934 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21935 index b74ebc7..2c95874 100644
21936 --- a/arch/x86/kernel/dumpstack.c
21937 +++ b/arch/x86/kernel/dumpstack.c
21938 @@ -2,6 +2,9 @@
21939 * Copyright (C) 1991, 1992 Linus Torvalds
21940 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21941 */
21942 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21943 +#define __INCLUDED_BY_HIDESYM 1
21944 +#endif
21945 #include <linux/kallsyms.h>
21946 #include <linux/kprobes.h>
21947 #include <linux/uaccess.h>
21948 @@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21949
21950 void printk_address(unsigned long address)
21951 {
21952 - pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21953 + pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21954 }
21955
21956 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21957 static void
21958 print_ftrace_graph_addr(unsigned long addr, void *data,
21959 const struct stacktrace_ops *ops,
21960 - struct thread_info *tinfo, int *graph)
21961 + struct task_struct *task, int *graph)
21962 {
21963 - struct task_struct *task;
21964 unsigned long ret_addr;
21965 int index;
21966
21967 if (addr != (unsigned long)return_to_handler)
21968 return;
21969
21970 - task = tinfo->task;
21971 index = task->curr_ret_stack;
21972
21973 if (!task->ret_stack || index < *graph)
21974 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21975 static inline void
21976 print_ftrace_graph_addr(unsigned long addr, void *data,
21977 const struct stacktrace_ops *ops,
21978 - struct thread_info *tinfo, int *graph)
21979 + struct task_struct *task, int *graph)
21980 { }
21981 #endif
21982
21983 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21984 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21985 */
21986
21987 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21988 - void *p, unsigned int size, void *end)
21989 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21990 {
21991 - void *t = tinfo;
21992 if (end) {
21993 if (p < end && p >= (end-THREAD_SIZE))
21994 return 1;
21995 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21996 }
21997
21998 unsigned long
21999 -print_context_stack(struct thread_info *tinfo,
22000 +print_context_stack(struct task_struct *task, void *stack_start,
22001 unsigned long *stack, unsigned long bp,
22002 const struct stacktrace_ops *ops, void *data,
22003 unsigned long *end, int *graph)
22004 {
22005 struct stack_frame *frame = (struct stack_frame *)bp;
22006
22007 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22008 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22009 unsigned long addr;
22010
22011 addr = *stack;
22012 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22013 } else {
22014 ops->address(data, addr, 0);
22015 }
22016 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22017 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22018 }
22019 stack++;
22020 }
22021 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22022 EXPORT_SYMBOL_GPL(print_context_stack);
22023
22024 unsigned long
22025 -print_context_stack_bp(struct thread_info *tinfo,
22026 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22027 unsigned long *stack, unsigned long bp,
22028 const struct stacktrace_ops *ops, void *data,
22029 unsigned long *end, int *graph)
22030 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22031 struct stack_frame *frame = (struct stack_frame *)bp;
22032 unsigned long *ret_addr = &frame->return_address;
22033
22034 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22035 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22036 unsigned long addr = *ret_addr;
22037
22038 if (!__kernel_text_address(addr))
22039 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22040 ops->address(data, addr, 1);
22041 frame = frame->next_frame;
22042 ret_addr = &frame->return_address;
22043 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22044 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22045 }
22046
22047 return (unsigned long)frame;
22048 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22049 static void print_trace_address(void *data, unsigned long addr, int reliable)
22050 {
22051 touch_nmi_watchdog();
22052 - printk(data);
22053 + printk("%s", (char *)data);
22054 printk_stack_address(addr, reliable);
22055 }
22056
22057 @@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22058 EXPORT_SYMBOL_GPL(oops_begin);
22059 NOKPROBE_SYMBOL(oops_begin);
22060
22061 +extern void gr_handle_kernel_exploit(void);
22062 +
22063 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22064 {
22065 if (regs && kexec_should_crash(current))
22066 @@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22067 panic("Fatal exception in interrupt");
22068 if (panic_on_oops)
22069 panic("Fatal exception");
22070 - do_exit(signr);
22071 +
22072 + gr_handle_kernel_exploit();
22073 +
22074 + do_group_exit(signr);
22075 }
22076 NOKPROBE_SYMBOL(oops_end);
22077
22078 @@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22079 print_modules();
22080 show_regs(regs);
22081 #ifdef CONFIG_X86_32
22082 - if (user_mode_vm(regs)) {
22083 + if (user_mode(regs)) {
22084 sp = regs->sp;
22085 ss = regs->ss & 0xffff;
22086 } else {
22087 @@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22088 unsigned long flags = oops_begin();
22089 int sig = SIGSEGV;
22090
22091 - if (!user_mode_vm(regs))
22092 + if (!user_mode(regs))
22093 report_bug(regs->ip, regs);
22094
22095 if (__die(str, regs, err))
22096 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22097 index 5abd4cd..c65733b 100644
22098 --- a/arch/x86/kernel/dumpstack_32.c
22099 +++ b/arch/x86/kernel/dumpstack_32.c
22100 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22101 bp = stack_frame(task, regs);
22102
22103 for (;;) {
22104 - struct thread_info *context;
22105 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22106 void *end_stack;
22107
22108 end_stack = is_hardirq_stack(stack, cpu);
22109 if (!end_stack)
22110 end_stack = is_softirq_stack(stack, cpu);
22111
22112 - context = task_thread_info(task);
22113 - bp = ops->walk_stack(context, stack, bp, ops, data,
22114 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22115 end_stack, &graph);
22116
22117 /* Stop if not on irq stack */
22118 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22119 int i;
22120
22121 show_regs_print_info(KERN_EMERG);
22122 - __show_regs(regs, !user_mode_vm(regs));
22123 + __show_regs(regs, !user_mode(regs));
22124
22125 /*
22126 * When in-kernel, we also print out the stack and code at the
22127 * time of the fault..
22128 */
22129 - if (!user_mode_vm(regs)) {
22130 + if (!user_mode(regs)) {
22131 unsigned int code_prologue = code_bytes * 43 / 64;
22132 unsigned int code_len = code_bytes;
22133 unsigned char c;
22134 u8 *ip;
22135 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22136
22137 pr_emerg("Stack:\n");
22138 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22139
22140 pr_emerg("Code:");
22141
22142 - ip = (u8 *)regs->ip - code_prologue;
22143 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22144 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22145 /* try starting at IP */
22146 - ip = (u8 *)regs->ip;
22147 + ip = (u8 *)regs->ip + cs_base;
22148 code_len = code_len - code_prologue + 1;
22149 }
22150 for (i = 0; i < code_len; i++, ip++) {
22151 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22152 pr_cont(" Bad EIP value.");
22153 break;
22154 }
22155 - if (ip == (u8 *)regs->ip)
22156 + if (ip == (u8 *)regs->ip + cs_base)
22157 pr_cont(" <%02x>", c);
22158 else
22159 pr_cont(" %02x", c);
22160 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22161 {
22162 unsigned short ud2;
22163
22164 + ip = ktla_ktva(ip);
22165 if (ip < PAGE_OFFSET)
22166 return 0;
22167 if (probe_kernel_address((unsigned short *)ip, ud2))
22168 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22169
22170 return ud2 == 0x0b0f;
22171 }
22172 +
22173 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22174 +void pax_check_alloca(unsigned long size)
22175 +{
22176 + unsigned long sp = (unsigned long)&sp, stack_left;
22177 +
22178 + /* all kernel stacks are of the same size */
22179 + stack_left = sp & (THREAD_SIZE - 1);
22180 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22181 +}
22182 +EXPORT_SYMBOL(pax_check_alloca);
22183 +#endif
22184 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22185 index ff86f19..73eabf4 100644
22186 --- a/arch/x86/kernel/dumpstack_64.c
22187 +++ b/arch/x86/kernel/dumpstack_64.c
22188 @@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22189 const struct stacktrace_ops *ops, void *data)
22190 {
22191 const unsigned cpu = get_cpu();
22192 - struct thread_info *tinfo;
22193 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22194 unsigned long dummy;
22195 unsigned used = 0;
22196 int graph = 0;
22197 int done = 0;
22198 + void *stack_start;
22199
22200 if (!task)
22201 task = current;
22202 @@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22203 * current stack address. If the stacks consist of nested
22204 * exceptions
22205 */
22206 - tinfo = task_thread_info(task);
22207 while (!done) {
22208 unsigned long *stack_end;
22209 enum stack_type stype;
22210 @@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22211 if (ops->stack(data, id) < 0)
22212 break;
22213
22214 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22215 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22216 data, stack_end, &graph);
22217 ops->stack(data, "<EOE>");
22218 /*
22219 @@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22220 * second-to-last pointer (index -2 to end) in the
22221 * exception stack:
22222 */
22223 + if ((u16)stack_end[-1] != __KERNEL_DS)
22224 + goto out;
22225 stack = (unsigned long *) stack_end[-2];
22226 done = 0;
22227 break;
22228 @@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22229
22230 if (ops->stack(data, "IRQ") < 0)
22231 break;
22232 - bp = ops->walk_stack(tinfo, stack, bp,
22233 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22234 ops, data, stack_end, &graph);
22235 /*
22236 * We link to the next stack (which would be
22237 @@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22238 /*
22239 * This handles the process stack:
22240 */
22241 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22242 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22243 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22244 +out:
22245 put_cpu();
22246 }
22247 EXPORT_SYMBOL(dump_trace);
22248 @@ -344,8 +347,55 @@ int is_valid_bugaddr(unsigned long ip)
22249 {
22250 unsigned short ud2;
22251
22252 - if (__copy_from_user(&ud2, (const void __user *) ip, sizeof(ud2)))
22253 + if (probe_kernel_address((unsigned short *)ip, ud2))
22254 return 0;
22255
22256 return ud2 == 0x0b0f;
22257 }
22258 +
22259 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22260 +void pax_check_alloca(unsigned long size)
22261 +{
22262 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22263 + unsigned cpu, used;
22264 + char *id;
22265 +
22266 + /* check the process stack first */
22267 + stack_start = (unsigned long)task_stack_page(current);
22268 + stack_end = stack_start + THREAD_SIZE;
22269 + if (likely(stack_start <= sp && sp < stack_end)) {
22270 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22271 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22272 + return;
22273 + }
22274 +
22275 + cpu = get_cpu();
22276 +
22277 + /* check the irq stacks */
22278 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22279 + stack_start = stack_end - IRQ_STACK_SIZE;
22280 + if (stack_start <= sp && sp < stack_end) {
22281 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22282 + put_cpu();
22283 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22284 + return;
22285 + }
22286 +
22287 + /* check the exception stacks */
22288 + used = 0;
22289 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22290 + stack_start = stack_end - EXCEPTION_STKSZ;
22291 + if (stack_end && stack_start <= sp && sp < stack_end) {
22292 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22293 + put_cpu();
22294 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22295 + return;
22296 + }
22297 +
22298 + put_cpu();
22299 +
22300 + /* unknown stack */
22301 + BUG();
22302 +}
22303 +EXPORT_SYMBOL(pax_check_alloca);
22304 +#endif
22305 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22306 index 49f8864..1cc6d07 100644
22307 --- a/arch/x86/kernel/e820.c
22308 +++ b/arch/x86/kernel/e820.c
22309 @@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22310
22311 static void early_panic(char *msg)
22312 {
22313 - early_printk(msg);
22314 - panic(msg);
22315 + early_printk("%s", msg);
22316 + panic("%s", msg);
22317 }
22318
22319 static int userdef __initdata;
22320 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22321 index 01d1c18..8073693 100644
22322 --- a/arch/x86/kernel/early_printk.c
22323 +++ b/arch/x86/kernel/early_printk.c
22324 @@ -7,6 +7,7 @@
22325 #include <linux/pci_regs.h>
22326 #include <linux/pci_ids.h>
22327 #include <linux/errno.h>
22328 +#include <linux/sched.h>
22329 #include <asm/io.h>
22330 #include <asm/processor.h>
22331 #include <asm/fcntl.h>
22332 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22333 index 344b63f..55adf14 100644
22334 --- a/arch/x86/kernel/entry_32.S
22335 +++ b/arch/x86/kernel/entry_32.S
22336 @@ -177,13 +177,154 @@
22337 /*CFI_REL_OFFSET gs, PT_GS*/
22338 .endm
22339 .macro SET_KERNEL_GS reg
22340 +
22341 +#ifdef CONFIG_CC_STACKPROTECTOR
22342 movl $(__KERNEL_STACK_CANARY), \reg
22343 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22344 + movl $(__USER_DS), \reg
22345 +#else
22346 + xorl \reg, \reg
22347 +#endif
22348 +
22349 movl \reg, %gs
22350 .endm
22351
22352 #endif /* CONFIG_X86_32_LAZY_GS */
22353
22354 -.macro SAVE_ALL
22355 +.macro pax_enter_kernel
22356 +#ifdef CONFIG_PAX_KERNEXEC
22357 + call pax_enter_kernel
22358 +#endif
22359 +.endm
22360 +
22361 +.macro pax_exit_kernel
22362 +#ifdef CONFIG_PAX_KERNEXEC
22363 + call pax_exit_kernel
22364 +#endif
22365 +.endm
22366 +
22367 +#ifdef CONFIG_PAX_KERNEXEC
22368 +ENTRY(pax_enter_kernel)
22369 +#ifdef CONFIG_PARAVIRT
22370 + pushl %eax
22371 + pushl %ecx
22372 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22373 + mov %eax, %esi
22374 +#else
22375 + mov %cr0, %esi
22376 +#endif
22377 + bts $16, %esi
22378 + jnc 1f
22379 + mov %cs, %esi
22380 + cmp $__KERNEL_CS, %esi
22381 + jz 3f
22382 + ljmp $__KERNEL_CS, $3f
22383 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22384 +2:
22385 +#ifdef CONFIG_PARAVIRT
22386 + mov %esi, %eax
22387 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22388 +#else
22389 + mov %esi, %cr0
22390 +#endif
22391 +3:
22392 +#ifdef CONFIG_PARAVIRT
22393 + popl %ecx
22394 + popl %eax
22395 +#endif
22396 + ret
22397 +ENDPROC(pax_enter_kernel)
22398 +
22399 +ENTRY(pax_exit_kernel)
22400 +#ifdef CONFIG_PARAVIRT
22401 + pushl %eax
22402 + pushl %ecx
22403 +#endif
22404 + mov %cs, %esi
22405 + cmp $__KERNEXEC_KERNEL_CS, %esi
22406 + jnz 2f
22407 +#ifdef CONFIG_PARAVIRT
22408 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22409 + mov %eax, %esi
22410 +#else
22411 + mov %cr0, %esi
22412 +#endif
22413 + btr $16, %esi
22414 + ljmp $__KERNEL_CS, $1f
22415 +1:
22416 +#ifdef CONFIG_PARAVIRT
22417 + mov %esi, %eax
22418 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22419 +#else
22420 + mov %esi, %cr0
22421 +#endif
22422 +2:
22423 +#ifdef CONFIG_PARAVIRT
22424 + popl %ecx
22425 + popl %eax
22426 +#endif
22427 + ret
22428 +ENDPROC(pax_exit_kernel)
22429 +#endif
22430 +
22431 + .macro pax_erase_kstack
22432 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22433 + call pax_erase_kstack
22434 +#endif
22435 + .endm
22436 +
22437 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22438 +/*
22439 + * ebp: thread_info
22440 + */
22441 +ENTRY(pax_erase_kstack)
22442 + pushl %edi
22443 + pushl %ecx
22444 + pushl %eax
22445 +
22446 + mov TI_lowest_stack(%ebp), %edi
22447 + mov $-0xBEEF, %eax
22448 + std
22449 +
22450 +1: mov %edi, %ecx
22451 + and $THREAD_SIZE_asm - 1, %ecx
22452 + shr $2, %ecx
22453 + repne scasl
22454 + jecxz 2f
22455 +
22456 + cmp $2*16, %ecx
22457 + jc 2f
22458 +
22459 + mov $2*16, %ecx
22460 + repe scasl
22461 + jecxz 2f
22462 + jne 1b
22463 +
22464 +2: cld
22465 + or $2*4, %edi
22466 + mov %esp, %ecx
22467 + sub %edi, %ecx
22468 +
22469 + cmp $THREAD_SIZE_asm, %ecx
22470 + jb 3f
22471 + ud2
22472 +3:
22473 +
22474 + shr $2, %ecx
22475 + rep stosl
22476 +
22477 + mov TI_task_thread_sp0(%ebp), %edi
22478 + sub $128, %edi
22479 + mov %edi, TI_lowest_stack(%ebp)
22480 +
22481 + popl %eax
22482 + popl %ecx
22483 + popl %edi
22484 + ret
22485 +ENDPROC(pax_erase_kstack)
22486 +#endif
22487 +
22488 +.macro __SAVE_ALL _DS
22489 cld
22490 PUSH_GS
22491 pushl_cfi %fs
22492 @@ -206,7 +347,7 @@
22493 CFI_REL_OFFSET ecx, 0
22494 pushl_cfi %ebx
22495 CFI_REL_OFFSET ebx, 0
22496 - movl $(__USER_DS), %edx
22497 + movl $\_DS, %edx
22498 movl %edx, %ds
22499 movl %edx, %es
22500 movl $(__KERNEL_PERCPU), %edx
22501 @@ -214,6 +355,15 @@
22502 SET_KERNEL_GS %edx
22503 .endm
22504
22505 +.macro SAVE_ALL
22506 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22507 + __SAVE_ALL __KERNEL_DS
22508 + pax_enter_kernel
22509 +#else
22510 + __SAVE_ALL __USER_DS
22511 +#endif
22512 +.endm
22513 +
22514 .macro RESTORE_INT_REGS
22515 popl_cfi %ebx
22516 CFI_RESTORE ebx
22517 @@ -297,7 +447,7 @@ ENTRY(ret_from_fork)
22518 popfl_cfi
22519 jmp syscall_exit
22520 CFI_ENDPROC
22521 -END(ret_from_fork)
22522 +ENDPROC(ret_from_fork)
22523
22524 ENTRY(ret_from_kernel_thread)
22525 CFI_STARTPROC
22526 @@ -340,7 +490,15 @@ ret_from_intr:
22527 andl $SEGMENT_RPL_MASK, %eax
22528 #endif
22529 cmpl $USER_RPL, %eax
22530 +
22531 +#ifdef CONFIG_PAX_KERNEXEC
22532 + jae resume_userspace
22533 +
22534 + pax_exit_kernel
22535 + jmp resume_kernel
22536 +#else
22537 jb resume_kernel # not returning to v8086 or userspace
22538 +#endif
22539
22540 ENTRY(resume_userspace)
22541 LOCKDEP_SYS_EXIT
22542 @@ -352,8 +510,8 @@ ENTRY(resume_userspace)
22543 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22544 # int/exception return?
22545 jne work_pending
22546 - jmp restore_all
22547 -END(ret_from_exception)
22548 + jmp restore_all_pax
22549 +ENDPROC(ret_from_exception)
22550
22551 #ifdef CONFIG_PREEMPT
22552 ENTRY(resume_kernel)
22553 @@ -365,7 +523,7 @@ need_resched:
22554 jz restore_all
22555 call preempt_schedule_irq
22556 jmp need_resched
22557 -END(resume_kernel)
22558 +ENDPROC(resume_kernel)
22559 #endif
22560 CFI_ENDPROC
22561
22562 @@ -395,30 +553,45 @@ sysenter_past_esp:
22563 /*CFI_REL_OFFSET cs, 0*/
22564 /*
22565 * Push current_thread_info()->sysenter_return to the stack.
22566 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22567 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22568 */
22569 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22570 + pushl_cfi $0
22571 CFI_REL_OFFSET eip, 0
22572
22573 pushl_cfi %eax
22574 SAVE_ALL
22575 + GET_THREAD_INFO(%ebp)
22576 + movl TI_sysenter_return(%ebp),%ebp
22577 + movl %ebp,PT_EIP(%esp)
22578 ENABLE_INTERRUPTS(CLBR_NONE)
22579
22580 /*
22581 * Load the potential sixth argument from user stack.
22582 * Careful about security.
22583 */
22584 + movl PT_OLDESP(%esp),%ebp
22585 +
22586 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22587 + mov PT_OLDSS(%esp),%ds
22588 +1: movl %ds:(%ebp),%ebp
22589 + push %ss
22590 + pop %ds
22591 +#else
22592 cmpl $__PAGE_OFFSET-3,%ebp
22593 jae syscall_fault
22594 ASM_STAC
22595 1: movl (%ebp),%ebp
22596 ASM_CLAC
22597 +#endif
22598 +
22599 movl %ebp,PT_EBP(%esp)
22600 _ASM_EXTABLE(1b,syscall_fault)
22601
22602 GET_THREAD_INFO(%ebp)
22603
22604 +#ifdef CONFIG_PAX_RANDKSTACK
22605 + pax_erase_kstack
22606 +#endif
22607 +
22608 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22609 jnz sysenter_audit
22610 sysenter_do_call:
22611 @@ -434,12 +607,24 @@ sysenter_after_call:
22612 testl $_TIF_ALLWORK_MASK, %ecx
22613 jne sysexit_audit
22614 sysenter_exit:
22615 +
22616 +#ifdef CONFIG_PAX_RANDKSTACK
22617 + pushl_cfi %eax
22618 + movl %esp, %eax
22619 + call pax_randomize_kstack
22620 + popl_cfi %eax
22621 +#endif
22622 +
22623 + pax_erase_kstack
22624 +
22625 /* if something modifies registers it must also disable sysexit */
22626 movl PT_EIP(%esp), %edx
22627 movl PT_OLDESP(%esp), %ecx
22628 xorl %ebp,%ebp
22629 TRACE_IRQS_ON
22630 1: mov PT_FS(%esp), %fs
22631 +2: mov PT_DS(%esp), %ds
22632 +3: mov PT_ES(%esp), %es
22633 PTGS_TO_GS
22634 ENABLE_INTERRUPTS_SYSEXIT
22635
22636 @@ -453,6 +638,9 @@ sysenter_audit:
22637 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22638 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22639 call __audit_syscall_entry
22640 +
22641 + pax_erase_kstack
22642 +
22643 popl_cfi %ecx /* get that remapped edx off the stack */
22644 popl_cfi %ecx /* get that remapped esi off the stack */
22645 movl PT_EAX(%esp),%eax /* reload syscall number */
22646 @@ -479,10 +667,16 @@ sysexit_audit:
22647
22648 CFI_ENDPROC
22649 .pushsection .fixup,"ax"
22650 -2: movl $0,PT_FS(%esp)
22651 +4: movl $0,PT_FS(%esp)
22652 + jmp 1b
22653 +5: movl $0,PT_DS(%esp)
22654 + jmp 1b
22655 +6: movl $0,PT_ES(%esp)
22656 jmp 1b
22657 .popsection
22658 - _ASM_EXTABLE(1b,2b)
22659 + _ASM_EXTABLE(1b,4b)
22660 + _ASM_EXTABLE(2b,5b)
22661 + _ASM_EXTABLE(3b,6b)
22662 PTGS_TO_GS_EX
22663 ENDPROC(ia32_sysenter_target)
22664
22665 @@ -493,6 +687,11 @@ ENTRY(system_call)
22666 pushl_cfi %eax # save orig_eax
22667 SAVE_ALL
22668 GET_THREAD_INFO(%ebp)
22669 +
22670 +#ifdef CONFIG_PAX_RANDKSTACK
22671 + pax_erase_kstack
22672 +#endif
22673 +
22674 # system call tracing in operation / emulation
22675 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22676 jnz syscall_trace_entry
22677 @@ -512,6 +711,15 @@ syscall_exit:
22678 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22679 jne syscall_exit_work
22680
22681 +restore_all_pax:
22682 +
22683 +#ifdef CONFIG_PAX_RANDKSTACK
22684 + movl %esp, %eax
22685 + call pax_randomize_kstack
22686 +#endif
22687 +
22688 + pax_erase_kstack
22689 +
22690 restore_all:
22691 TRACE_IRQS_IRET
22692 restore_all_notrace:
22693 @@ -566,14 +774,34 @@ ldt_ss:
22694 * compensating for the offset by changing to the ESPFIX segment with
22695 * a base address that matches for the difference.
22696 */
22697 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22698 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22699 mov %esp, %edx /* load kernel esp */
22700 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22701 mov %dx, %ax /* eax: new kernel esp */
22702 sub %eax, %edx /* offset (low word is 0) */
22703 +#ifdef CONFIG_SMP
22704 + movl PER_CPU_VAR(cpu_number), %ebx
22705 + shll $PAGE_SHIFT_asm, %ebx
22706 + addl $cpu_gdt_table, %ebx
22707 +#else
22708 + movl $cpu_gdt_table, %ebx
22709 +#endif
22710 shr $16, %edx
22711 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22712 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22713 +
22714 +#ifdef CONFIG_PAX_KERNEXEC
22715 + mov %cr0, %esi
22716 + btr $16, %esi
22717 + mov %esi, %cr0
22718 +#endif
22719 +
22720 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22721 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22722 +
22723 +#ifdef CONFIG_PAX_KERNEXEC
22724 + bts $16, %esi
22725 + mov %esi, %cr0
22726 +#endif
22727 +
22728 pushl_cfi $__ESPFIX_SS
22729 pushl_cfi %eax /* new kernel esp */
22730 /* Disable interrupts, but do not irqtrace this section: we
22731 @@ -603,20 +831,18 @@ work_resched:
22732 movl TI_flags(%ebp), %ecx
22733 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22734 # than syscall tracing?
22735 - jz restore_all
22736 + jz restore_all_pax
22737 testb $_TIF_NEED_RESCHED, %cl
22738 jnz work_resched
22739
22740 work_notifysig: # deal with pending signals and
22741 # notify-resume requests
22742 + movl %esp, %eax
22743 #ifdef CONFIG_VM86
22744 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22745 - movl %esp, %eax
22746 jne work_notifysig_v86 # returning to kernel-space or
22747 # vm86-space
22748 1:
22749 -#else
22750 - movl %esp, %eax
22751 #endif
22752 TRACE_IRQS_ON
22753 ENABLE_INTERRUPTS(CLBR_NONE)
22754 @@ -637,7 +863,7 @@ work_notifysig_v86:
22755 movl %eax, %esp
22756 jmp 1b
22757 #endif
22758 -END(work_pending)
22759 +ENDPROC(work_pending)
22760
22761 # perform syscall exit tracing
22762 ALIGN
22763 @@ -645,11 +871,14 @@ syscall_trace_entry:
22764 movl $-ENOSYS,PT_EAX(%esp)
22765 movl %esp, %eax
22766 call syscall_trace_enter
22767 +
22768 + pax_erase_kstack
22769 +
22770 /* What it returned is what we'll actually use. */
22771 cmpl $(NR_syscalls), %eax
22772 jnae syscall_call
22773 jmp syscall_exit
22774 -END(syscall_trace_entry)
22775 +ENDPROC(syscall_trace_entry)
22776
22777 # perform syscall exit tracing
22778 ALIGN
22779 @@ -662,26 +891,30 @@ syscall_exit_work:
22780 movl %esp, %eax
22781 call syscall_trace_leave
22782 jmp resume_userspace
22783 -END(syscall_exit_work)
22784 +ENDPROC(syscall_exit_work)
22785 CFI_ENDPROC
22786
22787 RING0_INT_FRAME # can't unwind into user space anyway
22788 syscall_fault:
22789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22790 + push %ss
22791 + pop %ds
22792 +#endif
22793 ASM_CLAC
22794 GET_THREAD_INFO(%ebp)
22795 movl $-EFAULT,PT_EAX(%esp)
22796 jmp resume_userspace
22797 -END(syscall_fault)
22798 +ENDPROC(syscall_fault)
22799
22800 syscall_badsys:
22801 movl $-ENOSYS,%eax
22802 jmp syscall_after_call
22803 -END(syscall_badsys)
22804 +ENDPROC(syscall_badsys)
22805
22806 sysenter_badsys:
22807 movl $-ENOSYS,%eax
22808 jmp sysenter_after_call
22809 -END(sysenter_badsys)
22810 +ENDPROC(sysenter_badsys)
22811 CFI_ENDPROC
22812
22813 .macro FIXUP_ESPFIX_STACK
22814 @@ -694,8 +927,15 @@ END(sysenter_badsys)
22815 */
22816 #ifdef CONFIG_X86_ESPFIX32
22817 /* fixup the stack */
22818 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22819 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22820 +#ifdef CONFIG_SMP
22821 + movl PER_CPU_VAR(cpu_number), %ebx
22822 + shll $PAGE_SHIFT_asm, %ebx
22823 + addl $cpu_gdt_table, %ebx
22824 +#else
22825 + movl $cpu_gdt_table, %ebx
22826 +#endif
22827 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22828 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22829 shl $16, %eax
22830 addl %esp, %eax /* the adjusted stack pointer */
22831 pushl_cfi $__KERNEL_DS
22832 @@ -751,7 +991,7 @@ vector=vector+1
22833 .endr
22834 2: jmp common_interrupt
22835 .endr
22836 -END(irq_entries_start)
22837 +ENDPROC(irq_entries_start)
22838
22839 .previous
22840 END(interrupt)
22841 @@ -808,7 +1048,7 @@ ENTRY(coprocessor_error)
22842 pushl_cfi $do_coprocessor_error
22843 jmp error_code
22844 CFI_ENDPROC
22845 -END(coprocessor_error)
22846 +ENDPROC(coprocessor_error)
22847
22848 ENTRY(simd_coprocessor_error)
22849 RING0_INT_FRAME
22850 @@ -821,7 +1061,7 @@ ENTRY(simd_coprocessor_error)
22851 .section .altinstructions,"a"
22852 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22853 .previous
22854 -.section .altinstr_replacement,"ax"
22855 +.section .altinstr_replacement,"a"
22856 663: pushl $do_simd_coprocessor_error
22857 664:
22858 .previous
22859 @@ -830,7 +1070,7 @@ ENTRY(simd_coprocessor_error)
22860 #endif
22861 jmp error_code
22862 CFI_ENDPROC
22863 -END(simd_coprocessor_error)
22864 +ENDPROC(simd_coprocessor_error)
22865
22866 ENTRY(device_not_available)
22867 RING0_INT_FRAME
22868 @@ -839,18 +1079,18 @@ ENTRY(device_not_available)
22869 pushl_cfi $do_device_not_available
22870 jmp error_code
22871 CFI_ENDPROC
22872 -END(device_not_available)
22873 +ENDPROC(device_not_available)
22874
22875 #ifdef CONFIG_PARAVIRT
22876 ENTRY(native_iret)
22877 iret
22878 _ASM_EXTABLE(native_iret, iret_exc)
22879 -END(native_iret)
22880 +ENDPROC(native_iret)
22881
22882 ENTRY(native_irq_enable_sysexit)
22883 sti
22884 sysexit
22885 -END(native_irq_enable_sysexit)
22886 +ENDPROC(native_irq_enable_sysexit)
22887 #endif
22888
22889 ENTRY(overflow)
22890 @@ -860,7 +1100,7 @@ ENTRY(overflow)
22891 pushl_cfi $do_overflow
22892 jmp error_code
22893 CFI_ENDPROC
22894 -END(overflow)
22895 +ENDPROC(overflow)
22896
22897 ENTRY(bounds)
22898 RING0_INT_FRAME
22899 @@ -869,7 +1109,7 @@ ENTRY(bounds)
22900 pushl_cfi $do_bounds
22901 jmp error_code
22902 CFI_ENDPROC
22903 -END(bounds)
22904 +ENDPROC(bounds)
22905
22906 ENTRY(invalid_op)
22907 RING0_INT_FRAME
22908 @@ -878,7 +1118,7 @@ ENTRY(invalid_op)
22909 pushl_cfi $do_invalid_op
22910 jmp error_code
22911 CFI_ENDPROC
22912 -END(invalid_op)
22913 +ENDPROC(invalid_op)
22914
22915 ENTRY(coprocessor_segment_overrun)
22916 RING0_INT_FRAME
22917 @@ -887,7 +1127,7 @@ ENTRY(coprocessor_segment_overrun)
22918 pushl_cfi $do_coprocessor_segment_overrun
22919 jmp error_code
22920 CFI_ENDPROC
22921 -END(coprocessor_segment_overrun)
22922 +ENDPROC(coprocessor_segment_overrun)
22923
22924 ENTRY(invalid_TSS)
22925 RING0_EC_FRAME
22926 @@ -895,7 +1135,7 @@ ENTRY(invalid_TSS)
22927 pushl_cfi $do_invalid_TSS
22928 jmp error_code
22929 CFI_ENDPROC
22930 -END(invalid_TSS)
22931 +ENDPROC(invalid_TSS)
22932
22933 ENTRY(segment_not_present)
22934 RING0_EC_FRAME
22935 @@ -903,7 +1143,7 @@ ENTRY(segment_not_present)
22936 pushl_cfi $do_segment_not_present
22937 jmp error_code
22938 CFI_ENDPROC
22939 -END(segment_not_present)
22940 +ENDPROC(segment_not_present)
22941
22942 ENTRY(stack_segment)
22943 RING0_EC_FRAME
22944 @@ -911,7 +1151,7 @@ ENTRY(stack_segment)
22945 pushl_cfi $do_stack_segment
22946 jmp error_code
22947 CFI_ENDPROC
22948 -END(stack_segment)
22949 +ENDPROC(stack_segment)
22950
22951 ENTRY(alignment_check)
22952 RING0_EC_FRAME
22953 @@ -919,7 +1159,7 @@ ENTRY(alignment_check)
22954 pushl_cfi $do_alignment_check
22955 jmp error_code
22956 CFI_ENDPROC
22957 -END(alignment_check)
22958 +ENDPROC(alignment_check)
22959
22960 ENTRY(divide_error)
22961 RING0_INT_FRAME
22962 @@ -928,7 +1168,7 @@ ENTRY(divide_error)
22963 pushl_cfi $do_divide_error
22964 jmp error_code
22965 CFI_ENDPROC
22966 -END(divide_error)
22967 +ENDPROC(divide_error)
22968
22969 #ifdef CONFIG_X86_MCE
22970 ENTRY(machine_check)
22971 @@ -938,7 +1178,7 @@ ENTRY(machine_check)
22972 pushl_cfi machine_check_vector
22973 jmp error_code
22974 CFI_ENDPROC
22975 -END(machine_check)
22976 +ENDPROC(machine_check)
22977 #endif
22978
22979 ENTRY(spurious_interrupt_bug)
22980 @@ -948,7 +1188,7 @@ ENTRY(spurious_interrupt_bug)
22981 pushl_cfi $do_spurious_interrupt_bug
22982 jmp error_code
22983 CFI_ENDPROC
22984 -END(spurious_interrupt_bug)
22985 +ENDPROC(spurious_interrupt_bug)
22986
22987 #ifdef CONFIG_XEN
22988 /* Xen doesn't set %esp to be precisely what the normal sysenter
22989 @@ -1054,7 +1294,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22990
22991 ENTRY(mcount)
22992 ret
22993 -END(mcount)
22994 +ENDPROC(mcount)
22995
22996 ENTRY(ftrace_caller)
22997 pushl %eax
22998 @@ -1084,7 +1324,7 @@ ftrace_graph_call:
22999 .globl ftrace_stub
23000 ftrace_stub:
23001 ret
23002 -END(ftrace_caller)
23003 +ENDPROC(ftrace_caller)
23004
23005 ENTRY(ftrace_regs_caller)
23006 pushf /* push flags before compare (in cs location) */
23007 @@ -1182,7 +1422,7 @@ trace:
23008 popl %ecx
23009 popl %eax
23010 jmp ftrace_stub
23011 -END(mcount)
23012 +ENDPROC(mcount)
23013 #endif /* CONFIG_DYNAMIC_FTRACE */
23014 #endif /* CONFIG_FUNCTION_TRACER */
23015
23016 @@ -1200,7 +1440,7 @@ ENTRY(ftrace_graph_caller)
23017 popl %ecx
23018 popl %eax
23019 ret
23020 -END(ftrace_graph_caller)
23021 +ENDPROC(ftrace_graph_caller)
23022
23023 .globl return_to_handler
23024 return_to_handler:
23025 @@ -1261,15 +1501,18 @@ error_code:
23026 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23027 REG_TO_PTGS %ecx
23028 SET_KERNEL_GS %ecx
23029 - movl $(__USER_DS), %ecx
23030 + movl $(__KERNEL_DS), %ecx
23031 movl %ecx, %ds
23032 movl %ecx, %es
23033 +
23034 + pax_enter_kernel
23035 +
23036 TRACE_IRQS_OFF
23037 movl %esp,%eax # pt_regs pointer
23038 call *%edi
23039 jmp ret_from_exception
23040 CFI_ENDPROC
23041 -END(page_fault)
23042 +ENDPROC(page_fault)
23043
23044 /*
23045 * Debug traps and NMI can happen at the one SYSENTER instruction
23046 @@ -1312,7 +1555,7 @@ debug_stack_correct:
23047 call do_debug
23048 jmp ret_from_exception
23049 CFI_ENDPROC
23050 -END(debug)
23051 +ENDPROC(debug)
23052
23053 /*
23054 * NMI is doubly nasty. It can happen _while_ we're handling
23055 @@ -1352,6 +1595,9 @@ nmi_stack_correct:
23056 xorl %edx,%edx # zero error code
23057 movl %esp,%eax # pt_regs pointer
23058 call do_nmi
23059 +
23060 + pax_exit_kernel
23061 +
23062 jmp restore_all_notrace
23063 CFI_ENDPROC
23064
23065 @@ -1389,13 +1635,16 @@ nmi_espfix_stack:
23066 FIXUP_ESPFIX_STACK # %eax == %esp
23067 xorl %edx,%edx # zero error code
23068 call do_nmi
23069 +
23070 + pax_exit_kernel
23071 +
23072 RESTORE_REGS
23073 lss 12+4(%esp), %esp # back to espfix stack
23074 CFI_ADJUST_CFA_OFFSET -24
23075 jmp irq_return
23076 #endif
23077 CFI_ENDPROC
23078 -END(nmi)
23079 +ENDPROC(nmi)
23080
23081 ENTRY(int3)
23082 RING0_INT_FRAME
23083 @@ -1408,14 +1657,14 @@ ENTRY(int3)
23084 call do_int3
23085 jmp ret_from_exception
23086 CFI_ENDPROC
23087 -END(int3)
23088 +ENDPROC(int3)
23089
23090 ENTRY(general_protection)
23091 RING0_EC_FRAME
23092 pushl_cfi $do_general_protection
23093 jmp error_code
23094 CFI_ENDPROC
23095 -END(general_protection)
23096 +ENDPROC(general_protection)
23097
23098 #ifdef CONFIG_KVM_GUEST
23099 ENTRY(async_page_fault)
23100 @@ -1424,6 +1673,6 @@ ENTRY(async_page_fault)
23101 pushl_cfi $do_async_page_fault
23102 jmp error_code
23103 CFI_ENDPROC
23104 -END(async_page_fault)
23105 +ENDPROC(async_page_fault)
23106 #endif
23107
23108 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23109 index c0226ab..386eb53 100644
23110 --- a/arch/x86/kernel/entry_64.S
23111 +++ b/arch/x86/kernel/entry_64.S
23112 @@ -59,6 +59,8 @@
23113 #include <asm/smap.h>
23114 #include <asm/pgtable_types.h>
23115 #include <linux/err.h>
23116 +#include <asm/pgtable.h>
23117 +#include <asm/alternative-asm.h>
23118
23119 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23120 #include <linux/elf-em.h>
23121 @@ -81,6 +83,431 @@ ENTRY(native_usergs_sysret64)
23122 ENDPROC(native_usergs_sysret64)
23123 #endif /* CONFIG_PARAVIRT */
23124
23125 + .macro ljmpq sel, off
23126 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23127 + .byte 0x48; ljmp *1234f(%rip)
23128 + .pushsection .rodata
23129 + .align 16
23130 + 1234: .quad \off; .word \sel
23131 + .popsection
23132 +#else
23133 + pushq $\sel
23134 + pushq $\off
23135 + lretq
23136 +#endif
23137 + .endm
23138 +
23139 + .macro pax_enter_kernel
23140 + pax_set_fptr_mask
23141 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23142 + call pax_enter_kernel
23143 +#endif
23144 + .endm
23145 +
23146 + .macro pax_exit_kernel
23147 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23148 + call pax_exit_kernel
23149 +#endif
23150 +
23151 + .endm
23152 +
23153 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23154 +ENTRY(pax_enter_kernel)
23155 + pushq %rdi
23156 +
23157 +#ifdef CONFIG_PARAVIRT
23158 + PV_SAVE_REGS(CLBR_RDI)
23159 +#endif
23160 +
23161 +#ifdef CONFIG_PAX_KERNEXEC
23162 + GET_CR0_INTO_RDI
23163 + bts $16,%rdi
23164 + jnc 3f
23165 + mov %cs,%edi
23166 + cmp $__KERNEL_CS,%edi
23167 + jnz 2f
23168 +1:
23169 +#endif
23170 +
23171 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23172 + 661: jmp 111f
23173 + .pushsection .altinstr_replacement, "a"
23174 + 662: ASM_NOP2
23175 + .popsection
23176 + .pushsection .altinstructions, "a"
23177 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23178 + .popsection
23179 + GET_CR3_INTO_RDI
23180 + cmp $0,%dil
23181 + jnz 112f
23182 + mov $__KERNEL_DS,%edi
23183 + mov %edi,%ss
23184 + jmp 111f
23185 +112: cmp $1,%dil
23186 + jz 113f
23187 + ud2
23188 +113: sub $4097,%rdi
23189 + bts $63,%rdi
23190 + SET_RDI_INTO_CR3
23191 + mov $__UDEREF_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: ljmpq __KERNEL_CS,1b
23206 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23207 +4: SET_RDI_INTO_CR0
23208 + jmp 1b
23209 +#endif
23210 +ENDPROC(pax_enter_kernel)
23211 +
23212 +ENTRY(pax_exit_kernel)
23213 + pushq %rdi
23214 +
23215 +#ifdef CONFIG_PARAVIRT
23216 + PV_SAVE_REGS(CLBR_RDI)
23217 +#endif
23218 +
23219 +#ifdef CONFIG_PAX_KERNEXEC
23220 + mov %cs,%rdi
23221 + cmp $__KERNEXEC_KERNEL_CS,%edi
23222 + jz 2f
23223 + GET_CR0_INTO_RDI
23224 + bts $16,%rdi
23225 + jnc 4f
23226 +1:
23227 +#endif
23228 +
23229 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23230 + 661: jmp 111f
23231 + .pushsection .altinstr_replacement, "a"
23232 + 662: ASM_NOP2
23233 + .popsection
23234 + .pushsection .altinstructions, "a"
23235 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23236 + .popsection
23237 + mov %ss,%edi
23238 + cmp $__UDEREF_KERNEL_DS,%edi
23239 + jnz 111f
23240 + GET_CR3_INTO_RDI
23241 + cmp $0,%dil
23242 + jz 112f
23243 + ud2
23244 +112: add $4097,%rdi
23245 + bts $63,%rdi
23246 + SET_RDI_INTO_CR3
23247 + mov $__KERNEL_DS,%edi
23248 + mov %edi,%ss
23249 +111:
23250 +#endif
23251 +
23252 +#ifdef CONFIG_PARAVIRT
23253 + PV_RESTORE_REGS(CLBR_RDI);
23254 +#endif
23255 +
23256 + popq %rdi
23257 + pax_force_retaddr
23258 + retq
23259 +
23260 +#ifdef CONFIG_PAX_KERNEXEC
23261 +2: GET_CR0_INTO_RDI
23262 + btr $16,%rdi
23263 + jnc 4f
23264 + ljmpq __KERNEL_CS,3f
23265 +3: SET_RDI_INTO_CR0
23266 + jmp 1b
23267 +4: ud2
23268 + jmp 4b
23269 +#endif
23270 +ENDPROC(pax_exit_kernel)
23271 +#endif
23272 +
23273 + .macro pax_enter_kernel_user
23274 + pax_set_fptr_mask
23275 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23276 + call pax_enter_kernel_user
23277 +#endif
23278 + .endm
23279 +
23280 + .macro pax_exit_kernel_user
23281 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23282 + call pax_exit_kernel_user
23283 +#endif
23284 +#ifdef CONFIG_PAX_RANDKSTACK
23285 + pushq %rax
23286 + pushq %r11
23287 + call pax_randomize_kstack
23288 + popq %r11
23289 + popq %rax
23290 +#endif
23291 + .endm
23292 +
23293 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23294 +ENTRY(pax_enter_kernel_user)
23295 + pushq %rdi
23296 + pushq %rbx
23297 +
23298 +#ifdef CONFIG_PARAVIRT
23299 + PV_SAVE_REGS(CLBR_RDI)
23300 +#endif
23301 +
23302 + 661: jmp 111f
23303 + .pushsection .altinstr_replacement, "a"
23304 + 662: ASM_NOP2
23305 + .popsection
23306 + .pushsection .altinstructions, "a"
23307 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23308 + .popsection
23309 + GET_CR3_INTO_RDI
23310 + cmp $1,%dil
23311 + jnz 4f
23312 + sub $4097,%rdi
23313 + bts $63,%rdi
23314 + SET_RDI_INTO_CR3
23315 + jmp 3f
23316 +111:
23317 +
23318 + GET_CR3_INTO_RDI
23319 + mov %rdi,%rbx
23320 + add $__START_KERNEL_map,%rbx
23321 + sub phys_base(%rip),%rbx
23322 +
23323 +#ifdef CONFIG_PARAVIRT
23324 + cmpl $0, pv_info+PARAVIRT_enabled
23325 + jz 1f
23326 + pushq %rdi
23327 + i = 0
23328 + .rept USER_PGD_PTRS
23329 + mov i*8(%rbx),%rsi
23330 + mov $0,%sil
23331 + lea i*8(%rbx),%rdi
23332 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23333 + i = i + 1
23334 + .endr
23335 + popq %rdi
23336 + jmp 2f
23337 +1:
23338 +#endif
23339 +
23340 + i = 0
23341 + .rept USER_PGD_PTRS
23342 + movb $0,i*8(%rbx)
23343 + i = i + 1
23344 + .endr
23345 +
23346 +2: SET_RDI_INTO_CR3
23347 +
23348 +#ifdef CONFIG_PAX_KERNEXEC
23349 + GET_CR0_INTO_RDI
23350 + bts $16,%rdi
23351 + SET_RDI_INTO_CR0
23352 +#endif
23353 +
23354 +3:
23355 +
23356 +#ifdef CONFIG_PARAVIRT
23357 + PV_RESTORE_REGS(CLBR_RDI)
23358 +#endif
23359 +
23360 + popq %rbx
23361 + popq %rdi
23362 + pax_force_retaddr
23363 + retq
23364 +4: ud2
23365 +ENDPROC(pax_enter_kernel_user)
23366 +
23367 +ENTRY(pax_exit_kernel_user)
23368 + pushq %rdi
23369 + pushq %rbx
23370 +
23371 +#ifdef CONFIG_PARAVIRT
23372 + PV_SAVE_REGS(CLBR_RDI)
23373 +#endif
23374 +
23375 + GET_CR3_INTO_RDI
23376 + 661: jmp 1f
23377 + .pushsection .altinstr_replacement, "a"
23378 + 662: ASM_NOP2
23379 + .popsection
23380 + .pushsection .altinstructions, "a"
23381 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23382 + .popsection
23383 + cmp $0,%dil
23384 + jnz 3f
23385 + add $4097,%rdi
23386 + bts $63,%rdi
23387 + SET_RDI_INTO_CR3
23388 + jmp 2f
23389 +1:
23390 +
23391 + mov %rdi,%rbx
23392 +
23393 +#ifdef CONFIG_PAX_KERNEXEC
23394 + GET_CR0_INTO_RDI
23395 + btr $16,%rdi
23396 + jnc 3f
23397 + SET_RDI_INTO_CR0
23398 +#endif
23399 +
23400 + add $__START_KERNEL_map,%rbx
23401 + sub phys_base(%rip),%rbx
23402 +
23403 +#ifdef CONFIG_PARAVIRT
23404 + cmpl $0, pv_info+PARAVIRT_enabled
23405 + jz 1f
23406 + i = 0
23407 + .rept USER_PGD_PTRS
23408 + mov i*8(%rbx),%rsi
23409 + mov $0x67,%sil
23410 + lea i*8(%rbx),%rdi
23411 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23412 + i = i + 1
23413 + .endr
23414 + jmp 2f
23415 +1:
23416 +#endif
23417 +
23418 + i = 0
23419 + .rept USER_PGD_PTRS
23420 + movb $0x67,i*8(%rbx)
23421 + i = i + 1
23422 + .endr
23423 +2:
23424 +
23425 +#ifdef CONFIG_PARAVIRT
23426 + PV_RESTORE_REGS(CLBR_RDI)
23427 +#endif
23428 +
23429 + popq %rbx
23430 + popq %rdi
23431 + pax_force_retaddr
23432 + retq
23433 +3: ud2
23434 +ENDPROC(pax_exit_kernel_user)
23435 +#endif
23436 +
23437 + .macro pax_enter_kernel_nmi
23438 + pax_set_fptr_mask
23439 +
23440 +#ifdef CONFIG_PAX_KERNEXEC
23441 + GET_CR0_INTO_RDI
23442 + bts $16,%rdi
23443 + jc 110f
23444 + SET_RDI_INTO_CR0
23445 + or $2,%ebx
23446 +110:
23447 +#endif
23448 +
23449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23450 + 661: jmp 111f
23451 + .pushsection .altinstr_replacement, "a"
23452 + 662: ASM_NOP2
23453 + .popsection
23454 + .pushsection .altinstructions, "a"
23455 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23456 + .popsection
23457 + GET_CR3_INTO_RDI
23458 + cmp $0,%dil
23459 + jz 111f
23460 + sub $4097,%rdi
23461 + or $4,%ebx
23462 + bts $63,%rdi
23463 + SET_RDI_INTO_CR3
23464 + mov $__UDEREF_KERNEL_DS,%edi
23465 + mov %edi,%ss
23466 +111:
23467 +#endif
23468 + .endm
23469 +
23470 + .macro pax_exit_kernel_nmi
23471 +#ifdef CONFIG_PAX_KERNEXEC
23472 + btr $1,%ebx
23473 + jnc 110f
23474 + GET_CR0_INTO_RDI
23475 + btr $16,%rdi
23476 + SET_RDI_INTO_CR0
23477 +110:
23478 +#endif
23479 +
23480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23481 + btr $2,%ebx
23482 + jnc 111f
23483 + GET_CR3_INTO_RDI
23484 + add $4097,%rdi
23485 + bts $63,%rdi
23486 + SET_RDI_INTO_CR3
23487 + mov $__KERNEL_DS,%edi
23488 + mov %edi,%ss
23489 +111:
23490 +#endif
23491 + .endm
23492 +
23493 + .macro pax_erase_kstack
23494 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23495 + call pax_erase_kstack
23496 +#endif
23497 + .endm
23498 +
23499 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23500 +ENTRY(pax_erase_kstack)
23501 + pushq %rdi
23502 + pushq %rcx
23503 + pushq %rax
23504 + pushq %r11
23505 +
23506 + GET_THREAD_INFO(%r11)
23507 + mov TI_lowest_stack(%r11), %rdi
23508 + mov $-0xBEEF, %rax
23509 + std
23510 +
23511 +1: mov %edi, %ecx
23512 + and $THREAD_SIZE_asm - 1, %ecx
23513 + shr $3, %ecx
23514 + repne scasq
23515 + jecxz 2f
23516 +
23517 + cmp $2*8, %ecx
23518 + jc 2f
23519 +
23520 + mov $2*8, %ecx
23521 + repe scasq
23522 + jecxz 2f
23523 + jne 1b
23524 +
23525 +2: cld
23526 + or $2*8, %rdi
23527 + mov %esp, %ecx
23528 + sub %edi, %ecx
23529 +
23530 + cmp $THREAD_SIZE_asm, %rcx
23531 + jb 3f
23532 + ud2
23533 +3:
23534 +
23535 + shr $3, %ecx
23536 + rep stosq
23537 +
23538 + mov TI_task_thread_sp0(%r11), %rdi
23539 + sub $256, %rdi
23540 + mov %rdi, TI_lowest_stack(%r11)
23541 +
23542 + popq %r11
23543 + popq %rax
23544 + popq %rcx
23545 + popq %rdi
23546 + pax_force_retaddr
23547 + ret
23548 +ENDPROC(pax_erase_kstack)
23549 +#endif
23550
23551 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23552 #ifdef CONFIG_TRACE_IRQFLAGS
23553 @@ -117,7 +544,7 @@ ENDPROC(native_usergs_sysret64)
23554 .endm
23555
23556 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23557 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23558 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23559 jnc 1f
23560 TRACE_IRQS_ON_DEBUG
23561 1:
23562 @@ -155,27 +582,6 @@ ENDPROC(native_usergs_sysret64)
23563 movq \tmp,R11+\offset(%rsp)
23564 .endm
23565
23566 - .macro FAKE_STACK_FRAME child_rip
23567 - /* push in order ss, rsp, eflags, cs, rip */
23568 - xorl %eax, %eax
23569 - pushq_cfi $__KERNEL_DS /* ss */
23570 - /*CFI_REL_OFFSET ss,0*/
23571 - pushq_cfi %rax /* rsp */
23572 - CFI_REL_OFFSET rsp,0
23573 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23574 - /*CFI_REL_OFFSET rflags,0*/
23575 - pushq_cfi $__KERNEL_CS /* cs */
23576 - /*CFI_REL_OFFSET cs,0*/
23577 - pushq_cfi \child_rip /* rip */
23578 - CFI_REL_OFFSET rip,0
23579 - pushq_cfi %rax /* orig rax */
23580 - .endm
23581 -
23582 - .macro UNFAKE_STACK_FRAME
23583 - addq $8*6, %rsp
23584 - CFI_ADJUST_CFA_OFFSET -(6*8)
23585 - .endm
23586 -
23587 /*
23588 * initial frame state for interrupts (and exceptions without error code)
23589 */
23590 @@ -241,25 +647,26 @@ ENDPROC(native_usergs_sysret64)
23591 /* save partial stack frame */
23592 .macro SAVE_ARGS_IRQ
23593 cld
23594 - /* start from rbp in pt_regs and jump over */
23595 - movq_cfi rdi, (RDI-RBP)
23596 - movq_cfi rsi, (RSI-RBP)
23597 - movq_cfi rdx, (RDX-RBP)
23598 - movq_cfi rcx, (RCX-RBP)
23599 - movq_cfi rax, (RAX-RBP)
23600 - movq_cfi r8, (R8-RBP)
23601 - movq_cfi r9, (R9-RBP)
23602 - movq_cfi r10, (R10-RBP)
23603 - movq_cfi r11, (R11-RBP)
23604 + /* start from r15 in pt_regs and jump over */
23605 + movq_cfi rdi, RDI
23606 + movq_cfi rsi, RSI
23607 + movq_cfi rdx, RDX
23608 + movq_cfi rcx, RCX
23609 + movq_cfi rax, RAX
23610 + movq_cfi r8, R8
23611 + movq_cfi r9, R9
23612 + movq_cfi r10, R10
23613 + movq_cfi r11, R11
23614 + movq_cfi r12, R12
23615
23616 /* Save rbp so that we can unwind from get_irq_regs() */
23617 - movq_cfi rbp, 0
23618 + movq_cfi rbp, RBP
23619
23620 /* Save previous stack value */
23621 movq %rsp, %rsi
23622
23623 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23624 - testl $3, CS-RBP(%rsi)
23625 + movq %rsp,%rdi /* arg1 for handler */
23626 + testb $3, CS(%rsi)
23627 je 1f
23628 SWAPGS
23629 /*
23630 @@ -279,6 +686,18 @@ ENDPROC(native_usergs_sysret64)
23631 0x06 /* DW_OP_deref */, \
23632 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23633 0x22 /* DW_OP_plus */
23634 +
23635 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23636 + testb $3, CS(%rdi)
23637 + jnz 1f
23638 + pax_enter_kernel
23639 + jmp 2f
23640 +1: pax_enter_kernel_user
23641 +2:
23642 +#else
23643 + pax_enter_kernel
23644 +#endif
23645 +
23646 /* We entered an interrupt context - irqs are off: */
23647 TRACE_IRQS_OFF
23648 .endm
23649 @@ -308,9 +727,52 @@ ENTRY(save_paranoid)
23650 js 1f /* negative -> in kernel */
23651 SWAPGS
23652 xorl %ebx,%ebx
23653 -1: ret
23654 +1:
23655 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23656 + testb $3, CS+8(%rsp)
23657 + jnz 1f
23658 + pax_enter_kernel
23659 + jmp 2f
23660 +1: pax_enter_kernel_user
23661 +2:
23662 +#else
23663 + pax_enter_kernel
23664 +#endif
23665 + pax_force_retaddr
23666 + ret
23667 CFI_ENDPROC
23668 -END(save_paranoid)
23669 +ENDPROC(save_paranoid)
23670 +
23671 +ENTRY(save_paranoid_nmi)
23672 + XCPT_FRAME 1 RDI+8
23673 + cld
23674 + movq_cfi rdi, RDI+8
23675 + movq_cfi rsi, RSI+8
23676 + movq_cfi rdx, RDX+8
23677 + movq_cfi rcx, RCX+8
23678 + movq_cfi rax, RAX+8
23679 + movq_cfi r8, R8+8
23680 + movq_cfi r9, R9+8
23681 + movq_cfi r10, R10+8
23682 + movq_cfi r11, R11+8
23683 + movq_cfi rbx, RBX+8
23684 + movq_cfi rbp, RBP+8
23685 + movq_cfi r12, R12+8
23686 + movq_cfi r13, R13+8
23687 + movq_cfi r14, R14+8
23688 + movq_cfi r15, R15+8
23689 + movl $1,%ebx
23690 + movl $MSR_GS_BASE,%ecx
23691 + rdmsr
23692 + testl %edx,%edx
23693 + js 1f /* negative -> in kernel */
23694 + SWAPGS
23695 + xorl %ebx,%ebx
23696 +1: pax_enter_kernel_nmi
23697 + pax_force_retaddr
23698 + ret
23699 + CFI_ENDPROC
23700 +ENDPROC(save_paranoid_nmi)
23701
23702 /*
23703 * A newly forked process directly context switches into this address.
23704 @@ -331,25 +793,26 @@ ENTRY(ret_from_fork)
23705
23706 RESTORE_REST
23707
23708 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23709 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23710 jz 1f
23711
23712 - testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23713 - jnz int_ret_from_sys_call
23714 -
23715 - RESTORE_TOP_OF_STACK %rdi, -ARGOFFSET
23716 - jmp ret_from_sys_call # go to the SYSRET fastpath
23717 + /*
23718 + * By the time we get here, we have no idea whether our pt_regs,
23719 + * ti flags, and ti status came from the 64-bit SYSCALL fast path,
23720 + * the slow path, or one of the ia32entry paths.
23721 + * Use int_ret_from_sys_call to return, since it can safely handle
23722 + * all of the above.
23723 + */
23724 + jmp int_ret_from_sys_call
23725
23726 1:
23727 - subq $REST_SKIP, %rsp # leave space for volatiles
23728 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23729 movq %rbp, %rdi
23730 call *%rbx
23731 movl $0, RAX(%rsp)
23732 RESTORE_REST
23733 jmp int_ret_from_sys_call
23734 CFI_ENDPROC
23735 -END(ret_from_fork)
23736 +ENDPROC(ret_from_fork)
23737
23738 /*
23739 * System call entry. Up to 6 arguments in registers are supported.
23740 @@ -386,7 +849,7 @@ END(ret_from_fork)
23741 ENTRY(system_call)
23742 CFI_STARTPROC simple
23743 CFI_SIGNAL_FRAME
23744 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23745 + CFI_DEF_CFA rsp,0
23746 CFI_REGISTER rip,rcx
23747 /*CFI_REGISTER rflags,r11*/
23748 SWAPGS_UNSAFE_STACK
23749 @@ -399,16 +862,23 @@ GLOBAL(system_call_after_swapgs)
23750
23751 movq %rsp,PER_CPU_VAR(old_rsp)
23752 movq PER_CPU_VAR(kernel_stack),%rsp
23753 + SAVE_ARGS 8*6, 0, rax_enosys=1
23754 + pax_enter_kernel_user
23755 +
23756 +#ifdef CONFIG_PAX_RANDKSTACK
23757 + pax_erase_kstack
23758 +#endif
23759 +
23760 /*
23761 * No need to follow this irqs off/on section - it's straight
23762 * and short:
23763 */
23764 ENABLE_INTERRUPTS(CLBR_NONE)
23765 - SAVE_ARGS 8, 0, rax_enosys=1
23766 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23767 movq %rcx,RIP-ARGOFFSET(%rsp)
23768 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23769 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23770 + GET_THREAD_INFO(%rcx)
23771 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23772 jnz tracesys
23773 system_call_fastpath:
23774 #if __SYSCALL_MASK == ~0
23775 @@ -432,10 +902,13 @@ sysret_check:
23776 LOCKDEP_SYS_EXIT
23777 DISABLE_INTERRUPTS(CLBR_NONE)
23778 TRACE_IRQS_OFF
23779 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23780 + GET_THREAD_INFO(%rcx)
23781 + movl TI_flags(%rcx),%edx
23782 andl %edi,%edx
23783 jnz sysret_careful
23784 CFI_REMEMBER_STATE
23785 + pax_exit_kernel_user
23786 + pax_erase_kstack
23787 /*
23788 * sysretq will re-enable interrupts:
23789 */
23790 @@ -494,12 +967,15 @@ sysret_audit:
23791
23792 /* Do syscall tracing */
23793 tracesys:
23794 - leaq -REST_SKIP(%rsp), %rdi
23795 + movq %rsp, %rdi
23796 movq $AUDIT_ARCH_X86_64, %rsi
23797 call syscall_trace_enter_phase1
23798 test %rax, %rax
23799 jnz tracesys_phase2 /* if needed, run the slow path */
23800 - LOAD_ARGS 0 /* else restore clobbered regs */
23801 +
23802 + pax_erase_kstack
23803 +
23804 + LOAD_ARGS /* else restore clobbered regs */
23805 jmp system_call_fastpath /* and return to the fast path */
23806
23807 tracesys_phase2:
23808 @@ -510,12 +986,14 @@ tracesys_phase2:
23809 movq %rax,%rdx
23810 call syscall_trace_enter_phase2
23811
23812 + pax_erase_kstack
23813 +
23814 /*
23815 * Reload arg registers from stack in case ptrace changed them.
23816 * We don't reload %rax because syscall_trace_entry_phase2() returned
23817 * the value it wants us to use in the table lookup.
23818 */
23819 - LOAD_ARGS ARGOFFSET, 1
23820 + LOAD_ARGS 1
23821 RESTORE_REST
23822 #if __SYSCALL_MASK == ~0
23823 cmpq $__NR_syscall_max,%rax
23824 @@ -545,7 +1023,9 @@ GLOBAL(int_with_check)
23825 andl %edi,%edx
23826 jnz int_careful
23827 andl $~TS_COMPAT,TI_status(%rcx)
23828 - jmp retint_swapgs
23829 + pax_exit_kernel_user
23830 + pax_erase_kstack
23831 + jmp retint_swapgs_pax
23832
23833 /* Either reschedule or signal or syscall exit tracking needed. */
23834 /* First do a reschedule test. */
23835 @@ -591,7 +1071,7 @@ int_restore_rest:
23836 TRACE_IRQS_OFF
23837 jmp int_with_check
23838 CFI_ENDPROC
23839 -END(system_call)
23840 +ENDPROC(system_call)
23841
23842 .macro FORK_LIKE func
23843 ENTRY(stub_\func)
23844 @@ -604,9 +1084,10 @@ ENTRY(stub_\func)
23845 DEFAULT_FRAME 0 8 /* offset 8: return address */
23846 call sys_\func
23847 RESTORE_TOP_OF_STACK %r11, 8
23848 - ret $REST_SKIP /* pop extended registers */
23849 + pax_force_retaddr
23850 + ret
23851 CFI_ENDPROC
23852 -END(stub_\func)
23853 +ENDPROC(stub_\func)
23854 .endm
23855
23856 .macro FIXED_FRAME label,func
23857 @@ -616,9 +1097,10 @@ ENTRY(\label)
23858 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23859 call \func
23860 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23861 + pax_force_retaddr
23862 ret
23863 CFI_ENDPROC
23864 -END(\label)
23865 +ENDPROC(\label)
23866 .endm
23867
23868 FORK_LIKE clone
23869 @@ -626,19 +1108,6 @@ END(\label)
23870 FORK_LIKE vfork
23871 FIXED_FRAME stub_iopl, sys_iopl
23872
23873 -ENTRY(ptregscall_common)
23874 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23875 - RESTORE_TOP_OF_STACK %r11, 8
23876 - movq_cfi_restore R15+8, r15
23877 - movq_cfi_restore R14+8, r14
23878 - movq_cfi_restore R13+8, r13
23879 - movq_cfi_restore R12+8, r12
23880 - movq_cfi_restore RBP+8, rbp
23881 - movq_cfi_restore RBX+8, rbx
23882 - ret $REST_SKIP /* pop extended registers */
23883 - CFI_ENDPROC
23884 -END(ptregscall_common)
23885 -
23886 ENTRY(stub_execve)
23887 CFI_STARTPROC
23888 addq $8, %rsp
23889 @@ -650,7 +1119,7 @@ ENTRY(stub_execve)
23890 RESTORE_REST
23891 jmp int_ret_from_sys_call
23892 CFI_ENDPROC
23893 -END(stub_execve)
23894 +ENDPROC(stub_execve)
23895
23896 /*
23897 * sigreturn is special because it needs to restore all registers on return.
23898 @@ -667,7 +1136,7 @@ ENTRY(stub_rt_sigreturn)
23899 RESTORE_REST
23900 jmp int_ret_from_sys_call
23901 CFI_ENDPROC
23902 -END(stub_rt_sigreturn)
23903 +ENDPROC(stub_rt_sigreturn)
23904
23905 #ifdef CONFIG_X86_X32_ABI
23906 ENTRY(stub_x32_rt_sigreturn)
23907 @@ -681,7 +1150,7 @@ ENTRY(stub_x32_rt_sigreturn)
23908 RESTORE_REST
23909 jmp int_ret_from_sys_call
23910 CFI_ENDPROC
23911 -END(stub_x32_rt_sigreturn)
23912 +ENDPROC(stub_x32_rt_sigreturn)
23913
23914 ENTRY(stub_x32_execve)
23915 CFI_STARTPROC
23916 @@ -695,7 +1164,7 @@ ENTRY(stub_x32_execve)
23917 RESTORE_REST
23918 jmp int_ret_from_sys_call
23919 CFI_ENDPROC
23920 -END(stub_x32_execve)
23921 +ENDPROC(stub_x32_execve)
23922
23923 #endif
23924
23925 @@ -732,7 +1201,7 @@ vector=vector+1
23926 2: jmp common_interrupt
23927 .endr
23928 CFI_ENDPROC
23929 -END(irq_entries_start)
23930 +ENDPROC(irq_entries_start)
23931
23932 .previous
23933 END(interrupt)
23934 @@ -749,8 +1218,8 @@ END(interrupt)
23935 /* 0(%rsp): ~(interrupt number) */
23936 .macro interrupt func
23937 /* reserve pt_regs for scratch regs and rbp */
23938 - subq $ORIG_RAX-RBP, %rsp
23939 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23940 + subq $ORIG_RAX, %rsp
23941 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23942 SAVE_ARGS_IRQ
23943 call \func
23944 .endm
23945 @@ -773,14 +1242,14 @@ ret_from_intr:
23946
23947 /* Restore saved previous stack */
23948 popq %rsi
23949 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23950 - leaq ARGOFFSET-RBP(%rsi), %rsp
23951 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23952 + movq %rsi, %rsp
23953 CFI_DEF_CFA_REGISTER rsp
23954 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23955 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23956
23957 exit_intr:
23958 GET_THREAD_INFO(%rcx)
23959 - testl $3,CS-ARGOFFSET(%rsp)
23960 + testb $3,CS-ARGOFFSET(%rsp)
23961 je retint_kernel
23962
23963 /* Interrupt came from user space */
23964 @@ -802,12 +1271,35 @@ retint_swapgs: /* return to user-space */
23965 * The iretq could re-enable interrupts:
23966 */
23967 DISABLE_INTERRUPTS(CLBR_ANY)
23968 + pax_exit_kernel_user
23969 +retint_swapgs_pax:
23970 TRACE_IRQS_IRETQ
23971 SWAPGS
23972 jmp restore_args
23973
23974 retint_restore_args: /* return to kernel space */
23975 DISABLE_INTERRUPTS(CLBR_ANY)
23976 + pax_exit_kernel
23977 +
23978 +#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23979 + /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23980 + * namely calling EFI runtime services with a phys mapping. We're
23981 + * starting off with NOPs and patch in the real instrumentation
23982 + * (BTS/OR) before starting any userland process; even before starting
23983 + * up the APs.
23984 + */
23985 + .pushsection .altinstr_replacement, "a"
23986 + 601: pax_force_retaddr (RIP-ARGOFFSET)
23987 + 602:
23988 + .popsection
23989 + 603: .fill 602b-601b, 1, 0x90
23990 + .pushsection .altinstructions, "a"
23991 + altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23992 + .popsection
23993 +#else
23994 + pax_force_retaddr (RIP-ARGOFFSET)
23995 +#endif
23996 +
23997 /*
23998 * The iretq could re-enable interrupts:
23999 */
24000 @@ -845,15 +1337,15 @@ native_irq_return_ldt:
24001 SWAPGS
24002 movq PER_CPU_VAR(espfix_waddr),%rdi
24003 movq %rax,(0*8)(%rdi) /* RAX */
24004 - movq (2*8)(%rsp),%rax /* RIP */
24005 + movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
24006 movq %rax,(1*8)(%rdi)
24007 - movq (3*8)(%rsp),%rax /* CS */
24008 + movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
24009 movq %rax,(2*8)(%rdi)
24010 - movq (4*8)(%rsp),%rax /* RFLAGS */
24011 + movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
24012 movq %rax,(3*8)(%rdi)
24013 - movq (6*8)(%rsp),%rax /* SS */
24014 + movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
24015 movq %rax,(5*8)(%rdi)
24016 - movq (5*8)(%rsp),%rax /* RSP */
24017 + movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
24018 movq %rax,(4*8)(%rdi)
24019 andl $0xffff0000,%eax
24020 popq_cfi %rdi
24021 @@ -907,7 +1399,7 @@ ENTRY(retint_kernel)
24022 jmp exit_intr
24023 #endif
24024 CFI_ENDPROC
24025 -END(common_interrupt)
24026 +ENDPROC(common_interrupt)
24027
24028 /*
24029 * APIC interrupts.
24030 @@ -921,7 +1413,7 @@ ENTRY(\sym)
24031 interrupt \do_sym
24032 jmp ret_from_intr
24033 CFI_ENDPROC
24034 -END(\sym)
24035 +ENDPROC(\sym)
24036 .endm
24037
24038 #ifdef CONFIG_TRACING
24039 @@ -994,7 +1486,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24040 /*
24041 * Exception entry points.
24042 */
24043 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24044 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24045
24046 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24047 ENTRY(\sym)
24048 @@ -1045,6 +1537,12 @@ ENTRY(\sym)
24049 .endif
24050
24051 .if \shift_ist != -1
24052 +#ifdef CONFIG_SMP
24053 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24054 + lea init_tss(%r13), %r13
24055 +#else
24056 + lea init_tss(%rip), %r13
24057 +#endif
24058 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24059 .endif
24060
24061 @@ -1061,7 +1559,7 @@ ENTRY(\sym)
24062 .endif
24063
24064 CFI_ENDPROC
24065 -END(\sym)
24066 +ENDPROC(\sym)
24067 .endm
24068
24069 #ifdef CONFIG_TRACING
24070 @@ -1102,9 +1600,10 @@ gs_change:
24071 2: mfence /* workaround */
24072 SWAPGS
24073 popfq_cfi
24074 + pax_force_retaddr
24075 ret
24076 CFI_ENDPROC
24077 -END(native_load_gs_index)
24078 +ENDPROC(native_load_gs_index)
24079
24080 _ASM_EXTABLE(gs_change,bad_gs)
24081 .section .fixup,"ax"
24082 @@ -1132,9 +1631,10 @@ ENTRY(do_softirq_own_stack)
24083 CFI_DEF_CFA_REGISTER rsp
24084 CFI_ADJUST_CFA_OFFSET -8
24085 decl PER_CPU_VAR(irq_count)
24086 + pax_force_retaddr
24087 ret
24088 CFI_ENDPROC
24089 -END(do_softirq_own_stack)
24090 +ENDPROC(do_softirq_own_stack)
24091
24092 #ifdef CONFIG_XEN
24093 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24094 @@ -1172,7 +1672,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24095 decl PER_CPU_VAR(irq_count)
24096 jmp error_exit
24097 CFI_ENDPROC
24098 -END(xen_do_hypervisor_callback)
24099 +ENDPROC(xen_do_hypervisor_callback)
24100
24101 /*
24102 * Hypervisor uses this for application faults while it executes.
24103 @@ -1231,7 +1731,7 @@ ENTRY(xen_failsafe_callback)
24104 SAVE_ALL
24105 jmp error_exit
24106 CFI_ENDPROC
24107 -END(xen_failsafe_callback)
24108 +ENDPROC(xen_failsafe_callback)
24109
24110 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24111 xen_hvm_callback_vector xen_evtchn_do_upcall
24112 @@ -1278,18 +1778,33 @@ ENTRY(paranoid_exit)
24113 DEFAULT_FRAME
24114 DISABLE_INTERRUPTS(CLBR_NONE)
24115 TRACE_IRQS_OFF_DEBUG
24116 - testl %ebx,%ebx /* swapgs needed? */
24117 + testl $1,%ebx /* swapgs needed? */
24118 jnz paranoid_restore
24119 - testl $3,CS(%rsp)
24120 + testb $3,CS(%rsp)
24121 jnz paranoid_userspace
24122 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24123 + pax_exit_kernel
24124 + TRACE_IRQS_IRETQ 0
24125 + SWAPGS_UNSAFE_STACK
24126 + RESTORE_ALL 8
24127 + pax_force_retaddr_bts
24128 + jmp irq_return
24129 +#endif
24130 paranoid_swapgs:
24131 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24132 + pax_exit_kernel_user
24133 +#else
24134 + pax_exit_kernel
24135 +#endif
24136 TRACE_IRQS_IRETQ 0
24137 SWAPGS_UNSAFE_STACK
24138 RESTORE_ALL 8
24139 jmp irq_return
24140 paranoid_restore:
24141 + pax_exit_kernel
24142 TRACE_IRQS_IRETQ_DEBUG 0
24143 RESTORE_ALL 8
24144 + pax_force_retaddr_bts
24145 jmp irq_return
24146 paranoid_userspace:
24147 GET_THREAD_INFO(%rcx)
24148 @@ -1318,7 +1833,7 @@ paranoid_schedule:
24149 TRACE_IRQS_OFF
24150 jmp paranoid_userspace
24151 CFI_ENDPROC
24152 -END(paranoid_exit)
24153 +ENDPROC(paranoid_exit)
24154
24155 /*
24156 * Exception entry point. This expects an error code/orig_rax on the stack.
24157 @@ -1345,12 +1860,23 @@ ENTRY(error_entry)
24158 movq %r14, R14+8(%rsp)
24159 movq %r15, R15+8(%rsp)
24160 xorl %ebx,%ebx
24161 - testl $3,CS+8(%rsp)
24162 + testb $3,CS+8(%rsp)
24163 je error_kernelspace
24164 error_swapgs:
24165 SWAPGS
24166 error_sti:
24167 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24168 + testb $3, CS+8(%rsp)
24169 + jnz 1f
24170 + pax_enter_kernel
24171 + jmp 2f
24172 +1: pax_enter_kernel_user
24173 +2:
24174 +#else
24175 + pax_enter_kernel
24176 +#endif
24177 TRACE_IRQS_OFF
24178 + pax_force_retaddr
24179 ret
24180
24181 /*
24182 @@ -1385,7 +1911,7 @@ error_bad_iret:
24183 decl %ebx /* Return to usergs */
24184 jmp error_sti
24185 CFI_ENDPROC
24186 -END(error_entry)
24187 +ENDPROC(error_entry)
24188
24189
24190 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24191 @@ -1396,7 +1922,7 @@ ENTRY(error_exit)
24192 DISABLE_INTERRUPTS(CLBR_NONE)
24193 TRACE_IRQS_OFF
24194 GET_THREAD_INFO(%rcx)
24195 - testl %eax,%eax
24196 + testl $1,%eax
24197 jne retint_kernel
24198 LOCKDEP_SYS_EXIT_IRQ
24199 movl TI_flags(%rcx),%edx
24200 @@ -1405,7 +1931,7 @@ ENTRY(error_exit)
24201 jnz retint_careful
24202 jmp retint_swapgs
24203 CFI_ENDPROC
24204 -END(error_exit)
24205 +ENDPROC(error_exit)
24206
24207 /*
24208 * Test if a given stack is an NMI stack or not.
24209 @@ -1463,9 +1989,11 @@ ENTRY(nmi)
24210 * If %cs was not the kernel segment, then the NMI triggered in user
24211 * space, which means it is definitely not nested.
24212 */
24213 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24214 + je 1f
24215 cmpl $__KERNEL_CS, 16(%rsp)
24216 jne first_nmi
24217 -
24218 +1:
24219 /*
24220 * Check the special variable on the stack to see if NMIs are
24221 * executing.
24222 @@ -1499,8 +2027,7 @@ nested_nmi:
24223
24224 1:
24225 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24226 - leaq -1*8(%rsp), %rdx
24227 - movq %rdx, %rsp
24228 + subq $8, %rsp
24229 CFI_ADJUST_CFA_OFFSET 1*8
24230 leaq -10*8(%rsp), %rdx
24231 pushq_cfi $__KERNEL_DS
24232 @@ -1518,6 +2045,7 @@ nested_nmi_out:
24233 CFI_RESTORE rdx
24234
24235 /* No need to check faults here */
24236 +# pax_force_retaddr_bts
24237 INTERRUPT_RETURN
24238
24239 CFI_RESTORE_STATE
24240 @@ -1614,13 +2142,13 @@ end_repeat_nmi:
24241 subq $ORIG_RAX-R15, %rsp
24242 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24243 /*
24244 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24245 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24246 * as we should not be calling schedule in NMI context.
24247 * Even with normal interrupts enabled. An NMI should not be
24248 * setting NEED_RESCHED or anything that normal interrupts and
24249 * exceptions might do.
24250 */
24251 - call save_paranoid
24252 + call save_paranoid_nmi
24253 DEFAULT_FRAME 0
24254
24255 /*
24256 @@ -1630,9 +2158,9 @@ end_repeat_nmi:
24257 * NMI itself takes a page fault, the page fault that was preempted
24258 * will read the information from the NMI page fault and not the
24259 * origin fault. Save it off and restore it if it changes.
24260 - * Use the r12 callee-saved register.
24261 + * Use the r13 callee-saved register.
24262 */
24263 - movq %cr2, %r12
24264 + movq %cr2, %r13
24265
24266 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24267 movq %rsp,%rdi
24268 @@ -1641,29 +2169,34 @@ end_repeat_nmi:
24269
24270 /* Did the NMI take a page fault? Restore cr2 if it did */
24271 movq %cr2, %rcx
24272 - cmpq %rcx, %r12
24273 + cmpq %rcx, %r13
24274 je 1f
24275 - movq %r12, %cr2
24276 + movq %r13, %cr2
24277 1:
24278
24279 - testl %ebx,%ebx /* swapgs needed? */
24280 + testl $1,%ebx /* swapgs needed? */
24281 jnz nmi_restore
24282 nmi_swapgs:
24283 SWAPGS_UNSAFE_STACK
24284 nmi_restore:
24285 + pax_exit_kernel_nmi
24286 /* Pop the extra iret frame at once */
24287 RESTORE_ALL 6*8
24288 + testb $3, 8(%rsp)
24289 + jnz 1f
24290 + pax_force_retaddr_bts
24291 +1:
24292
24293 /* Clear the NMI executing stack variable */
24294 movq $0, 5*8(%rsp)
24295 jmp irq_return
24296 CFI_ENDPROC
24297 -END(nmi)
24298 +ENDPROC(nmi)
24299
24300 ENTRY(ignore_sysret)
24301 CFI_STARTPROC
24302 mov $-ENOSYS,%eax
24303 sysret
24304 CFI_ENDPROC
24305 -END(ignore_sysret)
24306 +ENDPROC(ignore_sysret)
24307
24308 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24309 index 94d857f..5bce89c 100644
24310 --- a/arch/x86/kernel/espfix_64.c
24311 +++ b/arch/x86/kernel/espfix_64.c
24312 @@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24313 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24314 static void *espfix_pages[ESPFIX_MAX_PAGES];
24315
24316 -static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24317 - __aligned(PAGE_SIZE);
24318 +static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24319
24320 static unsigned int page_random, slot_random;
24321
24322 @@ -122,14 +121,17 @@ static void init_espfix_random(void)
24323 void __init init_espfix_bsp(void)
24324 {
24325 pgd_t *pgd_p;
24326 - pteval_t ptemask;
24327 -
24328 - ptemask = __supported_pte_mask;
24329 + unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24330
24331 /* Install the espfix pud into the kernel page directory */
24332 - pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24333 + pgd_p = &init_level4_pgt[index];
24334 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24335
24336 +#ifdef CONFIG_PAX_PER_CPU_PGD
24337 + clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24338 + clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24339 +#endif
24340 +
24341 /* Randomize the locations */
24342 init_espfix_random();
24343
24344 @@ -197,7 +199,7 @@ void init_espfix_ap(void)
24345 set_pte(&pte_p[n*PTE_STRIDE], pte);
24346
24347 /* Job is done for this CPU and any CPU which shares this page */
24348 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24349 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24350
24351 unlock_done:
24352 mutex_unlock(&espfix_init_mutex);
24353 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24354 index 3386dc9..28bdf81 100644
24355 --- a/arch/x86/kernel/ftrace.c
24356 +++ b/arch/x86/kernel/ftrace.c
24357 @@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24358 * kernel identity mapping to modify code.
24359 */
24360 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24361 - ip = (unsigned long)__va(__pa_symbol(ip));
24362 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24363
24364 return ip;
24365 }
24366 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24367 {
24368 unsigned char replaced[MCOUNT_INSN_SIZE];
24369
24370 + ip = ktla_ktva(ip);
24371 +
24372 /*
24373 * Note: Due to modules and __init, code can
24374 * disappear and change, we need to protect against faulting
24375 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24376 unsigned char old[MCOUNT_INSN_SIZE];
24377 int ret;
24378
24379 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24380 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24381
24382 ftrace_update_func = ip;
24383 /* Make sure the breakpoints see the ftrace_update_func update */
24384 @@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24385 unsigned char replaced[MCOUNT_INSN_SIZE];
24386 unsigned char brk = BREAKPOINT_INSTRUCTION;
24387
24388 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24389 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24390 return -EFAULT;
24391
24392 /* Make sure it is what we expect it to be */
24393 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24394 index eda1a86..8f6df48 100644
24395 --- a/arch/x86/kernel/head64.c
24396 +++ b/arch/x86/kernel/head64.c
24397 @@ -67,12 +67,12 @@ again:
24398 pgd = *pgd_p;
24399
24400 /*
24401 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24402 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24403 + * The use of __early_va rather than __va here is critical:
24404 + * __va would point us back into the dynamic
24405 * range and we might end up looping forever...
24406 */
24407 if (pgd)
24408 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24409 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24410 else {
24411 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24412 reset_early_page_tables();
24413 @@ -82,13 +82,13 @@ again:
24414 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24415 for (i = 0; i < PTRS_PER_PUD; i++)
24416 pud_p[i] = 0;
24417 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24418 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24419 }
24420 pud_p += pud_index(address);
24421 pud = *pud_p;
24422
24423 if (pud)
24424 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24425 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24426 else {
24427 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24428 reset_early_page_tables();
24429 @@ -98,7 +98,7 @@ again:
24430 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24431 for (i = 0; i < PTRS_PER_PMD; i++)
24432 pmd_p[i] = 0;
24433 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24434 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24435 }
24436 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24437 pmd_p[pmd_index(address)] = pmd;
24438 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24439 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24440 early_printk("Kernel alive\n");
24441
24442 - clear_page(init_level4_pgt);
24443 /* set init_level4_pgt kernel high mapping*/
24444 init_level4_pgt[511] = early_level4_pgt[511];
24445
24446 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24447 index f36bd42..0ab4474 100644
24448 --- a/arch/x86/kernel/head_32.S
24449 +++ b/arch/x86/kernel/head_32.S
24450 @@ -26,6 +26,12 @@
24451 /* Physical address */
24452 #define pa(X) ((X) - __PAGE_OFFSET)
24453
24454 +#ifdef CONFIG_PAX_KERNEXEC
24455 +#define ta(X) (X)
24456 +#else
24457 +#define ta(X) ((X) - __PAGE_OFFSET)
24458 +#endif
24459 +
24460 /*
24461 * References to members of the new_cpu_data structure.
24462 */
24463 @@ -55,11 +61,7 @@
24464 * and small than max_low_pfn, otherwise will waste some page table entries
24465 */
24466
24467 -#if PTRS_PER_PMD > 1
24468 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24469 -#else
24470 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24471 -#endif
24472 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24473
24474 /* Number of possible pages in the lowmem region */
24475 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24476 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24477 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24478
24479 /*
24480 + * Real beginning of normal "text" segment
24481 + */
24482 +ENTRY(stext)
24483 +ENTRY(_stext)
24484 +
24485 +/*
24486 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24487 * %esi points to the real-mode code as a 32-bit pointer.
24488 * CS and DS must be 4 GB flat segments, but we don't depend on
24489 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24490 * can.
24491 */
24492 __HEAD
24493 +
24494 +#ifdef CONFIG_PAX_KERNEXEC
24495 + jmp startup_32
24496 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24497 +.fill PAGE_SIZE-5,1,0xcc
24498 +#endif
24499 +
24500 ENTRY(startup_32)
24501 movl pa(stack_start),%ecx
24502
24503 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24504 2:
24505 leal -__PAGE_OFFSET(%ecx),%esp
24506
24507 +#ifdef CONFIG_SMP
24508 + movl $pa(cpu_gdt_table),%edi
24509 + movl $__per_cpu_load,%eax
24510 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24511 + rorl $16,%eax
24512 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24513 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24514 + movl $__per_cpu_end - 1,%eax
24515 + subl $__per_cpu_start,%eax
24516 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24517 +#endif
24518 +
24519 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24520 + movl $NR_CPUS,%ecx
24521 + movl $pa(cpu_gdt_table),%edi
24522 +1:
24523 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24524 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24525 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24526 + addl $PAGE_SIZE_asm,%edi
24527 + loop 1b
24528 +#endif
24529 +
24530 +#ifdef CONFIG_PAX_KERNEXEC
24531 + movl $pa(boot_gdt),%edi
24532 + movl $__LOAD_PHYSICAL_ADDR,%eax
24533 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24534 + rorl $16,%eax
24535 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24536 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24537 + rorl $16,%eax
24538 +
24539 + ljmp $(__BOOT_CS),$1f
24540 +1:
24541 +
24542 + movl $NR_CPUS,%ecx
24543 + movl $pa(cpu_gdt_table),%edi
24544 + addl $__PAGE_OFFSET,%eax
24545 +1:
24546 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24547 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24548 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24549 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24550 + rorl $16,%eax
24551 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24552 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24553 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24554 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24555 + rorl $16,%eax
24556 + addl $PAGE_SIZE_asm,%edi
24557 + loop 1b
24558 +#endif
24559 +
24560 /*
24561 * Clear BSS first so that there are no surprises...
24562 */
24563 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24564 movl %eax, pa(max_pfn_mapped)
24565
24566 /* Do early initialization of the fixmap area */
24567 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24568 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24569 +#ifdef CONFIG_COMPAT_VDSO
24570 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24571 +#else
24572 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24573 +#endif
24574 #else /* Not PAE */
24575
24576 page_pde_offset = (__PAGE_OFFSET >> 20);
24577 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24578 movl %eax, pa(max_pfn_mapped)
24579
24580 /* Do early initialization of the fixmap area */
24581 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24582 - movl %eax,pa(initial_page_table+0xffc)
24583 +#ifdef CONFIG_COMPAT_VDSO
24584 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24585 +#else
24586 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24587 +#endif
24588 #endif
24589
24590 #ifdef CONFIG_PARAVIRT
24591 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24592 cmpl $num_subarch_entries, %eax
24593 jae bad_subarch
24594
24595 - movl pa(subarch_entries)(,%eax,4), %eax
24596 - subl $__PAGE_OFFSET, %eax
24597 - jmp *%eax
24598 + jmp *pa(subarch_entries)(,%eax,4)
24599
24600 bad_subarch:
24601 WEAK(lguest_entry)
24602 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24603 __INITDATA
24604
24605 subarch_entries:
24606 - .long default_entry /* normal x86/PC */
24607 - .long lguest_entry /* lguest hypervisor */
24608 - .long xen_entry /* Xen hypervisor */
24609 - .long default_entry /* Moorestown MID */
24610 + .long ta(default_entry) /* normal x86/PC */
24611 + .long ta(lguest_entry) /* lguest hypervisor */
24612 + .long ta(xen_entry) /* Xen hypervisor */
24613 + .long ta(default_entry) /* Moorestown MID */
24614 num_subarch_entries = (. - subarch_entries) / 4
24615 .previous
24616 #else
24617 @@ -354,6 +426,7 @@ default_entry:
24618 movl pa(mmu_cr4_features),%eax
24619 movl %eax,%cr4
24620
24621 +#ifdef CONFIG_X86_PAE
24622 testb $X86_CR4_PAE, %al # check if PAE is enabled
24623 jz enable_paging
24624
24625 @@ -382,6 +455,9 @@ default_entry:
24626 /* Make changes effective */
24627 wrmsr
24628
24629 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24630 +#endif
24631 +
24632 enable_paging:
24633
24634 /*
24635 @@ -449,14 +525,20 @@ is486:
24636 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24637 movl %eax,%ss # after changing gdt.
24638
24639 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24640 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24641 movl %eax,%ds
24642 movl %eax,%es
24643
24644 movl $(__KERNEL_PERCPU), %eax
24645 movl %eax,%fs # set this cpu's percpu
24646
24647 +#ifdef CONFIG_CC_STACKPROTECTOR
24648 movl $(__KERNEL_STACK_CANARY),%eax
24649 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24650 + movl $(__USER_DS),%eax
24651 +#else
24652 + xorl %eax,%eax
24653 +#endif
24654 movl %eax,%gs
24655
24656 xorl %eax,%eax # Clear LDT
24657 @@ -512,8 +594,11 @@ setup_once:
24658 * relocation. Manually set base address in stack canary
24659 * segment descriptor.
24660 */
24661 - movl $gdt_page,%eax
24662 + movl $cpu_gdt_table,%eax
24663 movl $stack_canary,%ecx
24664 +#ifdef CONFIG_SMP
24665 + addl $__per_cpu_load,%ecx
24666 +#endif
24667 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24668 shrl $16, %ecx
24669 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24670 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24671 cmpl $2,(%esp) # X86_TRAP_NMI
24672 je is_nmi # Ignore NMI
24673
24674 - cmpl $2,%ss:early_recursion_flag
24675 + cmpl $1,%ss:early_recursion_flag
24676 je hlt_loop
24677 incl %ss:early_recursion_flag
24678
24679 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24680 pushl (20+6*4)(%esp) /* trapno */
24681 pushl $fault_msg
24682 call printk
24683 -#endif
24684 call dump_stack
24685 +#endif
24686 hlt_loop:
24687 hlt
24688 jmp hlt_loop
24689 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24690 /* This is the default interrupt "handler" :-) */
24691 ALIGN
24692 ignore_int:
24693 - cld
24694 #ifdef CONFIG_PRINTK
24695 + cmpl $2,%ss:early_recursion_flag
24696 + je hlt_loop
24697 + incl %ss:early_recursion_flag
24698 + cld
24699 pushl %eax
24700 pushl %ecx
24701 pushl %edx
24702 @@ -617,9 +705,6 @@ ignore_int:
24703 movl $(__KERNEL_DS),%eax
24704 movl %eax,%ds
24705 movl %eax,%es
24706 - cmpl $2,early_recursion_flag
24707 - je hlt_loop
24708 - incl early_recursion_flag
24709 pushl 16(%esp)
24710 pushl 24(%esp)
24711 pushl 32(%esp)
24712 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24713 /*
24714 * BSS section
24715 */
24716 -__PAGE_ALIGNED_BSS
24717 - .align PAGE_SIZE
24718 #ifdef CONFIG_X86_PAE
24719 +.section .initial_pg_pmd,"a",@progbits
24720 initial_pg_pmd:
24721 .fill 1024*KPMDS,4,0
24722 #else
24723 +.section .initial_page_table,"a",@progbits
24724 ENTRY(initial_page_table)
24725 .fill 1024,4,0
24726 #endif
24727 +.section .initial_pg_fixmap,"a",@progbits
24728 initial_pg_fixmap:
24729 .fill 1024,4,0
24730 +.section .empty_zero_page,"a",@progbits
24731 ENTRY(empty_zero_page)
24732 .fill 4096,1,0
24733 +.section .swapper_pg_dir,"a",@progbits
24734 ENTRY(swapper_pg_dir)
24735 +#ifdef CONFIG_X86_PAE
24736 + .fill 4,8,0
24737 +#else
24738 .fill 1024,4,0
24739 +#endif
24740
24741 /*
24742 * This starts the data section.
24743 */
24744 #ifdef CONFIG_X86_PAE
24745 -__PAGE_ALIGNED_DATA
24746 - /* Page-aligned for the benefit of paravirt? */
24747 - .align PAGE_SIZE
24748 +.section .initial_page_table,"a",@progbits
24749 ENTRY(initial_page_table)
24750 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24751 # if KPMDS == 3
24752 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24753 # error "Kernel PMDs should be 1, 2 or 3"
24754 # endif
24755 .align PAGE_SIZE /* needs to be page-sized too */
24756 +
24757 +#ifdef CONFIG_PAX_PER_CPU_PGD
24758 +ENTRY(cpu_pgd)
24759 + .rept 2*NR_CPUS
24760 + .fill 4,8,0
24761 + .endr
24762 +#endif
24763 +
24764 #endif
24765
24766 .data
24767 .balign 4
24768 ENTRY(stack_start)
24769 - .long init_thread_union+THREAD_SIZE
24770 + .long init_thread_union+THREAD_SIZE-8
24771
24772 __INITRODATA
24773 int_msg:
24774 @@ -727,7 +825,7 @@ fault_msg:
24775 * segment size, and 32-bit linear address value:
24776 */
24777
24778 - .data
24779 +.section .rodata,"a",@progbits
24780 .globl boot_gdt_descr
24781 .globl idt_descr
24782
24783 @@ -736,7 +834,7 @@ fault_msg:
24784 .word 0 # 32 bit align gdt_desc.address
24785 boot_gdt_descr:
24786 .word __BOOT_DS+7
24787 - .long boot_gdt - __PAGE_OFFSET
24788 + .long pa(boot_gdt)
24789
24790 .word 0 # 32-bit align idt_desc.address
24791 idt_descr:
24792 @@ -747,7 +845,7 @@ idt_descr:
24793 .word 0 # 32 bit align gdt_desc.address
24794 ENTRY(early_gdt_descr)
24795 .word GDT_ENTRIES*8-1
24796 - .long gdt_page /* Overwritten for secondary CPUs */
24797 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24798
24799 /*
24800 * The boot_gdt must mirror the equivalent in setup.S and is
24801 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24802 .align L1_CACHE_BYTES
24803 ENTRY(boot_gdt)
24804 .fill GDT_ENTRY_BOOT_CS,8,0
24805 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24806 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24807 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24808 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24809 +
24810 + .align PAGE_SIZE_asm
24811 +ENTRY(cpu_gdt_table)
24812 + .rept NR_CPUS
24813 + .quad 0x0000000000000000 /* NULL descriptor */
24814 + .quad 0x0000000000000000 /* 0x0b reserved */
24815 + .quad 0x0000000000000000 /* 0x13 reserved */
24816 + .quad 0x0000000000000000 /* 0x1b reserved */
24817 +
24818 +#ifdef CONFIG_PAX_KERNEXEC
24819 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24820 +#else
24821 + .quad 0x0000000000000000 /* 0x20 unused */
24822 +#endif
24823 +
24824 + .quad 0x0000000000000000 /* 0x28 unused */
24825 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24826 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24827 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24828 + .quad 0x0000000000000000 /* 0x4b reserved */
24829 + .quad 0x0000000000000000 /* 0x53 reserved */
24830 + .quad 0x0000000000000000 /* 0x5b reserved */
24831 +
24832 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24833 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24834 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24835 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24836 +
24837 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24838 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24839 +
24840 + /*
24841 + * Segments used for calling PnP BIOS have byte granularity.
24842 + * The code segments and data segments have fixed 64k limits,
24843 + * the transfer segment sizes are set at run time.
24844 + */
24845 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24846 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24847 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24848 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24849 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24850 +
24851 + /*
24852 + * The APM segments have byte granularity and their bases
24853 + * are set at run time. All have 64k limits.
24854 + */
24855 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24856 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24857 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24858 +
24859 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24860 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24861 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24862 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24863 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24864 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24865 +
24866 + /* Be sure this is zeroed to avoid false validations in Xen */
24867 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24868 + .endr
24869 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24870 index a468c0a..8b5a879 100644
24871 --- a/arch/x86/kernel/head_64.S
24872 +++ b/arch/x86/kernel/head_64.S
24873 @@ -20,6 +20,8 @@
24874 #include <asm/processor-flags.h>
24875 #include <asm/percpu.h>
24876 #include <asm/nops.h>
24877 +#include <asm/cpufeature.h>
24878 +#include <asm/alternative-asm.h>
24879
24880 #ifdef CONFIG_PARAVIRT
24881 #include <asm/asm-offsets.h>
24882 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24883 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24884 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24885 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24886 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24887 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24888 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24889 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24890 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24891 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24892
24893 .text
24894 __HEAD
24895 @@ -89,11 +97,24 @@ startup_64:
24896 * Fixup the physical addresses in the page table
24897 */
24898 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24899 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24900 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24901 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24902 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24903 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24904
24905 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24906 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24907 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24908 +#ifndef CONFIG_XEN
24909 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24910 +#endif
24911 +
24912 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24913 +
24914 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24915 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24916
24917 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24918 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24919
24920 /*
24921 * Set up the identity mapping for the switchover. These
24922 @@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24923 * after the boot processor executes this code.
24924 */
24925
24926 + orq $-1, %rbp
24927 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24928 1:
24929
24930 - /* Enable PAE mode and PGE */
24931 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24932 + /* Enable PAE mode and PSE/PGE */
24933 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24934 movq %rcx, %cr4
24935
24936 /* Setup early boot stage 4 level pagetables. */
24937 @@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24938 movl $MSR_EFER, %ecx
24939 rdmsr
24940 btsl $_EFER_SCE, %eax /* Enable System Call */
24941 - btl $20,%edi /* No Execute supported? */
24942 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24943 jnc 1f
24944 btsl $_EFER_NX, %eax
24945 + cmpq $-1, %rbp
24946 + je 1f
24947 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24948 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24949 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24950 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24951 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24952 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24953 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24954 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24955 1: wrmsr /* Make changes effective */
24956
24957 /* Setup cr0 */
24958 @@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24959 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24960 * address given in m16:64.
24961 */
24962 + pax_set_fptr_mask
24963 movq initial_code(%rip),%rax
24964 pushq $0 # fake return address to stop unwinder
24965 pushq $__KERNEL_CS # set correct cs
24966 @@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24967 .quad INIT_PER_CPU_VAR(irq_stack_union)
24968
24969 GLOBAL(stack_start)
24970 - .quad init_thread_union+THREAD_SIZE-8
24971 + .quad init_thread_union+THREAD_SIZE-16
24972 .word 0
24973 __FINITDATA
24974
24975 @@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24976 call dump_stack
24977 #ifdef CONFIG_KALLSYMS
24978 leaq early_idt_ripmsg(%rip),%rdi
24979 - movq 40(%rsp),%rsi # %rip again
24980 + movq 88(%rsp),%rsi # %rip again
24981 call __print_symbol
24982 #endif
24983 #endif /* EARLY_PRINTK */
24984 @@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24985 early_recursion_flag:
24986 .long 0
24987
24988 + .section .rodata,"a",@progbits
24989 #ifdef CONFIG_EARLY_PRINTK
24990 early_idt_msg:
24991 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24992 @@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24993 NEXT_PAGE(early_dynamic_pgts)
24994 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24995
24996 - .data
24997 + .section .rodata,"a",@progbits
24998
24999 -#ifndef CONFIG_XEN
25000 NEXT_PAGE(init_level4_pgt)
25001 - .fill 512,8,0
25002 -#else
25003 -NEXT_PAGE(init_level4_pgt)
25004 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25005 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25006 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25007 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25008 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25009 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25010 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25011 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25012 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25013 .org init_level4_pgt + L4_START_KERNEL*8, 0
25014 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25015 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25016
25017 +#ifdef CONFIG_PAX_PER_CPU_PGD
25018 +NEXT_PAGE(cpu_pgd)
25019 + .rept 2*NR_CPUS
25020 + .fill 512,8,0
25021 + .endr
25022 +#endif
25023 +
25024 NEXT_PAGE(level3_ident_pgt)
25025 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25026 +#ifdef CONFIG_XEN
25027 .fill 511, 8, 0
25028 +#else
25029 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25030 + .fill 510,8,0
25031 +#endif
25032 +
25033 +NEXT_PAGE(level3_vmalloc_start_pgt)
25034 + .fill 512,8,0
25035 +
25036 +NEXT_PAGE(level3_vmalloc_end_pgt)
25037 + .fill 512,8,0
25038 +
25039 +NEXT_PAGE(level3_vmemmap_pgt)
25040 + .fill L3_VMEMMAP_START,8,0
25041 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25042 +
25043 NEXT_PAGE(level2_ident_pgt)
25044 - /* Since I easily can, map the first 1G.
25045 + /* Since I easily can, map the first 2G.
25046 * Don't set NX because code runs from these pages.
25047 */
25048 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25049 -#endif
25050 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25051
25052 NEXT_PAGE(level3_kernel_pgt)
25053 .fill L3_START_KERNEL,8,0
25054 @@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25055 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25056 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25057
25058 +NEXT_PAGE(level2_vmemmap_pgt)
25059 + .fill 512,8,0
25060 +
25061 NEXT_PAGE(level2_kernel_pgt)
25062 /*
25063 * 512 MB kernel mapping. We spend a full page on this pagetable
25064 @@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25065 NEXT_PAGE(level2_fixmap_pgt)
25066 .fill 506,8,0
25067 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25068 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25069 - .fill 5,8,0
25070 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25071 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25072 + .fill 4,8,0
25073
25074 NEXT_PAGE(level1_fixmap_pgt)
25075 .fill 512,8,0
25076
25077 +NEXT_PAGE(level1_vsyscall_pgt)
25078 + .fill 512,8,0
25079 +
25080 #undef PMDS
25081
25082 - .data
25083 + .align PAGE_SIZE
25084 +ENTRY(cpu_gdt_table)
25085 + .rept NR_CPUS
25086 + .quad 0x0000000000000000 /* NULL descriptor */
25087 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25088 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25089 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25090 + .quad 0x00cffb000000ffff /* __USER32_CS */
25091 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25092 + .quad 0x00affb000000ffff /* __USER_CS */
25093 +
25094 +#ifdef CONFIG_PAX_KERNEXEC
25095 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25096 +#else
25097 + .quad 0x0 /* unused */
25098 +#endif
25099 +
25100 + .quad 0,0 /* TSS */
25101 + .quad 0,0 /* LDT */
25102 + .quad 0,0,0 /* three TLS descriptors */
25103 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25104 + /* asm/segment.h:GDT_ENTRIES must match this */
25105 +
25106 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25107 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25108 +#else
25109 + .quad 0x0 /* unused */
25110 +#endif
25111 +
25112 + /* zero the remaining page */
25113 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25114 + .endr
25115 +
25116 .align 16
25117 .globl early_gdt_descr
25118 early_gdt_descr:
25119 .word GDT_ENTRIES*8-1
25120 early_gdt_descr_base:
25121 - .quad INIT_PER_CPU_VAR(gdt_page)
25122 + .quad cpu_gdt_table
25123
25124 ENTRY(phys_base)
25125 /* This must match the first entry in level2_kernel_pgt */
25126 .quad 0x0000000000000000
25127
25128 #include "../../x86/xen/xen-head.S"
25129 -
25130 - __PAGE_ALIGNED_BSS
25131 +
25132 + .section .rodata,"a",@progbits
25133 NEXT_PAGE(empty_zero_page)
25134 .skip PAGE_SIZE
25135 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25136 index 05fd74f..c3548b1 100644
25137 --- a/arch/x86/kernel/i386_ksyms_32.c
25138 +++ b/arch/x86/kernel/i386_ksyms_32.c
25139 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25140 EXPORT_SYMBOL(cmpxchg8b_emu);
25141 #endif
25142
25143 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25144 +
25145 /* Networking helper routines. */
25146 EXPORT_SYMBOL(csum_partial_copy_generic);
25147 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25148 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25149
25150 EXPORT_SYMBOL(__get_user_1);
25151 EXPORT_SYMBOL(__get_user_2);
25152 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25153 EXPORT_SYMBOL(___preempt_schedule_context);
25154 #endif
25155 #endif
25156 +
25157 +#ifdef CONFIG_PAX_KERNEXEC
25158 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25159 +#endif
25160 +
25161 +#ifdef CONFIG_PAX_PER_CPU_PGD
25162 +EXPORT_SYMBOL(cpu_pgd);
25163 +#endif
25164 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25165 index a9a4229..6f4d476 100644
25166 --- a/arch/x86/kernel/i387.c
25167 +++ b/arch/x86/kernel/i387.c
25168 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25169 static inline bool interrupted_user_mode(void)
25170 {
25171 struct pt_regs *regs = get_irq_regs();
25172 - return regs && user_mode_vm(regs);
25173 + return regs && user_mode(regs);
25174 }
25175
25176 /*
25177 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25178 index e7cc537..67d7372 100644
25179 --- a/arch/x86/kernel/i8259.c
25180 +++ b/arch/x86/kernel/i8259.c
25181 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25182 static void make_8259A_irq(unsigned int irq)
25183 {
25184 disable_irq_nosync(irq);
25185 - io_apic_irqs &= ~(1<<irq);
25186 + io_apic_irqs &= ~(1UL<<irq);
25187 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25188 enable_irq(irq);
25189 }
25190 @@ -208,7 +208,7 @@ spurious_8259A_irq:
25191 "spurious 8259A interrupt: IRQ%d.\n", irq);
25192 spurious_irq_mask |= irqmask;
25193 }
25194 - atomic_inc(&irq_err_count);
25195 + atomic_inc_unchecked(&irq_err_count);
25196 /*
25197 * Theoretically we do not have to handle this IRQ,
25198 * but in Linux this does not cause problems and is
25199 @@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25200 /* (slave's support for AEOI in flat mode is to be investigated) */
25201 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25202
25203 + pax_open_kernel();
25204 if (auto_eoi)
25205 /*
25206 * In AEOI mode we just have to mask the interrupt
25207 * when acking.
25208 */
25209 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25210 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25211 else
25212 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25213 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25214 + pax_close_kernel();
25215
25216 udelay(100); /* wait for 8259A to initialize */
25217
25218 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25219 index a979b5b..1d6db75 100644
25220 --- a/arch/x86/kernel/io_delay.c
25221 +++ b/arch/x86/kernel/io_delay.c
25222 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25223 * Quirk table for systems that misbehave (lock up, etc.) if port
25224 * 0x80 is used:
25225 */
25226 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25227 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25228 {
25229 .callback = dmi_io_delay_0xed_port,
25230 .ident = "Compaq Presario V6000",
25231 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25232 index 4ddaf66..49d5c18 100644
25233 --- a/arch/x86/kernel/ioport.c
25234 +++ b/arch/x86/kernel/ioport.c
25235 @@ -6,6 +6,7 @@
25236 #include <linux/sched.h>
25237 #include <linux/kernel.h>
25238 #include <linux/capability.h>
25239 +#include <linux/security.h>
25240 #include <linux/errno.h>
25241 #include <linux/types.h>
25242 #include <linux/ioport.h>
25243 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25244 return -EINVAL;
25245 if (turn_on && !capable(CAP_SYS_RAWIO))
25246 return -EPERM;
25247 +#ifdef CONFIG_GRKERNSEC_IO
25248 + if (turn_on && grsec_disable_privio) {
25249 + gr_handle_ioperm();
25250 + return -ENODEV;
25251 + }
25252 +#endif
25253
25254 /*
25255 * If it's the first ioperm() call in this thread's lifetime, set the
25256 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25257 * because the ->io_bitmap_max value must match the bitmap
25258 * contents:
25259 */
25260 - tss = &per_cpu(init_tss, get_cpu());
25261 + tss = init_tss + get_cpu();
25262
25263 if (turn_on)
25264 bitmap_clear(t->io_bitmap_ptr, from, num);
25265 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25266 if (level > old) {
25267 if (!capable(CAP_SYS_RAWIO))
25268 return -EPERM;
25269 +#ifdef CONFIG_GRKERNSEC_IO
25270 + if (grsec_disable_privio) {
25271 + gr_handle_iopl();
25272 + return -ENODEV;
25273 + }
25274 +#endif
25275 }
25276 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25277 t->iopl = level << 12;
25278 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25279 index 3790775..53717dc 100644
25280 --- a/arch/x86/kernel/irq.c
25281 +++ b/arch/x86/kernel/irq.c
25282 @@ -22,7 +22,7 @@
25283 #define CREATE_TRACE_POINTS
25284 #include <asm/trace/irq_vectors.h>
25285
25286 -atomic_t irq_err_count;
25287 +atomic_unchecked_t irq_err_count;
25288
25289 /* Function pointer for generic interrupt vector handling */
25290 void (*x86_platform_ipi_callback)(void) = NULL;
25291 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25292 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25293 seq_printf(p, " Hypervisor callback interrupts\n");
25294 #endif
25295 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25296 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25297 #if defined(CONFIG_X86_IO_APIC)
25298 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25299 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25300 #endif
25301 return 0;
25302 }
25303 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25304
25305 u64 arch_irq_stat(void)
25306 {
25307 - u64 sum = atomic_read(&irq_err_count);
25308 + u64 sum = atomic_read_unchecked(&irq_err_count);
25309 return sum;
25310 }
25311
25312 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25313 index 63ce838..2ea3e06 100644
25314 --- a/arch/x86/kernel/irq_32.c
25315 +++ b/arch/x86/kernel/irq_32.c
25316 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25317
25318 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25319
25320 +extern void gr_handle_kernel_exploit(void);
25321 +
25322 int sysctl_panic_on_stackoverflow __read_mostly;
25323
25324 /* Debugging check for stack overflow: is there less than 1KB free? */
25325 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25326 __asm__ __volatile__("andl %%esp,%0" :
25327 "=r" (sp) : "0" (THREAD_SIZE - 1));
25328
25329 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25330 + return sp < STACK_WARN;
25331 }
25332
25333 static void print_stack_overflow(void)
25334 {
25335 printk(KERN_WARNING "low stack detected by irq handler\n");
25336 dump_stack();
25337 + gr_handle_kernel_exploit();
25338 if (sysctl_panic_on_stackoverflow)
25339 panic("low stack detected by irq handler - check messages\n");
25340 }
25341 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25342 static inline int
25343 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25344 {
25345 - struct irq_stack *curstk, *irqstk;
25346 + struct irq_stack *irqstk;
25347 u32 *isp, *prev_esp, arg1, arg2;
25348
25349 - curstk = (struct irq_stack *) current_stack();
25350 irqstk = __this_cpu_read(hardirq_stack);
25351
25352 /*
25353 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25354 * handler) we can't do that and just have to keep using the
25355 * current stack (which is the irq stack already after all)
25356 */
25357 - if (unlikely(curstk == irqstk))
25358 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25359 return 0;
25360
25361 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25362 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25363
25364 /* Save the next esp at the bottom of the stack */
25365 prev_esp = (u32 *)irqstk;
25366 *prev_esp = current_stack_pointer;
25367
25368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25369 + __set_fs(MAKE_MM_SEG(0));
25370 +#endif
25371 +
25372 if (unlikely(overflow))
25373 call_on_stack(print_stack_overflow, isp);
25374
25375 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25376 : "0" (irq), "1" (desc), "2" (isp),
25377 "D" (desc->handle_irq)
25378 : "memory", "cc", "ecx");
25379 +
25380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25381 + __set_fs(current_thread_info()->addr_limit);
25382 +#endif
25383 +
25384 return 1;
25385 }
25386
25387 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25388 */
25389 void irq_ctx_init(int cpu)
25390 {
25391 - struct irq_stack *irqstk;
25392 -
25393 if (per_cpu(hardirq_stack, cpu))
25394 return;
25395
25396 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25397 - THREADINFO_GFP,
25398 - THREAD_SIZE_ORDER));
25399 - per_cpu(hardirq_stack, cpu) = irqstk;
25400 -
25401 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25402 - THREADINFO_GFP,
25403 - THREAD_SIZE_ORDER));
25404 - per_cpu(softirq_stack, cpu) = irqstk;
25405 -
25406 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25407 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25408 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25409 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25410 }
25411
25412 void do_softirq_own_stack(void)
25413 {
25414 - struct thread_info *curstk;
25415 struct irq_stack *irqstk;
25416 u32 *isp, *prev_esp;
25417
25418 - curstk = current_stack();
25419 irqstk = __this_cpu_read(softirq_stack);
25420
25421 /* build the stack frame on the softirq stack */
25422 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25423 prev_esp = (u32 *)irqstk;
25424 *prev_esp = current_stack_pointer;
25425
25426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25427 + __set_fs(MAKE_MM_SEG(0));
25428 +#endif
25429 +
25430 call_on_stack(__do_softirq, isp);
25431 +
25432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25433 + __set_fs(current_thread_info()->addr_limit);
25434 +#endif
25435 +
25436 }
25437
25438 bool handle_irq(unsigned irq, struct pt_regs *regs)
25439 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25440 if (unlikely(!desc))
25441 return false;
25442
25443 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25444 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25445 if (unlikely(overflow))
25446 print_stack_overflow();
25447 desc->handle_irq(irq, desc);
25448 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25449 index e4b503d..824fce8 100644
25450 --- a/arch/x86/kernel/irq_64.c
25451 +++ b/arch/x86/kernel/irq_64.c
25452 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25453 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25454 EXPORT_PER_CPU_SYMBOL(irq_regs);
25455
25456 +extern void gr_handle_kernel_exploit(void);
25457 +
25458 int sysctl_panic_on_stackoverflow;
25459
25460 /*
25461 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25462 u64 estack_top, estack_bottom;
25463 u64 curbase = (u64)task_stack_page(current);
25464
25465 - if (user_mode_vm(regs))
25466 + if (user_mode(regs))
25467 return;
25468
25469 if (regs->sp >= curbase + sizeof(struct thread_info) +
25470 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25471 irq_stack_top, irq_stack_bottom,
25472 estack_top, estack_bottom);
25473
25474 + gr_handle_kernel_exploit();
25475 +
25476 if (sysctl_panic_on_stackoverflow)
25477 panic("low stack detected by irq handler - check messages\n");
25478 #endif
25479 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25480 index 26d5a55..a01160a 100644
25481 --- a/arch/x86/kernel/jump_label.c
25482 +++ b/arch/x86/kernel/jump_label.c
25483 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25484 * Jump label is enabled for the first time.
25485 * So we expect a default_nop...
25486 */
25487 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25488 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25489 != 0))
25490 bug_at((void *)entry->code, __LINE__);
25491 } else {
25492 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25493 * ...otherwise expect an ideal_nop. Otherwise
25494 * something went horribly wrong.
25495 */
25496 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25497 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25498 != 0))
25499 bug_at((void *)entry->code, __LINE__);
25500 }
25501 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25502 * are converting the default nop to the ideal nop.
25503 */
25504 if (init) {
25505 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25506 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25507 bug_at((void *)entry->code, __LINE__);
25508 } else {
25509 code.jump = 0xe9;
25510 code.offset = entry->target -
25511 (entry->code + JUMP_LABEL_NOP_SIZE);
25512 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25513 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25514 bug_at((void *)entry->code, __LINE__);
25515 }
25516 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25517 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25518 index 7ec1d5f..5a7d130 100644
25519 --- a/arch/x86/kernel/kgdb.c
25520 +++ b/arch/x86/kernel/kgdb.c
25521 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25522 #ifdef CONFIG_X86_32
25523 switch (regno) {
25524 case GDB_SS:
25525 - if (!user_mode_vm(regs))
25526 + if (!user_mode(regs))
25527 *(unsigned long *)mem = __KERNEL_DS;
25528 break;
25529 case GDB_SP:
25530 - if (!user_mode_vm(regs))
25531 + if (!user_mode(regs))
25532 *(unsigned long *)mem = kernel_stack_pointer(regs);
25533 break;
25534 case GDB_GS:
25535 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25536 bp->attr.bp_addr = breakinfo[breakno].addr;
25537 bp->attr.bp_len = breakinfo[breakno].len;
25538 bp->attr.bp_type = breakinfo[breakno].type;
25539 - info->address = breakinfo[breakno].addr;
25540 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25541 + info->address = ktla_ktva(breakinfo[breakno].addr);
25542 + else
25543 + info->address = breakinfo[breakno].addr;
25544 info->len = breakinfo[breakno].len;
25545 info->type = breakinfo[breakno].type;
25546 val = arch_install_hw_breakpoint(bp);
25547 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25548 case 'k':
25549 /* clear the trace bit */
25550 linux_regs->flags &= ~X86_EFLAGS_TF;
25551 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25552 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25553
25554 /* set the trace bit if we're stepping */
25555 if (remcomInBuffer[0] == 's') {
25556 linux_regs->flags |= X86_EFLAGS_TF;
25557 - atomic_set(&kgdb_cpu_doing_single_step,
25558 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25559 raw_smp_processor_id());
25560 }
25561
25562 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25563
25564 switch (cmd) {
25565 case DIE_DEBUG:
25566 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25567 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25568 if (user_mode(regs))
25569 return single_step_cont(regs, args);
25570 break;
25571 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25572 #endif /* CONFIG_DEBUG_RODATA */
25573
25574 bpt->type = BP_BREAKPOINT;
25575 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25576 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25577 BREAK_INSTR_SIZE);
25578 if (err)
25579 return err;
25580 - err = probe_kernel_write((char *)bpt->bpt_addr,
25581 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25582 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25583 #ifdef CONFIG_DEBUG_RODATA
25584 if (!err)
25585 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25586 return -EBUSY;
25587 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25588 BREAK_INSTR_SIZE);
25589 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25590 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25591 if (err)
25592 return err;
25593 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25594 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25595 if (mutex_is_locked(&text_mutex))
25596 goto knl_write;
25597 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25598 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25599 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25600 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25601 goto knl_write;
25602 return err;
25603 knl_write:
25604 #endif /* CONFIG_DEBUG_RODATA */
25605 - return probe_kernel_write((char *)bpt->bpt_addr,
25606 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25607 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25608 }
25609
25610 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25611 index 93d2c04..36d0e94 100644
25612 --- a/arch/x86/kernel/kprobes/core.c
25613 +++ b/arch/x86/kernel/kprobes/core.c
25614 @@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25615 s32 raddr;
25616 } __packed *insn;
25617
25618 - insn = (struct __arch_relative_insn *)from;
25619 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25620 +
25621 + pax_open_kernel();
25622 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25623 insn->op = op;
25624 + pax_close_kernel();
25625 }
25626
25627 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25628 @@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25629 kprobe_opcode_t opcode;
25630 kprobe_opcode_t *orig_opcodes = opcodes;
25631
25632 - if (search_exception_tables((unsigned long)opcodes))
25633 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25634 return 0; /* Page fault may occur on this address. */
25635
25636 retry:
25637 @@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25638 * for the first byte, we can recover the original instruction
25639 * from it and kp->opcode.
25640 */
25641 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25642 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25643 buf[0] = kp->opcode;
25644 - return (unsigned long)buf;
25645 + return ktva_ktla((unsigned long)buf);
25646 }
25647
25648 /*
25649 @@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25650 /* Another subsystem puts a breakpoint, failed to recover */
25651 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25652 return 0;
25653 + pax_open_kernel();
25654 memcpy(dest, insn.kaddr, insn.length);
25655 + pax_close_kernel();
25656
25657 #ifdef CONFIG_X86_64
25658 if (insn_rip_relative(&insn)) {
25659 @@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25660 return 0;
25661 }
25662 disp = (u8 *) dest + insn_offset_displacement(&insn);
25663 + pax_open_kernel();
25664 *(s32 *) disp = (s32) newdisp;
25665 + pax_close_kernel();
25666 }
25667 #endif
25668 return insn.length;
25669 @@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25670 * nor set current_kprobe, because it doesn't use single
25671 * stepping.
25672 */
25673 - regs->ip = (unsigned long)p->ainsn.insn;
25674 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25675 preempt_enable_no_resched();
25676 return;
25677 }
25678 @@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25679 regs->flags &= ~X86_EFLAGS_IF;
25680 /* single step inline if the instruction is an int3 */
25681 if (p->opcode == BREAKPOINT_INSTRUCTION)
25682 - regs->ip = (unsigned long)p->addr;
25683 + regs->ip = ktla_ktva((unsigned long)p->addr);
25684 else
25685 - regs->ip = (unsigned long)p->ainsn.insn;
25686 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25687 }
25688 NOKPROBE_SYMBOL(setup_singlestep);
25689
25690 @@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25691 struct kprobe *p;
25692 struct kprobe_ctlblk *kcb;
25693
25694 - if (user_mode_vm(regs))
25695 + if (user_mode(regs))
25696 return 0;
25697
25698 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25699 @@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25700 setup_singlestep(p, regs, kcb, 0);
25701 return 1;
25702 }
25703 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25704 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25705 /*
25706 * The breakpoint instruction was removed right
25707 * after we hit it. Another cpu has removed
25708 @@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25709 " movq %rax, 152(%rsp)\n"
25710 RESTORE_REGS_STRING
25711 " popfq\n"
25712 +#ifdef KERNEXEC_PLUGIN
25713 + " btsq $63,(%rsp)\n"
25714 +#endif
25715 #else
25716 " pushf\n"
25717 SAVE_REGS_STRING
25718 @@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25719 struct kprobe_ctlblk *kcb)
25720 {
25721 unsigned long *tos = stack_addr(regs);
25722 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25723 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25724 unsigned long orig_ip = (unsigned long)p->addr;
25725 kprobe_opcode_t *insn = p->ainsn.insn;
25726
25727 @@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25728 struct die_args *args = data;
25729 int ret = NOTIFY_DONE;
25730
25731 - if (args->regs && user_mode_vm(args->regs))
25732 + if (args->regs && user_mode(args->regs))
25733 return ret;
25734
25735 if (val == DIE_GPF) {
25736 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25737 index f1314d0..15f3154 100644
25738 --- a/arch/x86/kernel/kprobes/opt.c
25739 +++ b/arch/x86/kernel/kprobes/opt.c
25740 @@ -79,6 +79,7 @@ found:
25741 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25742 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25743 {
25744 + pax_open_kernel();
25745 #ifdef CONFIG_X86_64
25746 *addr++ = 0x48;
25747 *addr++ = 0xbf;
25748 @@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25749 *addr++ = 0xb8;
25750 #endif
25751 *(unsigned long *)addr = val;
25752 + pax_close_kernel();
25753 }
25754
25755 asm (
25756 @@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25757 * Verify if the address gap is in 2GB range, because this uses
25758 * a relative jump.
25759 */
25760 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25761 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25762 if (abs(rel) > 0x7fffffff) {
25763 __arch_remove_optimized_kprobe(op, 0);
25764 return -ERANGE;
25765 @@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25766 op->optinsn.size = ret;
25767
25768 /* Copy arch-dep-instance from template */
25769 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25770 + pax_open_kernel();
25771 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25772 + pax_close_kernel();
25773
25774 /* Set probe information */
25775 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25776
25777 /* Set probe function call */
25778 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25779 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25780
25781 /* Set returning jmp instruction at the tail of out-of-line buffer */
25782 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25783 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25784 (u8 *)op->kp.addr + op->optinsn.size);
25785
25786 flush_icache_range((unsigned long) buf,
25787 @@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25788 WARN_ON(kprobe_disabled(&op->kp));
25789
25790 /* Backup instructions which will be replaced by jump address */
25791 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25792 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25793 RELATIVE_ADDR_SIZE);
25794
25795 insn_buf[0] = RELATIVEJUMP_OPCODE;
25796 @@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25797 /* This kprobe is really able to run optimized path. */
25798 op = container_of(p, struct optimized_kprobe, kp);
25799 /* Detour through copied instructions */
25800 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25801 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25802 if (!reenter)
25803 reset_current_kprobe();
25804 preempt_enable_no_resched();
25805 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25806 index c2bedae..25e7ab60 100644
25807 --- a/arch/x86/kernel/ksysfs.c
25808 +++ b/arch/x86/kernel/ksysfs.c
25809 @@ -184,7 +184,7 @@ out:
25810
25811 static struct kobj_attribute type_attr = __ATTR_RO(type);
25812
25813 -static struct bin_attribute data_attr = {
25814 +static bin_attribute_no_const data_attr __read_only = {
25815 .attr = {
25816 .name = "data",
25817 .mode = S_IRUGO,
25818 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25819 index c37886d..d851d32 100644
25820 --- a/arch/x86/kernel/ldt.c
25821 +++ b/arch/x86/kernel/ldt.c
25822 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25823 if (reload) {
25824 #ifdef CONFIG_SMP
25825 preempt_disable();
25826 - load_LDT(pc);
25827 + load_LDT_nolock(pc);
25828 if (!cpumask_equal(mm_cpumask(current->mm),
25829 cpumask_of(smp_processor_id())))
25830 smp_call_function(flush_ldt, current->mm, 1);
25831 preempt_enable();
25832 #else
25833 - load_LDT(pc);
25834 + load_LDT_nolock(pc);
25835 #endif
25836 }
25837 if (oldsize) {
25838 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25839 return err;
25840
25841 for (i = 0; i < old->size; i++)
25842 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25843 + write_ldt_entry(new->ldt, i, old->ldt + i);
25844 return 0;
25845 }
25846
25847 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25848 retval = copy_ldt(&mm->context, &old_mm->context);
25849 mutex_unlock(&old_mm->context.lock);
25850 }
25851 +
25852 + if (tsk == current) {
25853 + mm->context.vdso = 0;
25854 +
25855 +#ifdef CONFIG_X86_32
25856 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25857 + mm->context.user_cs_base = 0UL;
25858 + mm->context.user_cs_limit = ~0UL;
25859 +
25860 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25861 + cpus_clear(mm->context.cpu_user_cs_mask);
25862 +#endif
25863 +
25864 +#endif
25865 +#endif
25866 +
25867 + }
25868 +
25869 return retval;
25870 }
25871
25872 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25873 }
25874 }
25875
25876 +#ifdef CONFIG_PAX_SEGMEXEC
25877 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25878 + error = -EINVAL;
25879 + goto out_unlock;
25880 + }
25881 +#endif
25882 +
25883 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25884 error = -EINVAL;
25885 goto out_unlock;
25886 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25887 index 72e8e31..f2f1605 100644
25888 --- a/arch/x86/kernel/machine_kexec_32.c
25889 +++ b/arch/x86/kernel/machine_kexec_32.c
25890 @@ -25,7 +25,7 @@
25891 #include <asm/cacheflush.h>
25892 #include <asm/debugreg.h>
25893
25894 -static void set_idt(void *newidt, __u16 limit)
25895 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25896 {
25897 struct desc_ptr curidt;
25898
25899 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25900 }
25901
25902
25903 -static void set_gdt(void *newgdt, __u16 limit)
25904 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25905 {
25906 struct desc_ptr curgdt;
25907
25908 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25909 }
25910
25911 control_page = page_address(image->control_code_page);
25912 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25913 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25914
25915 relocate_kernel_ptr = control_page;
25916 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25917 diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25918 index c73aecf..4c63630 100644
25919 --- a/arch/x86/kernel/mcount_64.S
25920 +++ b/arch/x86/kernel/mcount_64.S
25921 @@ -7,7 +7,7 @@
25922 #include <linux/linkage.h>
25923 #include <asm/ptrace.h>
25924 #include <asm/ftrace.h>
25925 -
25926 +#include <asm/alternative-asm.h>
25927
25928 .code64
25929 .section .entry.text, "ax"
25930 @@ -24,8 +24,9 @@
25931 #ifdef CONFIG_DYNAMIC_FTRACE
25932
25933 ENTRY(function_hook)
25934 + pax_force_retaddr
25935 retq
25936 -END(function_hook)
25937 +ENDPROC(function_hook)
25938
25939 /* skip is set if stack has been adjusted */
25940 .macro ftrace_caller_setup skip=0
25941 @@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25942 #endif
25943
25944 GLOBAL(ftrace_stub)
25945 + pax_force_retaddr
25946 retq
25947 -END(ftrace_caller)
25948 +ENDPROC(ftrace_caller)
25949
25950 ENTRY(ftrace_regs_caller)
25951 /* Save the current flags before compare (in SS location)*/
25952 @@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25953 popfq
25954 jmp ftrace_stub
25955
25956 -END(ftrace_regs_caller)
25957 +ENDPROC(ftrace_regs_caller)
25958
25959
25960 #else /* ! CONFIG_DYNAMIC_FTRACE */
25961 @@ -145,6 +147,7 @@ ENTRY(function_hook)
25962 #endif
25963
25964 GLOBAL(ftrace_stub)
25965 + pax_force_retaddr
25966 retq
25967
25968 trace:
25969 @@ -158,12 +161,13 @@ trace:
25970 #endif
25971 subq $MCOUNT_INSN_SIZE, %rdi
25972
25973 + pax_force_fptr ftrace_trace_function
25974 call *ftrace_trace_function
25975
25976 MCOUNT_RESTORE_FRAME
25977
25978 jmp ftrace_stub
25979 -END(function_hook)
25980 +ENDPROC(function_hook)
25981 #endif /* CONFIG_DYNAMIC_FTRACE */
25982 #endif /* CONFIG_FUNCTION_TRACER */
25983
25984 @@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25985
25986 MCOUNT_RESTORE_FRAME
25987
25988 + pax_force_retaddr
25989 retq
25990 -END(ftrace_graph_caller)
25991 +ENDPROC(ftrace_graph_caller)
25992
25993 GLOBAL(return_to_handler)
25994 subq $24, %rsp
25995 @@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25996 movq 8(%rsp), %rdx
25997 movq (%rsp), %rax
25998 addq $24, %rsp
25999 + pax_force_fptr %rdi
26000 jmp *%rdi
26001 +ENDPROC(return_to_handler)
26002 #endif
26003 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26004 index e69f988..da078ea 100644
26005 --- a/arch/x86/kernel/module.c
26006 +++ b/arch/x86/kernel/module.c
26007 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26008 }
26009 #endif
26010
26011 -void *module_alloc(unsigned long size)
26012 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26013 {
26014 - if (PAGE_ALIGN(size) > MODULES_LEN)
26015 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26016 return NULL;
26017 return __vmalloc_node_range(size, 1,
26018 MODULES_VADDR + get_module_load_offset(),
26019 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26020 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26021 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26022 + prot, NUMA_NO_NODE,
26023 __builtin_return_address(0));
26024 }
26025
26026 +void *module_alloc(unsigned long size)
26027 +{
26028 +
26029 +#ifdef CONFIG_PAX_KERNEXEC
26030 + return __module_alloc(size, PAGE_KERNEL);
26031 +#else
26032 + return __module_alloc(size, PAGE_KERNEL_EXEC);
26033 +#endif
26034 +
26035 +}
26036 +
26037 +#ifdef CONFIG_PAX_KERNEXEC
26038 +#ifdef CONFIG_X86_32
26039 +void *module_alloc_exec(unsigned long size)
26040 +{
26041 + struct vm_struct *area;
26042 +
26043 + if (size == 0)
26044 + return NULL;
26045 +
26046 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26047 +return area ? area->addr : NULL;
26048 +}
26049 +EXPORT_SYMBOL(module_alloc_exec);
26050 +
26051 +void module_free_exec(struct module *mod, void *module_region)
26052 +{
26053 + vunmap(module_region);
26054 +}
26055 +EXPORT_SYMBOL(module_free_exec);
26056 +#else
26057 +void module_free_exec(struct module *mod, void *module_region)
26058 +{
26059 + module_free(mod, module_region);
26060 +}
26061 +EXPORT_SYMBOL(module_free_exec);
26062 +
26063 +void *module_alloc_exec(unsigned long size)
26064 +{
26065 + return __module_alloc(size, PAGE_KERNEL_RX);
26066 +}
26067 +EXPORT_SYMBOL(module_alloc_exec);
26068 +#endif
26069 +#endif
26070 +
26071 #ifdef CONFIG_X86_32
26072 int apply_relocate(Elf32_Shdr *sechdrs,
26073 const char *strtab,
26074 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26075 unsigned int i;
26076 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26077 Elf32_Sym *sym;
26078 - uint32_t *location;
26079 + uint32_t *plocation, location;
26080
26081 DEBUGP("Applying relocate section %u to %u\n",
26082 relsec, sechdrs[relsec].sh_info);
26083 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26084 /* This is where to make the change */
26085 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26086 - + rel[i].r_offset;
26087 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26088 + location = (uint32_t)plocation;
26089 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26090 + plocation = ktla_ktva((void *)plocation);
26091 /* This is the symbol it is referring to. Note that all
26092 undefined symbols have been resolved. */
26093 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26094 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26095 switch (ELF32_R_TYPE(rel[i].r_info)) {
26096 case R_386_32:
26097 /* We add the value into the location given */
26098 - *location += sym->st_value;
26099 + pax_open_kernel();
26100 + *plocation += sym->st_value;
26101 + pax_close_kernel();
26102 break;
26103 case R_386_PC32:
26104 /* Add the value, subtract its position */
26105 - *location += sym->st_value - (uint32_t)location;
26106 + pax_open_kernel();
26107 + *plocation += sym->st_value - location;
26108 + pax_close_kernel();
26109 break;
26110 default:
26111 pr_err("%s: Unknown relocation: %u\n",
26112 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26113 case R_X86_64_NONE:
26114 break;
26115 case R_X86_64_64:
26116 + pax_open_kernel();
26117 *(u64 *)loc = val;
26118 + pax_close_kernel();
26119 break;
26120 case R_X86_64_32:
26121 + pax_open_kernel();
26122 *(u32 *)loc = val;
26123 + pax_close_kernel();
26124 if (val != *(u32 *)loc)
26125 goto overflow;
26126 break;
26127 case R_X86_64_32S:
26128 + pax_open_kernel();
26129 *(s32 *)loc = val;
26130 + pax_close_kernel();
26131 if ((s64)val != *(s32 *)loc)
26132 goto overflow;
26133 break;
26134 case R_X86_64_PC32:
26135 val -= (u64)loc;
26136 + pax_open_kernel();
26137 *(u32 *)loc = val;
26138 + pax_close_kernel();
26139 +
26140 #if 0
26141 if ((s64)val != *(s32 *)loc)
26142 goto overflow;
26143 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26144 index c9603ac..9f88728 100644
26145 --- a/arch/x86/kernel/msr.c
26146 +++ b/arch/x86/kernel/msr.c
26147 @@ -37,6 +37,7 @@
26148 #include <linux/notifier.h>
26149 #include <linux/uaccess.h>
26150 #include <linux/gfp.h>
26151 +#include <linux/grsecurity.h>
26152
26153 #include <asm/processor.h>
26154 #include <asm/msr.h>
26155 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26156 int err = 0;
26157 ssize_t bytes = 0;
26158
26159 +#ifdef CONFIG_GRKERNSEC_KMEM
26160 + gr_handle_msr_write();
26161 + return -EPERM;
26162 +#endif
26163 +
26164 if (count % 8)
26165 return -EINVAL; /* Invalid chunk size */
26166
26167 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26168 err = -EBADF;
26169 break;
26170 }
26171 +#ifdef CONFIG_GRKERNSEC_KMEM
26172 + gr_handle_msr_write();
26173 + return -EPERM;
26174 +#endif
26175 if (copy_from_user(&regs, uregs, sizeof regs)) {
26176 err = -EFAULT;
26177 break;
26178 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26179 return notifier_from_errno(err);
26180 }
26181
26182 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26183 +static struct notifier_block msr_class_cpu_notifier = {
26184 .notifier_call = msr_class_cpu_callback,
26185 };
26186
26187 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26188 index c3e985d..110a36a 100644
26189 --- a/arch/x86/kernel/nmi.c
26190 +++ b/arch/x86/kernel/nmi.c
26191 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26192
26193 static void nmi_max_handler(struct irq_work *w)
26194 {
26195 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26196 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26197 int remainder_ns, decimal_msecs;
26198 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26199 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26200
26201 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26202 decimal_msecs = remainder_ns / 1000;
26203
26204 printk_ratelimited(KERN_INFO
26205 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26206 - a->handler, whole_msecs, decimal_msecs);
26207 + n->action->handler, whole_msecs, decimal_msecs);
26208 }
26209
26210 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26211 @@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26212 delta = sched_clock() - delta;
26213 trace_nmi_handler(a->handler, (int)delta, thishandled);
26214
26215 - if (delta < nmi_longest_ns || delta < a->max_duration)
26216 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
26217 continue;
26218
26219 - a->max_duration = delta;
26220 - irq_work_queue(&a->irq_work);
26221 + a->work->max_duration = delta;
26222 + irq_work_queue(&a->work->irq_work);
26223 }
26224
26225 rcu_read_unlock();
26226 @@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26227 }
26228 NOKPROBE_SYMBOL(nmi_handle);
26229
26230 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26231 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26232 {
26233 struct nmi_desc *desc = nmi_to_desc(type);
26234 unsigned long flags;
26235 @@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26236 if (!action->handler)
26237 return -EINVAL;
26238
26239 - init_irq_work(&action->irq_work, nmi_max_handler);
26240 + action->work->action = action;
26241 + init_irq_work(&action->work->irq_work, nmi_max_handler);
26242
26243 spin_lock_irqsave(&desc->lock, flags);
26244
26245 @@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26246 * event confuses some handlers (kdump uses this flag)
26247 */
26248 if (action->flags & NMI_FLAG_FIRST)
26249 - list_add_rcu(&action->list, &desc->head);
26250 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26251 else
26252 - list_add_tail_rcu(&action->list, &desc->head);
26253 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26254
26255 spin_unlock_irqrestore(&desc->lock, flags);
26256 return 0;
26257 @@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26258 if (!strcmp(n->name, name)) {
26259 WARN(in_nmi(),
26260 "Trying to free NMI (%s) from NMI context!\n", n->name);
26261 - list_del_rcu(&n->list);
26262 + pax_list_del_rcu((struct list_head *)&n->list);
26263 break;
26264 }
26265 }
26266 @@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26267 dotraplinkage notrace void
26268 do_nmi(struct pt_regs *regs, long error_code)
26269 {
26270 +
26271 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26272 + if (!user_mode(regs)) {
26273 + unsigned long cs = regs->cs & 0xFFFF;
26274 + unsigned long ip = ktva_ktla(regs->ip);
26275 +
26276 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26277 + regs->ip = ip;
26278 + }
26279 +#endif
26280 +
26281 nmi_nesting_preprocess(regs);
26282
26283 nmi_enter();
26284 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26285 index 6d9582e..f746287 100644
26286 --- a/arch/x86/kernel/nmi_selftest.c
26287 +++ b/arch/x86/kernel/nmi_selftest.c
26288 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26289 {
26290 /* trap all the unknown NMIs we may generate */
26291 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26292 - __initdata);
26293 + __initconst);
26294 }
26295
26296 static void __init cleanup_nmi_testsuite(void)
26297 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26298 unsigned long timeout;
26299
26300 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26301 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26302 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26303 nmi_fail = FAILURE;
26304 return;
26305 }
26306 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26307 index bbb6c73..24a58ef 100644
26308 --- a/arch/x86/kernel/paravirt-spinlocks.c
26309 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26310 @@ -8,7 +8,7 @@
26311
26312 #include <asm/paravirt.h>
26313
26314 -struct pv_lock_ops pv_lock_ops = {
26315 +struct pv_lock_ops pv_lock_ops __read_only = {
26316 #ifdef CONFIG_SMP
26317 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26318 .unlock_kick = paravirt_nop,
26319 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26320 index 548d25f..f8fb99c 100644
26321 --- a/arch/x86/kernel/paravirt.c
26322 +++ b/arch/x86/kernel/paravirt.c
26323 @@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26324 {
26325 return x;
26326 }
26327 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26328 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26329 +#endif
26330
26331 void __init default_banner(void)
26332 {
26333 @@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26334
26335 if (opfunc == NULL)
26336 /* If there's no function, patch it with a ud2a (BUG) */
26337 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26338 - else if (opfunc == _paravirt_nop)
26339 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26340 + else if (opfunc == (void *)_paravirt_nop)
26341 /* If the operation is a nop, then nop the callsite */
26342 ret = paravirt_patch_nop();
26343
26344 /* identity functions just return their single argument */
26345 - else if (opfunc == _paravirt_ident_32)
26346 + else if (opfunc == (void *)_paravirt_ident_32)
26347 ret = paravirt_patch_ident_32(insnbuf, len);
26348 - else if (opfunc == _paravirt_ident_64)
26349 + else if (opfunc == (void *)_paravirt_ident_64)
26350 ret = paravirt_patch_ident_64(insnbuf, len);
26351 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26352 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26353 + ret = paravirt_patch_ident_64(insnbuf, len);
26354 +#endif
26355
26356 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26357 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26358 @@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26359 if (insn_len > len || start == NULL)
26360 insn_len = len;
26361 else
26362 - memcpy(insnbuf, start, insn_len);
26363 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26364
26365 return insn_len;
26366 }
26367 @@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26368 return this_cpu_read(paravirt_lazy_mode);
26369 }
26370
26371 -struct pv_info pv_info = {
26372 +struct pv_info pv_info __read_only = {
26373 .name = "bare hardware",
26374 .paravirt_enabled = 0,
26375 .kernel_rpl = 0,
26376 @@ -311,16 +318,16 @@ struct pv_info pv_info = {
26377 #endif
26378 };
26379
26380 -struct pv_init_ops pv_init_ops = {
26381 +struct pv_init_ops pv_init_ops __read_only = {
26382 .patch = native_patch,
26383 };
26384
26385 -struct pv_time_ops pv_time_ops = {
26386 +struct pv_time_ops pv_time_ops __read_only = {
26387 .sched_clock = native_sched_clock,
26388 .steal_clock = native_steal_clock,
26389 };
26390
26391 -__visible struct pv_irq_ops pv_irq_ops = {
26392 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26393 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26394 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26395 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26396 @@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26397 #endif
26398 };
26399
26400 -__visible struct pv_cpu_ops pv_cpu_ops = {
26401 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26402 .cpuid = native_cpuid,
26403 .get_debugreg = native_get_debugreg,
26404 .set_debugreg = native_set_debugreg,
26405 @@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26406 NOKPROBE_SYMBOL(native_set_debugreg);
26407 NOKPROBE_SYMBOL(native_load_idt);
26408
26409 -struct pv_apic_ops pv_apic_ops = {
26410 +struct pv_apic_ops pv_apic_ops __read_only= {
26411 #ifdef CONFIG_X86_LOCAL_APIC
26412 .startup_ipi_hook = paravirt_nop,
26413 #endif
26414 };
26415
26416 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26417 +#ifdef CONFIG_X86_32
26418 +#ifdef CONFIG_X86_PAE
26419 +/* 64-bit pagetable entries */
26420 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26421 +#else
26422 /* 32-bit pagetable entries */
26423 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26424 +#endif
26425 #else
26426 /* 64-bit pagetable entries */
26427 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26428 #endif
26429
26430 -struct pv_mmu_ops pv_mmu_ops = {
26431 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26432
26433 .read_cr2 = native_read_cr2,
26434 .write_cr2 = native_write_cr2,
26435 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26436 .make_pud = PTE_IDENT,
26437
26438 .set_pgd = native_set_pgd,
26439 + .set_pgd_batched = native_set_pgd_batched,
26440 #endif
26441 #endif /* PAGETABLE_LEVELS >= 3 */
26442
26443 @@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26444 },
26445
26446 .set_fixmap = native_set_fixmap,
26447 +
26448 +#ifdef CONFIG_PAX_KERNEXEC
26449 + .pax_open_kernel = native_pax_open_kernel,
26450 + .pax_close_kernel = native_pax_close_kernel,
26451 +#endif
26452 +
26453 };
26454
26455 EXPORT_SYMBOL_GPL(pv_time_ops);
26456 diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26457 index a1da673..b6f5831 100644
26458 --- a/arch/x86/kernel/paravirt_patch_64.c
26459 +++ b/arch/x86/kernel/paravirt_patch_64.c
26460 @@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26461 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26462 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26463 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26464 +
26465 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26466 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26467 +#endif
26468 +
26469 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26470 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26471
26472 @@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26473 PATCH_SITE(pv_mmu_ops, read_cr3);
26474 PATCH_SITE(pv_mmu_ops, write_cr3);
26475 PATCH_SITE(pv_cpu_ops, clts);
26476 +
26477 +#ifndef CONFIG_PAX_MEMORY_UDEREF
26478 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26479 +#endif
26480 +
26481 PATCH_SITE(pv_cpu_ops, wbinvd);
26482
26483 patch_site:
26484 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26485 index 0497f71..7186c0d 100644
26486 --- a/arch/x86/kernel/pci-calgary_64.c
26487 +++ b/arch/x86/kernel/pci-calgary_64.c
26488 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26489 tce_space = be64_to_cpu(readq(target));
26490 tce_space = tce_space & TAR_SW_BITS;
26491
26492 - tce_space = tce_space & (~specified_table_size);
26493 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26494 info->tce_space = (u64 *)__va(tce_space);
26495 }
26496 }
26497 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26498 index 35ccf75..7a15747 100644
26499 --- a/arch/x86/kernel/pci-iommu_table.c
26500 +++ b/arch/x86/kernel/pci-iommu_table.c
26501 @@ -2,7 +2,7 @@
26502 #include <asm/iommu_table.h>
26503 #include <linux/string.h>
26504 #include <linux/kallsyms.h>
26505 -
26506 +#include <linux/sched.h>
26507
26508 #define DEBUG 1
26509
26510 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26511 index 77dd0ad..9ec4723 100644
26512 --- a/arch/x86/kernel/pci-swiotlb.c
26513 +++ b/arch/x86/kernel/pci-swiotlb.c
26514 @@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26515 struct dma_attrs *attrs)
26516 {
26517 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26518 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26519 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26520 else
26521 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26522 }
26523 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26524 index e127dda..94e384d 100644
26525 --- a/arch/x86/kernel/process.c
26526 +++ b/arch/x86/kernel/process.c
26527 @@ -36,7 +36,8 @@
26528 * section. Since TSS's are completely CPU-local, we want them
26529 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26530 */
26531 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26532 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26533 +EXPORT_SYMBOL(init_tss);
26534
26535 #ifdef CONFIG_X86_64
26536 static DEFINE_PER_CPU(unsigned char, is_idle);
26537 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26538 task_xstate_cachep =
26539 kmem_cache_create("task_xstate", xstate_size,
26540 __alignof__(union thread_xstate),
26541 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26542 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26543 setup_xstate_comp();
26544 }
26545
26546 @@ -108,7 +109,7 @@ void exit_thread(void)
26547 unsigned long *bp = t->io_bitmap_ptr;
26548
26549 if (bp) {
26550 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26551 + struct tss_struct *tss = init_tss + get_cpu();
26552
26553 t->io_bitmap_ptr = NULL;
26554 clear_thread_flag(TIF_IO_BITMAP);
26555 @@ -128,6 +129,9 @@ void flush_thread(void)
26556 {
26557 struct task_struct *tsk = current;
26558
26559 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26560 + loadsegment(gs, 0);
26561 +#endif
26562 flush_ptrace_hw_breakpoint(tsk);
26563 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26564 drop_init_fpu(tsk);
26565 @@ -274,7 +278,7 @@ static void __exit_idle(void)
26566 void exit_idle(void)
26567 {
26568 /* idle loop has pid 0 */
26569 - if (current->pid)
26570 + if (task_pid_nr(current))
26571 return;
26572 __exit_idle();
26573 }
26574 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26575 return ret;
26576 }
26577 #endif
26578 -void stop_this_cpu(void *dummy)
26579 +__noreturn void stop_this_cpu(void *dummy)
26580 {
26581 local_irq_disable();
26582 /*
26583 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26584 }
26585 early_param("idle", idle_setup);
26586
26587 -unsigned long arch_align_stack(unsigned long sp)
26588 +#ifdef CONFIG_PAX_RANDKSTACK
26589 +void pax_randomize_kstack(struct pt_regs *regs)
26590 {
26591 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26592 - sp -= get_random_int() % 8192;
26593 - return sp & ~0xf;
26594 -}
26595 + struct thread_struct *thread = &current->thread;
26596 + unsigned long time;
26597
26598 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26599 -{
26600 - unsigned long range_end = mm->brk + 0x02000000;
26601 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26602 -}
26603 + if (!randomize_va_space)
26604 + return;
26605 +
26606 + if (v8086_mode(regs))
26607 + return;
26608
26609 + rdtscl(time);
26610 +
26611 + /* P4 seems to return a 0 LSB, ignore it */
26612 +#ifdef CONFIG_MPENTIUM4
26613 + time &= 0x3EUL;
26614 + time <<= 2;
26615 +#elif defined(CONFIG_X86_64)
26616 + time &= 0xFUL;
26617 + time <<= 4;
26618 +#else
26619 + time &= 0x1FUL;
26620 + time <<= 3;
26621 +#endif
26622 +
26623 + thread->sp0 ^= time;
26624 + load_sp0(init_tss + smp_processor_id(), thread);
26625 +
26626 +#ifdef CONFIG_X86_64
26627 + this_cpu_write(kernel_stack, thread->sp0);
26628 +#endif
26629 +}
26630 +#endif
26631 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26632 index 8f3ebfe..cbc731b 100644
26633 --- a/arch/x86/kernel/process_32.c
26634 +++ b/arch/x86/kernel/process_32.c
26635 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26636 unsigned long thread_saved_pc(struct task_struct *tsk)
26637 {
26638 return ((unsigned long *)tsk->thread.sp)[3];
26639 +//XXX return tsk->thread.eip;
26640 }
26641
26642 void __show_regs(struct pt_regs *regs, int all)
26643 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26644 unsigned long sp;
26645 unsigned short ss, gs;
26646
26647 - if (user_mode_vm(regs)) {
26648 + if (user_mode(regs)) {
26649 sp = regs->sp;
26650 ss = regs->ss & 0xffff;
26651 - gs = get_user_gs(regs);
26652 } else {
26653 sp = kernel_stack_pointer(regs);
26654 savesegment(ss, ss);
26655 - savesegment(gs, gs);
26656 }
26657 + gs = get_user_gs(regs);
26658
26659 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26660 (u16)regs->cs, regs->ip, regs->flags,
26661 - smp_processor_id());
26662 + raw_smp_processor_id());
26663 print_symbol("EIP is at %s\n", regs->ip);
26664
26665 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26666 @@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26667 int copy_thread(unsigned long clone_flags, unsigned long sp,
26668 unsigned long arg, struct task_struct *p)
26669 {
26670 - struct pt_regs *childregs = task_pt_regs(p);
26671 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26672 struct task_struct *tsk;
26673 int err;
26674
26675 p->thread.sp = (unsigned long) childregs;
26676 p->thread.sp0 = (unsigned long) (childregs+1);
26677 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26678 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26679
26680 if (unlikely(p->flags & PF_KTHREAD)) {
26681 /* kernel thread */
26682 memset(childregs, 0, sizeof(struct pt_regs));
26683 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26684 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26685 - childregs->ds = __USER_DS;
26686 - childregs->es = __USER_DS;
26687 + savesegment(gs, childregs->gs);
26688 + childregs->ds = __KERNEL_DS;
26689 + childregs->es = __KERNEL_DS;
26690 childregs->fs = __KERNEL_PERCPU;
26691 childregs->bx = sp; /* function */
26692 childregs->bp = arg;
26693 @@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26694 struct thread_struct *prev = &prev_p->thread,
26695 *next = &next_p->thread;
26696 int cpu = smp_processor_id();
26697 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26698 + struct tss_struct *tss = init_tss + cpu;
26699 fpu_switch_t fpu;
26700
26701 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26702 @@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26703 */
26704 lazy_save_gs(prev->gs);
26705
26706 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26707 + __set_fs(task_thread_info(next_p)->addr_limit);
26708 +#endif
26709 +
26710 /*
26711 * Load the per-thread Thread-Local Storage descriptor.
26712 */
26713 @@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26714 */
26715 arch_end_context_switch(next_p);
26716
26717 - this_cpu_write(kernel_stack,
26718 - (unsigned long)task_stack_page(next_p) +
26719 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26720 + this_cpu_write(current_task, next_p);
26721 + this_cpu_write(current_tinfo, &next_p->tinfo);
26722 + this_cpu_write(kernel_stack, next->sp0);
26723
26724 /*
26725 * Restore %gs if needed (which is common)
26726 @@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26727
26728 switch_fpu_finish(next_p, fpu);
26729
26730 - this_cpu_write(current_task, next_p);
26731 -
26732 return prev_p;
26733 }
26734
26735 @@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26736 } while (count++ < 16);
26737 return 0;
26738 }
26739 -
26740 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26741 index 5a2c029..ec8611d 100644
26742 --- a/arch/x86/kernel/process_64.c
26743 +++ b/arch/x86/kernel/process_64.c
26744 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26745 struct pt_regs *childregs;
26746 struct task_struct *me = current;
26747
26748 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26749 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26750 childregs = task_pt_regs(p);
26751 p->thread.sp = (unsigned long) childregs;
26752 p->thread.usersp = me->thread.usersp;
26753 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p) + 2 * sizeof(unsigned long);
26754 set_tsk_thread_flag(p, TIF_FORK);
26755 p->thread.io_bitmap_ptr = NULL;
26756
26757 @@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26758 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26759 savesegment(es, p->thread.es);
26760 savesegment(ds, p->thread.ds);
26761 + savesegment(ss, p->thread.ss);
26762 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26763 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26764
26765 if (unlikely(p->flags & PF_KTHREAD)) {
26766 @@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26767 struct thread_struct *prev = &prev_p->thread;
26768 struct thread_struct *next = &next_p->thread;
26769 int cpu = smp_processor_id();
26770 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26771 + struct tss_struct *tss = init_tss + cpu;
26772 unsigned fsindex, gsindex;
26773 fpu_switch_t fpu;
26774
26775 @@ -331,6 +334,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26776 if (unlikely(next->ds | prev->ds))
26777 loadsegment(ds, next->ds);
26778
26779 + savesegment(ss, prev->ss);
26780 + if (unlikely(next->ss != prev->ss))
26781 + loadsegment(ss, next->ss);
26782 +
26783 /*
26784 * Switch FS and GS.
26785 *
26786 @@ -404,6 +411,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26787 prev->usersp = this_cpu_read(old_rsp);
26788 this_cpu_write(old_rsp, next->usersp);
26789 this_cpu_write(current_task, next_p);
26790 + this_cpu_write(current_tinfo, &next_p->tinfo);
26791
26792 /*
26793 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26794 @@ -413,9 +421,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26795 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26796 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26797
26798 - this_cpu_write(kernel_stack,
26799 - (unsigned long)task_stack_page(next_p) +
26800 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26801 + this_cpu_write(kernel_stack, next->sp0);
26802
26803 /*
26804 * Now maybe reload the debug registers and handle I/O bitmaps
26805 @@ -485,12 +491,11 @@ unsigned long get_wchan(struct task_struct *p)
26806 if (!p || p == current || p->state == TASK_RUNNING)
26807 return 0;
26808 stack = (unsigned long)task_stack_page(p);
26809 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26810 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26811 return 0;
26812 fp = *(u64 *)(p->thread.sp);
26813 do {
26814 - if (fp < (unsigned long)stack ||
26815 - fp >= (unsigned long)stack+THREAD_SIZE)
26816 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26817 return 0;
26818 ip = *(u64 *)(fp+8);
26819 if (!in_sched_functions(ip))
26820 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26821 index e510618..5165ac0 100644
26822 --- a/arch/x86/kernel/ptrace.c
26823 +++ b/arch/x86/kernel/ptrace.c
26824 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26825 unsigned long sp = (unsigned long)&regs->sp;
26826 u32 *prev_esp;
26827
26828 - if (context == (sp & ~(THREAD_SIZE - 1)))
26829 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26830 return sp;
26831
26832 - prev_esp = (u32 *)(context);
26833 + prev_esp = *(u32 **)(context);
26834 if (prev_esp)
26835 return (unsigned long)prev_esp;
26836
26837 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26838 if (child->thread.gs != value)
26839 return do_arch_prctl(child, ARCH_SET_GS, value);
26840 return 0;
26841 +
26842 + case offsetof(struct user_regs_struct,ip):
26843 + /*
26844 + * Protect against any attempt to set ip to an
26845 + * impossible address. There are dragons lurking if the
26846 + * address is noncanonical. (This explicitly allows
26847 + * setting ip to TASK_SIZE_MAX, because user code can do
26848 + * that all by itself by running off the end of its
26849 + * address space.
26850 + */
26851 + if (value > TASK_SIZE_MAX)
26852 + return -EIO;
26853 + break;
26854 +
26855 #endif
26856 }
26857
26858 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26859 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26860 {
26861 int i;
26862 - int dr7 = 0;
26863 + unsigned long dr7 = 0;
26864 struct arch_hw_breakpoint *info;
26865
26866 for (i = 0; i < HBP_NUM; i++) {
26867 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26868 unsigned long addr, unsigned long data)
26869 {
26870 int ret;
26871 - unsigned long __user *datap = (unsigned long __user *)data;
26872 + unsigned long __user *datap = (__force unsigned long __user *)data;
26873
26874 switch (request) {
26875 /* read the word at location addr in the USER area. */
26876 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26877 if ((int) addr < 0)
26878 return -EIO;
26879 ret = do_get_thread_area(child, addr,
26880 - (struct user_desc __user *)data);
26881 + (__force struct user_desc __user *) data);
26882 break;
26883
26884 case PTRACE_SET_THREAD_AREA:
26885 if ((int) addr < 0)
26886 return -EIO;
26887 ret = do_set_thread_area(child, addr,
26888 - (struct user_desc __user *)data, 0);
26889 + (__force struct user_desc __user *) data, 0);
26890 break;
26891 #endif
26892
26893 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26894
26895 #ifdef CONFIG_X86_64
26896
26897 -static struct user_regset x86_64_regsets[] __read_mostly = {
26898 +static user_regset_no_const x86_64_regsets[] __read_only = {
26899 [REGSET_GENERAL] = {
26900 .core_note_type = NT_PRSTATUS,
26901 .n = sizeof(struct user_regs_struct) / sizeof(long),
26902 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26903 #endif /* CONFIG_X86_64 */
26904
26905 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26906 -static struct user_regset x86_32_regsets[] __read_mostly = {
26907 +static user_regset_no_const x86_32_regsets[] __read_only = {
26908 [REGSET_GENERAL] = {
26909 .core_note_type = NT_PRSTATUS,
26910 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26911 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26912 */
26913 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26914
26915 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26916 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26917 {
26918 #ifdef CONFIG_X86_64
26919 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26920 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26921 memset(info, 0, sizeof(*info));
26922 info->si_signo = SIGTRAP;
26923 info->si_code = si_code;
26924 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26925 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26926 }
26927
26928 void user_single_step_siginfo(struct task_struct *tsk,
26929 @@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26930 }
26931 }
26932
26933 +#ifdef CONFIG_GRKERNSEC_SETXID
26934 +extern void gr_delayed_cred_worker(void);
26935 +#endif
26936 +
26937 /*
26938 * We can return 0 to resume the syscall or anything else to go to phase
26939 * 2. If we resume the syscall, we need to put something appropriate in
26940 @@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26941
26942 BUG_ON(regs != task_pt_regs(current));
26943
26944 +#ifdef CONFIG_GRKERNSEC_SETXID
26945 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26946 + gr_delayed_cred_worker();
26947 +#endif
26948 +
26949 /*
26950 * If we stepped into a sysenter/syscall insn, it trapped in
26951 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26952 @@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26953 */
26954 user_exit();
26955
26956 +#ifdef CONFIG_GRKERNSEC_SETXID
26957 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26958 + gr_delayed_cred_worker();
26959 +#endif
26960 +
26961 audit_syscall_exit(regs);
26962
26963 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26964 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26965 index 2f355d2..e75ed0a 100644
26966 --- a/arch/x86/kernel/pvclock.c
26967 +++ b/arch/x86/kernel/pvclock.c
26968 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26969 reset_hung_task_detector();
26970 }
26971
26972 -static atomic64_t last_value = ATOMIC64_INIT(0);
26973 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26974
26975 void pvclock_resume(void)
26976 {
26977 - atomic64_set(&last_value, 0);
26978 + atomic64_set_unchecked(&last_value, 0);
26979 }
26980
26981 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26982 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26983 * updating at the same time, and one of them could be slightly behind,
26984 * making the assumption that last_value always go forward fail to hold.
26985 */
26986 - last = atomic64_read(&last_value);
26987 + last = atomic64_read_unchecked(&last_value);
26988 do {
26989 if (ret < last)
26990 return last;
26991 - last = atomic64_cmpxchg(&last_value, last, ret);
26992 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26993 } while (unlikely(last != ret));
26994
26995 return ret;
26996 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26997 index 17962e6..47f55db 100644
26998 --- a/arch/x86/kernel/reboot.c
26999 +++ b/arch/x86/kernel/reboot.c
27000 @@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27001
27002 void __noreturn machine_real_restart(unsigned int type)
27003 {
27004 +
27005 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27006 + struct desc_struct *gdt;
27007 +#endif
27008 +
27009 local_irq_disable();
27010
27011 /*
27012 @@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27013
27014 /* Jump to the identity-mapped low memory code */
27015 #ifdef CONFIG_X86_32
27016 - asm volatile("jmpl *%0" : :
27017 +
27018 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27019 + gdt = get_cpu_gdt_table(smp_processor_id());
27020 + pax_open_kernel();
27021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27022 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27023 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27024 + loadsegment(ds, __KERNEL_DS);
27025 + loadsegment(es, __KERNEL_DS);
27026 + loadsegment(ss, __KERNEL_DS);
27027 +#endif
27028 +#ifdef CONFIG_PAX_KERNEXEC
27029 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27030 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27031 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27032 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27033 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27034 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27035 +#endif
27036 + pax_close_kernel();
27037 +#endif
27038 +
27039 + asm volatile("ljmpl *%0" : :
27040 "rm" (real_mode_header->machine_real_restart_asm),
27041 "a" (type));
27042 #else
27043 @@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27044 * This means that this function can never return, it can misbehave
27045 * by not rebooting properly and hanging.
27046 */
27047 -static void native_machine_emergency_restart(void)
27048 +static void __noreturn native_machine_emergency_restart(void)
27049 {
27050 int i;
27051 int attempt = 0;
27052 @@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27053 #endif
27054 }
27055
27056 -static void __machine_emergency_restart(int emergency)
27057 +static void __noreturn __machine_emergency_restart(int emergency)
27058 {
27059 reboot_emergency = emergency;
27060 machine_ops.emergency_restart();
27061 }
27062
27063 -static void native_machine_restart(char *__unused)
27064 +static void __noreturn native_machine_restart(char *__unused)
27065 {
27066 pr_notice("machine restart\n");
27067
27068 @@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27069 __machine_emergency_restart(0);
27070 }
27071
27072 -static void native_machine_halt(void)
27073 +static void __noreturn native_machine_halt(void)
27074 {
27075 /* Stop other cpus and apics */
27076 machine_shutdown();
27077 @@ -645,7 +672,7 @@ static void native_machine_halt(void)
27078 stop_this_cpu(NULL);
27079 }
27080
27081 -static void native_machine_power_off(void)
27082 +static void __noreturn native_machine_power_off(void)
27083 {
27084 if (pm_power_off) {
27085 if (!reboot_force)
27086 @@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27087 }
27088 /* A fallback in case there is no PM info available */
27089 tboot_shutdown(TB_SHUTDOWN_HALT);
27090 + unreachable();
27091 }
27092
27093 -struct machine_ops machine_ops = {
27094 +struct machine_ops machine_ops __read_only = {
27095 .power_off = native_machine_power_off,
27096 .shutdown = native_machine_shutdown,
27097 .emergency_restart = native_machine_emergency_restart,
27098 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27099 index c8e41e9..64049ef 100644
27100 --- a/arch/x86/kernel/reboot_fixups_32.c
27101 +++ b/arch/x86/kernel/reboot_fixups_32.c
27102 @@ -57,7 +57,7 @@ struct device_fixup {
27103 unsigned int vendor;
27104 unsigned int device;
27105 void (*reboot_fixup)(struct pci_dev *);
27106 -};
27107 +} __do_const;
27108
27109 /*
27110 * PCI ids solely used for fixups_table go here
27111 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27112 index 3fd2c69..a444264 100644
27113 --- a/arch/x86/kernel/relocate_kernel_64.S
27114 +++ b/arch/x86/kernel/relocate_kernel_64.S
27115 @@ -96,8 +96,7 @@ relocate_kernel:
27116
27117 /* jump to identity mapped page */
27118 addq $(identity_mapped - relocate_kernel), %r8
27119 - pushq %r8
27120 - ret
27121 + jmp *%r8
27122
27123 identity_mapped:
27124 /* set return address to 0 if not preserving context */
27125 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27126 index ab08aa2..6d74a3a 100644
27127 --- a/arch/x86/kernel/setup.c
27128 +++ b/arch/x86/kernel/setup.c
27129 @@ -110,6 +110,7 @@
27130 #include <asm/mce.h>
27131 #include <asm/alternative.h>
27132 #include <asm/prom.h>
27133 +#include <asm/boot.h>
27134
27135 /*
27136 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27137 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27138 #endif
27139
27140
27141 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27142 -__visible unsigned long mmu_cr4_features;
27143 +#ifdef CONFIG_X86_64
27144 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27145 +#elif defined(CONFIG_X86_PAE)
27146 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27147 #else
27148 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27149 +__visible unsigned long mmu_cr4_features __read_only;
27150 #endif
27151
27152 +void set_in_cr4(unsigned long mask)
27153 +{
27154 + unsigned long cr4 = read_cr4();
27155 +
27156 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27157 + return;
27158 +
27159 + pax_open_kernel();
27160 + mmu_cr4_features |= mask;
27161 + pax_close_kernel();
27162 +
27163 + if (trampoline_cr4_features)
27164 + *trampoline_cr4_features = mmu_cr4_features;
27165 + cr4 |= mask;
27166 + write_cr4(cr4);
27167 +}
27168 +EXPORT_SYMBOL(set_in_cr4);
27169 +
27170 +void clear_in_cr4(unsigned long mask)
27171 +{
27172 + unsigned long cr4 = read_cr4();
27173 +
27174 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27175 + return;
27176 +
27177 + pax_open_kernel();
27178 + mmu_cr4_features &= ~mask;
27179 + pax_close_kernel();
27180 +
27181 + if (trampoline_cr4_features)
27182 + *trampoline_cr4_features = mmu_cr4_features;
27183 + cr4 &= ~mask;
27184 + write_cr4(cr4);
27185 +}
27186 +EXPORT_SYMBOL(clear_in_cr4);
27187 +
27188 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27189 int bootloader_type, bootloader_version;
27190
27191 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27192 * area (640->1Mb) as ram even though it is not.
27193 * take them out.
27194 */
27195 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27196 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27197
27198 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27199 }
27200 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27201 /* called before trim_bios_range() to spare extra sanitize */
27202 static void __init e820_add_kernel_range(void)
27203 {
27204 - u64 start = __pa_symbol(_text);
27205 + u64 start = __pa_symbol(ktla_ktva(_text));
27206 u64 size = __pa_symbol(_end) - start;
27207
27208 /*
27209 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27210
27211 void __init setup_arch(char **cmdline_p)
27212 {
27213 +#ifdef CONFIG_X86_32
27214 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27215 +#else
27216 memblock_reserve(__pa_symbol(_text),
27217 (unsigned long)__bss_stop - (unsigned long)_text);
27218 +#endif
27219
27220 early_reserve_initrd();
27221
27222 @@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27223
27224 if (!boot_params.hdr.root_flags)
27225 root_mountflags &= ~MS_RDONLY;
27226 - init_mm.start_code = (unsigned long) _text;
27227 - init_mm.end_code = (unsigned long) _etext;
27228 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27229 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27230 init_mm.end_data = (unsigned long) _edata;
27231 init_mm.brk = _brk_end;
27232
27233 - code_resource.start = __pa_symbol(_text);
27234 - code_resource.end = __pa_symbol(_etext)-1;
27235 - data_resource.start = __pa_symbol(_etext);
27236 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27237 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27238 + data_resource.start = __pa_symbol(_sdata);
27239 data_resource.end = __pa_symbol(_edata)-1;
27240 bss_resource.start = __pa_symbol(__bss_start);
27241 bss_resource.end = __pa_symbol(__bss_stop)-1;
27242 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27243 index 5cdff03..80fa283 100644
27244 --- a/arch/x86/kernel/setup_percpu.c
27245 +++ b/arch/x86/kernel/setup_percpu.c
27246 @@ -21,19 +21,17 @@
27247 #include <asm/cpu.h>
27248 #include <asm/stackprotector.h>
27249
27250 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27251 +#ifdef CONFIG_SMP
27252 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27253 EXPORT_PER_CPU_SYMBOL(cpu_number);
27254 +#endif
27255
27256 -#ifdef CONFIG_X86_64
27257 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27258 -#else
27259 -#define BOOT_PERCPU_OFFSET 0
27260 -#endif
27261
27262 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27263 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27264
27265 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27266 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27267 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27268 };
27269 EXPORT_SYMBOL(__per_cpu_offset);
27270 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27271 {
27272 #ifdef CONFIG_NEED_MULTIPLE_NODES
27273 pg_data_t *last = NULL;
27274 - unsigned int cpu;
27275 + int cpu;
27276
27277 for_each_possible_cpu(cpu) {
27278 int node = early_cpu_to_node(cpu);
27279 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27280 {
27281 #ifdef CONFIG_X86_32
27282 struct desc_struct gdt;
27283 + unsigned long base = per_cpu_offset(cpu);
27284
27285 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27286 - 0x2 | DESCTYPE_S, 0x8);
27287 - gdt.s = 1;
27288 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27289 + 0x83 | DESCTYPE_S, 0xC);
27290 write_gdt_entry(get_cpu_gdt_table(cpu),
27291 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27292 #endif
27293 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27294 /* alrighty, percpu areas up and running */
27295 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27296 for_each_possible_cpu(cpu) {
27297 +#ifdef CONFIG_CC_STACKPROTECTOR
27298 +#ifdef CONFIG_X86_32
27299 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27300 +#endif
27301 +#endif
27302 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27303 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27304 per_cpu(cpu_number, cpu) = cpu;
27305 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27306 */
27307 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27308 #endif
27309 +#ifdef CONFIG_CC_STACKPROTECTOR
27310 +#ifdef CONFIG_X86_32
27311 + if (!cpu)
27312 + per_cpu(stack_canary.canary, cpu) = canary;
27313 +#endif
27314 +#endif
27315 /*
27316 * Up to this point, the boot CPU has been using .init.data
27317 * area. Reload any changed state for the boot CPU.
27318 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27319 index ed37a76..39f936e 100644
27320 --- a/arch/x86/kernel/signal.c
27321 +++ b/arch/x86/kernel/signal.c
27322 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27323 * Align the stack pointer according to the i386 ABI,
27324 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27325 */
27326 - sp = ((sp + 4) & -16ul) - 4;
27327 + sp = ((sp - 12) & -16ul) - 4;
27328 #else /* !CONFIG_X86_32 */
27329 sp = round_down(sp, 16) - 8;
27330 #endif
27331 @@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27332 }
27333
27334 if (current->mm->context.vdso)
27335 - restorer = current->mm->context.vdso +
27336 - selected_vdso32->sym___kernel_sigreturn;
27337 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27338 else
27339 - restorer = &frame->retcode;
27340 + restorer = (void __user *)&frame->retcode;
27341 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27342 restorer = ksig->ka.sa.sa_restorer;
27343
27344 @@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27345 * reasons and because gdb uses it as a signature to notice
27346 * signal handler stack frames.
27347 */
27348 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27349 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27350
27351 if (err)
27352 return -EFAULT;
27353 @@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27354 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27355
27356 /* Set up to return from userspace. */
27357 - restorer = current->mm->context.vdso +
27358 - selected_vdso32->sym___kernel_rt_sigreturn;
27359 + if (current->mm->context.vdso)
27360 + restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27361 + else
27362 + restorer = (void __user *)&frame->retcode;
27363 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27364 restorer = ksig->ka.sa.sa_restorer;
27365 put_user_ex(restorer, &frame->pretcode);
27366 @@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27367 * reasons and because gdb uses it as a signature to notice
27368 * signal handler stack frames.
27369 */
27370 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27371 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27372 } put_user_catch(err);
27373
27374 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27375 @@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27376 {
27377 int usig = signr_convert(ksig->sig);
27378 sigset_t *set = sigmask_to_save();
27379 - compat_sigset_t *cset = (compat_sigset_t *) set;
27380 + sigset_t sigcopy;
27381 + compat_sigset_t *cset;
27382 +
27383 + sigcopy = *set;
27384 +
27385 + cset = (compat_sigset_t *) &sigcopy;
27386
27387 /* Set up the stack frame */
27388 if (is_ia32_frame()) {
27389 @@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27390 } else if (is_x32_frame()) {
27391 return x32_setup_rt_frame(ksig, cset, regs);
27392 } else {
27393 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27394 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27395 }
27396 }
27397
27398 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27399 index be8e1bd..a3d93fa 100644
27400 --- a/arch/x86/kernel/smp.c
27401 +++ b/arch/x86/kernel/smp.c
27402 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27403
27404 __setup("nonmi_ipi", nonmi_ipi_setup);
27405
27406 -struct smp_ops smp_ops = {
27407 +struct smp_ops smp_ops __read_only = {
27408 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27409 .smp_prepare_cpus = native_smp_prepare_cpus,
27410 .smp_cpus_done = native_smp_cpus_done,
27411 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27412 index 668d8f2..84a9d54 100644
27413 --- a/arch/x86/kernel/smpboot.c
27414 +++ b/arch/x86/kernel/smpboot.c
27415 @@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27416
27417 enable_start_cpu0 = 0;
27418
27419 -#ifdef CONFIG_X86_32
27420 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27421 + barrier();
27422 +
27423 /* switch away from the initial page table */
27424 +#ifdef CONFIG_PAX_PER_CPU_PGD
27425 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27426 +#else
27427 load_cr3(swapper_pg_dir);
27428 +#endif
27429 __flush_tlb_all();
27430 -#endif
27431
27432 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27433 - barrier();
27434 /*
27435 * Check TSC synchronization with the BP:
27436 */
27437 @@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27438 alternatives_enable_smp();
27439
27440 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27441 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27442 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27443 per_cpu(current_task, cpu) = idle;
27444 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27445
27446 #ifdef CONFIG_X86_32
27447 /* Stack for startup_32 can be just as for start_secondary onwards */
27448 @@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27449 clear_tsk_thread_flag(idle, TIF_FORK);
27450 initial_gs = per_cpu_offset(cpu);
27451 #endif
27452 - per_cpu(kernel_stack, cpu) =
27453 - (unsigned long)task_stack_page(idle) -
27454 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27455 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27456 + pax_open_kernel();
27457 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27458 + pax_close_kernel();
27459 initial_code = (unsigned long)start_secondary;
27460 stack_start = idle->thread.sp;
27461
27462 @@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27463 /* the FPU context is blank, nobody can own it */
27464 __cpu_disable_lazy_restore(cpu);
27465
27466 +#ifdef CONFIG_PAX_PER_CPU_PGD
27467 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27468 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27469 + KERNEL_PGD_PTRS);
27470 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27471 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27472 + KERNEL_PGD_PTRS);
27473 +#endif
27474 +
27475 err = do_boot_cpu(apicid, cpu, tidle);
27476 if (err) {
27477 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27478 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27479 index 9b4d51d..5d28b58 100644
27480 --- a/arch/x86/kernel/step.c
27481 +++ b/arch/x86/kernel/step.c
27482 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27483 struct desc_struct *desc;
27484 unsigned long base;
27485
27486 - seg &= ~7UL;
27487 + seg >>= 3;
27488
27489 mutex_lock(&child->mm->context.lock);
27490 - if (unlikely((seg >> 3) >= child->mm->context.size))
27491 + if (unlikely(seg >= child->mm->context.size))
27492 addr = -1L; /* bogus selector, access would fault */
27493 else {
27494 desc = child->mm->context.ldt + seg;
27495 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27496 addr += base;
27497 }
27498 mutex_unlock(&child->mm->context.lock);
27499 - }
27500 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27501 + addr = ktla_ktva(addr);
27502
27503 return addr;
27504 }
27505 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27506 unsigned char opcode[15];
27507 unsigned long addr = convert_ip_to_linear(child, regs);
27508
27509 + if (addr == -EINVAL)
27510 + return 0;
27511 +
27512 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27513 for (i = 0; i < copied; i++) {
27514 switch (opcode[i]) {
27515 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27516 new file mode 100644
27517 index 0000000..5877189
27518 --- /dev/null
27519 +++ b/arch/x86/kernel/sys_i386_32.c
27520 @@ -0,0 +1,189 @@
27521 +/*
27522 + * This file contains various random system calls that
27523 + * have a non-standard calling sequence on the Linux/i386
27524 + * platform.
27525 + */
27526 +
27527 +#include <linux/errno.h>
27528 +#include <linux/sched.h>
27529 +#include <linux/mm.h>
27530 +#include <linux/fs.h>
27531 +#include <linux/smp.h>
27532 +#include <linux/sem.h>
27533 +#include <linux/msg.h>
27534 +#include <linux/shm.h>
27535 +#include <linux/stat.h>
27536 +#include <linux/syscalls.h>
27537 +#include <linux/mman.h>
27538 +#include <linux/file.h>
27539 +#include <linux/utsname.h>
27540 +#include <linux/ipc.h>
27541 +#include <linux/elf.h>
27542 +
27543 +#include <linux/uaccess.h>
27544 +#include <linux/unistd.h>
27545 +
27546 +#include <asm/syscalls.h>
27547 +
27548 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27549 +{
27550 + unsigned long pax_task_size = TASK_SIZE;
27551 +
27552 +#ifdef CONFIG_PAX_SEGMEXEC
27553 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27554 + pax_task_size = SEGMEXEC_TASK_SIZE;
27555 +#endif
27556 +
27557 + if (flags & MAP_FIXED)
27558 + if (len > pax_task_size || addr > pax_task_size - len)
27559 + return -EINVAL;
27560 +
27561 + return 0;
27562 +}
27563 +
27564 +/*
27565 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27566 + */
27567 +static unsigned long get_align_mask(void)
27568 +{
27569 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27570 + return 0;
27571 +
27572 + if (!(current->flags & PF_RANDOMIZE))
27573 + return 0;
27574 +
27575 + return va_align.mask;
27576 +}
27577 +
27578 +unsigned long
27579 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27580 + unsigned long len, unsigned long pgoff, unsigned long flags)
27581 +{
27582 + struct mm_struct *mm = current->mm;
27583 + struct vm_area_struct *vma;
27584 + unsigned long pax_task_size = TASK_SIZE;
27585 + struct vm_unmapped_area_info info;
27586 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27587 +
27588 +#ifdef CONFIG_PAX_SEGMEXEC
27589 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27590 + pax_task_size = SEGMEXEC_TASK_SIZE;
27591 +#endif
27592 +
27593 + pax_task_size -= PAGE_SIZE;
27594 +
27595 + if (len > pax_task_size)
27596 + return -ENOMEM;
27597 +
27598 + if (flags & MAP_FIXED)
27599 + return addr;
27600 +
27601 +#ifdef CONFIG_PAX_RANDMMAP
27602 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27603 +#endif
27604 +
27605 + if (addr) {
27606 + addr = PAGE_ALIGN(addr);
27607 + if (pax_task_size - len >= addr) {
27608 + vma = find_vma(mm, addr);
27609 + if (check_heap_stack_gap(vma, addr, len, offset))
27610 + return addr;
27611 + }
27612 + }
27613 +
27614 + info.flags = 0;
27615 + info.length = len;
27616 + info.align_mask = filp ? get_align_mask() : 0;
27617 + info.align_offset = pgoff << PAGE_SHIFT;
27618 + info.threadstack_offset = offset;
27619 +
27620 +#ifdef CONFIG_PAX_PAGEEXEC
27621 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27622 + info.low_limit = 0x00110000UL;
27623 + info.high_limit = mm->start_code;
27624 +
27625 +#ifdef CONFIG_PAX_RANDMMAP
27626 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27627 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27628 +#endif
27629 +
27630 + if (info.low_limit < info.high_limit) {
27631 + addr = vm_unmapped_area(&info);
27632 + if (!IS_ERR_VALUE(addr))
27633 + return addr;
27634 + }
27635 + } else
27636 +#endif
27637 +
27638 + info.low_limit = mm->mmap_base;
27639 + info.high_limit = pax_task_size;
27640 +
27641 + return vm_unmapped_area(&info);
27642 +}
27643 +
27644 +unsigned long
27645 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27646 + const unsigned long len, const unsigned long pgoff,
27647 + const unsigned long flags)
27648 +{
27649 + struct vm_area_struct *vma;
27650 + struct mm_struct *mm = current->mm;
27651 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27652 + struct vm_unmapped_area_info info;
27653 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27654 +
27655 +#ifdef CONFIG_PAX_SEGMEXEC
27656 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27657 + pax_task_size = SEGMEXEC_TASK_SIZE;
27658 +#endif
27659 +
27660 + pax_task_size -= PAGE_SIZE;
27661 +
27662 + /* requested length too big for entire address space */
27663 + if (len > pax_task_size)
27664 + return -ENOMEM;
27665 +
27666 + if (flags & MAP_FIXED)
27667 + return addr;
27668 +
27669 +#ifdef CONFIG_PAX_PAGEEXEC
27670 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27671 + goto bottomup;
27672 +#endif
27673 +
27674 +#ifdef CONFIG_PAX_RANDMMAP
27675 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27676 +#endif
27677 +
27678 + /* requesting a specific address */
27679 + if (addr) {
27680 + addr = PAGE_ALIGN(addr);
27681 + if (pax_task_size - len >= addr) {
27682 + vma = find_vma(mm, addr);
27683 + if (check_heap_stack_gap(vma, addr, len, offset))
27684 + return addr;
27685 + }
27686 + }
27687 +
27688 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27689 + info.length = len;
27690 + info.low_limit = PAGE_SIZE;
27691 + info.high_limit = mm->mmap_base;
27692 + info.align_mask = filp ? get_align_mask() : 0;
27693 + info.align_offset = pgoff << PAGE_SHIFT;
27694 + info.threadstack_offset = offset;
27695 +
27696 + addr = vm_unmapped_area(&info);
27697 + if (!(addr & ~PAGE_MASK))
27698 + return addr;
27699 + VM_BUG_ON(addr != -ENOMEM);
27700 +
27701 +bottomup:
27702 + /*
27703 + * A failed mmap() very likely causes application failure,
27704 + * so fall back to the bottom-up function here. This scenario
27705 + * can happen with large stack limits and large mmap()
27706 + * allocations.
27707 + */
27708 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27709 +}
27710 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27711 index 30277e2..5664a29 100644
27712 --- a/arch/x86/kernel/sys_x86_64.c
27713 +++ b/arch/x86/kernel/sys_x86_64.c
27714 @@ -81,8 +81,8 @@ out:
27715 return error;
27716 }
27717
27718 -static void find_start_end(unsigned long flags, unsigned long *begin,
27719 - unsigned long *end)
27720 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27721 + unsigned long *begin, unsigned long *end)
27722 {
27723 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27724 unsigned long new_begin;
27725 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27726 *begin = new_begin;
27727 }
27728 } else {
27729 - *begin = current->mm->mmap_legacy_base;
27730 + *begin = mm->mmap_legacy_base;
27731 *end = TASK_SIZE;
27732 }
27733 }
27734 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27735 struct vm_area_struct *vma;
27736 struct vm_unmapped_area_info info;
27737 unsigned long begin, end;
27738 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27739
27740 if (flags & MAP_FIXED)
27741 return addr;
27742
27743 - find_start_end(flags, &begin, &end);
27744 + find_start_end(mm, flags, &begin, &end);
27745
27746 if (len > end)
27747 return -ENOMEM;
27748
27749 +#ifdef CONFIG_PAX_RANDMMAP
27750 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27751 +#endif
27752 +
27753 if (addr) {
27754 addr = PAGE_ALIGN(addr);
27755 vma = find_vma(mm, addr);
27756 - if (end - len >= addr &&
27757 - (!vma || addr + len <= vma->vm_start))
27758 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27759 return addr;
27760 }
27761
27762 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27763 info.high_limit = end;
27764 info.align_mask = filp ? get_align_mask() : 0;
27765 info.align_offset = pgoff << PAGE_SHIFT;
27766 + info.threadstack_offset = offset;
27767 return vm_unmapped_area(&info);
27768 }
27769
27770 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27771 struct mm_struct *mm = current->mm;
27772 unsigned long addr = addr0;
27773 struct vm_unmapped_area_info info;
27774 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27775
27776 /* requested length too big for entire address space */
27777 if (len > TASK_SIZE)
27778 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27779 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27780 goto bottomup;
27781
27782 +#ifdef CONFIG_PAX_RANDMMAP
27783 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27784 +#endif
27785 +
27786 /* requesting a specific address */
27787 if (addr) {
27788 addr = PAGE_ALIGN(addr);
27789 vma = find_vma(mm, addr);
27790 - if (TASK_SIZE - len >= addr &&
27791 - (!vma || addr + len <= vma->vm_start))
27792 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27793 return addr;
27794 }
27795
27796 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27797 info.high_limit = mm->mmap_base;
27798 info.align_mask = filp ? get_align_mask() : 0;
27799 info.align_offset = pgoff << PAGE_SHIFT;
27800 + info.threadstack_offset = offset;
27801 addr = vm_unmapped_area(&info);
27802 if (!(addr & ~PAGE_MASK))
27803 return addr;
27804 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27805 index 91a4496..bb87552 100644
27806 --- a/arch/x86/kernel/tboot.c
27807 +++ b/arch/x86/kernel/tboot.c
27808 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27809
27810 void tboot_shutdown(u32 shutdown_type)
27811 {
27812 - void (*shutdown)(void);
27813 + void (* __noreturn shutdown)(void);
27814
27815 if (!tboot_enabled())
27816 return;
27817 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27818
27819 switch_to_tboot_pt();
27820
27821 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27822 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27823 shutdown();
27824
27825 /* should not reach here */
27826 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27827 return -ENODEV;
27828 }
27829
27830 -static atomic_t ap_wfs_count;
27831 +static atomic_unchecked_t ap_wfs_count;
27832
27833 static int tboot_wait_for_aps(int num_aps)
27834 {
27835 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27836 {
27837 switch (action) {
27838 case CPU_DYING:
27839 - atomic_inc(&ap_wfs_count);
27840 + atomic_inc_unchecked(&ap_wfs_count);
27841 if (num_online_cpus() == 1)
27842 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27843 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27844 return NOTIFY_BAD;
27845 break;
27846 }
27847 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27848
27849 tboot_create_trampoline();
27850
27851 - atomic_set(&ap_wfs_count, 0);
27852 + atomic_set_unchecked(&ap_wfs_count, 0);
27853 register_hotcpu_notifier(&tboot_cpu_notifier);
27854
27855 #ifdef CONFIG_DEBUG_FS
27856 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27857 index 0fa2960..91eabbe 100644
27858 --- a/arch/x86/kernel/time.c
27859 +++ b/arch/x86/kernel/time.c
27860 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27861 {
27862 unsigned long pc = instruction_pointer(regs);
27863
27864 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27865 + if (!user_mode(regs) && in_lock_functions(pc)) {
27866 #ifdef CONFIG_FRAME_POINTER
27867 - return *(unsigned long *)(regs->bp + sizeof(long));
27868 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27869 #else
27870 unsigned long *sp =
27871 (unsigned long *)kernel_stack_pointer(regs);
27872 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27873 * or above a saved flags. Eflags has bits 22-31 zero,
27874 * kernel addresses don't.
27875 */
27876 +
27877 +#ifdef CONFIG_PAX_KERNEXEC
27878 + return ktla_ktva(sp[0]);
27879 +#else
27880 if (sp[0] >> 22)
27881 return sp[0];
27882 if (sp[1] >> 22)
27883 return sp[1];
27884 #endif
27885 +
27886 +#endif
27887 }
27888 return pc;
27889 }
27890 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27891 index 7fc5e84..c6e445a 100644
27892 --- a/arch/x86/kernel/tls.c
27893 +++ b/arch/x86/kernel/tls.c
27894 @@ -139,6 +139,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27895 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27896 return -EINVAL;
27897
27898 +#ifdef CONFIG_PAX_SEGMEXEC
27899 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27900 + return -EINVAL;
27901 +#endif
27902 +
27903 set_tls_desc(p, idx, &info, 1);
27904
27905 return 0;
27906 @@ -256,7 +261,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27907
27908 if (kbuf)
27909 info = kbuf;
27910 - else if (__copy_from_user(infobuf, ubuf, count))
27911 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27912 return -EFAULT;
27913 else
27914 info = infobuf;
27915 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27916 index 1c113db..287b42e 100644
27917 --- a/arch/x86/kernel/tracepoint.c
27918 +++ b/arch/x86/kernel/tracepoint.c
27919 @@ -9,11 +9,11 @@
27920 #include <linux/atomic.h>
27921
27922 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27923 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27924 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27925 (unsigned long) trace_idt_table };
27926
27927 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27928 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27929 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27930
27931 static int trace_irq_vector_refcount;
27932 static DEFINE_MUTEX(irq_vector_mutex);
27933 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27934 index 07ab8e9..99c8456 100644
27935 --- a/arch/x86/kernel/traps.c
27936 +++ b/arch/x86/kernel/traps.c
27937 @@ -67,7 +67,7 @@
27938 #include <asm/proto.h>
27939
27940 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27941 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27942 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27943 #else
27944 #include <asm/processor-flags.h>
27945 #include <asm/setup.h>
27946 @@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27947 #endif
27948
27949 /* Must be page-aligned because the real IDT is used in a fixmap. */
27950 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27951 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27952
27953 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27954 EXPORT_SYMBOL_GPL(used_vectors);
27955 @@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27956 }
27957
27958 static nokprobe_inline int
27959 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27960 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27961 struct pt_regs *regs, long error_code)
27962 {
27963 #ifdef CONFIG_X86_32
27964 - if (regs->flags & X86_VM_MASK) {
27965 + if (v8086_mode(regs)) {
27966 /*
27967 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27968 * On nmi (interrupt 2), do_trap should not be called.
27969 @@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27970 return -1;
27971 }
27972 #endif
27973 - if (!user_mode(regs)) {
27974 + if (!user_mode_novm(regs)) {
27975 if (!fixup_exception(regs)) {
27976 tsk->thread.error_code = error_code;
27977 tsk->thread.trap_nr = trapnr;
27978 +
27979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27980 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27981 + str = "PAX: suspicious stack segment fault";
27982 +#endif
27983 +
27984 die(str, regs, error_code);
27985 }
27986 +
27987 +#ifdef CONFIG_PAX_REFCOUNT
27988 + if (trapnr == X86_TRAP_OF)
27989 + pax_report_refcount_overflow(regs);
27990 +#endif
27991 +
27992 return 0;
27993 }
27994
27995 @@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
27996 }
27997
27998 static void
27999 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28000 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28001 long error_code, siginfo_t *info)
28002 {
28003 struct task_struct *tsk = current;
28004 @@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28005 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28006 printk_ratelimit()) {
28007 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28008 - tsk->comm, tsk->pid, str,
28009 + tsk->comm, task_pid_nr(tsk), str,
28010 regs->ip, regs->sp, error_code);
28011 print_vma_addr(" in ", regs->ip);
28012 pr_cont("\n");
28013 @@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28014 tsk->thread.error_code = error_code;
28015 tsk->thread.trap_nr = X86_TRAP_DF;
28016
28017 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28018 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28019 + die("grsec: kernel stack overflow detected", regs, error_code);
28020 +#endif
28021 +
28022 #ifdef CONFIG_DOUBLEFAULT
28023 df_debug(regs, error_code);
28024 #endif
28025 @@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28026 conditional_sti(regs);
28027
28028 #ifdef CONFIG_X86_32
28029 - if (regs->flags & X86_VM_MASK) {
28030 + if (v8086_mode(regs)) {
28031 local_irq_enable();
28032 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28033 goto exit;
28034 @@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28035 #endif
28036
28037 tsk = current;
28038 - if (!user_mode(regs)) {
28039 + if (!user_mode_novm(regs)) {
28040 if (fixup_exception(regs))
28041 goto exit;
28042
28043 tsk->thread.error_code = error_code;
28044 tsk->thread.trap_nr = X86_TRAP_GP;
28045 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28046 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28047 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28048 +
28049 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28050 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28051 + die("PAX: suspicious general protection fault", regs, error_code);
28052 + else
28053 +#endif
28054 +
28055 die("general protection fault", regs, error_code);
28056 + }
28057 goto exit;
28058 }
28059
28060 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28061 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28062 + struct mm_struct *mm = tsk->mm;
28063 + unsigned long limit;
28064 +
28065 + down_write(&mm->mmap_sem);
28066 + limit = mm->context.user_cs_limit;
28067 + if (limit < TASK_SIZE) {
28068 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28069 + up_write(&mm->mmap_sem);
28070 + return;
28071 + }
28072 + up_write(&mm->mmap_sem);
28073 + }
28074 +#endif
28075 +
28076 tsk->thread.error_code = error_code;
28077 tsk->thread.trap_nr = X86_TRAP_GP;
28078
28079 @@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28080 container_of(task_pt_regs(current),
28081 struct bad_iret_stack, regs);
28082
28083 + if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28084 + new_stack = s;
28085 +
28086 /* Copy the IRET target to the new stack. */
28087 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28088
28089 /* Copy the remainder of the stack from the current stack. */
28090 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28091
28092 - BUG_ON(!user_mode_vm(&new_stack->regs));
28093 + BUG_ON(!user_mode(&new_stack->regs));
28094 return new_stack;
28095 }
28096 NOKPROBE_SYMBOL(fixup_bad_iret);
28097 @@ -519,7 +563,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28098 /* It's safe to allow irq's after DR6 has been saved */
28099 preempt_conditional_sti(regs);
28100
28101 - if (regs->flags & X86_VM_MASK) {
28102 + if (v8086_mode(regs)) {
28103 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28104 X86_TRAP_DB);
28105 preempt_conditional_cli(regs);
28106 @@ -534,7 +578,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28107 * We already checked v86 mode above, so we can check for kernel mode
28108 * by just checking the CPL of CS.
28109 */
28110 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
28111 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28112 tsk->thread.debugreg6 &= ~DR_STEP;
28113 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28114 regs->flags &= ~X86_EFLAGS_TF;
28115 @@ -567,7 +611,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28116 return;
28117 conditional_sti(regs);
28118
28119 - if (!user_mode_vm(regs))
28120 + if (!user_mode(regs))
28121 {
28122 if (!fixup_exception(regs)) {
28123 task->thread.error_code = error_code;
28124 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28125 index 5054497..139f8f8 100644
28126 --- a/arch/x86/kernel/tsc.c
28127 +++ b/arch/x86/kernel/tsc.c
28128 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28129 */
28130 smp_wmb();
28131
28132 - ACCESS_ONCE(c2n->head) = data;
28133 + ACCESS_ONCE_RW(c2n->head) = data;
28134 }
28135
28136 /*
28137 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28138 index 5d1cbfe..2a21feb 100644
28139 --- a/arch/x86/kernel/uprobes.c
28140 +++ b/arch/x86/kernel/uprobes.c
28141 @@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28142 int ret = NOTIFY_DONE;
28143
28144 /* We are only interested in userspace traps */
28145 - if (regs && !user_mode_vm(regs))
28146 + if (regs && !user_mode(regs))
28147 return NOTIFY_DONE;
28148
28149 switch (val) {
28150 @@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28151
28152 if (nleft != rasize) {
28153 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28154 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28155 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28156
28157 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28158 }
28159 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28160 index b9242ba..50c5edd 100644
28161 --- a/arch/x86/kernel/verify_cpu.S
28162 +++ b/arch/x86/kernel/verify_cpu.S
28163 @@ -20,6 +20,7 @@
28164 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28165 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28166 * arch/x86/kernel/head_32.S: processor startup
28167 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28168 *
28169 * verify_cpu, returns the status of longmode and SSE in register %eax.
28170 * 0: Success 1: Failure
28171 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28172 index e8edcf5..27f9344 100644
28173 --- a/arch/x86/kernel/vm86_32.c
28174 +++ b/arch/x86/kernel/vm86_32.c
28175 @@ -44,6 +44,7 @@
28176 #include <linux/ptrace.h>
28177 #include <linux/audit.h>
28178 #include <linux/stddef.h>
28179 +#include <linux/grsecurity.h>
28180
28181 #include <asm/uaccess.h>
28182 #include <asm/io.h>
28183 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28184 do_exit(SIGSEGV);
28185 }
28186
28187 - tss = &per_cpu(init_tss, get_cpu());
28188 + tss = init_tss + get_cpu();
28189 current->thread.sp0 = current->thread.saved_sp0;
28190 current->thread.sysenter_cs = __KERNEL_CS;
28191 load_sp0(tss, &current->thread);
28192 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28193
28194 if (tsk->thread.saved_sp0)
28195 return -EPERM;
28196 +
28197 +#ifdef CONFIG_GRKERNSEC_VM86
28198 + if (!capable(CAP_SYS_RAWIO)) {
28199 + gr_handle_vm86();
28200 + return -EPERM;
28201 + }
28202 +#endif
28203 +
28204 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28205 offsetof(struct kernel_vm86_struct, vm86plus) -
28206 sizeof(info.regs));
28207 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28208 int tmp;
28209 struct vm86plus_struct __user *v86;
28210
28211 +#ifdef CONFIG_GRKERNSEC_VM86
28212 + if (!capable(CAP_SYS_RAWIO)) {
28213 + gr_handle_vm86();
28214 + return -EPERM;
28215 + }
28216 +#endif
28217 +
28218 tsk = current;
28219 switch (cmd) {
28220 case VM86_REQUEST_IRQ:
28221 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28222 tsk->thread.saved_fs = info->regs32->fs;
28223 tsk->thread.saved_gs = get_user_gs(info->regs32);
28224
28225 - tss = &per_cpu(init_tss, get_cpu());
28226 + tss = init_tss + get_cpu();
28227 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28228 if (cpu_has_sep)
28229 tsk->thread.sysenter_cs = 0;
28230 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28231 goto cannot_handle;
28232 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28233 goto cannot_handle;
28234 - intr_ptr = (unsigned long __user *) (i << 2);
28235 + intr_ptr = (__force unsigned long __user *) (i << 2);
28236 if (get_user(segoffs, intr_ptr))
28237 goto cannot_handle;
28238 if ((segoffs >> 16) == BIOSSEG)
28239 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28240 index 49edf2d..df596b1 100644
28241 --- a/arch/x86/kernel/vmlinux.lds.S
28242 +++ b/arch/x86/kernel/vmlinux.lds.S
28243 @@ -26,6 +26,13 @@
28244 #include <asm/page_types.h>
28245 #include <asm/cache.h>
28246 #include <asm/boot.h>
28247 +#include <asm/segment.h>
28248 +
28249 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28250 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28251 +#else
28252 +#define __KERNEL_TEXT_OFFSET 0
28253 +#endif
28254
28255 #undef i386 /* in case the preprocessor is a 32bit one */
28256
28257 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28258
28259 PHDRS {
28260 text PT_LOAD FLAGS(5); /* R_E */
28261 +#ifdef CONFIG_X86_32
28262 + module PT_LOAD FLAGS(5); /* R_E */
28263 +#endif
28264 +#ifdef CONFIG_XEN
28265 + rodata PT_LOAD FLAGS(5); /* R_E */
28266 +#else
28267 + rodata PT_LOAD FLAGS(4); /* R__ */
28268 +#endif
28269 data PT_LOAD FLAGS(6); /* RW_ */
28270 -#ifdef CONFIG_X86_64
28271 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28272 #ifdef CONFIG_SMP
28273 percpu PT_LOAD FLAGS(6); /* RW_ */
28274 #endif
28275 + text.init PT_LOAD FLAGS(5); /* R_E */
28276 + text.exit PT_LOAD FLAGS(5); /* R_E */
28277 init PT_LOAD FLAGS(7); /* RWE */
28278 -#endif
28279 note PT_NOTE FLAGS(0); /* ___ */
28280 }
28281
28282 SECTIONS
28283 {
28284 #ifdef CONFIG_X86_32
28285 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28286 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28287 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28288 #else
28289 - . = __START_KERNEL;
28290 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28291 + . = __START_KERNEL;
28292 #endif
28293
28294 /* Text and read-only data */
28295 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28296 - _text = .;
28297 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28298 /* bootstrapping code */
28299 +#ifdef CONFIG_X86_32
28300 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28301 +#else
28302 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28303 +#endif
28304 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28305 + _text = .;
28306 HEAD_TEXT
28307 . = ALIGN(8);
28308 _stext = .;
28309 @@ -104,13 +124,47 @@ SECTIONS
28310 IRQENTRY_TEXT
28311 *(.fixup)
28312 *(.gnu.warning)
28313 - /* End of text section */
28314 - _etext = .;
28315 } :text = 0x9090
28316
28317 - NOTES :text :note
28318 + . += __KERNEL_TEXT_OFFSET;
28319
28320 - EXCEPTION_TABLE(16) :text = 0x9090
28321 +#ifdef CONFIG_X86_32
28322 + . = ALIGN(PAGE_SIZE);
28323 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28324 +
28325 +#ifdef CONFIG_PAX_KERNEXEC
28326 + MODULES_EXEC_VADDR = .;
28327 + BYTE(0)
28328 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28329 + . = ALIGN(HPAGE_SIZE) - 1;
28330 + MODULES_EXEC_END = .;
28331 +#endif
28332 +
28333 + } :module
28334 +#endif
28335 +
28336 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28337 + /* End of text section */
28338 + BYTE(0)
28339 + _etext = . - __KERNEL_TEXT_OFFSET;
28340 + }
28341 +
28342 +#ifdef CONFIG_X86_32
28343 + . = ALIGN(PAGE_SIZE);
28344 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28345 + . = ALIGN(PAGE_SIZE);
28346 + *(.empty_zero_page)
28347 + *(.initial_pg_fixmap)
28348 + *(.initial_pg_pmd)
28349 + *(.initial_page_table)
28350 + *(.swapper_pg_dir)
28351 + } :rodata
28352 +#endif
28353 +
28354 + . = ALIGN(PAGE_SIZE);
28355 + NOTES :rodata :note
28356 +
28357 + EXCEPTION_TABLE(16) :rodata
28358
28359 #if defined(CONFIG_DEBUG_RODATA)
28360 /* .text should occupy whole number of pages */
28361 @@ -122,16 +176,20 @@ SECTIONS
28362
28363 /* Data */
28364 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28365 +
28366 +#ifdef CONFIG_PAX_KERNEXEC
28367 + . = ALIGN(HPAGE_SIZE);
28368 +#else
28369 + . = ALIGN(PAGE_SIZE);
28370 +#endif
28371 +
28372 /* Start of data section */
28373 _sdata = .;
28374
28375 /* init_task */
28376 INIT_TASK_DATA(THREAD_SIZE)
28377
28378 -#ifdef CONFIG_X86_32
28379 - /* 32 bit has nosave before _edata */
28380 NOSAVE_DATA
28381 -#endif
28382
28383 PAGE_ALIGNED_DATA(PAGE_SIZE)
28384
28385 @@ -174,12 +232,19 @@ SECTIONS
28386 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28387
28388 /* Init code and data - will be freed after init */
28389 - . = ALIGN(PAGE_SIZE);
28390 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28391 + BYTE(0)
28392 +
28393 +#ifdef CONFIG_PAX_KERNEXEC
28394 + . = ALIGN(HPAGE_SIZE);
28395 +#else
28396 + . = ALIGN(PAGE_SIZE);
28397 +#endif
28398 +
28399 __init_begin = .; /* paired with __init_end */
28400 - }
28401 + } :init.begin
28402
28403 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28404 +#ifdef CONFIG_SMP
28405 /*
28406 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28407 * output PHDR, so the next output section - .init.text - should
28408 @@ -188,12 +253,27 @@ SECTIONS
28409 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28410 #endif
28411
28412 - INIT_TEXT_SECTION(PAGE_SIZE)
28413 -#ifdef CONFIG_X86_64
28414 - :init
28415 -#endif
28416 + . = ALIGN(PAGE_SIZE);
28417 + init_begin = .;
28418 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28419 + VMLINUX_SYMBOL(_sinittext) = .;
28420 + INIT_TEXT
28421 + . = ALIGN(PAGE_SIZE);
28422 + } :text.init
28423
28424 - INIT_DATA_SECTION(16)
28425 + /*
28426 + * .exit.text is discard at runtime, not link time, to deal with
28427 + * references from .altinstructions and .eh_frame
28428 + */
28429 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28430 + EXIT_TEXT
28431 + VMLINUX_SYMBOL(_einittext) = .;
28432 + . = ALIGN(16);
28433 + } :text.exit
28434 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28435 +
28436 + . = ALIGN(PAGE_SIZE);
28437 + INIT_DATA_SECTION(16) :init
28438
28439 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28440 __x86_cpu_dev_start = .;
28441 @@ -264,19 +344,12 @@ SECTIONS
28442 }
28443
28444 . = ALIGN(8);
28445 - /*
28446 - * .exit.text is discard at runtime, not link time, to deal with
28447 - * references from .altinstructions and .eh_frame
28448 - */
28449 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28450 - EXIT_TEXT
28451 - }
28452
28453 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28454 EXIT_DATA
28455 }
28456
28457 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28458 +#ifndef CONFIG_SMP
28459 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28460 #endif
28461
28462 @@ -295,16 +368,10 @@ SECTIONS
28463 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28464 __smp_locks = .;
28465 *(.smp_locks)
28466 - . = ALIGN(PAGE_SIZE);
28467 __smp_locks_end = .;
28468 + . = ALIGN(PAGE_SIZE);
28469 }
28470
28471 -#ifdef CONFIG_X86_64
28472 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28473 - NOSAVE_DATA
28474 - }
28475 -#endif
28476 -
28477 /* BSS */
28478 . = ALIGN(PAGE_SIZE);
28479 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28480 @@ -320,6 +387,7 @@ SECTIONS
28481 __brk_base = .;
28482 . += 64 * 1024; /* 64k alignment slop space */
28483 *(.brk_reservation) /* areas brk users have reserved */
28484 + . = ALIGN(HPAGE_SIZE);
28485 __brk_limit = .;
28486 }
28487
28488 @@ -346,13 +414,12 @@ SECTIONS
28489 * for the boot processor.
28490 */
28491 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28492 -INIT_PER_CPU(gdt_page);
28493 INIT_PER_CPU(irq_stack_union);
28494
28495 /*
28496 * Build-time check on the image size:
28497 */
28498 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28499 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28500 "kernel image bigger than KERNEL_IMAGE_SIZE");
28501
28502 #ifdef CONFIG_SMP
28503 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28504 index 957779f..74e405c 100644
28505 --- a/arch/x86/kernel/vsyscall_64.c
28506 +++ b/arch/x86/kernel/vsyscall_64.c
28507 @@ -54,15 +54,13 @@
28508
28509 DEFINE_VVAR(int, vgetcpu_mode);
28510
28511 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28512 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28513
28514 static int __init vsyscall_setup(char *str)
28515 {
28516 if (str) {
28517 if (!strcmp("emulate", str))
28518 vsyscall_mode = EMULATE;
28519 - else if (!strcmp("native", str))
28520 - vsyscall_mode = NATIVE;
28521 else if (!strcmp("none", str))
28522 vsyscall_mode = NONE;
28523 else
28524 @@ -279,8 +277,7 @@ do_ret:
28525 return true;
28526
28527 sigsegv:
28528 - force_sig(SIGSEGV, current);
28529 - return true;
28530 + do_group_exit(SIGKILL);
28531 }
28532
28533 /*
28534 @@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28535 extern char __vsyscall_page;
28536 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28537
28538 - __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28539 - vsyscall_mode == NATIVE
28540 - ? PAGE_KERNEL_VSYSCALL
28541 - : PAGE_KERNEL_VVAR);
28542 + __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28543 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28544 (unsigned long)VSYSCALL_ADDR);
28545 }
28546 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28547 index 04068192..4d75aa6 100644
28548 --- a/arch/x86/kernel/x8664_ksyms_64.c
28549 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28550 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28551 EXPORT_SYMBOL(copy_user_generic_unrolled);
28552 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28553 EXPORT_SYMBOL(__copy_user_nocache);
28554 -EXPORT_SYMBOL(_copy_from_user);
28555 -EXPORT_SYMBOL(_copy_to_user);
28556
28557 EXPORT_SYMBOL(copy_page);
28558 EXPORT_SYMBOL(clear_page);
28559 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28560 EXPORT_SYMBOL(___preempt_schedule_context);
28561 #endif
28562 #endif
28563 +
28564 +#ifdef CONFIG_PAX_PER_CPU_PGD
28565 +EXPORT_SYMBOL(cpu_pgd);
28566 +#endif
28567 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28568 index e48b674..a451dd9 100644
28569 --- a/arch/x86/kernel/x86_init.c
28570 +++ b/arch/x86/kernel/x86_init.c
28571 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28572 static void default_nmi_init(void) { };
28573 static int default_i8042_detect(void) { return 1; };
28574
28575 -struct x86_platform_ops x86_platform = {
28576 +struct x86_platform_ops x86_platform __read_only = {
28577 .calibrate_tsc = native_calibrate_tsc,
28578 .get_wallclock = mach_get_cmos_time,
28579 .set_wallclock = mach_set_rtc_mmss,
28580 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28581 EXPORT_SYMBOL_GPL(x86_platform);
28582
28583 #if defined(CONFIG_PCI_MSI)
28584 -struct x86_msi_ops x86_msi = {
28585 +struct x86_msi_ops x86_msi __read_only = {
28586 .setup_msi_irqs = native_setup_msi_irqs,
28587 .compose_msi_msg = native_compose_msi_msg,
28588 .teardown_msi_irq = native_teardown_msi_irq,
28589 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28590 }
28591 #endif
28592
28593 -struct x86_io_apic_ops x86_io_apic_ops = {
28594 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28595 .init = native_io_apic_init_mappings,
28596 .read = native_io_apic_read,
28597 .write = native_io_apic_write,
28598 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28599 index 0de1fae..298d037 100644
28600 --- a/arch/x86/kernel/xsave.c
28601 +++ b/arch/x86/kernel/xsave.c
28602 @@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28603
28604 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28605 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28606 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28607 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28608
28609 if (!use_xsave())
28610 return err;
28611
28612 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28613 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28614
28615 /*
28616 * Read the xstate_bv which we copied (directly from the cpu or
28617 * from the state in task struct) to the user buffers.
28618 */
28619 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28620 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28621
28622 /*
28623 * For legacy compatible, we always set FP/SSE bits in the bit
28624 @@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28625 */
28626 xstate_bv |= XSTATE_FPSSE;
28627
28628 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28629 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28630
28631 return err;
28632 }
28633 @@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28634 {
28635 int err;
28636
28637 + buf = (struct xsave_struct __user *)____m(buf);
28638 if (use_xsave())
28639 err = xsave_user(buf);
28640 else if (use_fxsr())
28641 @@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28642 */
28643 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28644 {
28645 + buf = (void __user *)____m(buf);
28646 if (use_xsave()) {
28647 if ((unsigned long)buf % 64 || fx_only) {
28648 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28649 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28650 index 88f9201..0e7f1a3 100644
28651 --- a/arch/x86/kvm/cpuid.c
28652 +++ b/arch/x86/kvm/cpuid.c
28653 @@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28654 struct kvm_cpuid2 *cpuid,
28655 struct kvm_cpuid_entry2 __user *entries)
28656 {
28657 - int r;
28658 + int r, i;
28659
28660 r = -E2BIG;
28661 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28662 goto out;
28663 r = -EFAULT;
28664 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28665 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28666 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28667 goto out;
28668 + for (i = 0; i < cpuid->nent; ++i) {
28669 + struct kvm_cpuid_entry2 cpuid_entry;
28670 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28671 + goto out;
28672 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28673 + }
28674 vcpu->arch.cpuid_nent = cpuid->nent;
28675 kvm_apic_set_version(vcpu);
28676 kvm_x86_ops->cpuid_update(vcpu);
28677 @@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28678 struct kvm_cpuid2 *cpuid,
28679 struct kvm_cpuid_entry2 __user *entries)
28680 {
28681 - int r;
28682 + int r, i;
28683
28684 r = -E2BIG;
28685 if (cpuid->nent < vcpu->arch.cpuid_nent)
28686 goto out;
28687 r = -EFAULT;
28688 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28689 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28690 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28691 goto out;
28692 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28693 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28694 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28695 + goto out;
28696 + }
28697 return 0;
28698
28699 out:
28700 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28701 index c7327a7..c3e2419 100644
28702 --- a/arch/x86/kvm/emulate.c
28703 +++ b/arch/x86/kvm/emulate.c
28704 @@ -3508,7 +3508,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28705 int cr = ctxt->modrm_reg;
28706 u64 efer = 0;
28707
28708 - static u64 cr_reserved_bits[] = {
28709 + static const u64 cr_reserved_bits[] = {
28710 0xffffffff00000000ULL,
28711 0, 0, 0, /* CR3 checked later */
28712 CR4_RESERVED_BITS,
28713 @@ -3543,7 +3543,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28714
28715 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28716 if (efer & EFER_LMA)
28717 - rsvd = CR3_L_MODE_RESERVED_BITS;
28718 + rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28719
28720 if (new_val & rsvd)
28721 return emulate_gp(ctxt, 0);
28722 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28723 index b8345dd..f225d71 100644
28724 --- a/arch/x86/kvm/lapic.c
28725 +++ b/arch/x86/kvm/lapic.c
28726 @@ -55,7 +55,7 @@
28727 #define APIC_BUS_CYCLE_NS 1
28728
28729 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28730 -#define apic_debug(fmt, arg...)
28731 +#define apic_debug(fmt, arg...) do {} while (0)
28732
28733 #define APIC_LVT_NUM 6
28734 /* 14 is the version for Xeon and Pentium 8.4.8*/
28735 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28736 index fd49c86..77e1aa0 100644
28737 --- a/arch/x86/kvm/paging_tmpl.h
28738 +++ b/arch/x86/kvm/paging_tmpl.h
28739 @@ -343,7 +343,7 @@ retry_walk:
28740 if (unlikely(kvm_is_error_hva(host_addr)))
28741 goto error;
28742
28743 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28744 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28745 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28746 goto error;
28747 walker->ptep_user[walker->level - 1] = ptep_user;
28748 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28749 index 7527cef..c63a838e 100644
28750 --- a/arch/x86/kvm/svm.c
28751 +++ b/arch/x86/kvm/svm.c
28752 @@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28753 int cpu = raw_smp_processor_id();
28754
28755 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28756 +
28757 + pax_open_kernel();
28758 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28759 + pax_close_kernel();
28760 +
28761 load_TR_desc();
28762 }
28763
28764 @@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28765 #endif
28766 #endif
28767
28768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28769 + __set_fs(current_thread_info()->addr_limit);
28770 +#endif
28771 +
28772 reload_tss(vcpu);
28773
28774 local_irq_disable();
28775 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28776 index ed70394..c629a68 100644
28777 --- a/arch/x86/kvm/vmx.c
28778 +++ b/arch/x86/kvm/vmx.c
28779 @@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28780 #endif
28781 }
28782
28783 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28784 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28785 {
28786 vmcs_writel(field, vmcs_readl(field) & ~mask);
28787 }
28788
28789 -static void vmcs_set_bits(unsigned long field, u32 mask)
28790 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28791 {
28792 vmcs_writel(field, vmcs_readl(field) | mask);
28793 }
28794 @@ -1631,7 +1631,11 @@ static void reload_tss(void)
28795 struct desc_struct *descs;
28796
28797 descs = (void *)gdt->address;
28798 +
28799 + pax_open_kernel();
28800 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28801 + pax_close_kernel();
28802 +
28803 load_TR_desc();
28804 }
28805
28806 @@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28807 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28808 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28809
28810 +#ifdef CONFIG_PAX_PER_CPU_PGD
28811 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28812 +#endif
28813 +
28814 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28815 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28816 vmx->loaded_vmcs->cpu = cpu;
28817 @@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28818 * reads and returns guest's timestamp counter "register"
28819 * guest_tsc = host_tsc + tsc_offset -- 21.3
28820 */
28821 -static u64 guest_read_tsc(void)
28822 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28823 {
28824 u64 host_tsc, tsc_offset;
28825
28826 @@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28827 * page upon invalidation. No need to do anything if the
28828 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28829 */
28830 - kvm_x86_ops->set_apic_access_page_addr = NULL;
28831 + pax_open_kernel();
28832 + *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28833 + pax_close_kernel();
28834 }
28835
28836 - if (!cpu_has_vmx_tpr_shadow())
28837 - kvm_x86_ops->update_cr8_intercept = NULL;
28838 + if (!cpu_has_vmx_tpr_shadow()) {
28839 + pax_open_kernel();
28840 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28841 + pax_close_kernel();
28842 + }
28843
28844 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28845 kvm_disable_largepages();
28846 @@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28847 if (!cpu_has_vmx_apicv())
28848 enable_apicv = 0;
28849
28850 + pax_open_kernel();
28851 if (enable_apicv)
28852 - kvm_x86_ops->update_cr8_intercept = NULL;
28853 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28854 else {
28855 - kvm_x86_ops->hwapic_irr_update = NULL;
28856 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28857 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28858 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28859 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28860 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28861 }
28862 + pax_close_kernel();
28863
28864 if (nested)
28865 nested_vmx_setup_ctls_msrs();
28866 @@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28867 unsigned long cr4;
28868
28869 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28870 +
28871 +#ifndef CONFIG_PAX_PER_CPU_PGD
28872 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28873 +#endif
28874
28875 /* Save the most likely value for this task's CR4 in the VMCS. */
28876 cr4 = read_cr4();
28877 @@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28878 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28879 vmx->host_idt_base = dt.address;
28880
28881 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28882 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28883
28884 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28885 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28886 @@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28887 "jmp 2f \n\t"
28888 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28889 "2: "
28890 +
28891 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28892 + "ljmp %[cs],$3f\n\t"
28893 + "3: "
28894 +#endif
28895 +
28896 /* Save guest registers, load host registers, keep flags */
28897 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28898 "pop %0 \n\t"
28899 @@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28900 #endif
28901 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28902 [wordsize]"i"(sizeof(ulong))
28903 +
28904 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28905 + ,[cs]"i"(__KERNEL_CS)
28906 +#endif
28907 +
28908 : "cc", "memory"
28909 #ifdef CONFIG_X86_64
28910 , "rax", "rbx", "rdi", "rsi"
28911 @@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28912 if (debugctlmsr)
28913 update_debugctlmsr(debugctlmsr);
28914
28915 -#ifndef CONFIG_X86_64
28916 +#ifdef CONFIG_X86_32
28917 /*
28918 * The sysexit path does not restore ds/es, so we must set them to
28919 * a reasonable value ourselves.
28920 @@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28921 * may be executed in interrupt context, which saves and restore segments
28922 * around it, nullifying its effect.
28923 */
28924 - loadsegment(ds, __USER_DS);
28925 - loadsegment(es, __USER_DS);
28926 + loadsegment(ds, __KERNEL_DS);
28927 + loadsegment(es, __KERNEL_DS);
28928 + loadsegment(ss, __KERNEL_DS);
28929 +
28930 +#ifdef CONFIG_PAX_KERNEXEC
28931 + loadsegment(fs, __KERNEL_PERCPU);
28932 +#endif
28933 +
28934 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28935 + __set_fs(current_thread_info()->addr_limit);
28936 +#endif
28937 +
28938 #endif
28939
28940 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28941 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28942 index 8b92cf4..ee50439 100644
28943 --- a/arch/x86/kvm/x86.c
28944 +++ b/arch/x86/kvm/x86.c
28945 @@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28946
28947 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28948 {
28949 + cr3 &= ~CR3_PCID_INVD;
28950 +
28951 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28952 kvm_mmu_sync_roots(vcpu);
28953 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28954 @@ -1879,8 +1881,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28955 {
28956 struct kvm *kvm = vcpu->kvm;
28957 int lm = is_long_mode(vcpu);
28958 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28959 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28960 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28961 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28962 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28963 : kvm->arch.xen_hvm_config.blob_size_32;
28964 u32 page_num = data & ~PAGE_MASK;
28965 @@ -2807,6 +2809,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28966 if (n < msr_list.nmsrs)
28967 goto out;
28968 r = -EFAULT;
28969 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28970 + goto out;
28971 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28972 num_msrs_to_save * sizeof(u32)))
28973 goto out;
28974 @@ -5744,7 +5748,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28975 };
28976 #endif
28977
28978 -int kvm_arch_init(void *opaque)
28979 +int kvm_arch_init(const void *opaque)
28980 {
28981 int r;
28982 struct kvm_x86_ops *ops = opaque;
28983 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28984 index aae9413..d11e829 100644
28985 --- a/arch/x86/lguest/boot.c
28986 +++ b/arch/x86/lguest/boot.c
28987 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28988 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28989 * Launcher to reboot us.
28990 */
28991 -static void lguest_restart(char *reason)
28992 +static __noreturn void lguest_restart(char *reason)
28993 {
28994 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28995 + BUG();
28996 }
28997
28998 /*G:050
28999 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29000 index 00933d5..3a64af9 100644
29001 --- a/arch/x86/lib/atomic64_386_32.S
29002 +++ b/arch/x86/lib/atomic64_386_32.S
29003 @@ -48,6 +48,10 @@ BEGIN(read)
29004 movl (v), %eax
29005 movl 4(v), %edx
29006 RET_ENDP
29007 +BEGIN(read_unchecked)
29008 + movl (v), %eax
29009 + movl 4(v), %edx
29010 +RET_ENDP
29011 #undef v
29012
29013 #define v %esi
29014 @@ -55,6 +59,10 @@ BEGIN(set)
29015 movl %ebx, (v)
29016 movl %ecx, 4(v)
29017 RET_ENDP
29018 +BEGIN(set_unchecked)
29019 + movl %ebx, (v)
29020 + movl %ecx, 4(v)
29021 +RET_ENDP
29022 #undef v
29023
29024 #define v %esi
29025 @@ -70,6 +78,20 @@ RET_ENDP
29026 BEGIN(add)
29027 addl %eax, (v)
29028 adcl %edx, 4(v)
29029 +
29030 +#ifdef CONFIG_PAX_REFCOUNT
29031 + jno 0f
29032 + subl %eax, (v)
29033 + sbbl %edx, 4(v)
29034 + int $4
29035 +0:
29036 + _ASM_EXTABLE(0b, 0b)
29037 +#endif
29038 +
29039 +RET_ENDP
29040 +BEGIN(add_unchecked)
29041 + addl %eax, (v)
29042 + adcl %edx, 4(v)
29043 RET_ENDP
29044 #undef v
29045
29046 @@ -77,6 +99,24 @@ RET_ENDP
29047 BEGIN(add_return)
29048 addl (v), %eax
29049 adcl 4(v), %edx
29050 +
29051 +#ifdef CONFIG_PAX_REFCOUNT
29052 + into
29053 +1234:
29054 + _ASM_EXTABLE(1234b, 2f)
29055 +#endif
29056 +
29057 + movl %eax, (v)
29058 + movl %edx, 4(v)
29059 +
29060 +#ifdef CONFIG_PAX_REFCOUNT
29061 +2:
29062 +#endif
29063 +
29064 +RET_ENDP
29065 +BEGIN(add_return_unchecked)
29066 + addl (v), %eax
29067 + adcl 4(v), %edx
29068 movl %eax, (v)
29069 movl %edx, 4(v)
29070 RET_ENDP
29071 @@ -86,6 +126,20 @@ RET_ENDP
29072 BEGIN(sub)
29073 subl %eax, (v)
29074 sbbl %edx, 4(v)
29075 +
29076 +#ifdef CONFIG_PAX_REFCOUNT
29077 + jno 0f
29078 + addl %eax, (v)
29079 + adcl %edx, 4(v)
29080 + int $4
29081 +0:
29082 + _ASM_EXTABLE(0b, 0b)
29083 +#endif
29084 +
29085 +RET_ENDP
29086 +BEGIN(sub_unchecked)
29087 + subl %eax, (v)
29088 + sbbl %edx, 4(v)
29089 RET_ENDP
29090 #undef v
29091
29092 @@ -96,6 +150,27 @@ BEGIN(sub_return)
29093 sbbl $0, %edx
29094 addl (v), %eax
29095 adcl 4(v), %edx
29096 +
29097 +#ifdef CONFIG_PAX_REFCOUNT
29098 + into
29099 +1234:
29100 + _ASM_EXTABLE(1234b, 2f)
29101 +#endif
29102 +
29103 + movl %eax, (v)
29104 + movl %edx, 4(v)
29105 +
29106 +#ifdef CONFIG_PAX_REFCOUNT
29107 +2:
29108 +#endif
29109 +
29110 +RET_ENDP
29111 +BEGIN(sub_return_unchecked)
29112 + negl %edx
29113 + negl %eax
29114 + sbbl $0, %edx
29115 + addl (v), %eax
29116 + adcl 4(v), %edx
29117 movl %eax, (v)
29118 movl %edx, 4(v)
29119 RET_ENDP
29120 @@ -105,6 +180,20 @@ RET_ENDP
29121 BEGIN(inc)
29122 addl $1, (v)
29123 adcl $0, 4(v)
29124 +
29125 +#ifdef CONFIG_PAX_REFCOUNT
29126 + jno 0f
29127 + subl $1, (v)
29128 + sbbl $0, 4(v)
29129 + int $4
29130 +0:
29131 + _ASM_EXTABLE(0b, 0b)
29132 +#endif
29133 +
29134 +RET_ENDP
29135 +BEGIN(inc_unchecked)
29136 + addl $1, (v)
29137 + adcl $0, 4(v)
29138 RET_ENDP
29139 #undef v
29140
29141 @@ -114,6 +203,26 @@ BEGIN(inc_return)
29142 movl 4(v), %edx
29143 addl $1, %eax
29144 adcl $0, %edx
29145 +
29146 +#ifdef CONFIG_PAX_REFCOUNT
29147 + into
29148 +1234:
29149 + _ASM_EXTABLE(1234b, 2f)
29150 +#endif
29151 +
29152 + movl %eax, (v)
29153 + movl %edx, 4(v)
29154 +
29155 +#ifdef CONFIG_PAX_REFCOUNT
29156 +2:
29157 +#endif
29158 +
29159 +RET_ENDP
29160 +BEGIN(inc_return_unchecked)
29161 + movl (v), %eax
29162 + movl 4(v), %edx
29163 + addl $1, %eax
29164 + adcl $0, %edx
29165 movl %eax, (v)
29166 movl %edx, 4(v)
29167 RET_ENDP
29168 @@ -123,6 +232,20 @@ RET_ENDP
29169 BEGIN(dec)
29170 subl $1, (v)
29171 sbbl $0, 4(v)
29172 +
29173 +#ifdef CONFIG_PAX_REFCOUNT
29174 + jno 0f
29175 + addl $1, (v)
29176 + adcl $0, 4(v)
29177 + int $4
29178 +0:
29179 + _ASM_EXTABLE(0b, 0b)
29180 +#endif
29181 +
29182 +RET_ENDP
29183 +BEGIN(dec_unchecked)
29184 + subl $1, (v)
29185 + sbbl $0, 4(v)
29186 RET_ENDP
29187 #undef v
29188
29189 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29190 movl 4(v), %edx
29191 subl $1, %eax
29192 sbbl $0, %edx
29193 +
29194 +#ifdef CONFIG_PAX_REFCOUNT
29195 + into
29196 +1234:
29197 + _ASM_EXTABLE(1234b, 2f)
29198 +#endif
29199 +
29200 + movl %eax, (v)
29201 + movl %edx, 4(v)
29202 +
29203 +#ifdef CONFIG_PAX_REFCOUNT
29204 +2:
29205 +#endif
29206 +
29207 +RET_ENDP
29208 +BEGIN(dec_return_unchecked)
29209 + movl (v), %eax
29210 + movl 4(v), %edx
29211 + subl $1, %eax
29212 + sbbl $0, %edx
29213 movl %eax, (v)
29214 movl %edx, 4(v)
29215 RET_ENDP
29216 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29217 adcl %edx, %edi
29218 addl (v), %eax
29219 adcl 4(v), %edx
29220 +
29221 +#ifdef CONFIG_PAX_REFCOUNT
29222 + into
29223 +1234:
29224 + _ASM_EXTABLE(1234b, 2f)
29225 +#endif
29226 +
29227 cmpl %eax, %ecx
29228 je 3f
29229 1:
29230 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29231 1:
29232 addl $1, %eax
29233 adcl $0, %edx
29234 +
29235 +#ifdef CONFIG_PAX_REFCOUNT
29236 + into
29237 +1234:
29238 + _ASM_EXTABLE(1234b, 2f)
29239 +#endif
29240 +
29241 movl %eax, (v)
29242 movl %edx, 4(v)
29243 movl $1, %eax
29244 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29245 movl 4(v), %edx
29246 subl $1, %eax
29247 sbbl $0, %edx
29248 +
29249 +#ifdef CONFIG_PAX_REFCOUNT
29250 + into
29251 +1234:
29252 + _ASM_EXTABLE(1234b, 1f)
29253 +#endif
29254 +
29255 js 1f
29256 movl %eax, (v)
29257 movl %edx, 4(v)
29258 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29259 index f5cc9eb..51fa319 100644
29260 --- a/arch/x86/lib/atomic64_cx8_32.S
29261 +++ b/arch/x86/lib/atomic64_cx8_32.S
29262 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29263 CFI_STARTPROC
29264
29265 read64 %ecx
29266 + pax_force_retaddr
29267 ret
29268 CFI_ENDPROC
29269 ENDPROC(atomic64_read_cx8)
29270
29271 +ENTRY(atomic64_read_unchecked_cx8)
29272 + CFI_STARTPROC
29273 +
29274 + read64 %ecx
29275 + pax_force_retaddr
29276 + ret
29277 + CFI_ENDPROC
29278 +ENDPROC(atomic64_read_unchecked_cx8)
29279 +
29280 ENTRY(atomic64_set_cx8)
29281 CFI_STARTPROC
29282
29283 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29284 cmpxchg8b (%esi)
29285 jne 1b
29286
29287 + pax_force_retaddr
29288 ret
29289 CFI_ENDPROC
29290 ENDPROC(atomic64_set_cx8)
29291
29292 +ENTRY(atomic64_set_unchecked_cx8)
29293 + CFI_STARTPROC
29294 +
29295 +1:
29296 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29297 + * are atomic on 586 and newer */
29298 + cmpxchg8b (%esi)
29299 + jne 1b
29300 +
29301 + pax_force_retaddr
29302 + ret
29303 + CFI_ENDPROC
29304 +ENDPROC(atomic64_set_unchecked_cx8)
29305 +
29306 ENTRY(atomic64_xchg_cx8)
29307 CFI_STARTPROC
29308
29309 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29310 cmpxchg8b (%esi)
29311 jne 1b
29312
29313 + pax_force_retaddr
29314 ret
29315 CFI_ENDPROC
29316 ENDPROC(atomic64_xchg_cx8)
29317
29318 -.macro addsub_return func ins insc
29319 -ENTRY(atomic64_\func\()_return_cx8)
29320 +.macro addsub_return func ins insc unchecked=""
29321 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29322 CFI_STARTPROC
29323 SAVE ebp
29324 SAVE ebx
29325 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29326 movl %edx, %ecx
29327 \ins\()l %esi, %ebx
29328 \insc\()l %edi, %ecx
29329 +
29330 +.ifb \unchecked
29331 +#ifdef CONFIG_PAX_REFCOUNT
29332 + into
29333 +2:
29334 + _ASM_EXTABLE(2b, 3f)
29335 +#endif
29336 +.endif
29337 +
29338 LOCK_PREFIX
29339 cmpxchg8b (%ebp)
29340 jne 1b
29341 -
29342 -10:
29343 movl %ebx, %eax
29344 movl %ecx, %edx
29345 +
29346 +.ifb \unchecked
29347 +#ifdef CONFIG_PAX_REFCOUNT
29348 +3:
29349 +#endif
29350 +.endif
29351 +
29352 RESTORE edi
29353 RESTORE esi
29354 RESTORE ebx
29355 RESTORE ebp
29356 + pax_force_retaddr
29357 ret
29358 CFI_ENDPROC
29359 -ENDPROC(atomic64_\func\()_return_cx8)
29360 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29361 .endm
29362
29363 addsub_return add add adc
29364 addsub_return sub sub sbb
29365 +addsub_return add add adc _unchecked
29366 +addsub_return sub sub sbb _unchecked
29367
29368 -.macro incdec_return func ins insc
29369 -ENTRY(atomic64_\func\()_return_cx8)
29370 +.macro incdec_return func ins insc unchecked=""
29371 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29372 CFI_STARTPROC
29373 SAVE ebx
29374
29375 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29376 movl %edx, %ecx
29377 \ins\()l $1, %ebx
29378 \insc\()l $0, %ecx
29379 +
29380 +.ifb \unchecked
29381 +#ifdef CONFIG_PAX_REFCOUNT
29382 + into
29383 +2:
29384 + _ASM_EXTABLE(2b, 3f)
29385 +#endif
29386 +.endif
29387 +
29388 LOCK_PREFIX
29389 cmpxchg8b (%esi)
29390 jne 1b
29391
29392 -10:
29393 movl %ebx, %eax
29394 movl %ecx, %edx
29395 +
29396 +.ifb \unchecked
29397 +#ifdef CONFIG_PAX_REFCOUNT
29398 +3:
29399 +#endif
29400 +.endif
29401 +
29402 RESTORE ebx
29403 + pax_force_retaddr
29404 ret
29405 CFI_ENDPROC
29406 -ENDPROC(atomic64_\func\()_return_cx8)
29407 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29408 .endm
29409
29410 incdec_return inc add adc
29411 incdec_return dec sub sbb
29412 +incdec_return inc add adc _unchecked
29413 +incdec_return dec sub sbb _unchecked
29414
29415 ENTRY(atomic64_dec_if_positive_cx8)
29416 CFI_STARTPROC
29417 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29418 movl %edx, %ecx
29419 subl $1, %ebx
29420 sbb $0, %ecx
29421 +
29422 +#ifdef CONFIG_PAX_REFCOUNT
29423 + into
29424 +1234:
29425 + _ASM_EXTABLE(1234b, 2f)
29426 +#endif
29427 +
29428 js 2f
29429 LOCK_PREFIX
29430 cmpxchg8b (%esi)
29431 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29432 movl %ebx, %eax
29433 movl %ecx, %edx
29434 RESTORE ebx
29435 + pax_force_retaddr
29436 ret
29437 CFI_ENDPROC
29438 ENDPROC(atomic64_dec_if_positive_cx8)
29439 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29440 movl %edx, %ecx
29441 addl %ebp, %ebx
29442 adcl %edi, %ecx
29443 +
29444 +#ifdef CONFIG_PAX_REFCOUNT
29445 + into
29446 +1234:
29447 + _ASM_EXTABLE(1234b, 3f)
29448 +#endif
29449 +
29450 LOCK_PREFIX
29451 cmpxchg8b (%esi)
29452 jne 1b
29453 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29454 CFI_ADJUST_CFA_OFFSET -8
29455 RESTORE ebx
29456 RESTORE ebp
29457 + pax_force_retaddr
29458 ret
29459 4:
29460 cmpl %edx, 4(%esp)
29461 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29462 xorl %ecx, %ecx
29463 addl $1, %ebx
29464 adcl %edx, %ecx
29465 +
29466 +#ifdef CONFIG_PAX_REFCOUNT
29467 + into
29468 +1234:
29469 + _ASM_EXTABLE(1234b, 3f)
29470 +#endif
29471 +
29472 LOCK_PREFIX
29473 cmpxchg8b (%esi)
29474 jne 1b
29475 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29476 movl $1, %eax
29477 3:
29478 RESTORE ebx
29479 + pax_force_retaddr
29480 ret
29481 CFI_ENDPROC
29482 ENDPROC(atomic64_inc_not_zero_cx8)
29483 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29484 index e78b8eee..7e173a8 100644
29485 --- a/arch/x86/lib/checksum_32.S
29486 +++ b/arch/x86/lib/checksum_32.S
29487 @@ -29,7 +29,8 @@
29488 #include <asm/dwarf2.h>
29489 #include <asm/errno.h>
29490 #include <asm/asm.h>
29491 -
29492 +#include <asm/segment.h>
29493 +
29494 /*
29495 * computes a partial checksum, e.g. for TCP/UDP fragments
29496 */
29497 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29498
29499 #define ARGBASE 16
29500 #define FP 12
29501 -
29502 -ENTRY(csum_partial_copy_generic)
29503 +
29504 +ENTRY(csum_partial_copy_generic_to_user)
29505 CFI_STARTPROC
29506 +
29507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29508 + pushl_cfi %gs
29509 + popl_cfi %es
29510 + jmp csum_partial_copy_generic
29511 +#endif
29512 +
29513 +ENTRY(csum_partial_copy_generic_from_user)
29514 +
29515 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29516 + pushl_cfi %gs
29517 + popl_cfi %ds
29518 +#endif
29519 +
29520 +ENTRY(csum_partial_copy_generic)
29521 subl $4,%esp
29522 CFI_ADJUST_CFA_OFFSET 4
29523 pushl_cfi %edi
29524 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29525 jmp 4f
29526 SRC(1: movw (%esi), %bx )
29527 addl $2, %esi
29528 -DST( movw %bx, (%edi) )
29529 +DST( movw %bx, %es:(%edi) )
29530 addl $2, %edi
29531 addw %bx, %ax
29532 adcl $0, %eax
29533 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29534 SRC(1: movl (%esi), %ebx )
29535 SRC( movl 4(%esi), %edx )
29536 adcl %ebx, %eax
29537 -DST( movl %ebx, (%edi) )
29538 +DST( movl %ebx, %es:(%edi) )
29539 adcl %edx, %eax
29540 -DST( movl %edx, 4(%edi) )
29541 +DST( movl %edx, %es:4(%edi) )
29542
29543 SRC( movl 8(%esi), %ebx )
29544 SRC( movl 12(%esi), %edx )
29545 adcl %ebx, %eax
29546 -DST( movl %ebx, 8(%edi) )
29547 +DST( movl %ebx, %es:8(%edi) )
29548 adcl %edx, %eax
29549 -DST( movl %edx, 12(%edi) )
29550 +DST( movl %edx, %es:12(%edi) )
29551
29552 SRC( movl 16(%esi), %ebx )
29553 SRC( movl 20(%esi), %edx )
29554 adcl %ebx, %eax
29555 -DST( movl %ebx, 16(%edi) )
29556 +DST( movl %ebx, %es:16(%edi) )
29557 adcl %edx, %eax
29558 -DST( movl %edx, 20(%edi) )
29559 +DST( movl %edx, %es:20(%edi) )
29560
29561 SRC( movl 24(%esi), %ebx )
29562 SRC( movl 28(%esi), %edx )
29563 adcl %ebx, %eax
29564 -DST( movl %ebx, 24(%edi) )
29565 +DST( movl %ebx, %es:24(%edi) )
29566 adcl %edx, %eax
29567 -DST( movl %edx, 28(%edi) )
29568 +DST( movl %edx, %es:28(%edi) )
29569
29570 lea 32(%esi), %esi
29571 lea 32(%edi), %edi
29572 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29573 shrl $2, %edx # This clears CF
29574 SRC(3: movl (%esi), %ebx )
29575 adcl %ebx, %eax
29576 -DST( movl %ebx, (%edi) )
29577 +DST( movl %ebx, %es:(%edi) )
29578 lea 4(%esi), %esi
29579 lea 4(%edi), %edi
29580 dec %edx
29581 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29582 jb 5f
29583 SRC( movw (%esi), %cx )
29584 leal 2(%esi), %esi
29585 -DST( movw %cx, (%edi) )
29586 +DST( movw %cx, %es:(%edi) )
29587 leal 2(%edi), %edi
29588 je 6f
29589 shll $16,%ecx
29590 SRC(5: movb (%esi), %cl )
29591 -DST( movb %cl, (%edi) )
29592 +DST( movb %cl, %es:(%edi) )
29593 6: addl %ecx, %eax
29594 adcl $0, %eax
29595 7:
29596 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29597
29598 6001:
29599 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29600 - movl $-EFAULT, (%ebx)
29601 + movl $-EFAULT, %ss:(%ebx)
29602
29603 # zero the complete destination - computing the rest
29604 # is too much work
29605 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29606
29607 6002:
29608 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29609 - movl $-EFAULT,(%ebx)
29610 + movl $-EFAULT,%ss:(%ebx)
29611 jmp 5000b
29612
29613 .previous
29614
29615 + pushl_cfi %ss
29616 + popl_cfi %ds
29617 + pushl_cfi %ss
29618 + popl_cfi %es
29619 popl_cfi %ebx
29620 CFI_RESTORE ebx
29621 popl_cfi %esi
29622 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29623 popl_cfi %ecx # equivalent to addl $4,%esp
29624 ret
29625 CFI_ENDPROC
29626 -ENDPROC(csum_partial_copy_generic)
29627 +ENDPROC(csum_partial_copy_generic_to_user)
29628
29629 #else
29630
29631 /* Version for PentiumII/PPro */
29632
29633 #define ROUND1(x) \
29634 + nop; nop; nop; \
29635 SRC(movl x(%esi), %ebx ) ; \
29636 addl %ebx, %eax ; \
29637 - DST(movl %ebx, x(%edi) ) ;
29638 + DST(movl %ebx, %es:x(%edi)) ;
29639
29640 #define ROUND(x) \
29641 + nop; nop; nop; \
29642 SRC(movl x(%esi), %ebx ) ; \
29643 adcl %ebx, %eax ; \
29644 - DST(movl %ebx, x(%edi) ) ;
29645 + DST(movl %ebx, %es:x(%edi)) ;
29646
29647 #define ARGBASE 12
29648 -
29649 -ENTRY(csum_partial_copy_generic)
29650 +
29651 +ENTRY(csum_partial_copy_generic_to_user)
29652 CFI_STARTPROC
29653 +
29654 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29655 + pushl_cfi %gs
29656 + popl_cfi %es
29657 + jmp csum_partial_copy_generic
29658 +#endif
29659 +
29660 +ENTRY(csum_partial_copy_generic_from_user)
29661 +
29662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29663 + pushl_cfi %gs
29664 + popl_cfi %ds
29665 +#endif
29666 +
29667 +ENTRY(csum_partial_copy_generic)
29668 pushl_cfi %ebx
29669 CFI_REL_OFFSET ebx, 0
29670 pushl_cfi %edi
29671 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29672 subl %ebx, %edi
29673 lea -1(%esi),%edx
29674 andl $-32,%edx
29675 - lea 3f(%ebx,%ebx), %ebx
29676 + lea 3f(%ebx,%ebx,2), %ebx
29677 testl %esi, %esi
29678 jmp *%ebx
29679 1: addl $64,%esi
29680 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29681 jb 5f
29682 SRC( movw (%esi), %dx )
29683 leal 2(%esi), %esi
29684 -DST( movw %dx, (%edi) )
29685 +DST( movw %dx, %es:(%edi) )
29686 leal 2(%edi), %edi
29687 je 6f
29688 shll $16,%edx
29689 5:
29690 SRC( movb (%esi), %dl )
29691 -DST( movb %dl, (%edi) )
29692 +DST( movb %dl, %es:(%edi) )
29693 6: addl %edx, %eax
29694 adcl $0, %eax
29695 7:
29696 .section .fixup, "ax"
29697 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29698 - movl $-EFAULT, (%ebx)
29699 + movl $-EFAULT, %ss:(%ebx)
29700 # zero the complete destination (computing the rest is too much work)
29701 movl ARGBASE+8(%esp),%edi # dst
29702 movl ARGBASE+12(%esp),%ecx # len
29703 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29704 rep; stosb
29705 jmp 7b
29706 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29707 - movl $-EFAULT, (%ebx)
29708 + movl $-EFAULT, %ss:(%ebx)
29709 jmp 7b
29710 .previous
29711
29712 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29713 + pushl_cfi %ss
29714 + popl_cfi %ds
29715 + pushl_cfi %ss
29716 + popl_cfi %es
29717 +#endif
29718 +
29719 popl_cfi %esi
29720 CFI_RESTORE esi
29721 popl_cfi %edi
29722 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29723 CFI_RESTORE ebx
29724 ret
29725 CFI_ENDPROC
29726 -ENDPROC(csum_partial_copy_generic)
29727 +ENDPROC(csum_partial_copy_generic_to_user)
29728
29729 #undef ROUND
29730 #undef ROUND1
29731 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29732 index f2145cf..cea889d 100644
29733 --- a/arch/x86/lib/clear_page_64.S
29734 +++ b/arch/x86/lib/clear_page_64.S
29735 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29736 movl $4096/8,%ecx
29737 xorl %eax,%eax
29738 rep stosq
29739 + pax_force_retaddr
29740 ret
29741 CFI_ENDPROC
29742 ENDPROC(clear_page_c)
29743 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29744 movl $4096,%ecx
29745 xorl %eax,%eax
29746 rep stosb
29747 + pax_force_retaddr
29748 ret
29749 CFI_ENDPROC
29750 ENDPROC(clear_page_c_e)
29751 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29752 leaq 64(%rdi),%rdi
29753 jnz .Lloop
29754 nop
29755 + pax_force_retaddr
29756 ret
29757 CFI_ENDPROC
29758 .Lclear_page_end:
29759 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29760
29761 #include <asm/cpufeature.h>
29762
29763 - .section .altinstr_replacement,"ax"
29764 + .section .altinstr_replacement,"a"
29765 1: .byte 0xeb /* jmp <disp8> */
29766 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29767 2: .byte 0xeb /* jmp <disp8> */
29768 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29769 index 40a1725..5d12ac4 100644
29770 --- a/arch/x86/lib/cmpxchg16b_emu.S
29771 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29772 @@ -8,6 +8,7 @@
29773 #include <linux/linkage.h>
29774 #include <asm/dwarf2.h>
29775 #include <asm/percpu.h>
29776 +#include <asm/alternative-asm.h>
29777
29778 .text
29779
29780 @@ -46,12 +47,14 @@ CFI_STARTPROC
29781 CFI_REMEMBER_STATE
29782 popfq_cfi
29783 mov $1, %al
29784 + pax_force_retaddr
29785 ret
29786
29787 CFI_RESTORE_STATE
29788 .Lnot_same:
29789 popfq_cfi
29790 xor %al,%al
29791 + pax_force_retaddr
29792 ret
29793
29794 CFI_ENDPROC
29795 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29796 index 176cca6..e0d658e 100644
29797 --- a/arch/x86/lib/copy_page_64.S
29798 +++ b/arch/x86/lib/copy_page_64.S
29799 @@ -9,6 +9,7 @@ copy_page_rep:
29800 CFI_STARTPROC
29801 movl $4096/8, %ecx
29802 rep movsq
29803 + pax_force_retaddr
29804 ret
29805 CFI_ENDPROC
29806 ENDPROC(copy_page_rep)
29807 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29808 CFI_ADJUST_CFA_OFFSET 2*8
29809 movq %rbx, (%rsp)
29810 CFI_REL_OFFSET rbx, 0
29811 - movq %r12, 1*8(%rsp)
29812 - CFI_REL_OFFSET r12, 1*8
29813 + movq %r13, 1*8(%rsp)
29814 + CFI_REL_OFFSET r13, 1*8
29815
29816 movl $(4096/64)-5, %ecx
29817 .p2align 4
29818 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29819 movq 0x8*4(%rsi), %r9
29820 movq 0x8*5(%rsi), %r10
29821 movq 0x8*6(%rsi), %r11
29822 - movq 0x8*7(%rsi), %r12
29823 + movq 0x8*7(%rsi), %r13
29824
29825 prefetcht0 5*64(%rsi)
29826
29827 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29828 movq %r9, 0x8*4(%rdi)
29829 movq %r10, 0x8*5(%rdi)
29830 movq %r11, 0x8*6(%rdi)
29831 - movq %r12, 0x8*7(%rdi)
29832 + movq %r13, 0x8*7(%rdi)
29833
29834 leaq 64 (%rsi), %rsi
29835 leaq 64 (%rdi), %rdi
29836 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29837 movq 0x8*4(%rsi), %r9
29838 movq 0x8*5(%rsi), %r10
29839 movq 0x8*6(%rsi), %r11
29840 - movq 0x8*7(%rsi), %r12
29841 + movq 0x8*7(%rsi), %r13
29842
29843 movq %rax, 0x8*0(%rdi)
29844 movq %rbx, 0x8*1(%rdi)
29845 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29846 movq %r9, 0x8*4(%rdi)
29847 movq %r10, 0x8*5(%rdi)
29848 movq %r11, 0x8*6(%rdi)
29849 - movq %r12, 0x8*7(%rdi)
29850 + movq %r13, 0x8*7(%rdi)
29851
29852 leaq 64(%rdi), %rdi
29853 leaq 64(%rsi), %rsi
29854 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29855
29856 movq (%rsp), %rbx
29857 CFI_RESTORE rbx
29858 - movq 1*8(%rsp), %r12
29859 - CFI_RESTORE r12
29860 + movq 1*8(%rsp), %r13
29861 + CFI_RESTORE r13
29862 addq $2*8, %rsp
29863 CFI_ADJUST_CFA_OFFSET -2*8
29864 + pax_force_retaddr
29865 ret
29866 .Lcopy_page_end:
29867 CFI_ENDPROC
29868 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29869
29870 #include <asm/cpufeature.h>
29871
29872 - .section .altinstr_replacement,"ax"
29873 + .section .altinstr_replacement,"a"
29874 1: .byte 0xeb /* jmp <disp8> */
29875 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29876 2:
29877 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29878 index dee945d..a84067b 100644
29879 --- a/arch/x86/lib/copy_user_64.S
29880 +++ b/arch/x86/lib/copy_user_64.S
29881 @@ -18,31 +18,7 @@
29882 #include <asm/alternative-asm.h>
29883 #include <asm/asm.h>
29884 #include <asm/smap.h>
29885 -
29886 -/*
29887 - * By placing feature2 after feature1 in altinstructions section, we logically
29888 - * implement:
29889 - * If CPU has feature2, jmp to alt2 is used
29890 - * else if CPU has feature1, jmp to alt1 is used
29891 - * else jmp to orig is used.
29892 - */
29893 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29894 -0:
29895 - .byte 0xe9 /* 32bit jump */
29896 - .long \orig-1f /* by default jump to orig */
29897 -1:
29898 - .section .altinstr_replacement,"ax"
29899 -2: .byte 0xe9 /* near jump with 32bit immediate */
29900 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29901 -3: .byte 0xe9 /* near jump with 32bit immediate */
29902 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29903 - .previous
29904 -
29905 - .section .altinstructions,"a"
29906 - altinstruction_entry 0b,2b,\feature1,5,5
29907 - altinstruction_entry 0b,3b,\feature2,5,5
29908 - .previous
29909 - .endm
29910 +#include <asm/pgtable.h>
29911
29912 .macro ALIGN_DESTINATION
29913 #ifdef FIX_ALIGNMENT
29914 @@ -70,52 +46,6 @@
29915 #endif
29916 .endm
29917
29918 -/* Standard copy_to_user with segment limit checking */
29919 -ENTRY(_copy_to_user)
29920 - CFI_STARTPROC
29921 - GET_THREAD_INFO(%rax)
29922 - movq %rdi,%rcx
29923 - addq %rdx,%rcx
29924 - jc bad_to_user
29925 - cmpq TI_addr_limit(%rax),%rcx
29926 - ja bad_to_user
29927 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29928 - copy_user_generic_unrolled,copy_user_generic_string, \
29929 - copy_user_enhanced_fast_string
29930 - CFI_ENDPROC
29931 -ENDPROC(_copy_to_user)
29932 -
29933 -/* Standard copy_from_user with segment limit checking */
29934 -ENTRY(_copy_from_user)
29935 - CFI_STARTPROC
29936 - GET_THREAD_INFO(%rax)
29937 - movq %rsi,%rcx
29938 - addq %rdx,%rcx
29939 - jc bad_from_user
29940 - cmpq TI_addr_limit(%rax),%rcx
29941 - ja bad_from_user
29942 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29943 - copy_user_generic_unrolled,copy_user_generic_string, \
29944 - copy_user_enhanced_fast_string
29945 - CFI_ENDPROC
29946 -ENDPROC(_copy_from_user)
29947 -
29948 - .section .fixup,"ax"
29949 - /* must zero dest */
29950 -ENTRY(bad_from_user)
29951 -bad_from_user:
29952 - CFI_STARTPROC
29953 - movl %edx,%ecx
29954 - xorl %eax,%eax
29955 - rep
29956 - stosb
29957 -bad_to_user:
29958 - movl %edx,%eax
29959 - ret
29960 - CFI_ENDPROC
29961 -ENDPROC(bad_from_user)
29962 - .previous
29963 -
29964 /*
29965 * copy_user_generic_unrolled - memory copy with exception handling.
29966 * This version is for CPUs like P4 that don't have efficient micro
29967 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29968 */
29969 ENTRY(copy_user_generic_unrolled)
29970 CFI_STARTPROC
29971 + ASM_PAX_OPEN_USERLAND
29972 ASM_STAC
29973 cmpl $8,%edx
29974 jb 20f /* less then 8 bytes, go to byte copy loop */
29975 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29976 jnz 21b
29977 23: xor %eax,%eax
29978 ASM_CLAC
29979 + ASM_PAX_CLOSE_USERLAND
29980 + pax_force_retaddr
29981 ret
29982
29983 .section .fixup,"ax"
29984 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29985 */
29986 ENTRY(copy_user_generic_string)
29987 CFI_STARTPROC
29988 + ASM_PAX_OPEN_USERLAND
29989 ASM_STAC
29990 cmpl $8,%edx
29991 jb 2f /* less than 8 bytes, go to byte copy loop */
29992 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29993 movsb
29994 xorl %eax,%eax
29995 ASM_CLAC
29996 + ASM_PAX_CLOSE_USERLAND
29997 + pax_force_retaddr
29998 ret
29999
30000 .section .fixup,"ax"
30001 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30002 */
30003 ENTRY(copy_user_enhanced_fast_string)
30004 CFI_STARTPROC
30005 + ASM_PAX_OPEN_USERLAND
30006 ASM_STAC
30007 movl %edx,%ecx
30008 1: rep
30009 movsb
30010 xorl %eax,%eax
30011 ASM_CLAC
30012 + ASM_PAX_CLOSE_USERLAND
30013 + pax_force_retaddr
30014 ret
30015
30016 .section .fixup,"ax"
30017 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30018 index 6a4f43c..c70fb52 100644
30019 --- a/arch/x86/lib/copy_user_nocache_64.S
30020 +++ b/arch/x86/lib/copy_user_nocache_64.S
30021 @@ -8,6 +8,7 @@
30022
30023 #include <linux/linkage.h>
30024 #include <asm/dwarf2.h>
30025 +#include <asm/alternative-asm.h>
30026
30027 #define FIX_ALIGNMENT 1
30028
30029 @@ -16,6 +17,7 @@
30030 #include <asm/thread_info.h>
30031 #include <asm/asm.h>
30032 #include <asm/smap.h>
30033 +#include <asm/pgtable.h>
30034
30035 .macro ALIGN_DESTINATION
30036 #ifdef FIX_ALIGNMENT
30037 @@ -49,6 +51,16 @@
30038 */
30039 ENTRY(__copy_user_nocache)
30040 CFI_STARTPROC
30041 +
30042 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30043 + mov pax_user_shadow_base,%rcx
30044 + cmp %rcx,%rsi
30045 + jae 1f
30046 + add %rcx,%rsi
30047 +1:
30048 +#endif
30049 +
30050 + ASM_PAX_OPEN_USERLAND
30051 ASM_STAC
30052 cmpl $8,%edx
30053 jb 20f /* less then 8 bytes, go to byte copy loop */
30054 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30055 jnz 21b
30056 23: xorl %eax,%eax
30057 ASM_CLAC
30058 + ASM_PAX_CLOSE_USERLAND
30059 sfence
30060 + pax_force_retaddr
30061 ret
30062
30063 .section .fixup,"ax"
30064 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30065 index 2419d5f..fe52d0e 100644
30066 --- a/arch/x86/lib/csum-copy_64.S
30067 +++ b/arch/x86/lib/csum-copy_64.S
30068 @@ -9,6 +9,7 @@
30069 #include <asm/dwarf2.h>
30070 #include <asm/errno.h>
30071 #include <asm/asm.h>
30072 +#include <asm/alternative-asm.h>
30073
30074 /*
30075 * Checksum copy with exception handling.
30076 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30077 CFI_ADJUST_CFA_OFFSET 7*8
30078 movq %rbx, 2*8(%rsp)
30079 CFI_REL_OFFSET rbx, 2*8
30080 - movq %r12, 3*8(%rsp)
30081 - CFI_REL_OFFSET r12, 3*8
30082 + movq %r15, 3*8(%rsp)
30083 + CFI_REL_OFFSET r15, 3*8
30084 movq %r14, 4*8(%rsp)
30085 CFI_REL_OFFSET r14, 4*8
30086 movq %r13, 5*8(%rsp)
30087 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30088 movl %edx, %ecx
30089
30090 xorl %r9d, %r9d
30091 - movq %rcx, %r12
30092 + movq %rcx, %r15
30093
30094 - shrq $6, %r12
30095 + shrq $6, %r15
30096 jz .Lhandle_tail /* < 64 */
30097
30098 clc
30099
30100 /* main loop. clear in 64 byte blocks */
30101 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30102 - /* r11: temp3, rdx: temp4, r12 loopcnt */
30103 + /* r11: temp3, rdx: temp4, r15 loopcnt */
30104 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30105 .p2align 4
30106 .Lloop:
30107 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30108 adcq %r14, %rax
30109 adcq %r13, %rax
30110
30111 - decl %r12d
30112 + decl %r15d
30113
30114 dest
30115 movq %rbx, (%rsi)
30116 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30117 .Lende:
30118 movq 2*8(%rsp), %rbx
30119 CFI_RESTORE rbx
30120 - movq 3*8(%rsp), %r12
30121 - CFI_RESTORE r12
30122 + movq 3*8(%rsp), %r15
30123 + CFI_RESTORE r15
30124 movq 4*8(%rsp), %r14
30125 CFI_RESTORE r14
30126 movq 5*8(%rsp), %r13
30127 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30128 CFI_RESTORE rbp
30129 addq $7*8, %rsp
30130 CFI_ADJUST_CFA_OFFSET -7*8
30131 + pax_force_retaddr
30132 ret
30133 CFI_RESTORE_STATE
30134
30135 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30136 index 1318f75..44c30fd 100644
30137 --- a/arch/x86/lib/csum-wrappers_64.c
30138 +++ b/arch/x86/lib/csum-wrappers_64.c
30139 @@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30140 len -= 2;
30141 }
30142 }
30143 + pax_open_userland();
30144 stac();
30145 - isum = csum_partial_copy_generic((__force const void *)src,
30146 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30147 dst, len, isum, errp, NULL);
30148 clac();
30149 + pax_close_userland();
30150 if (unlikely(*errp))
30151 goto out_err;
30152
30153 @@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30154 }
30155
30156 *errp = 0;
30157 + pax_open_userland();
30158 stac();
30159 - ret = csum_partial_copy_generic(src, (void __force *)dst,
30160 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30161 len, isum, NULL, errp);
30162 clac();
30163 + pax_close_userland();
30164 return ret;
30165 }
30166 EXPORT_SYMBOL(csum_partial_copy_to_user);
30167 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30168 index a451235..1daa956 100644
30169 --- a/arch/x86/lib/getuser.S
30170 +++ b/arch/x86/lib/getuser.S
30171 @@ -33,17 +33,40 @@
30172 #include <asm/thread_info.h>
30173 #include <asm/asm.h>
30174 #include <asm/smap.h>
30175 +#include <asm/segment.h>
30176 +#include <asm/pgtable.h>
30177 +#include <asm/alternative-asm.h>
30178 +
30179 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30180 +#define __copyuser_seg gs;
30181 +#else
30182 +#define __copyuser_seg
30183 +#endif
30184
30185 .text
30186 ENTRY(__get_user_1)
30187 CFI_STARTPROC
30188 +
30189 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30190 GET_THREAD_INFO(%_ASM_DX)
30191 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30192 jae bad_get_user
30193 ASM_STAC
30194 -1: movzbl (%_ASM_AX),%edx
30195 +
30196 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30197 + mov pax_user_shadow_base,%_ASM_DX
30198 + cmp %_ASM_DX,%_ASM_AX
30199 + jae 1234f
30200 + add %_ASM_DX,%_ASM_AX
30201 +1234:
30202 +#endif
30203 +
30204 +#endif
30205 +
30206 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30207 xor %eax,%eax
30208 ASM_CLAC
30209 + pax_force_retaddr
30210 ret
30211 CFI_ENDPROC
30212 ENDPROC(__get_user_1)
30213 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30214 ENTRY(__get_user_2)
30215 CFI_STARTPROC
30216 add $1,%_ASM_AX
30217 +
30218 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30219 jc bad_get_user
30220 GET_THREAD_INFO(%_ASM_DX)
30221 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30222 jae bad_get_user
30223 ASM_STAC
30224 -2: movzwl -1(%_ASM_AX),%edx
30225 +
30226 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30227 + mov pax_user_shadow_base,%_ASM_DX
30228 + cmp %_ASM_DX,%_ASM_AX
30229 + jae 1234f
30230 + add %_ASM_DX,%_ASM_AX
30231 +1234:
30232 +#endif
30233 +
30234 +#endif
30235 +
30236 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30237 xor %eax,%eax
30238 ASM_CLAC
30239 + pax_force_retaddr
30240 ret
30241 CFI_ENDPROC
30242 ENDPROC(__get_user_2)
30243 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30244 ENTRY(__get_user_4)
30245 CFI_STARTPROC
30246 add $3,%_ASM_AX
30247 +
30248 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30249 jc bad_get_user
30250 GET_THREAD_INFO(%_ASM_DX)
30251 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30252 jae bad_get_user
30253 ASM_STAC
30254 -3: movl -3(%_ASM_AX),%edx
30255 +
30256 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30257 + mov pax_user_shadow_base,%_ASM_DX
30258 + cmp %_ASM_DX,%_ASM_AX
30259 + jae 1234f
30260 + add %_ASM_DX,%_ASM_AX
30261 +1234:
30262 +#endif
30263 +
30264 +#endif
30265 +
30266 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30267 xor %eax,%eax
30268 ASM_CLAC
30269 + pax_force_retaddr
30270 ret
30271 CFI_ENDPROC
30272 ENDPROC(__get_user_4)
30273 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30274 GET_THREAD_INFO(%_ASM_DX)
30275 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30276 jae bad_get_user
30277 +
30278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30279 + mov pax_user_shadow_base,%_ASM_DX
30280 + cmp %_ASM_DX,%_ASM_AX
30281 + jae 1234f
30282 + add %_ASM_DX,%_ASM_AX
30283 +1234:
30284 +#endif
30285 +
30286 ASM_STAC
30287 4: movq -7(%_ASM_AX),%rdx
30288 xor %eax,%eax
30289 ASM_CLAC
30290 + pax_force_retaddr
30291 ret
30292 #else
30293 add $7,%_ASM_AX
30294 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30295 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30296 jae bad_get_user_8
30297 ASM_STAC
30298 -4: movl -7(%_ASM_AX),%edx
30299 -5: movl -3(%_ASM_AX),%ecx
30300 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30301 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30302 xor %eax,%eax
30303 ASM_CLAC
30304 + pax_force_retaddr
30305 ret
30306 #endif
30307 CFI_ENDPROC
30308 @@ -113,6 +175,7 @@ bad_get_user:
30309 xor %edx,%edx
30310 mov $(-EFAULT),%_ASM_AX
30311 ASM_CLAC
30312 + pax_force_retaddr
30313 ret
30314 CFI_ENDPROC
30315 END(bad_get_user)
30316 @@ -124,6 +187,7 @@ bad_get_user_8:
30317 xor %ecx,%ecx
30318 mov $(-EFAULT),%_ASM_AX
30319 ASM_CLAC
30320 + pax_force_retaddr
30321 ret
30322 CFI_ENDPROC
30323 END(bad_get_user_8)
30324 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30325 index 54fcffe..7be149e 100644
30326 --- a/arch/x86/lib/insn.c
30327 +++ b/arch/x86/lib/insn.c
30328 @@ -20,8 +20,10 @@
30329
30330 #ifdef __KERNEL__
30331 #include <linux/string.h>
30332 +#include <asm/pgtable_types.h>
30333 #else
30334 #include <string.h>
30335 +#define ktla_ktva(addr) addr
30336 #endif
30337 #include <asm/inat.h>
30338 #include <asm/insn.h>
30339 @@ -53,8 +55,8 @@
30340 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30341 {
30342 memset(insn, 0, sizeof(*insn));
30343 - insn->kaddr = kaddr;
30344 - insn->next_byte = kaddr;
30345 + insn->kaddr = ktla_ktva(kaddr);
30346 + insn->next_byte = ktla_ktva(kaddr);
30347 insn->x86_64 = x86_64 ? 1 : 0;
30348 insn->opnd_bytes = 4;
30349 if (x86_64)
30350 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30351 index 05a95e7..326f2fa 100644
30352 --- a/arch/x86/lib/iomap_copy_64.S
30353 +++ b/arch/x86/lib/iomap_copy_64.S
30354 @@ -17,6 +17,7 @@
30355
30356 #include <linux/linkage.h>
30357 #include <asm/dwarf2.h>
30358 +#include <asm/alternative-asm.h>
30359
30360 /*
30361 * override generic version in lib/iomap_copy.c
30362 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30363 CFI_STARTPROC
30364 movl %edx,%ecx
30365 rep movsd
30366 + pax_force_retaddr
30367 ret
30368 CFI_ENDPROC
30369 ENDPROC(__iowrite32_copy)
30370 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30371 index 56313a3..0db417e 100644
30372 --- a/arch/x86/lib/memcpy_64.S
30373 +++ b/arch/x86/lib/memcpy_64.S
30374 @@ -24,7 +24,7 @@
30375 * This gets patched over the unrolled variant (below) via the
30376 * alternative instructions framework:
30377 */
30378 - .section .altinstr_replacement, "ax", @progbits
30379 + .section .altinstr_replacement, "a", @progbits
30380 .Lmemcpy_c:
30381 movq %rdi, %rax
30382 movq %rdx, %rcx
30383 @@ -33,6 +33,7 @@
30384 rep movsq
30385 movl %edx, %ecx
30386 rep movsb
30387 + pax_force_retaddr
30388 ret
30389 .Lmemcpy_e:
30390 .previous
30391 @@ -44,11 +45,12 @@
30392 * This gets patched over the unrolled variant (below) via the
30393 * alternative instructions framework:
30394 */
30395 - .section .altinstr_replacement, "ax", @progbits
30396 + .section .altinstr_replacement, "a", @progbits
30397 .Lmemcpy_c_e:
30398 movq %rdi, %rax
30399 movq %rdx, %rcx
30400 rep movsb
30401 + pax_force_retaddr
30402 ret
30403 .Lmemcpy_e_e:
30404 .previous
30405 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30406 movq %r9, 1*8(%rdi)
30407 movq %r10, -2*8(%rdi, %rdx)
30408 movq %r11, -1*8(%rdi, %rdx)
30409 + pax_force_retaddr
30410 retq
30411 .p2align 4
30412 .Lless_16bytes:
30413 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30414 movq -1*8(%rsi, %rdx), %r9
30415 movq %r8, 0*8(%rdi)
30416 movq %r9, -1*8(%rdi, %rdx)
30417 + pax_force_retaddr
30418 retq
30419 .p2align 4
30420 .Lless_8bytes:
30421 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30422 movl -4(%rsi, %rdx), %r8d
30423 movl %ecx, (%rdi)
30424 movl %r8d, -4(%rdi, %rdx)
30425 + pax_force_retaddr
30426 retq
30427 .p2align 4
30428 .Lless_3bytes:
30429 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30430 movb %cl, (%rdi)
30431
30432 .Lend:
30433 + pax_force_retaddr
30434 retq
30435 CFI_ENDPROC
30436 ENDPROC(memcpy)
30437 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30438 index 65268a6..dd1de11 100644
30439 --- a/arch/x86/lib/memmove_64.S
30440 +++ b/arch/x86/lib/memmove_64.S
30441 @@ -202,14 +202,16 @@ ENTRY(memmove)
30442 movb (%rsi), %r11b
30443 movb %r11b, (%rdi)
30444 13:
30445 + pax_force_retaddr
30446 retq
30447 CFI_ENDPROC
30448
30449 - .section .altinstr_replacement,"ax"
30450 + .section .altinstr_replacement,"a"
30451 .Lmemmove_begin_forward_efs:
30452 /* Forward moving data. */
30453 movq %rdx, %rcx
30454 rep movsb
30455 + pax_force_retaddr
30456 retq
30457 .Lmemmove_end_forward_efs:
30458 .previous
30459 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30460 index 2dcb380..2eb79fe 100644
30461 --- a/arch/x86/lib/memset_64.S
30462 +++ b/arch/x86/lib/memset_64.S
30463 @@ -16,7 +16,7 @@
30464 *
30465 * rax original destination
30466 */
30467 - .section .altinstr_replacement, "ax", @progbits
30468 + .section .altinstr_replacement, "a", @progbits
30469 .Lmemset_c:
30470 movq %rdi,%r9
30471 movq %rdx,%rcx
30472 @@ -30,6 +30,7 @@
30473 movl %edx,%ecx
30474 rep stosb
30475 movq %r9,%rax
30476 + pax_force_retaddr
30477 ret
30478 .Lmemset_e:
30479 .previous
30480 @@ -45,13 +46,14 @@
30481 *
30482 * rax original destination
30483 */
30484 - .section .altinstr_replacement, "ax", @progbits
30485 + .section .altinstr_replacement, "a", @progbits
30486 .Lmemset_c_e:
30487 movq %rdi,%r9
30488 movb %sil,%al
30489 movq %rdx,%rcx
30490 rep stosb
30491 movq %r9,%rax
30492 + pax_force_retaddr
30493 ret
30494 .Lmemset_e_e:
30495 .previous
30496 @@ -118,6 +120,7 @@ ENTRY(__memset)
30497
30498 .Lende:
30499 movq %r10,%rax
30500 + pax_force_retaddr
30501 ret
30502
30503 CFI_RESTORE_STATE
30504 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30505 index c9f2d9b..e7fd2c0 100644
30506 --- a/arch/x86/lib/mmx_32.c
30507 +++ b/arch/x86/lib/mmx_32.c
30508 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30509 {
30510 void *p;
30511 int i;
30512 + unsigned long cr0;
30513
30514 if (unlikely(in_interrupt()))
30515 return __memcpy(to, from, len);
30516 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30517 kernel_fpu_begin();
30518
30519 __asm__ __volatile__ (
30520 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30521 - " prefetch 64(%0)\n"
30522 - " prefetch 128(%0)\n"
30523 - " prefetch 192(%0)\n"
30524 - " prefetch 256(%0)\n"
30525 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30526 + " prefetch 64(%1)\n"
30527 + " prefetch 128(%1)\n"
30528 + " prefetch 192(%1)\n"
30529 + " prefetch 256(%1)\n"
30530 "2: \n"
30531 ".section .fixup, \"ax\"\n"
30532 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30533 + "3: \n"
30534 +
30535 +#ifdef CONFIG_PAX_KERNEXEC
30536 + " movl %%cr0, %0\n"
30537 + " movl %0, %%eax\n"
30538 + " andl $0xFFFEFFFF, %%eax\n"
30539 + " movl %%eax, %%cr0\n"
30540 +#endif
30541 +
30542 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30543 +
30544 +#ifdef CONFIG_PAX_KERNEXEC
30545 + " movl %0, %%cr0\n"
30546 +#endif
30547 +
30548 " jmp 2b\n"
30549 ".previous\n"
30550 _ASM_EXTABLE(1b, 3b)
30551 - : : "r" (from));
30552 + : "=&r" (cr0) : "r" (from) : "ax");
30553
30554 for ( ; i > 5; i--) {
30555 __asm__ __volatile__ (
30556 - "1: prefetch 320(%0)\n"
30557 - "2: movq (%0), %%mm0\n"
30558 - " movq 8(%0), %%mm1\n"
30559 - " movq 16(%0), %%mm2\n"
30560 - " movq 24(%0), %%mm3\n"
30561 - " movq %%mm0, (%1)\n"
30562 - " movq %%mm1, 8(%1)\n"
30563 - " movq %%mm2, 16(%1)\n"
30564 - " movq %%mm3, 24(%1)\n"
30565 - " movq 32(%0), %%mm0\n"
30566 - " movq 40(%0), %%mm1\n"
30567 - " movq 48(%0), %%mm2\n"
30568 - " movq 56(%0), %%mm3\n"
30569 - " movq %%mm0, 32(%1)\n"
30570 - " movq %%mm1, 40(%1)\n"
30571 - " movq %%mm2, 48(%1)\n"
30572 - " movq %%mm3, 56(%1)\n"
30573 + "1: prefetch 320(%1)\n"
30574 + "2: movq (%1), %%mm0\n"
30575 + " movq 8(%1), %%mm1\n"
30576 + " movq 16(%1), %%mm2\n"
30577 + " movq 24(%1), %%mm3\n"
30578 + " movq %%mm0, (%2)\n"
30579 + " movq %%mm1, 8(%2)\n"
30580 + " movq %%mm2, 16(%2)\n"
30581 + " movq %%mm3, 24(%2)\n"
30582 + " movq 32(%1), %%mm0\n"
30583 + " movq 40(%1), %%mm1\n"
30584 + " movq 48(%1), %%mm2\n"
30585 + " movq 56(%1), %%mm3\n"
30586 + " movq %%mm0, 32(%2)\n"
30587 + " movq %%mm1, 40(%2)\n"
30588 + " movq %%mm2, 48(%2)\n"
30589 + " movq %%mm3, 56(%2)\n"
30590 ".section .fixup, \"ax\"\n"
30591 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30592 + "3:\n"
30593 +
30594 +#ifdef CONFIG_PAX_KERNEXEC
30595 + " movl %%cr0, %0\n"
30596 + " movl %0, %%eax\n"
30597 + " andl $0xFFFEFFFF, %%eax\n"
30598 + " movl %%eax, %%cr0\n"
30599 +#endif
30600 +
30601 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30602 +
30603 +#ifdef CONFIG_PAX_KERNEXEC
30604 + " movl %0, %%cr0\n"
30605 +#endif
30606 +
30607 " jmp 2b\n"
30608 ".previous\n"
30609 _ASM_EXTABLE(1b, 3b)
30610 - : : "r" (from), "r" (to) : "memory");
30611 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30612
30613 from += 64;
30614 to += 64;
30615 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30616 static void fast_copy_page(void *to, void *from)
30617 {
30618 int i;
30619 + unsigned long cr0;
30620
30621 kernel_fpu_begin();
30622
30623 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30624 * but that is for later. -AV
30625 */
30626 __asm__ __volatile__(
30627 - "1: prefetch (%0)\n"
30628 - " prefetch 64(%0)\n"
30629 - " prefetch 128(%0)\n"
30630 - " prefetch 192(%0)\n"
30631 - " prefetch 256(%0)\n"
30632 + "1: prefetch (%1)\n"
30633 + " prefetch 64(%1)\n"
30634 + " prefetch 128(%1)\n"
30635 + " prefetch 192(%1)\n"
30636 + " prefetch 256(%1)\n"
30637 "2: \n"
30638 ".section .fixup, \"ax\"\n"
30639 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30640 + "3: \n"
30641 +
30642 +#ifdef CONFIG_PAX_KERNEXEC
30643 + " movl %%cr0, %0\n"
30644 + " movl %0, %%eax\n"
30645 + " andl $0xFFFEFFFF, %%eax\n"
30646 + " movl %%eax, %%cr0\n"
30647 +#endif
30648 +
30649 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30650 +
30651 +#ifdef CONFIG_PAX_KERNEXEC
30652 + " movl %0, %%cr0\n"
30653 +#endif
30654 +
30655 " jmp 2b\n"
30656 ".previous\n"
30657 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30658 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30659
30660 for (i = 0; i < (4096-320)/64; i++) {
30661 __asm__ __volatile__ (
30662 - "1: prefetch 320(%0)\n"
30663 - "2: movq (%0), %%mm0\n"
30664 - " movntq %%mm0, (%1)\n"
30665 - " movq 8(%0), %%mm1\n"
30666 - " movntq %%mm1, 8(%1)\n"
30667 - " movq 16(%0), %%mm2\n"
30668 - " movntq %%mm2, 16(%1)\n"
30669 - " movq 24(%0), %%mm3\n"
30670 - " movntq %%mm3, 24(%1)\n"
30671 - " movq 32(%0), %%mm4\n"
30672 - " movntq %%mm4, 32(%1)\n"
30673 - " movq 40(%0), %%mm5\n"
30674 - " movntq %%mm5, 40(%1)\n"
30675 - " movq 48(%0), %%mm6\n"
30676 - " movntq %%mm6, 48(%1)\n"
30677 - " movq 56(%0), %%mm7\n"
30678 - " movntq %%mm7, 56(%1)\n"
30679 + "1: prefetch 320(%1)\n"
30680 + "2: movq (%1), %%mm0\n"
30681 + " movntq %%mm0, (%2)\n"
30682 + " movq 8(%1), %%mm1\n"
30683 + " movntq %%mm1, 8(%2)\n"
30684 + " movq 16(%1), %%mm2\n"
30685 + " movntq %%mm2, 16(%2)\n"
30686 + " movq 24(%1), %%mm3\n"
30687 + " movntq %%mm3, 24(%2)\n"
30688 + " movq 32(%1), %%mm4\n"
30689 + " movntq %%mm4, 32(%2)\n"
30690 + " movq 40(%1), %%mm5\n"
30691 + " movntq %%mm5, 40(%2)\n"
30692 + " movq 48(%1), %%mm6\n"
30693 + " movntq %%mm6, 48(%2)\n"
30694 + " movq 56(%1), %%mm7\n"
30695 + " movntq %%mm7, 56(%2)\n"
30696 ".section .fixup, \"ax\"\n"
30697 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30698 + "3:\n"
30699 +
30700 +#ifdef CONFIG_PAX_KERNEXEC
30701 + " movl %%cr0, %0\n"
30702 + " movl %0, %%eax\n"
30703 + " andl $0xFFFEFFFF, %%eax\n"
30704 + " movl %%eax, %%cr0\n"
30705 +#endif
30706 +
30707 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30708 +
30709 +#ifdef CONFIG_PAX_KERNEXEC
30710 + " movl %0, %%cr0\n"
30711 +#endif
30712 +
30713 " jmp 2b\n"
30714 ".previous\n"
30715 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30716 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30717
30718 from += 64;
30719 to += 64;
30720 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30721 static void fast_copy_page(void *to, void *from)
30722 {
30723 int i;
30724 + unsigned long cr0;
30725
30726 kernel_fpu_begin();
30727
30728 __asm__ __volatile__ (
30729 - "1: prefetch (%0)\n"
30730 - " prefetch 64(%0)\n"
30731 - " prefetch 128(%0)\n"
30732 - " prefetch 192(%0)\n"
30733 - " prefetch 256(%0)\n"
30734 + "1: prefetch (%1)\n"
30735 + " prefetch 64(%1)\n"
30736 + " prefetch 128(%1)\n"
30737 + " prefetch 192(%1)\n"
30738 + " prefetch 256(%1)\n"
30739 "2: \n"
30740 ".section .fixup, \"ax\"\n"
30741 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30742 + "3: \n"
30743 +
30744 +#ifdef CONFIG_PAX_KERNEXEC
30745 + " movl %%cr0, %0\n"
30746 + " movl %0, %%eax\n"
30747 + " andl $0xFFFEFFFF, %%eax\n"
30748 + " movl %%eax, %%cr0\n"
30749 +#endif
30750 +
30751 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30752 +
30753 +#ifdef CONFIG_PAX_KERNEXEC
30754 + " movl %0, %%cr0\n"
30755 +#endif
30756 +
30757 " jmp 2b\n"
30758 ".previous\n"
30759 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30760 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30761
30762 for (i = 0; i < 4096/64; i++) {
30763 __asm__ __volatile__ (
30764 - "1: prefetch 320(%0)\n"
30765 - "2: movq (%0), %%mm0\n"
30766 - " movq 8(%0), %%mm1\n"
30767 - " movq 16(%0), %%mm2\n"
30768 - " movq 24(%0), %%mm3\n"
30769 - " movq %%mm0, (%1)\n"
30770 - " movq %%mm1, 8(%1)\n"
30771 - " movq %%mm2, 16(%1)\n"
30772 - " movq %%mm3, 24(%1)\n"
30773 - " movq 32(%0), %%mm0\n"
30774 - " movq 40(%0), %%mm1\n"
30775 - " movq 48(%0), %%mm2\n"
30776 - " movq 56(%0), %%mm3\n"
30777 - " movq %%mm0, 32(%1)\n"
30778 - " movq %%mm1, 40(%1)\n"
30779 - " movq %%mm2, 48(%1)\n"
30780 - " movq %%mm3, 56(%1)\n"
30781 + "1: prefetch 320(%1)\n"
30782 + "2: movq (%1), %%mm0\n"
30783 + " movq 8(%1), %%mm1\n"
30784 + " movq 16(%1), %%mm2\n"
30785 + " movq 24(%1), %%mm3\n"
30786 + " movq %%mm0, (%2)\n"
30787 + " movq %%mm1, 8(%2)\n"
30788 + " movq %%mm2, 16(%2)\n"
30789 + " movq %%mm3, 24(%2)\n"
30790 + " movq 32(%1), %%mm0\n"
30791 + " movq 40(%1), %%mm1\n"
30792 + " movq 48(%1), %%mm2\n"
30793 + " movq 56(%1), %%mm3\n"
30794 + " movq %%mm0, 32(%2)\n"
30795 + " movq %%mm1, 40(%2)\n"
30796 + " movq %%mm2, 48(%2)\n"
30797 + " movq %%mm3, 56(%2)\n"
30798 ".section .fixup, \"ax\"\n"
30799 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30800 + "3:\n"
30801 +
30802 +#ifdef CONFIG_PAX_KERNEXEC
30803 + " movl %%cr0, %0\n"
30804 + " movl %0, %%eax\n"
30805 + " andl $0xFFFEFFFF, %%eax\n"
30806 + " movl %%eax, %%cr0\n"
30807 +#endif
30808 +
30809 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30810 +
30811 +#ifdef CONFIG_PAX_KERNEXEC
30812 + " movl %0, %%cr0\n"
30813 +#endif
30814 +
30815 " jmp 2b\n"
30816 ".previous\n"
30817 _ASM_EXTABLE(1b, 3b)
30818 - : : "r" (from), "r" (to) : "memory");
30819 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30820
30821 from += 64;
30822 to += 64;
30823 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30824 index f6d13ee..d789440 100644
30825 --- a/arch/x86/lib/msr-reg.S
30826 +++ b/arch/x86/lib/msr-reg.S
30827 @@ -3,6 +3,7 @@
30828 #include <asm/dwarf2.h>
30829 #include <asm/asm.h>
30830 #include <asm/msr.h>
30831 +#include <asm/alternative-asm.h>
30832
30833 #ifdef CONFIG_X86_64
30834 /*
30835 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30836 movl %edi, 28(%r10)
30837 popq_cfi %rbp
30838 popq_cfi %rbx
30839 + pax_force_retaddr
30840 ret
30841 3:
30842 CFI_RESTORE_STATE
30843 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30844 index fc6ba17..d4d989d 100644
30845 --- a/arch/x86/lib/putuser.S
30846 +++ b/arch/x86/lib/putuser.S
30847 @@ -16,7 +16,9 @@
30848 #include <asm/errno.h>
30849 #include <asm/asm.h>
30850 #include <asm/smap.h>
30851 -
30852 +#include <asm/segment.h>
30853 +#include <asm/pgtable.h>
30854 +#include <asm/alternative-asm.h>
30855
30856 /*
30857 * __put_user_X
30858 @@ -30,57 +32,125 @@
30859 * as they get called from within inline assembly.
30860 */
30861
30862 -#define ENTER CFI_STARTPROC ; \
30863 - GET_THREAD_INFO(%_ASM_BX)
30864 -#define EXIT ASM_CLAC ; \
30865 - ret ; \
30866 +#define ENTER CFI_STARTPROC
30867 +#define EXIT ASM_CLAC ; \
30868 + pax_force_retaddr ; \
30869 + ret ; \
30870 CFI_ENDPROC
30871
30872 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30873 +#define _DEST %_ASM_CX,%_ASM_BX
30874 +#else
30875 +#define _DEST %_ASM_CX
30876 +#endif
30877 +
30878 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30879 +#define __copyuser_seg gs;
30880 +#else
30881 +#define __copyuser_seg
30882 +#endif
30883 +
30884 .text
30885 ENTRY(__put_user_1)
30886 ENTER
30887 +
30888 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30889 + GET_THREAD_INFO(%_ASM_BX)
30890 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30891 jae bad_put_user
30892 ASM_STAC
30893 -1: movb %al,(%_ASM_CX)
30894 +
30895 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30896 + mov pax_user_shadow_base,%_ASM_BX
30897 + cmp %_ASM_BX,%_ASM_CX
30898 + jb 1234f
30899 + xor %ebx,%ebx
30900 +1234:
30901 +#endif
30902 +
30903 +#endif
30904 +
30905 +1: __copyuser_seg movb %al,(_DEST)
30906 xor %eax,%eax
30907 EXIT
30908 ENDPROC(__put_user_1)
30909
30910 ENTRY(__put_user_2)
30911 ENTER
30912 +
30913 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30914 + GET_THREAD_INFO(%_ASM_BX)
30915 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30916 sub $1,%_ASM_BX
30917 cmp %_ASM_BX,%_ASM_CX
30918 jae bad_put_user
30919 ASM_STAC
30920 -2: movw %ax,(%_ASM_CX)
30921 +
30922 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30923 + mov pax_user_shadow_base,%_ASM_BX
30924 + cmp %_ASM_BX,%_ASM_CX
30925 + jb 1234f
30926 + xor %ebx,%ebx
30927 +1234:
30928 +#endif
30929 +
30930 +#endif
30931 +
30932 +2: __copyuser_seg movw %ax,(_DEST)
30933 xor %eax,%eax
30934 EXIT
30935 ENDPROC(__put_user_2)
30936
30937 ENTRY(__put_user_4)
30938 ENTER
30939 +
30940 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30941 + GET_THREAD_INFO(%_ASM_BX)
30942 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30943 sub $3,%_ASM_BX
30944 cmp %_ASM_BX,%_ASM_CX
30945 jae bad_put_user
30946 ASM_STAC
30947 -3: movl %eax,(%_ASM_CX)
30948 +
30949 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30950 + mov pax_user_shadow_base,%_ASM_BX
30951 + cmp %_ASM_BX,%_ASM_CX
30952 + jb 1234f
30953 + xor %ebx,%ebx
30954 +1234:
30955 +#endif
30956 +
30957 +#endif
30958 +
30959 +3: __copyuser_seg movl %eax,(_DEST)
30960 xor %eax,%eax
30961 EXIT
30962 ENDPROC(__put_user_4)
30963
30964 ENTRY(__put_user_8)
30965 ENTER
30966 +
30967 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30968 + GET_THREAD_INFO(%_ASM_BX)
30969 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30970 sub $7,%_ASM_BX
30971 cmp %_ASM_BX,%_ASM_CX
30972 jae bad_put_user
30973 ASM_STAC
30974 -4: mov %_ASM_AX,(%_ASM_CX)
30975 +
30976 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30977 + mov pax_user_shadow_base,%_ASM_BX
30978 + cmp %_ASM_BX,%_ASM_CX
30979 + jb 1234f
30980 + xor %ebx,%ebx
30981 +1234:
30982 +#endif
30983 +
30984 +#endif
30985 +
30986 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30987 #ifdef CONFIG_X86_32
30988 -5: movl %edx,4(%_ASM_CX)
30989 +5: __copyuser_seg movl %edx,4(_DEST)
30990 #endif
30991 xor %eax,%eax
30992 EXIT
30993 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30994 index 5dff5f0..cadebf4 100644
30995 --- a/arch/x86/lib/rwsem.S
30996 +++ b/arch/x86/lib/rwsem.S
30997 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30998 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30999 CFI_RESTORE __ASM_REG(dx)
31000 restore_common_regs
31001 + pax_force_retaddr
31002 ret
31003 CFI_ENDPROC
31004 ENDPROC(call_rwsem_down_read_failed)
31005 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31006 movq %rax,%rdi
31007 call rwsem_down_write_failed
31008 restore_common_regs
31009 + pax_force_retaddr
31010 ret
31011 CFI_ENDPROC
31012 ENDPROC(call_rwsem_down_write_failed)
31013 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31014 movq %rax,%rdi
31015 call rwsem_wake
31016 restore_common_regs
31017 -1: ret
31018 +1: pax_force_retaddr
31019 + ret
31020 CFI_ENDPROC
31021 ENDPROC(call_rwsem_wake)
31022
31023 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31024 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31025 CFI_RESTORE __ASM_REG(dx)
31026 restore_common_regs
31027 + pax_force_retaddr
31028 ret
31029 CFI_ENDPROC
31030 ENDPROC(call_rwsem_downgrade_wake)
31031 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31032 index b30b5eb..2b57052 100644
31033 --- a/arch/x86/lib/thunk_64.S
31034 +++ b/arch/x86/lib/thunk_64.S
31035 @@ -9,6 +9,7 @@
31036 #include <asm/dwarf2.h>
31037 #include <asm/calling.h>
31038 #include <asm/asm.h>
31039 +#include <asm/alternative-asm.h>
31040
31041 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31042 .macro THUNK name, func, put_ret_addr_in_rdi=0
31043 @@ -16,11 +17,11 @@
31044 \name:
31045 CFI_STARTPROC
31046
31047 - /* this one pushes 9 elems, the next one would be %rIP */
31048 - SAVE_ARGS
31049 + /* this one pushes 15+1 elems, the next one would be %rIP */
31050 + SAVE_ARGS 8
31051
31052 .if \put_ret_addr_in_rdi
31053 - movq_cfi_restore 9*8, rdi
31054 + movq_cfi_restore RIP, rdi
31055 .endif
31056
31057 call \func
31058 @@ -47,9 +48,10 @@
31059
31060 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31061 CFI_STARTPROC
31062 - SAVE_ARGS
31063 + SAVE_ARGS 8
31064 restore:
31065 - RESTORE_ARGS
31066 + RESTORE_ARGS 1,8
31067 + pax_force_retaddr
31068 ret
31069 CFI_ENDPROC
31070 _ASM_NOKPROBE(restore)
31071 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31072 index e2f5e21..4b22130 100644
31073 --- a/arch/x86/lib/usercopy_32.c
31074 +++ b/arch/x86/lib/usercopy_32.c
31075 @@ -42,11 +42,13 @@ do { \
31076 int __d0; \
31077 might_fault(); \
31078 __asm__ __volatile__( \
31079 + __COPYUSER_SET_ES \
31080 ASM_STAC "\n" \
31081 "0: rep; stosl\n" \
31082 " movl %2,%0\n" \
31083 "1: rep; stosb\n" \
31084 "2: " ASM_CLAC "\n" \
31085 + __COPYUSER_RESTORE_ES \
31086 ".section .fixup,\"ax\"\n" \
31087 "3: lea 0(%2,%0,4),%0\n" \
31088 " jmp 2b\n" \
31089 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31090
31091 #ifdef CONFIG_X86_INTEL_USERCOPY
31092 static unsigned long
31093 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
31094 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31095 {
31096 int d0, d1;
31097 __asm__ __volatile__(
31098 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31099 " .align 2,0x90\n"
31100 "3: movl 0(%4), %%eax\n"
31101 "4: movl 4(%4), %%edx\n"
31102 - "5: movl %%eax, 0(%3)\n"
31103 - "6: movl %%edx, 4(%3)\n"
31104 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31105 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31106 "7: movl 8(%4), %%eax\n"
31107 "8: movl 12(%4),%%edx\n"
31108 - "9: movl %%eax, 8(%3)\n"
31109 - "10: movl %%edx, 12(%3)\n"
31110 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31111 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31112 "11: movl 16(%4), %%eax\n"
31113 "12: movl 20(%4), %%edx\n"
31114 - "13: movl %%eax, 16(%3)\n"
31115 - "14: movl %%edx, 20(%3)\n"
31116 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31117 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31118 "15: movl 24(%4), %%eax\n"
31119 "16: movl 28(%4), %%edx\n"
31120 - "17: movl %%eax, 24(%3)\n"
31121 - "18: movl %%edx, 28(%3)\n"
31122 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31123 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31124 "19: movl 32(%4), %%eax\n"
31125 "20: movl 36(%4), %%edx\n"
31126 - "21: movl %%eax, 32(%3)\n"
31127 - "22: movl %%edx, 36(%3)\n"
31128 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31129 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31130 "23: movl 40(%4), %%eax\n"
31131 "24: movl 44(%4), %%edx\n"
31132 - "25: movl %%eax, 40(%3)\n"
31133 - "26: movl %%edx, 44(%3)\n"
31134 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31135 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31136 "27: movl 48(%4), %%eax\n"
31137 "28: movl 52(%4), %%edx\n"
31138 - "29: movl %%eax, 48(%3)\n"
31139 - "30: movl %%edx, 52(%3)\n"
31140 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31141 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31142 "31: movl 56(%4), %%eax\n"
31143 "32: movl 60(%4), %%edx\n"
31144 - "33: movl %%eax, 56(%3)\n"
31145 - "34: movl %%edx, 60(%3)\n"
31146 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31147 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31148 " addl $-64, %0\n"
31149 " addl $64, %4\n"
31150 " addl $64, %3\n"
31151 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31152 " shrl $2, %0\n"
31153 " andl $3, %%eax\n"
31154 " cld\n"
31155 + __COPYUSER_SET_ES
31156 "99: rep; movsl\n"
31157 "36: movl %%eax, %0\n"
31158 "37: rep; movsb\n"
31159 "100:\n"
31160 + __COPYUSER_RESTORE_ES
31161 + ".section .fixup,\"ax\"\n"
31162 + "101: lea 0(%%eax,%0,4),%0\n"
31163 + " jmp 100b\n"
31164 + ".previous\n"
31165 + _ASM_EXTABLE(1b,100b)
31166 + _ASM_EXTABLE(2b,100b)
31167 + _ASM_EXTABLE(3b,100b)
31168 + _ASM_EXTABLE(4b,100b)
31169 + _ASM_EXTABLE(5b,100b)
31170 + _ASM_EXTABLE(6b,100b)
31171 + _ASM_EXTABLE(7b,100b)
31172 + _ASM_EXTABLE(8b,100b)
31173 + _ASM_EXTABLE(9b,100b)
31174 + _ASM_EXTABLE(10b,100b)
31175 + _ASM_EXTABLE(11b,100b)
31176 + _ASM_EXTABLE(12b,100b)
31177 + _ASM_EXTABLE(13b,100b)
31178 + _ASM_EXTABLE(14b,100b)
31179 + _ASM_EXTABLE(15b,100b)
31180 + _ASM_EXTABLE(16b,100b)
31181 + _ASM_EXTABLE(17b,100b)
31182 + _ASM_EXTABLE(18b,100b)
31183 + _ASM_EXTABLE(19b,100b)
31184 + _ASM_EXTABLE(20b,100b)
31185 + _ASM_EXTABLE(21b,100b)
31186 + _ASM_EXTABLE(22b,100b)
31187 + _ASM_EXTABLE(23b,100b)
31188 + _ASM_EXTABLE(24b,100b)
31189 + _ASM_EXTABLE(25b,100b)
31190 + _ASM_EXTABLE(26b,100b)
31191 + _ASM_EXTABLE(27b,100b)
31192 + _ASM_EXTABLE(28b,100b)
31193 + _ASM_EXTABLE(29b,100b)
31194 + _ASM_EXTABLE(30b,100b)
31195 + _ASM_EXTABLE(31b,100b)
31196 + _ASM_EXTABLE(32b,100b)
31197 + _ASM_EXTABLE(33b,100b)
31198 + _ASM_EXTABLE(34b,100b)
31199 + _ASM_EXTABLE(35b,100b)
31200 + _ASM_EXTABLE(36b,100b)
31201 + _ASM_EXTABLE(37b,100b)
31202 + _ASM_EXTABLE(99b,101b)
31203 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31204 + : "1"(to), "2"(from), "0"(size)
31205 + : "eax", "edx", "memory");
31206 + return size;
31207 +}
31208 +
31209 +static unsigned long
31210 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31211 +{
31212 + int d0, d1;
31213 + __asm__ __volatile__(
31214 + " .align 2,0x90\n"
31215 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31216 + " cmpl $67, %0\n"
31217 + " jbe 3f\n"
31218 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31219 + " .align 2,0x90\n"
31220 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31221 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31222 + "5: movl %%eax, 0(%3)\n"
31223 + "6: movl %%edx, 4(%3)\n"
31224 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31225 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31226 + "9: movl %%eax, 8(%3)\n"
31227 + "10: movl %%edx, 12(%3)\n"
31228 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31229 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31230 + "13: movl %%eax, 16(%3)\n"
31231 + "14: movl %%edx, 20(%3)\n"
31232 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31233 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31234 + "17: movl %%eax, 24(%3)\n"
31235 + "18: movl %%edx, 28(%3)\n"
31236 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31237 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31238 + "21: movl %%eax, 32(%3)\n"
31239 + "22: movl %%edx, 36(%3)\n"
31240 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31241 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31242 + "25: movl %%eax, 40(%3)\n"
31243 + "26: movl %%edx, 44(%3)\n"
31244 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31245 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31246 + "29: movl %%eax, 48(%3)\n"
31247 + "30: movl %%edx, 52(%3)\n"
31248 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31249 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31250 + "33: movl %%eax, 56(%3)\n"
31251 + "34: movl %%edx, 60(%3)\n"
31252 + " addl $-64, %0\n"
31253 + " addl $64, %4\n"
31254 + " addl $64, %3\n"
31255 + " cmpl $63, %0\n"
31256 + " ja 1b\n"
31257 + "35: movl %0, %%eax\n"
31258 + " shrl $2, %0\n"
31259 + " andl $3, %%eax\n"
31260 + " cld\n"
31261 + "99: rep; "__copyuser_seg" movsl\n"
31262 + "36: movl %%eax, %0\n"
31263 + "37: rep; "__copyuser_seg" movsb\n"
31264 + "100:\n"
31265 ".section .fixup,\"ax\"\n"
31266 "101: lea 0(%%eax,%0,4),%0\n"
31267 " jmp 100b\n"
31268 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31269 int d0, d1;
31270 __asm__ __volatile__(
31271 " .align 2,0x90\n"
31272 - "0: movl 32(%4), %%eax\n"
31273 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31274 " cmpl $67, %0\n"
31275 " jbe 2f\n"
31276 - "1: movl 64(%4), %%eax\n"
31277 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31278 " .align 2,0x90\n"
31279 - "2: movl 0(%4), %%eax\n"
31280 - "21: movl 4(%4), %%edx\n"
31281 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31282 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31283 " movl %%eax, 0(%3)\n"
31284 " movl %%edx, 4(%3)\n"
31285 - "3: movl 8(%4), %%eax\n"
31286 - "31: movl 12(%4),%%edx\n"
31287 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31288 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31289 " movl %%eax, 8(%3)\n"
31290 " movl %%edx, 12(%3)\n"
31291 - "4: movl 16(%4), %%eax\n"
31292 - "41: movl 20(%4), %%edx\n"
31293 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31294 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31295 " movl %%eax, 16(%3)\n"
31296 " movl %%edx, 20(%3)\n"
31297 - "10: movl 24(%4), %%eax\n"
31298 - "51: movl 28(%4), %%edx\n"
31299 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31300 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31301 " movl %%eax, 24(%3)\n"
31302 " movl %%edx, 28(%3)\n"
31303 - "11: movl 32(%4), %%eax\n"
31304 - "61: movl 36(%4), %%edx\n"
31305 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31306 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31307 " movl %%eax, 32(%3)\n"
31308 " movl %%edx, 36(%3)\n"
31309 - "12: movl 40(%4), %%eax\n"
31310 - "71: movl 44(%4), %%edx\n"
31311 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31312 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31313 " movl %%eax, 40(%3)\n"
31314 " movl %%edx, 44(%3)\n"
31315 - "13: movl 48(%4), %%eax\n"
31316 - "81: movl 52(%4), %%edx\n"
31317 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31318 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31319 " movl %%eax, 48(%3)\n"
31320 " movl %%edx, 52(%3)\n"
31321 - "14: movl 56(%4), %%eax\n"
31322 - "91: movl 60(%4), %%edx\n"
31323 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31324 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31325 " movl %%eax, 56(%3)\n"
31326 " movl %%edx, 60(%3)\n"
31327 " addl $-64, %0\n"
31328 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31329 " shrl $2, %0\n"
31330 " andl $3, %%eax\n"
31331 " cld\n"
31332 - "6: rep; movsl\n"
31333 + "6: rep; "__copyuser_seg" movsl\n"
31334 " movl %%eax,%0\n"
31335 - "7: rep; movsb\n"
31336 + "7: rep; "__copyuser_seg" movsb\n"
31337 "8:\n"
31338 ".section .fixup,\"ax\"\n"
31339 "9: lea 0(%%eax,%0,4),%0\n"
31340 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31341
31342 __asm__ __volatile__(
31343 " .align 2,0x90\n"
31344 - "0: movl 32(%4), %%eax\n"
31345 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31346 " cmpl $67, %0\n"
31347 " jbe 2f\n"
31348 - "1: movl 64(%4), %%eax\n"
31349 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31350 " .align 2,0x90\n"
31351 - "2: movl 0(%4), %%eax\n"
31352 - "21: movl 4(%4), %%edx\n"
31353 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31354 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31355 " movnti %%eax, 0(%3)\n"
31356 " movnti %%edx, 4(%3)\n"
31357 - "3: movl 8(%4), %%eax\n"
31358 - "31: movl 12(%4),%%edx\n"
31359 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31360 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31361 " movnti %%eax, 8(%3)\n"
31362 " movnti %%edx, 12(%3)\n"
31363 - "4: movl 16(%4), %%eax\n"
31364 - "41: movl 20(%4), %%edx\n"
31365 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31366 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31367 " movnti %%eax, 16(%3)\n"
31368 " movnti %%edx, 20(%3)\n"
31369 - "10: movl 24(%4), %%eax\n"
31370 - "51: movl 28(%4), %%edx\n"
31371 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31372 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31373 " movnti %%eax, 24(%3)\n"
31374 " movnti %%edx, 28(%3)\n"
31375 - "11: movl 32(%4), %%eax\n"
31376 - "61: movl 36(%4), %%edx\n"
31377 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31378 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31379 " movnti %%eax, 32(%3)\n"
31380 " movnti %%edx, 36(%3)\n"
31381 - "12: movl 40(%4), %%eax\n"
31382 - "71: movl 44(%4), %%edx\n"
31383 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31384 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31385 " movnti %%eax, 40(%3)\n"
31386 " movnti %%edx, 44(%3)\n"
31387 - "13: movl 48(%4), %%eax\n"
31388 - "81: movl 52(%4), %%edx\n"
31389 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31390 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31391 " movnti %%eax, 48(%3)\n"
31392 " movnti %%edx, 52(%3)\n"
31393 - "14: movl 56(%4), %%eax\n"
31394 - "91: movl 60(%4), %%edx\n"
31395 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31396 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31397 " movnti %%eax, 56(%3)\n"
31398 " movnti %%edx, 60(%3)\n"
31399 " addl $-64, %0\n"
31400 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31401 " shrl $2, %0\n"
31402 " andl $3, %%eax\n"
31403 " cld\n"
31404 - "6: rep; movsl\n"
31405 + "6: rep; "__copyuser_seg" movsl\n"
31406 " movl %%eax,%0\n"
31407 - "7: rep; movsb\n"
31408 + "7: rep; "__copyuser_seg" movsb\n"
31409 "8:\n"
31410 ".section .fixup,\"ax\"\n"
31411 "9: lea 0(%%eax,%0,4),%0\n"
31412 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31413
31414 __asm__ __volatile__(
31415 " .align 2,0x90\n"
31416 - "0: movl 32(%4), %%eax\n"
31417 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31418 " cmpl $67, %0\n"
31419 " jbe 2f\n"
31420 - "1: movl 64(%4), %%eax\n"
31421 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31422 " .align 2,0x90\n"
31423 - "2: movl 0(%4), %%eax\n"
31424 - "21: movl 4(%4), %%edx\n"
31425 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31426 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31427 " movnti %%eax, 0(%3)\n"
31428 " movnti %%edx, 4(%3)\n"
31429 - "3: movl 8(%4), %%eax\n"
31430 - "31: movl 12(%4),%%edx\n"
31431 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31432 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31433 " movnti %%eax, 8(%3)\n"
31434 " movnti %%edx, 12(%3)\n"
31435 - "4: movl 16(%4), %%eax\n"
31436 - "41: movl 20(%4), %%edx\n"
31437 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31438 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31439 " movnti %%eax, 16(%3)\n"
31440 " movnti %%edx, 20(%3)\n"
31441 - "10: movl 24(%4), %%eax\n"
31442 - "51: movl 28(%4), %%edx\n"
31443 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31444 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31445 " movnti %%eax, 24(%3)\n"
31446 " movnti %%edx, 28(%3)\n"
31447 - "11: movl 32(%4), %%eax\n"
31448 - "61: movl 36(%4), %%edx\n"
31449 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31450 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31451 " movnti %%eax, 32(%3)\n"
31452 " movnti %%edx, 36(%3)\n"
31453 - "12: movl 40(%4), %%eax\n"
31454 - "71: movl 44(%4), %%edx\n"
31455 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31456 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31457 " movnti %%eax, 40(%3)\n"
31458 " movnti %%edx, 44(%3)\n"
31459 - "13: movl 48(%4), %%eax\n"
31460 - "81: movl 52(%4), %%edx\n"
31461 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31462 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31463 " movnti %%eax, 48(%3)\n"
31464 " movnti %%edx, 52(%3)\n"
31465 - "14: movl 56(%4), %%eax\n"
31466 - "91: movl 60(%4), %%edx\n"
31467 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31468 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31469 " movnti %%eax, 56(%3)\n"
31470 " movnti %%edx, 60(%3)\n"
31471 " addl $-64, %0\n"
31472 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31473 " shrl $2, %0\n"
31474 " andl $3, %%eax\n"
31475 " cld\n"
31476 - "6: rep; movsl\n"
31477 + "6: rep; "__copyuser_seg" movsl\n"
31478 " movl %%eax,%0\n"
31479 - "7: rep; movsb\n"
31480 + "7: rep; "__copyuser_seg" movsb\n"
31481 "8:\n"
31482 ".section .fixup,\"ax\"\n"
31483 "9: lea 0(%%eax,%0,4),%0\n"
31484 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31485 */
31486 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31487 unsigned long size);
31488 -unsigned long __copy_user_intel(void __user *to, const void *from,
31489 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31490 + unsigned long size);
31491 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31492 unsigned long size);
31493 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31494 const void __user *from, unsigned long size);
31495 #endif /* CONFIG_X86_INTEL_USERCOPY */
31496
31497 /* Generic arbitrary sized copy. */
31498 -#define __copy_user(to, from, size) \
31499 +#define __copy_user(to, from, size, prefix, set, restore) \
31500 do { \
31501 int __d0, __d1, __d2; \
31502 __asm__ __volatile__( \
31503 + set \
31504 " cmp $7,%0\n" \
31505 " jbe 1f\n" \
31506 " movl %1,%0\n" \
31507 " negl %0\n" \
31508 " andl $7,%0\n" \
31509 " subl %0,%3\n" \
31510 - "4: rep; movsb\n" \
31511 + "4: rep; "prefix"movsb\n" \
31512 " movl %3,%0\n" \
31513 " shrl $2,%0\n" \
31514 " andl $3,%3\n" \
31515 " .align 2,0x90\n" \
31516 - "0: rep; movsl\n" \
31517 + "0: rep; "prefix"movsl\n" \
31518 " movl %3,%0\n" \
31519 - "1: rep; movsb\n" \
31520 + "1: rep; "prefix"movsb\n" \
31521 "2:\n" \
31522 + restore \
31523 ".section .fixup,\"ax\"\n" \
31524 "5: addl %3,%0\n" \
31525 " jmp 2b\n" \
31526 @@ -538,14 +650,14 @@ do { \
31527 " negl %0\n" \
31528 " andl $7,%0\n" \
31529 " subl %0,%3\n" \
31530 - "4: rep; movsb\n" \
31531 + "4: rep; "__copyuser_seg"movsb\n" \
31532 " movl %3,%0\n" \
31533 " shrl $2,%0\n" \
31534 " andl $3,%3\n" \
31535 " .align 2,0x90\n" \
31536 - "0: rep; movsl\n" \
31537 + "0: rep; "__copyuser_seg"movsl\n" \
31538 " movl %3,%0\n" \
31539 - "1: rep; movsb\n" \
31540 + "1: rep; "__copyuser_seg"movsb\n" \
31541 "2:\n" \
31542 ".section .fixup,\"ax\"\n" \
31543 "5: addl %3,%0\n" \
31544 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31545 {
31546 stac();
31547 if (movsl_is_ok(to, from, n))
31548 - __copy_user(to, from, n);
31549 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31550 else
31551 - n = __copy_user_intel(to, from, n);
31552 + n = __generic_copy_to_user_intel(to, from, n);
31553 clac();
31554 return n;
31555 }
31556 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31557 {
31558 stac();
31559 if (movsl_is_ok(to, from, n))
31560 - __copy_user(to, from, n);
31561 + __copy_user(to, from, n, __copyuser_seg, "", "");
31562 else
31563 - n = __copy_user_intel((void __user *)to,
31564 - (const void *)from, n);
31565 + n = __generic_copy_from_user_intel(to, from, n);
31566 clac();
31567 return n;
31568 }
31569 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31570 if (n > 64 && cpu_has_xmm2)
31571 n = __copy_user_intel_nocache(to, from, n);
31572 else
31573 - __copy_user(to, from, n);
31574 + __copy_user(to, from, n, __copyuser_seg, "", "");
31575 #else
31576 - __copy_user(to, from, n);
31577 + __copy_user(to, from, n, __copyuser_seg, "", "");
31578 #endif
31579 clac();
31580 return n;
31581 }
31582 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31583
31584 -/**
31585 - * copy_to_user: - Copy a block of data into user space.
31586 - * @to: Destination address, in user space.
31587 - * @from: Source address, in kernel space.
31588 - * @n: Number of bytes to copy.
31589 - *
31590 - * Context: User context only. This function may sleep.
31591 - *
31592 - * Copy data from kernel space to user space.
31593 - *
31594 - * Returns number of bytes that could not be copied.
31595 - * On success, this will be zero.
31596 - */
31597 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31598 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31599 +void __set_fs(mm_segment_t x)
31600 {
31601 - if (access_ok(VERIFY_WRITE, to, n))
31602 - n = __copy_to_user(to, from, n);
31603 - return n;
31604 + switch (x.seg) {
31605 + case 0:
31606 + loadsegment(gs, 0);
31607 + break;
31608 + case TASK_SIZE_MAX:
31609 + loadsegment(gs, __USER_DS);
31610 + break;
31611 + case -1UL:
31612 + loadsegment(gs, __KERNEL_DS);
31613 + break;
31614 + default:
31615 + BUG();
31616 + }
31617 }
31618 -EXPORT_SYMBOL(_copy_to_user);
31619 +EXPORT_SYMBOL(__set_fs);
31620
31621 -/**
31622 - * copy_from_user: - Copy a block of data from user space.
31623 - * @to: Destination address, in kernel space.
31624 - * @from: Source address, in user space.
31625 - * @n: Number of bytes to copy.
31626 - *
31627 - * Context: User context only. This function may sleep.
31628 - *
31629 - * Copy data from user space to kernel space.
31630 - *
31631 - * Returns number of bytes that could not be copied.
31632 - * On success, this will be zero.
31633 - *
31634 - * If some data could not be copied, this function will pad the copied
31635 - * data to the requested size using zero bytes.
31636 - */
31637 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31638 +void set_fs(mm_segment_t x)
31639 {
31640 - if (access_ok(VERIFY_READ, from, n))
31641 - n = __copy_from_user(to, from, n);
31642 - else
31643 - memset(to, 0, n);
31644 - return n;
31645 + current_thread_info()->addr_limit = x;
31646 + __set_fs(x);
31647 }
31648 -EXPORT_SYMBOL(_copy_from_user);
31649 +EXPORT_SYMBOL(set_fs);
31650 +#endif
31651 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31652 index c905e89..01ab928 100644
31653 --- a/arch/x86/lib/usercopy_64.c
31654 +++ b/arch/x86/lib/usercopy_64.c
31655 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31656 might_fault();
31657 /* no memory constraint because it doesn't change any memory gcc knows
31658 about */
31659 + pax_open_userland();
31660 stac();
31661 asm volatile(
31662 " testq %[size8],%[size8]\n"
31663 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31664 _ASM_EXTABLE(0b,3b)
31665 _ASM_EXTABLE(1b,2b)
31666 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31667 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31668 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31669 [zero] "r" (0UL), [eight] "r" (8UL));
31670 clac();
31671 + pax_close_userland();
31672 return size;
31673 }
31674 EXPORT_SYMBOL(__clear_user);
31675 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31676 }
31677 EXPORT_SYMBOL(clear_user);
31678
31679 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31680 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31681 {
31682 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31683 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31684 - }
31685 - return len;
31686 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31687 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31688 + return len;
31689 }
31690 EXPORT_SYMBOL(copy_in_user);
31691
31692 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31693 * it is not necessary to optimize tail handling.
31694 */
31695 __visible unsigned long
31696 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31697 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31698 {
31699 char c;
31700 unsigned zero_len;
31701
31702 + clac();
31703 + pax_close_userland();
31704 for (; len; --len, to++) {
31705 if (__get_user_nocheck(c, from++, sizeof(char)))
31706 break;
31707 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31708 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31709 if (__put_user_nocheck(c, to++, sizeof(char)))
31710 break;
31711 - clac();
31712 return len;
31713 }
31714 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31715 index 6a19ad9..1c48f9a 100644
31716 --- a/arch/x86/mm/Makefile
31717 +++ b/arch/x86/mm/Makefile
31718 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31719 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31720
31721 obj-$(CONFIG_MEMTEST) += memtest.o
31722 +
31723 +quote:="
31724 +obj-$(CONFIG_X86_64) += uderef_64.o
31725 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31726 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31727 index 903ec1e..c4166b2 100644
31728 --- a/arch/x86/mm/extable.c
31729 +++ b/arch/x86/mm/extable.c
31730 @@ -6,12 +6,24 @@
31731 static inline unsigned long
31732 ex_insn_addr(const struct exception_table_entry *x)
31733 {
31734 - return (unsigned long)&x->insn + x->insn;
31735 + unsigned long reloc = 0;
31736 +
31737 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31738 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31739 +#endif
31740 +
31741 + return (unsigned long)&x->insn + x->insn + reloc;
31742 }
31743 static inline unsigned long
31744 ex_fixup_addr(const struct exception_table_entry *x)
31745 {
31746 - return (unsigned long)&x->fixup + x->fixup;
31747 + unsigned long reloc = 0;
31748 +
31749 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31750 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31751 +#endif
31752 +
31753 + return (unsigned long)&x->fixup + x->fixup + reloc;
31754 }
31755
31756 int fixup_exception(struct pt_regs *regs)
31757 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31758 unsigned long new_ip;
31759
31760 #ifdef CONFIG_PNPBIOS
31761 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31762 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31763 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31764 extern u32 pnp_bios_is_utter_crap;
31765 pnp_bios_is_utter_crap = 1;
31766 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31767 i += 4;
31768 p->fixup -= i;
31769 i += 4;
31770 +
31771 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31772 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31773 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31774 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31775 +#endif
31776 +
31777 }
31778 }
31779
31780 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31781 index 4d8ee82..ffc1011 100644
31782 --- a/arch/x86/mm/fault.c
31783 +++ b/arch/x86/mm/fault.c
31784 @@ -13,12 +13,19 @@
31785 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31786 #include <linux/prefetch.h> /* prefetchw */
31787 #include <linux/context_tracking.h> /* exception_enter(), ... */
31788 +#include <linux/unistd.h>
31789 +#include <linux/compiler.h>
31790
31791 #include <asm/traps.h> /* dotraplinkage, ... */
31792 #include <asm/pgalloc.h> /* pgd_*(), ... */
31793 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31794 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31795 #include <asm/vsyscall.h> /* emulate_vsyscall */
31796 +#include <asm/tlbflush.h>
31797 +
31798 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31799 +#include <asm/stacktrace.h>
31800 +#endif
31801
31802 #define CREATE_TRACE_POINTS
31803 #include <asm/trace/exceptions.h>
31804 @@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31805 int ret = 0;
31806
31807 /* kprobe_running() needs smp_processor_id() */
31808 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31809 + if (kprobes_built_in() && !user_mode(regs)) {
31810 preempt_disable();
31811 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31812 ret = 1;
31813 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31814 return !instr_lo || (instr_lo>>1) == 1;
31815 case 0x00:
31816 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31817 - if (probe_kernel_address(instr, opcode))
31818 + if (user_mode(regs)) {
31819 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31820 + return 0;
31821 + } else if (probe_kernel_address(instr, opcode))
31822 return 0;
31823
31824 *prefetch = (instr_lo == 0xF) &&
31825 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31826 while (instr < max_instr) {
31827 unsigned char opcode;
31828
31829 - if (probe_kernel_address(instr, opcode))
31830 + if (user_mode(regs)) {
31831 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31832 + break;
31833 + } else if (probe_kernel_address(instr, opcode))
31834 break;
31835
31836 instr++;
31837 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31838 force_sig_info(si_signo, &info, tsk);
31839 }
31840
31841 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31842 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31843 +#endif
31844 +
31845 +#ifdef CONFIG_PAX_EMUTRAMP
31846 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31847 +#endif
31848 +
31849 +#ifdef CONFIG_PAX_PAGEEXEC
31850 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31851 +{
31852 + pgd_t *pgd;
31853 + pud_t *pud;
31854 + pmd_t *pmd;
31855 +
31856 + pgd = pgd_offset(mm, address);
31857 + if (!pgd_present(*pgd))
31858 + return NULL;
31859 + pud = pud_offset(pgd, address);
31860 + if (!pud_present(*pud))
31861 + return NULL;
31862 + pmd = pmd_offset(pud, address);
31863 + if (!pmd_present(*pmd))
31864 + return NULL;
31865 + return pmd;
31866 +}
31867 +#endif
31868 +
31869 DEFINE_SPINLOCK(pgd_lock);
31870 LIST_HEAD(pgd_list);
31871
31872 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31873 for (address = VMALLOC_START & PMD_MASK;
31874 address >= TASK_SIZE && address < FIXADDR_TOP;
31875 address += PMD_SIZE) {
31876 +
31877 +#ifdef CONFIG_PAX_PER_CPU_PGD
31878 + unsigned long cpu;
31879 +#else
31880 struct page *page;
31881 +#endif
31882
31883 spin_lock(&pgd_lock);
31884 +
31885 +#ifdef CONFIG_PAX_PER_CPU_PGD
31886 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31887 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31888 + pmd_t *ret;
31889 +
31890 + ret = vmalloc_sync_one(pgd, address);
31891 + if (!ret)
31892 + break;
31893 + pgd = get_cpu_pgd(cpu, kernel);
31894 +#else
31895 list_for_each_entry(page, &pgd_list, lru) {
31896 + pgd_t *pgd;
31897 spinlock_t *pgt_lock;
31898 pmd_t *ret;
31899
31900 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31901 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31902
31903 spin_lock(pgt_lock);
31904 - ret = vmalloc_sync_one(page_address(page), address);
31905 + pgd = page_address(page);
31906 +#endif
31907 +
31908 + ret = vmalloc_sync_one(pgd, address);
31909 +
31910 +#ifndef CONFIG_PAX_PER_CPU_PGD
31911 spin_unlock(pgt_lock);
31912 +#endif
31913
31914 if (!ret)
31915 break;
31916 @@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31917 * an interrupt in the middle of a task switch..
31918 */
31919 pgd_paddr = read_cr3();
31920 +
31921 +#ifdef CONFIG_PAX_PER_CPU_PGD
31922 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31923 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31924 +#endif
31925 +
31926 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31927 if (!pmd_k)
31928 return -1;
31929 @@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31930 * happen within a race in page table update. In the later
31931 * case just flush:
31932 */
31933 - pgd = pgd_offset(current->active_mm, address);
31934 +
31935 pgd_ref = pgd_offset_k(address);
31936 if (pgd_none(*pgd_ref))
31937 return -1;
31938
31939 +#ifdef CONFIG_PAX_PER_CPU_PGD
31940 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31941 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31942 + if (pgd_none(*pgd)) {
31943 + set_pgd(pgd, *pgd_ref);
31944 + arch_flush_lazy_mmu_mode();
31945 + } else {
31946 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31947 + }
31948 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31949 +#else
31950 + pgd = pgd_offset(current->active_mm, address);
31951 +#endif
31952 +
31953 if (pgd_none(*pgd)) {
31954 set_pgd(pgd, *pgd_ref);
31955 arch_flush_lazy_mmu_mode();
31956 @@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31957 static int is_errata100(struct pt_regs *regs, unsigned long address)
31958 {
31959 #ifdef CONFIG_X86_64
31960 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31961 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31962 return 1;
31963 #endif
31964 return 0;
31965 @@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31966 }
31967
31968 static const char nx_warning[] = KERN_CRIT
31969 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31970 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31971 static const char smep_warning[] = KERN_CRIT
31972 -"unable to execute userspace code (SMEP?) (uid: %d)\n";
31973 +"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
31974
31975 static void
31976 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31977 @@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31978 if (!oops_may_print())
31979 return;
31980
31981 - if (error_code & PF_INSTR) {
31982 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31983 unsigned int level;
31984 pgd_t *pgd;
31985 pte_t *pte;
31986 @@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31987 pte = lookup_address_in_pgd(pgd, address, &level);
31988
31989 if (pte && pte_present(*pte) && !pte_exec(*pte))
31990 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31991 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31992 if (pte && pte_present(*pte) && pte_exec(*pte) &&
31993 (pgd_flags(*pgd) & _PAGE_USER) &&
31994 (read_cr4() & X86_CR4_SMEP))
31995 - printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
31996 + printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31997 }
31998
31999 +#ifdef CONFIG_PAX_KERNEXEC
32000 + if (init_mm.start_code <= address && address < init_mm.end_code) {
32001 + if (current->signal->curr_ip)
32002 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32003 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
32004 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32005 + else
32006 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32007 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32008 + }
32009 +#endif
32010 +
32011 printk(KERN_ALERT "BUG: unable to handle kernel ");
32012 if (address < PAGE_SIZE)
32013 printk(KERN_CONT "NULL pointer dereference");
32014 @@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32015 return;
32016 }
32017 #endif
32018 +
32019 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32020 + if (pax_is_fetch_fault(regs, error_code, address)) {
32021 +
32022 +#ifdef CONFIG_PAX_EMUTRAMP
32023 + switch (pax_handle_fetch_fault(regs)) {
32024 + case 2:
32025 + return;
32026 + }
32027 +#endif
32028 +
32029 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32030 + do_group_exit(SIGKILL);
32031 + }
32032 +#endif
32033 +
32034 /* Kernel addresses are always protection faults: */
32035 if (address >= TASK_SIZE)
32036 error_code |= PF_PROT;
32037 @@ -864,7 +976,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32038 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32039 printk(KERN_ERR
32040 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32041 - tsk->comm, tsk->pid, address);
32042 + tsk->comm, task_pid_nr(tsk), address);
32043 code = BUS_MCEERR_AR;
32044 }
32045 #endif
32046 @@ -916,6 +1028,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32047 return 1;
32048 }
32049
32050 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32051 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32052 +{
32053 + pte_t *pte;
32054 + pmd_t *pmd;
32055 + spinlock_t *ptl;
32056 + unsigned char pte_mask;
32057 +
32058 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32059 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
32060 + return 0;
32061 +
32062 + /* PaX: it's our fault, let's handle it if we can */
32063 +
32064 + /* PaX: take a look at read faults before acquiring any locks */
32065 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32066 + /* instruction fetch attempt from a protected page in user mode */
32067 + up_read(&mm->mmap_sem);
32068 +
32069 +#ifdef CONFIG_PAX_EMUTRAMP
32070 + switch (pax_handle_fetch_fault(regs)) {
32071 + case 2:
32072 + return 1;
32073 + }
32074 +#endif
32075 +
32076 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32077 + do_group_exit(SIGKILL);
32078 + }
32079 +
32080 + pmd = pax_get_pmd(mm, address);
32081 + if (unlikely(!pmd))
32082 + return 0;
32083 +
32084 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32085 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32086 + pte_unmap_unlock(pte, ptl);
32087 + return 0;
32088 + }
32089 +
32090 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32091 + /* write attempt to a protected page in user mode */
32092 + pte_unmap_unlock(pte, ptl);
32093 + return 0;
32094 + }
32095 +
32096 +#ifdef CONFIG_SMP
32097 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32098 +#else
32099 + if (likely(address > get_limit(regs->cs)))
32100 +#endif
32101 + {
32102 + set_pte(pte, pte_mkread(*pte));
32103 + __flush_tlb_one(address);
32104 + pte_unmap_unlock(pte, ptl);
32105 + up_read(&mm->mmap_sem);
32106 + return 1;
32107 + }
32108 +
32109 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32110 +
32111 + /*
32112 + * PaX: fill DTLB with user rights and retry
32113 + */
32114 + __asm__ __volatile__ (
32115 + "orb %2,(%1)\n"
32116 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32117 +/*
32118 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32119 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32120 + * page fault when examined during a TLB load attempt. this is true not only
32121 + * for PTEs holding a non-present entry but also present entries that will
32122 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32123 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32124 + * for our target pages since their PTEs are simply not in the TLBs at all.
32125 +
32126 + * the best thing in omitting it is that we gain around 15-20% speed in the
32127 + * fast path of the page fault handler and can get rid of tracing since we
32128 + * can no longer flush unintended entries.
32129 + */
32130 + "invlpg (%0)\n"
32131 +#endif
32132 + __copyuser_seg"testb $0,(%0)\n"
32133 + "xorb %3,(%1)\n"
32134 + :
32135 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32136 + : "memory", "cc");
32137 + pte_unmap_unlock(pte, ptl);
32138 + up_read(&mm->mmap_sem);
32139 + return 1;
32140 +}
32141 +#endif
32142 +
32143 /*
32144 * Handle a spurious fault caused by a stale TLB entry.
32145 *
32146 @@ -1001,6 +1206,9 @@ int show_unhandled_signals = 1;
32147 static inline int
32148 access_error(unsigned long error_code, struct vm_area_struct *vma)
32149 {
32150 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32151 + return 1;
32152 +
32153 if (error_code & PF_WRITE) {
32154 /* write, present and write, not present: */
32155 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32156 @@ -1035,7 +1243,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32157 if (error_code & PF_USER)
32158 return false;
32159
32160 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32161 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32162 return false;
32163
32164 return true;
32165 @@ -1063,6 +1271,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32166 tsk = current;
32167 mm = tsk->mm;
32168
32169 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32170 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32171 + if (!search_exception_tables(regs->ip)) {
32172 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32173 + bad_area_nosemaphore(regs, error_code, address);
32174 + return;
32175 + }
32176 + if (address < pax_user_shadow_base) {
32177 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32178 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32179 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32180 + } else
32181 + address -= pax_user_shadow_base;
32182 + }
32183 +#endif
32184 +
32185 /*
32186 * Detect and handle instructions that would cause a page fault for
32187 * both a tracked kernel page and a userspace page.
32188 @@ -1140,7 +1364,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32189 * User-mode registers count as a user access even for any
32190 * potential system fault or CPU buglet:
32191 */
32192 - if (user_mode_vm(regs)) {
32193 + if (user_mode(regs)) {
32194 local_irq_enable();
32195 error_code |= PF_USER;
32196 flags |= FAULT_FLAG_USER;
32197 @@ -1187,6 +1411,11 @@ retry:
32198 might_sleep();
32199 }
32200
32201 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32202 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32203 + return;
32204 +#endif
32205 +
32206 vma = find_vma(mm, address);
32207 if (unlikely(!vma)) {
32208 bad_area(regs, error_code, address);
32209 @@ -1198,18 +1427,24 @@ retry:
32210 bad_area(regs, error_code, address);
32211 return;
32212 }
32213 - if (error_code & PF_USER) {
32214 - /*
32215 - * Accessing the stack below %sp is always a bug.
32216 - * The large cushion allows instructions like enter
32217 - * and pusha to work. ("enter $65535, $31" pushes
32218 - * 32 pointers and then decrements %sp by 65535.)
32219 - */
32220 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32221 - bad_area(regs, error_code, address);
32222 - return;
32223 - }
32224 + /*
32225 + * Accessing the stack below %sp is always a bug.
32226 + * The large cushion allows instructions like enter
32227 + * and pusha to work. ("enter $65535, $31" pushes
32228 + * 32 pointers and then decrements %sp by 65535.)
32229 + */
32230 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32231 + bad_area(regs, error_code, address);
32232 + return;
32233 }
32234 +
32235 +#ifdef CONFIG_PAX_SEGMEXEC
32236 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32237 + bad_area(regs, error_code, address);
32238 + return;
32239 + }
32240 +#endif
32241 +
32242 if (unlikely(expand_stack(vma, address))) {
32243 bad_area(regs, error_code, address);
32244 return;
32245 @@ -1327,3 +1562,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32246 }
32247 NOKPROBE_SYMBOL(trace_do_page_fault);
32248 #endif /* CONFIG_TRACING */
32249 +
32250 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32251 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32252 +{
32253 + struct mm_struct *mm = current->mm;
32254 + unsigned long ip = regs->ip;
32255 +
32256 + if (v8086_mode(regs))
32257 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32258 +
32259 +#ifdef CONFIG_PAX_PAGEEXEC
32260 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32261 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32262 + return true;
32263 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32264 + return true;
32265 + return false;
32266 + }
32267 +#endif
32268 +
32269 +#ifdef CONFIG_PAX_SEGMEXEC
32270 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32271 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32272 + return true;
32273 + return false;
32274 + }
32275 +#endif
32276 +
32277 + return false;
32278 +}
32279 +#endif
32280 +
32281 +#ifdef CONFIG_PAX_EMUTRAMP
32282 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32283 +{
32284 + int err;
32285 +
32286 + do { /* PaX: libffi trampoline emulation */
32287 + unsigned char mov, jmp;
32288 + unsigned int addr1, addr2;
32289 +
32290 +#ifdef CONFIG_X86_64
32291 + if ((regs->ip + 9) >> 32)
32292 + break;
32293 +#endif
32294 +
32295 + err = get_user(mov, (unsigned char __user *)regs->ip);
32296 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32297 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32298 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32299 +
32300 + if (err)
32301 + break;
32302 +
32303 + if (mov == 0xB8 && jmp == 0xE9) {
32304 + regs->ax = addr1;
32305 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32306 + return 2;
32307 + }
32308 + } while (0);
32309 +
32310 + do { /* PaX: gcc trampoline emulation #1 */
32311 + unsigned char mov1, mov2;
32312 + unsigned short jmp;
32313 + unsigned int addr1, addr2;
32314 +
32315 +#ifdef CONFIG_X86_64
32316 + if ((regs->ip + 11) >> 32)
32317 + break;
32318 +#endif
32319 +
32320 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32321 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32322 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32323 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32324 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32325 +
32326 + if (err)
32327 + break;
32328 +
32329 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32330 + regs->cx = addr1;
32331 + regs->ax = addr2;
32332 + regs->ip = addr2;
32333 + return 2;
32334 + }
32335 + } while (0);
32336 +
32337 + do { /* PaX: gcc trampoline emulation #2 */
32338 + unsigned char mov, jmp;
32339 + unsigned int addr1, addr2;
32340 +
32341 +#ifdef CONFIG_X86_64
32342 + if ((regs->ip + 9) >> 32)
32343 + break;
32344 +#endif
32345 +
32346 + err = get_user(mov, (unsigned char __user *)regs->ip);
32347 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32348 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32349 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32350 +
32351 + if (err)
32352 + break;
32353 +
32354 + if (mov == 0xB9 && jmp == 0xE9) {
32355 + regs->cx = addr1;
32356 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32357 + return 2;
32358 + }
32359 + } while (0);
32360 +
32361 + return 1; /* PaX in action */
32362 +}
32363 +
32364 +#ifdef CONFIG_X86_64
32365 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32366 +{
32367 + int err;
32368 +
32369 + do { /* PaX: libffi trampoline emulation */
32370 + unsigned short mov1, mov2, jmp1;
32371 + unsigned char stcclc, jmp2;
32372 + unsigned long addr1, addr2;
32373 +
32374 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32375 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32376 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32377 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32378 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32379 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32380 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32381 +
32382 + if (err)
32383 + break;
32384 +
32385 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32386 + regs->r11 = addr1;
32387 + regs->r10 = addr2;
32388 + if (stcclc == 0xF8)
32389 + regs->flags &= ~X86_EFLAGS_CF;
32390 + else
32391 + regs->flags |= X86_EFLAGS_CF;
32392 + regs->ip = addr1;
32393 + return 2;
32394 + }
32395 + } while (0);
32396 +
32397 + do { /* PaX: gcc trampoline emulation #1 */
32398 + unsigned short mov1, mov2, jmp1;
32399 + unsigned char jmp2;
32400 + unsigned int addr1;
32401 + unsigned long addr2;
32402 +
32403 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32404 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32405 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32406 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32407 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32408 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32409 +
32410 + if (err)
32411 + break;
32412 +
32413 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32414 + regs->r11 = addr1;
32415 + regs->r10 = addr2;
32416 + regs->ip = addr1;
32417 + return 2;
32418 + }
32419 + } while (0);
32420 +
32421 + do { /* PaX: gcc trampoline emulation #2 */
32422 + unsigned short mov1, mov2, jmp1;
32423 + unsigned char jmp2;
32424 + unsigned long addr1, addr2;
32425 +
32426 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32427 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32428 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32429 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32430 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32431 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32432 +
32433 + if (err)
32434 + break;
32435 +
32436 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32437 + regs->r11 = addr1;
32438 + regs->r10 = addr2;
32439 + regs->ip = addr1;
32440 + return 2;
32441 + }
32442 + } while (0);
32443 +
32444 + return 1; /* PaX in action */
32445 +}
32446 +#endif
32447 +
32448 +/*
32449 + * PaX: decide what to do with offenders (regs->ip = fault address)
32450 + *
32451 + * returns 1 when task should be killed
32452 + * 2 when gcc trampoline was detected
32453 + */
32454 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32455 +{
32456 + if (v8086_mode(regs))
32457 + return 1;
32458 +
32459 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32460 + return 1;
32461 +
32462 +#ifdef CONFIG_X86_32
32463 + return pax_handle_fetch_fault_32(regs);
32464 +#else
32465 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32466 + return pax_handle_fetch_fault_32(regs);
32467 + else
32468 + return pax_handle_fetch_fault_64(regs);
32469 +#endif
32470 +}
32471 +#endif
32472 +
32473 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32474 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32475 +{
32476 + long i;
32477 +
32478 + printk(KERN_ERR "PAX: bytes at PC: ");
32479 + for (i = 0; i < 20; i++) {
32480 + unsigned char c;
32481 + if (get_user(c, (unsigned char __force_user *)pc+i))
32482 + printk(KERN_CONT "?? ");
32483 + else
32484 + printk(KERN_CONT "%02x ", c);
32485 + }
32486 + printk("\n");
32487 +
32488 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32489 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32490 + unsigned long c;
32491 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32492 +#ifdef CONFIG_X86_32
32493 + printk(KERN_CONT "???????? ");
32494 +#else
32495 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32496 + printk(KERN_CONT "???????? ???????? ");
32497 + else
32498 + printk(KERN_CONT "???????????????? ");
32499 +#endif
32500 + } else {
32501 +#ifdef CONFIG_X86_64
32502 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32503 + printk(KERN_CONT "%08x ", (unsigned int)c);
32504 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32505 + } else
32506 +#endif
32507 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32508 + }
32509 + }
32510 + printk("\n");
32511 +}
32512 +#endif
32513 +
32514 +/**
32515 + * probe_kernel_write(): safely attempt to write to a location
32516 + * @dst: address to write to
32517 + * @src: pointer to the data that shall be written
32518 + * @size: size of the data chunk
32519 + *
32520 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32521 + * happens, handle that and return -EFAULT.
32522 + */
32523 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32524 +{
32525 + long ret;
32526 + mm_segment_t old_fs = get_fs();
32527 +
32528 + set_fs(KERNEL_DS);
32529 + pagefault_disable();
32530 + pax_open_kernel();
32531 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32532 + pax_close_kernel();
32533 + pagefault_enable();
32534 + set_fs(old_fs);
32535 +
32536 + return ret ? -EFAULT : 0;
32537 +}
32538 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32539 index 448ee89..88fe381 100644
32540 --- a/arch/x86/mm/gup.c
32541 +++ b/arch/x86/mm/gup.c
32542 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32543 addr = start;
32544 len = (unsigned long) nr_pages << PAGE_SHIFT;
32545 end = start + len;
32546 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32547 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32548 (void __user *)start, len)))
32549 return 0;
32550
32551 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32552 goto slow_irqon;
32553 #endif
32554
32555 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32556 + (void __user *)start, len)))
32557 + return 0;
32558 +
32559 /*
32560 * XXX: batch / limit 'nr', to avoid large irq off latency
32561 * needs some instrumenting to determine the common sizes used by
32562 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32563 index 4500142..53a363c 100644
32564 --- a/arch/x86/mm/highmem_32.c
32565 +++ b/arch/x86/mm/highmem_32.c
32566 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32567 idx = type + KM_TYPE_NR*smp_processor_id();
32568 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32569 BUG_ON(!pte_none(*(kmap_pte-idx)));
32570 +
32571 + pax_open_kernel();
32572 set_pte(kmap_pte-idx, mk_pte(page, prot));
32573 + pax_close_kernel();
32574 +
32575 arch_flush_lazy_mmu_mode();
32576
32577 return (void *)vaddr;
32578 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32579 index 006cc91..bf05a83 100644
32580 --- a/arch/x86/mm/hugetlbpage.c
32581 +++ b/arch/x86/mm/hugetlbpage.c
32582 @@ -86,23 +86,24 @@ int pud_huge(pud_t pud)
32583 #ifdef CONFIG_HUGETLB_PAGE
32584 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32585 unsigned long addr, unsigned long len,
32586 - unsigned long pgoff, unsigned long flags)
32587 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32588 {
32589 struct hstate *h = hstate_file(file);
32590 struct vm_unmapped_area_info info;
32591 -
32592 +
32593 info.flags = 0;
32594 info.length = len;
32595 info.low_limit = current->mm->mmap_legacy_base;
32596 info.high_limit = TASK_SIZE;
32597 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32598 info.align_offset = 0;
32599 + info.threadstack_offset = offset;
32600 return vm_unmapped_area(&info);
32601 }
32602
32603 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32604 unsigned long addr0, unsigned long len,
32605 - unsigned long pgoff, unsigned long flags)
32606 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32607 {
32608 struct hstate *h = hstate_file(file);
32609 struct vm_unmapped_area_info info;
32610 @@ -114,6 +115,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32611 info.high_limit = current->mm->mmap_base;
32612 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32613 info.align_offset = 0;
32614 + info.threadstack_offset = offset;
32615 addr = vm_unmapped_area(&info);
32616
32617 /*
32618 @@ -126,6 +128,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32619 VM_BUG_ON(addr != -ENOMEM);
32620 info.flags = 0;
32621 info.low_limit = TASK_UNMAPPED_BASE;
32622 +
32623 +#ifdef CONFIG_PAX_RANDMMAP
32624 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32625 + info.low_limit += current->mm->delta_mmap;
32626 +#endif
32627 +
32628 info.high_limit = TASK_SIZE;
32629 addr = vm_unmapped_area(&info);
32630 }
32631 @@ -140,10 +148,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32632 struct hstate *h = hstate_file(file);
32633 struct mm_struct *mm = current->mm;
32634 struct vm_area_struct *vma;
32635 + unsigned long pax_task_size = TASK_SIZE;
32636 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32637
32638 if (len & ~huge_page_mask(h))
32639 return -EINVAL;
32640 - if (len > TASK_SIZE)
32641 +
32642 +#ifdef CONFIG_PAX_SEGMEXEC
32643 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32644 + pax_task_size = SEGMEXEC_TASK_SIZE;
32645 +#endif
32646 +
32647 + pax_task_size -= PAGE_SIZE;
32648 +
32649 + if (len > pax_task_size)
32650 return -ENOMEM;
32651
32652 if (flags & MAP_FIXED) {
32653 @@ -152,19 +170,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32654 return addr;
32655 }
32656
32657 +#ifdef CONFIG_PAX_RANDMMAP
32658 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32659 +#endif
32660 +
32661 if (addr) {
32662 addr = ALIGN(addr, huge_page_size(h));
32663 vma = find_vma(mm, addr);
32664 - if (TASK_SIZE - len >= addr &&
32665 - (!vma || addr + len <= vma->vm_start))
32666 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32667 return addr;
32668 }
32669 if (mm->get_unmapped_area == arch_get_unmapped_area)
32670 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32671 - pgoff, flags);
32672 + pgoff, flags, offset);
32673 else
32674 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32675 - pgoff, flags);
32676 + pgoff, flags, offset);
32677 }
32678 #endif /* CONFIG_HUGETLB_PAGE */
32679
32680 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32681 index 66dba36..f8082ec 100644
32682 --- a/arch/x86/mm/init.c
32683 +++ b/arch/x86/mm/init.c
32684 @@ -4,6 +4,7 @@
32685 #include <linux/swap.h>
32686 #include <linux/memblock.h>
32687 #include <linux/bootmem.h> /* for max_low_pfn */
32688 +#include <linux/tboot.h>
32689
32690 #include <asm/cacheflush.h>
32691 #include <asm/e820.h>
32692 @@ -17,6 +18,8 @@
32693 #include <asm/proto.h>
32694 #include <asm/dma.h> /* for MAX_DMA_PFN */
32695 #include <asm/microcode.h>
32696 +#include <asm/desc.h>
32697 +#include <asm/bios_ebda.h>
32698
32699 /*
32700 * We need to define the tracepoints somewhere, and tlb.c
32701 @@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32702 early_ioremap_page_table_range_init();
32703 #endif
32704
32705 +#ifdef CONFIG_PAX_PER_CPU_PGD
32706 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32707 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32708 + KERNEL_PGD_PTRS);
32709 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32710 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32711 + KERNEL_PGD_PTRS);
32712 + load_cr3(get_cpu_pgd(0, kernel));
32713 +#else
32714 load_cr3(swapper_pg_dir);
32715 +#endif
32716 +
32717 __flush_tlb_all();
32718
32719 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32720 @@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32721 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32722 * mmio resources as well as potential bios/acpi data regions.
32723 */
32724 +
32725 +#ifdef CONFIG_GRKERNSEC_KMEM
32726 +static unsigned int ebda_start __read_only;
32727 +static unsigned int ebda_end __read_only;
32728 +#endif
32729 +
32730 int devmem_is_allowed(unsigned long pagenr)
32731 {
32732 - if (pagenr < 256)
32733 +#ifdef CONFIG_GRKERNSEC_KMEM
32734 + /* allow BDA */
32735 + if (!pagenr)
32736 return 1;
32737 + /* allow EBDA */
32738 + if (pagenr >= ebda_start && pagenr < ebda_end)
32739 + return 1;
32740 + /* if tboot is in use, allow access to its hardcoded serial log range */
32741 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32742 + return 1;
32743 +#else
32744 + if (!pagenr)
32745 + return 1;
32746 +#ifdef CONFIG_VM86
32747 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32748 + return 1;
32749 +#endif
32750 +#endif
32751 +
32752 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32753 + return 1;
32754 +#ifdef CONFIG_GRKERNSEC_KMEM
32755 + /* throw out everything else below 1MB */
32756 + if (pagenr <= 256)
32757 + return 0;
32758 +#endif
32759 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32760 return 0;
32761 if (!page_is_ram(pagenr))
32762 @@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32763 #endif
32764 }
32765
32766 +#ifdef CONFIG_GRKERNSEC_KMEM
32767 +static inline void gr_init_ebda(void)
32768 +{
32769 + unsigned int ebda_addr;
32770 + unsigned int ebda_size = 0;
32771 +
32772 + ebda_addr = get_bios_ebda();
32773 + if (ebda_addr) {
32774 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32775 + ebda_size <<= 10;
32776 + }
32777 + if (ebda_addr && ebda_size) {
32778 + ebda_start = ebda_addr >> PAGE_SHIFT;
32779 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32780 + } else {
32781 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32782 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32783 + }
32784 +}
32785 +#else
32786 +static inline void gr_init_ebda(void) { }
32787 +#endif
32788 +
32789 void free_initmem(void)
32790 {
32791 +#ifdef CONFIG_PAX_KERNEXEC
32792 +#ifdef CONFIG_X86_32
32793 + /* PaX: limit KERNEL_CS to actual size */
32794 + unsigned long addr, limit;
32795 + struct desc_struct d;
32796 + int cpu;
32797 +#else
32798 + pgd_t *pgd;
32799 + pud_t *pud;
32800 + pmd_t *pmd;
32801 + unsigned long addr, end;
32802 +#endif
32803 +#endif
32804 +
32805 + gr_init_ebda();
32806 +
32807 +#ifdef CONFIG_PAX_KERNEXEC
32808 +#ifdef CONFIG_X86_32
32809 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32810 + limit = (limit - 1UL) >> PAGE_SHIFT;
32811 +
32812 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32813 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32814 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32815 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32816 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32817 + }
32818 +
32819 + /* PaX: make KERNEL_CS read-only */
32820 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32821 + if (!paravirt_enabled())
32822 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32823 +/*
32824 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32825 + pgd = pgd_offset_k(addr);
32826 + pud = pud_offset(pgd, addr);
32827 + pmd = pmd_offset(pud, addr);
32828 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32829 + }
32830 +*/
32831 +#ifdef CONFIG_X86_PAE
32832 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32833 +/*
32834 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32835 + pgd = pgd_offset_k(addr);
32836 + pud = pud_offset(pgd, addr);
32837 + pmd = pmd_offset(pud, addr);
32838 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32839 + }
32840 +*/
32841 +#endif
32842 +
32843 +#ifdef CONFIG_MODULES
32844 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32845 +#endif
32846 +
32847 +#else
32848 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32849 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32850 + pgd = pgd_offset_k(addr);
32851 + pud = pud_offset(pgd, addr);
32852 + pmd = pmd_offset(pud, addr);
32853 + if (!pmd_present(*pmd))
32854 + continue;
32855 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32856 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32857 + else
32858 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32859 + }
32860 +
32861 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32862 + end = addr + KERNEL_IMAGE_SIZE;
32863 + for (; addr < end; addr += PMD_SIZE) {
32864 + pgd = pgd_offset_k(addr);
32865 + pud = pud_offset(pgd, addr);
32866 + pmd = pmd_offset(pud, addr);
32867 + if (!pmd_present(*pmd))
32868 + continue;
32869 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32870 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32871 + }
32872 +#endif
32873 +
32874 + flush_tlb_all();
32875 +#endif
32876 +
32877 free_init_pages("unused kernel",
32878 (unsigned long)(&__init_begin),
32879 (unsigned long)(&__init_end));
32880 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32881 index c8140e1..59257fc 100644
32882 --- a/arch/x86/mm/init_32.c
32883 +++ b/arch/x86/mm/init_32.c
32884 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32885 bool __read_mostly __vmalloc_start_set = false;
32886
32887 /*
32888 - * Creates a middle page table and puts a pointer to it in the
32889 - * given global directory entry. This only returns the gd entry
32890 - * in non-PAE compilation mode, since the middle layer is folded.
32891 - */
32892 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32893 -{
32894 - pud_t *pud;
32895 - pmd_t *pmd_table;
32896 -
32897 -#ifdef CONFIG_X86_PAE
32898 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32899 - pmd_table = (pmd_t *)alloc_low_page();
32900 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32901 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32902 - pud = pud_offset(pgd, 0);
32903 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32904 -
32905 - return pmd_table;
32906 - }
32907 -#endif
32908 - pud = pud_offset(pgd, 0);
32909 - pmd_table = pmd_offset(pud, 0);
32910 -
32911 - return pmd_table;
32912 -}
32913 -
32914 -/*
32915 * Create a page table and place a pointer to it in a middle page
32916 * directory entry:
32917 */
32918 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32919 pte_t *page_table = (pte_t *)alloc_low_page();
32920
32921 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32922 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32923 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32924 +#else
32925 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32926 +#endif
32927 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32928 }
32929
32930 return pte_offset_kernel(pmd, 0);
32931 }
32932
32933 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32934 +{
32935 + pud_t *pud;
32936 + pmd_t *pmd_table;
32937 +
32938 + pud = pud_offset(pgd, 0);
32939 + pmd_table = pmd_offset(pud, 0);
32940 +
32941 + return pmd_table;
32942 +}
32943 +
32944 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32945 {
32946 int pgd_idx = pgd_index(vaddr);
32947 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32948 int pgd_idx, pmd_idx;
32949 unsigned long vaddr;
32950 pgd_t *pgd;
32951 + pud_t *pud;
32952 pmd_t *pmd;
32953 pte_t *pte = NULL;
32954 unsigned long count = page_table_range_init_count(start, end);
32955 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32956 pgd = pgd_base + pgd_idx;
32957
32958 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32959 - pmd = one_md_table_init(pgd);
32960 - pmd = pmd + pmd_index(vaddr);
32961 + pud = pud_offset(pgd, vaddr);
32962 + pmd = pmd_offset(pud, vaddr);
32963 +
32964 +#ifdef CONFIG_X86_PAE
32965 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32966 +#endif
32967 +
32968 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32969 pmd++, pmd_idx++) {
32970 pte = page_table_kmap_check(one_page_table_init(pmd),
32971 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32972 }
32973 }
32974
32975 -static inline int is_kernel_text(unsigned long addr)
32976 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32977 {
32978 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32979 - return 1;
32980 - return 0;
32981 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32982 + end <= ktla_ktva((unsigned long)_stext)) &&
32983 + (start >= ktla_ktva((unsigned long)_einittext) ||
32984 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32985 +
32986 +#ifdef CONFIG_ACPI_SLEEP
32987 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32988 +#endif
32989 +
32990 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32991 + return 0;
32992 + return 1;
32993 }
32994
32995 /*
32996 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32997 unsigned long last_map_addr = end;
32998 unsigned long start_pfn, end_pfn;
32999 pgd_t *pgd_base = swapper_pg_dir;
33000 - int pgd_idx, pmd_idx, pte_ofs;
33001 + unsigned int pgd_idx, pmd_idx, pte_ofs;
33002 unsigned long pfn;
33003 pgd_t *pgd;
33004 + pud_t *pud;
33005 pmd_t *pmd;
33006 pte_t *pte;
33007 unsigned pages_2m, pages_4k;
33008 @@ -291,8 +295,13 @@ repeat:
33009 pfn = start_pfn;
33010 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33011 pgd = pgd_base + pgd_idx;
33012 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33013 - pmd = one_md_table_init(pgd);
33014 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33015 + pud = pud_offset(pgd, 0);
33016 + pmd = pmd_offset(pud, 0);
33017 +
33018 +#ifdef CONFIG_X86_PAE
33019 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33020 +#endif
33021
33022 if (pfn >= end_pfn)
33023 continue;
33024 @@ -304,14 +313,13 @@ repeat:
33025 #endif
33026 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33027 pmd++, pmd_idx++) {
33028 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33029 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33030
33031 /*
33032 * Map with big pages if possible, otherwise
33033 * create normal page tables:
33034 */
33035 if (use_pse) {
33036 - unsigned int addr2;
33037 pgprot_t prot = PAGE_KERNEL_LARGE;
33038 /*
33039 * first pass will use the same initial
33040 @@ -322,11 +330,7 @@ repeat:
33041 _PAGE_PSE);
33042
33043 pfn &= PMD_MASK >> PAGE_SHIFT;
33044 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33045 - PAGE_OFFSET + PAGE_SIZE-1;
33046 -
33047 - if (is_kernel_text(addr) ||
33048 - is_kernel_text(addr2))
33049 + if (is_kernel_text(address, address + PMD_SIZE))
33050 prot = PAGE_KERNEL_LARGE_EXEC;
33051
33052 pages_2m++;
33053 @@ -343,7 +347,7 @@ repeat:
33054 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33055 pte += pte_ofs;
33056 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33057 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33058 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33059 pgprot_t prot = PAGE_KERNEL;
33060 /*
33061 * first pass will use the same initial
33062 @@ -351,7 +355,7 @@ repeat:
33063 */
33064 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33065
33066 - if (is_kernel_text(addr))
33067 + if (is_kernel_text(address, address + PAGE_SIZE))
33068 prot = PAGE_KERNEL_EXEC;
33069
33070 pages_4k++;
33071 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33072
33073 pud = pud_offset(pgd, va);
33074 pmd = pmd_offset(pud, va);
33075 - if (!pmd_present(*pmd))
33076 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33077 break;
33078
33079 /* should not be large page here */
33080 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33081
33082 static void __init pagetable_init(void)
33083 {
33084 - pgd_t *pgd_base = swapper_pg_dir;
33085 -
33086 - permanent_kmaps_init(pgd_base);
33087 + permanent_kmaps_init(swapper_pg_dir);
33088 }
33089
33090 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33091 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33092 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33093
33094 /* user-defined highmem size */
33095 @@ -787,10 +789,10 @@ void __init mem_init(void)
33096 ((unsigned long)&__init_end -
33097 (unsigned long)&__init_begin) >> 10,
33098
33099 - (unsigned long)&_etext, (unsigned long)&_edata,
33100 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33101 + (unsigned long)&_sdata, (unsigned long)&_edata,
33102 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33103
33104 - (unsigned long)&_text, (unsigned long)&_etext,
33105 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33106 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33107
33108 /*
33109 @@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33110 if (!kernel_set_to_readonly)
33111 return;
33112
33113 + start = ktla_ktva(start);
33114 pr_debug("Set kernel text: %lx - %lx for read write\n",
33115 start, start+size);
33116
33117 @@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33118 if (!kernel_set_to_readonly)
33119 return;
33120
33121 + start = ktla_ktva(start);
33122 pr_debug("Set kernel text: %lx - %lx for read only\n",
33123 start, start+size);
33124
33125 @@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33126 unsigned long start = PFN_ALIGN(_text);
33127 unsigned long size = PFN_ALIGN(_etext) - start;
33128
33129 + start = ktla_ktva(start);
33130 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33131 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33132 size >> 10);
33133 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33134 index 4e5dfec..6fd6dc5 100644
33135 --- a/arch/x86/mm/init_64.c
33136 +++ b/arch/x86/mm/init_64.c
33137 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33138 * around without checking the pgd every time.
33139 */
33140
33141 -pteval_t __supported_pte_mask __read_mostly = ~0;
33142 +pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33143 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33144
33145 int force_personality32;
33146 @@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33147
33148 for (address = start; address <= end; address += PGDIR_SIZE) {
33149 const pgd_t *pgd_ref = pgd_offset_k(address);
33150 +
33151 +#ifdef CONFIG_PAX_PER_CPU_PGD
33152 + unsigned long cpu;
33153 +#else
33154 struct page *page;
33155 +#endif
33156
33157 /*
33158 * When it is called after memory hot remove, pgd_none()
33159 @@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33160 continue;
33161
33162 spin_lock(&pgd_lock);
33163 +
33164 +#ifdef CONFIG_PAX_PER_CPU_PGD
33165 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33166 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33167 +
33168 + if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33169 + BUG_ON(pgd_page_vaddr(*pgd)
33170 + != pgd_page_vaddr(*pgd_ref));
33171 +
33172 + if (removed) {
33173 + if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33174 + pgd_clear(pgd);
33175 + } else {
33176 + if (pgd_none(*pgd))
33177 + set_pgd(pgd, *pgd_ref);
33178 + }
33179 +
33180 + pgd = pgd_offset_cpu(cpu, kernel, address);
33181 +#else
33182 list_for_each_entry(page, &pgd_list, lru) {
33183 pgd_t *pgd;
33184 spinlock_t *pgt_lock;
33185 @@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33186 /* the pgt_lock only for Xen */
33187 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33188 spin_lock(pgt_lock);
33189 +#endif
33190
33191 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33192 BUG_ON(pgd_page_vaddr(*pgd)
33193 @@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33194 set_pgd(pgd, *pgd_ref);
33195 }
33196
33197 +#ifndef CONFIG_PAX_PER_CPU_PGD
33198 spin_unlock(pgt_lock);
33199 +#endif
33200 +
33201 }
33202 spin_unlock(&pgd_lock);
33203 }
33204 @@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33205 {
33206 if (pgd_none(*pgd)) {
33207 pud_t *pud = (pud_t *)spp_getpage();
33208 - pgd_populate(&init_mm, pgd, pud);
33209 + pgd_populate_kernel(&init_mm, pgd, pud);
33210 if (pud != pud_offset(pgd, 0))
33211 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33212 pud, pud_offset(pgd, 0));
33213 @@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33214 {
33215 if (pud_none(*pud)) {
33216 pmd_t *pmd = (pmd_t *) spp_getpage();
33217 - pud_populate(&init_mm, pud, pmd);
33218 + pud_populate_kernel(&init_mm, pud, pmd);
33219 if (pmd != pmd_offset(pud, 0))
33220 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33221 pmd, pmd_offset(pud, 0));
33222 @@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33223 pmd = fill_pmd(pud, vaddr);
33224 pte = fill_pte(pmd, vaddr);
33225
33226 + pax_open_kernel();
33227 set_pte(pte, new_pte);
33228 + pax_close_kernel();
33229
33230 /*
33231 * It's enough to flush this one mapping.
33232 @@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33233 pgd = pgd_offset_k((unsigned long)__va(phys));
33234 if (pgd_none(*pgd)) {
33235 pud = (pud_t *) spp_getpage();
33236 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33237 - _PAGE_USER));
33238 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33239 }
33240 pud = pud_offset(pgd, (unsigned long)__va(phys));
33241 if (pud_none(*pud)) {
33242 pmd = (pmd_t *) spp_getpage();
33243 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33244 - _PAGE_USER));
33245 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33246 }
33247 pmd = pmd_offset(pud, phys);
33248 BUG_ON(!pmd_none(*pmd));
33249 @@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33250 prot);
33251
33252 spin_lock(&init_mm.page_table_lock);
33253 - pud_populate(&init_mm, pud, pmd);
33254 + pud_populate_kernel(&init_mm, pud, pmd);
33255 spin_unlock(&init_mm.page_table_lock);
33256 }
33257 __flush_tlb_all();
33258 @@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33259 page_size_mask);
33260
33261 spin_lock(&init_mm.page_table_lock);
33262 - pgd_populate(&init_mm, pgd, pud);
33263 + pgd_populate_kernel(&init_mm, pgd, pud);
33264 spin_unlock(&init_mm.page_table_lock);
33265 pgd_changed = true;
33266 }
33267 @@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33268 static struct vm_area_struct gate_vma = {
33269 .vm_start = VSYSCALL_ADDR,
33270 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33271 - .vm_page_prot = PAGE_READONLY_EXEC,
33272 - .vm_flags = VM_READ | VM_EXEC,
33273 + .vm_page_prot = PAGE_READONLY,
33274 + .vm_flags = VM_READ,
33275 .vm_ops = &gate_vma_ops,
33276 };
33277
33278 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33279 index 7b179b49..6bd17777 100644
33280 --- a/arch/x86/mm/iomap_32.c
33281 +++ b/arch/x86/mm/iomap_32.c
33282 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33283 type = kmap_atomic_idx_push();
33284 idx = type + KM_TYPE_NR * smp_processor_id();
33285 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33286 +
33287 + pax_open_kernel();
33288 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33289 + pax_close_kernel();
33290 +
33291 arch_flush_lazy_mmu_mode();
33292
33293 return (void *)vaddr;
33294 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33295 index af78e50..4f1fe56 100644
33296 --- a/arch/x86/mm/ioremap.c
33297 +++ b/arch/x86/mm/ioremap.c
33298 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33299 unsigned long i;
33300
33301 for (i = 0; i < nr_pages; ++i)
33302 - if (pfn_valid(start_pfn + i) &&
33303 - !PageReserved(pfn_to_page(start_pfn + i)))
33304 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33305 + !PageReserved(pfn_to_page(start_pfn + i))))
33306 return 1;
33307
33308 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33309 @@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33310 *
33311 * Caller must ensure there is only one unmapping for the same pointer.
33312 */
33313 -void iounmap(volatile void __iomem *addr)
33314 +void iounmap(const volatile void __iomem *addr)
33315 {
33316 struct vm_struct *p, *o;
33317
33318 @@ -329,30 +329,29 @@ EXPORT_SYMBOL(iounmap);
33319 */
33320 void *xlate_dev_mem_ptr(unsigned long phys)
33321 {
33322 - void *addr;
33323 - unsigned long start = phys & PAGE_MASK;
33324 -
33325 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33326 - if (page_is_ram(start >> PAGE_SHIFT))
33327 + if (page_is_ram(phys >> PAGE_SHIFT))
33328 +#ifdef CONFIG_HIGHMEM
33329 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33330 +#endif
33331 return __va(phys);
33332
33333 - addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33334 - if (addr)
33335 - addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
33336 -
33337 - return addr;
33338 + return (void __force *)ioremap_cache(phys, PAGE_SIZE);
33339 }
33340
33341 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33342 {
33343 if (page_is_ram(phys >> PAGE_SHIFT))
33344 +#ifdef CONFIG_HIGHMEM
33345 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33346 +#endif
33347 return;
33348
33349 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33350 return;
33351 }
33352
33353 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33354 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33355
33356 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33357 {
33358 @@ -388,8 +387,7 @@ void __init early_ioremap_init(void)
33359 early_ioremap_setup();
33360
33361 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33362 - memset(bm_pte, 0, sizeof(bm_pte));
33363 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33364 + pmd_populate_user(&init_mm, pmd, bm_pte);
33365
33366 /*
33367 * The boot-ioremap range spans multiple pmds, for which
33368 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33369 index b4f2e7e..96c9c3e 100644
33370 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33371 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33372 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33373 * memory (e.g. tracked pages)? For now, we need this to avoid
33374 * invoking kmemcheck for PnP BIOS calls.
33375 */
33376 - if (regs->flags & X86_VM_MASK)
33377 + if (v8086_mode(regs))
33378 return false;
33379 - if (regs->cs != __KERNEL_CS)
33380 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33381 return false;
33382
33383 pte = kmemcheck_pte_lookup(address);
33384 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33385 index df4552b..12c129c 100644
33386 --- a/arch/x86/mm/mmap.c
33387 +++ b/arch/x86/mm/mmap.c
33388 @@ -52,7 +52,7 @@ static unsigned long stack_maxrandom_size(void)
33389 * Leave an at least ~128 MB hole with possible stack randomization.
33390 */
33391 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33392 -#define MAX_GAP (TASK_SIZE/6*5)
33393 +#define MAX_GAP (pax_task_size/6*5)
33394
33395 static int mmap_is_legacy(void)
33396 {
33397 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33398 return rnd << PAGE_SHIFT;
33399 }
33400
33401 -static unsigned long mmap_base(void)
33402 +static unsigned long mmap_base(struct mm_struct *mm)
33403 {
33404 unsigned long gap = rlimit(RLIMIT_STACK);
33405 + unsigned long pax_task_size = TASK_SIZE;
33406 +
33407 +#ifdef CONFIG_PAX_SEGMEXEC
33408 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33409 + pax_task_size = SEGMEXEC_TASK_SIZE;
33410 +#endif
33411
33412 if (gap < MIN_GAP)
33413 gap = MIN_GAP;
33414 else if (gap > MAX_GAP)
33415 gap = MAX_GAP;
33416
33417 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33418 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33419 }
33420
33421 /*
33422 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33423 * does, but not when emulating X86_32
33424 */
33425 -static unsigned long mmap_legacy_base(void)
33426 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33427 {
33428 - if (mmap_is_ia32())
33429 + if (mmap_is_ia32()) {
33430 +
33431 +#ifdef CONFIG_PAX_SEGMEXEC
33432 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33433 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33434 + else
33435 +#endif
33436 +
33437 return TASK_UNMAPPED_BASE;
33438 - else
33439 + } else
33440 return TASK_UNMAPPED_BASE + mmap_rnd();
33441 }
33442
33443 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33444 */
33445 void arch_pick_mmap_layout(struct mm_struct *mm)
33446 {
33447 - mm->mmap_legacy_base = mmap_legacy_base();
33448 - mm->mmap_base = mmap_base();
33449 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33450 + mm->mmap_base = mmap_base(mm);
33451 +
33452 +#ifdef CONFIG_PAX_RANDMMAP
33453 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33454 + mm->mmap_legacy_base += mm->delta_mmap;
33455 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33456 + }
33457 +#endif
33458
33459 if (mmap_is_legacy()) {
33460 mm->mmap_base = mm->mmap_legacy_base;
33461 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33462 index 0057a7a..95c7edd 100644
33463 --- a/arch/x86/mm/mmio-mod.c
33464 +++ b/arch/x86/mm/mmio-mod.c
33465 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33466 break;
33467 default:
33468 {
33469 - unsigned char *ip = (unsigned char *)instptr;
33470 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33471 my_trace->opcode = MMIO_UNKNOWN_OP;
33472 my_trace->width = 0;
33473 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33474 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33475 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33476 void __iomem *addr)
33477 {
33478 - static atomic_t next_id;
33479 + static atomic_unchecked_t next_id;
33480 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33481 /* These are page-unaligned. */
33482 struct mmiotrace_map map = {
33483 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33484 .private = trace
33485 },
33486 .phys = offset,
33487 - .id = atomic_inc_return(&next_id)
33488 + .id = atomic_inc_return_unchecked(&next_id)
33489 };
33490 map.map_id = trace->id;
33491
33492 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33493 ioremap_trace_core(offset, size, addr);
33494 }
33495
33496 -static void iounmap_trace_core(volatile void __iomem *addr)
33497 +static void iounmap_trace_core(const volatile void __iomem *addr)
33498 {
33499 struct mmiotrace_map map = {
33500 .phys = 0,
33501 @@ -328,7 +328,7 @@ not_enabled:
33502 }
33503 }
33504
33505 -void mmiotrace_iounmap(volatile void __iomem *addr)
33506 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33507 {
33508 might_sleep();
33509 if (is_enabled()) /* recheck and proper locking in *_core() */
33510 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33511 index 1a88370..3f598b5 100644
33512 --- a/arch/x86/mm/numa.c
33513 +++ b/arch/x86/mm/numa.c
33514 @@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33515 }
33516 }
33517
33518 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33519 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33520 {
33521 unsigned long uninitialized_var(pfn_align);
33522 int i, nid;
33523 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33524 index 36de293..b820ddc 100644
33525 --- a/arch/x86/mm/pageattr.c
33526 +++ b/arch/x86/mm/pageattr.c
33527 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33528 */
33529 #ifdef CONFIG_PCI_BIOS
33530 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33531 - pgprot_val(forbidden) |= _PAGE_NX;
33532 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33533 #endif
33534
33535 /*
33536 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33537 * Does not cover __inittext since that is gone later on. On
33538 * 64bit we do not enforce !NX on the low mapping
33539 */
33540 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33541 - pgprot_val(forbidden) |= _PAGE_NX;
33542 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33543 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33544
33545 +#ifdef CONFIG_DEBUG_RODATA
33546 /*
33547 * The .rodata section needs to be read-only. Using the pfn
33548 * catches all aliases.
33549 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33550 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33551 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33552 pgprot_val(forbidden) |= _PAGE_RW;
33553 +#endif
33554
33555 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33556 /*
33557 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33558 }
33559 #endif
33560
33561 +#ifdef CONFIG_PAX_KERNEXEC
33562 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33563 + pgprot_val(forbidden) |= _PAGE_RW;
33564 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33565 + }
33566 +#endif
33567 +
33568 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33569
33570 return prot;
33571 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33572 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33573 {
33574 /* change init_mm */
33575 + pax_open_kernel();
33576 set_pte_atomic(kpte, pte);
33577 +
33578 #ifdef CONFIG_X86_32
33579 if (!SHARED_KERNEL_PMD) {
33580 +
33581 +#ifdef CONFIG_PAX_PER_CPU_PGD
33582 + unsigned long cpu;
33583 +#else
33584 struct page *page;
33585 +#endif
33586
33587 +#ifdef CONFIG_PAX_PER_CPU_PGD
33588 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33589 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33590 +#else
33591 list_for_each_entry(page, &pgd_list, lru) {
33592 - pgd_t *pgd;
33593 + pgd_t *pgd = (pgd_t *)page_address(page);
33594 +#endif
33595 +
33596 pud_t *pud;
33597 pmd_t *pmd;
33598
33599 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33600 + pgd += pgd_index(address);
33601 pud = pud_offset(pgd, address);
33602 pmd = pmd_offset(pud, address);
33603 set_pte_atomic((pte_t *)pmd, pte);
33604 }
33605 }
33606 #endif
33607 + pax_close_kernel();
33608 }
33609
33610 static int
33611 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33612 index 6574388..87e9bef 100644
33613 --- a/arch/x86/mm/pat.c
33614 +++ b/arch/x86/mm/pat.c
33615 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33616
33617 if (!entry) {
33618 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33619 - current->comm, current->pid, start, end - 1);
33620 + current->comm, task_pid_nr(current), start, end - 1);
33621 return -EINVAL;
33622 }
33623
33624 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33625
33626 while (cursor < to) {
33627 if (!devmem_is_allowed(pfn)) {
33628 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33629 - current->comm, from, to - 1);
33630 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33631 + current->comm, from, to - 1, cursor);
33632 return 0;
33633 }
33634 cursor += PAGE_SIZE;
33635 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33636 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33637 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33638 "for [mem %#010Lx-%#010Lx]\n",
33639 - current->comm, current->pid,
33640 + current->comm, task_pid_nr(current),
33641 cattr_name(flags),
33642 base, (unsigned long long)(base + size-1));
33643 return -EINVAL;
33644 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33645 flags = lookup_memtype(paddr);
33646 if (want_flags != flags) {
33647 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33648 - current->comm, current->pid,
33649 + current->comm, task_pid_nr(current),
33650 cattr_name(want_flags),
33651 (unsigned long long)paddr,
33652 (unsigned long long)(paddr + size - 1),
33653 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33654 free_memtype(paddr, paddr + size);
33655 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33656 " for [mem %#010Lx-%#010Lx], got %s\n",
33657 - current->comm, current->pid,
33658 + current->comm, task_pid_nr(current),
33659 cattr_name(want_flags),
33660 (unsigned long long)paddr,
33661 (unsigned long long)(paddr + size - 1),
33662 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33663 index 415f6c4..d319983 100644
33664 --- a/arch/x86/mm/pat_rbtree.c
33665 +++ b/arch/x86/mm/pat_rbtree.c
33666 @@ -160,7 +160,7 @@ success:
33667
33668 failure:
33669 printk(KERN_INFO "%s:%d conflicting memory types "
33670 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33671 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33672 end, cattr_name(found_type), cattr_name(match->type));
33673 return -EBUSY;
33674 }
33675 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33676 index 9f0614d..92ae64a 100644
33677 --- a/arch/x86/mm/pf_in.c
33678 +++ b/arch/x86/mm/pf_in.c
33679 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33680 int i;
33681 enum reason_type rv = OTHERS;
33682
33683 - p = (unsigned char *)ins_addr;
33684 + p = (unsigned char *)ktla_ktva(ins_addr);
33685 p += skip_prefix(p, &prf);
33686 p += get_opcode(p, &opcode);
33687
33688 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33689 struct prefix_bits prf;
33690 int i;
33691
33692 - p = (unsigned char *)ins_addr;
33693 + p = (unsigned char *)ktla_ktva(ins_addr);
33694 p += skip_prefix(p, &prf);
33695 p += get_opcode(p, &opcode);
33696
33697 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33698 struct prefix_bits prf;
33699 int i;
33700
33701 - p = (unsigned char *)ins_addr;
33702 + p = (unsigned char *)ktla_ktva(ins_addr);
33703 p += skip_prefix(p, &prf);
33704 p += get_opcode(p, &opcode);
33705
33706 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33707 struct prefix_bits prf;
33708 int i;
33709
33710 - p = (unsigned char *)ins_addr;
33711 + p = (unsigned char *)ktla_ktva(ins_addr);
33712 p += skip_prefix(p, &prf);
33713 p += get_opcode(p, &opcode);
33714 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33715 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33716 struct prefix_bits prf;
33717 int i;
33718
33719 - p = (unsigned char *)ins_addr;
33720 + p = (unsigned char *)ktla_ktva(ins_addr);
33721 p += skip_prefix(p, &prf);
33722 p += get_opcode(p, &opcode);
33723 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33724 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33725 index 6fb6927..4fc13c0 100644
33726 --- a/arch/x86/mm/pgtable.c
33727 +++ b/arch/x86/mm/pgtable.c
33728 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33729 list_del(&page->lru);
33730 }
33731
33732 -#define UNSHARED_PTRS_PER_PGD \
33733 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33734 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33735 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33736
33737 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33738 +{
33739 + unsigned int count = USER_PGD_PTRS;
33740
33741 + if (!pax_user_shadow_base)
33742 + return;
33743 +
33744 + while (count--)
33745 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33746 +}
33747 +#endif
33748 +
33749 +#ifdef CONFIG_PAX_PER_CPU_PGD
33750 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33751 +{
33752 + unsigned int count = USER_PGD_PTRS;
33753 +
33754 + while (count--) {
33755 + pgd_t pgd;
33756 +
33757 +#ifdef CONFIG_X86_64
33758 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33759 +#else
33760 + pgd = *src++;
33761 +#endif
33762 +
33763 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33764 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33765 +#endif
33766 +
33767 + *dst++ = pgd;
33768 + }
33769 +
33770 +}
33771 +#endif
33772 +
33773 +#ifdef CONFIG_X86_64
33774 +#define pxd_t pud_t
33775 +#define pyd_t pgd_t
33776 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33777 +#define pgtable_pxd_page_ctor(page) true
33778 +#define pgtable_pxd_page_dtor(page)
33779 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33780 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33781 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33782 +#define PYD_SIZE PGDIR_SIZE
33783 +#else
33784 +#define pxd_t pmd_t
33785 +#define pyd_t pud_t
33786 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33787 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33788 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33789 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33790 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33791 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33792 +#define PYD_SIZE PUD_SIZE
33793 +#endif
33794 +
33795 +#ifdef CONFIG_PAX_PER_CPU_PGD
33796 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33797 +static inline void pgd_dtor(pgd_t *pgd) {}
33798 +#else
33799 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33800 {
33801 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33802 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33803 pgd_list_del(pgd);
33804 spin_unlock(&pgd_lock);
33805 }
33806 +#endif
33807
33808 /*
33809 * List of all pgd's needed for non-PAE so it can invalidate entries
33810 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33811 * -- nyc
33812 */
33813
33814 -#ifdef CONFIG_X86_PAE
33815 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33816 /*
33817 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33818 * updating the top-level pagetable entries to guarantee the
33819 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33820 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33821 * and initialize the kernel pmds here.
33822 */
33823 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33824 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33825
33826 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33827 {
33828 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33829 */
33830 flush_tlb_mm(mm);
33831 }
33832 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33833 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33834 #else /* !CONFIG_X86_PAE */
33835
33836 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33837 -#define PREALLOCATED_PMDS 0
33838 +#define PREALLOCATED_PXDS 0
33839
33840 #endif /* CONFIG_X86_PAE */
33841
33842 -static void free_pmds(pmd_t *pmds[])
33843 +static void free_pxds(pxd_t *pxds[])
33844 {
33845 int i;
33846
33847 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33848 - if (pmds[i]) {
33849 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33850 - free_page((unsigned long)pmds[i]);
33851 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33852 + if (pxds[i]) {
33853 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33854 + free_page((unsigned long)pxds[i]);
33855 }
33856 }
33857
33858 -static int preallocate_pmds(pmd_t *pmds[])
33859 +static int preallocate_pxds(pxd_t *pxds[])
33860 {
33861 int i;
33862 bool failed = false;
33863
33864 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33865 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33866 - if (!pmd)
33867 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33868 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33869 + if (!pxd)
33870 failed = true;
33871 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33872 - free_page((unsigned long)pmd);
33873 - pmd = NULL;
33874 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33875 + free_page((unsigned long)pxd);
33876 + pxd = NULL;
33877 failed = true;
33878 }
33879 - pmds[i] = pmd;
33880 + pxds[i] = pxd;
33881 }
33882
33883 if (failed) {
33884 - free_pmds(pmds);
33885 + free_pxds(pxds);
33886 return -ENOMEM;
33887 }
33888
33889 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33890 * preallocate which never got a corresponding vma will need to be
33891 * freed manually.
33892 */
33893 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33894 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33895 {
33896 int i;
33897
33898 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33899 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33900 pgd_t pgd = pgdp[i];
33901
33902 if (pgd_val(pgd) != 0) {
33903 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33904 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33905
33906 - pgdp[i] = native_make_pgd(0);
33907 + set_pgd(pgdp + i, native_make_pgd(0));
33908
33909 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33910 - pmd_free(mm, pmd);
33911 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33912 + pxd_free(mm, pxd);
33913 }
33914 }
33915 }
33916
33917 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33918 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33919 {
33920 - pud_t *pud;
33921 + pyd_t *pyd;
33922 int i;
33923
33924 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33925 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33926 return;
33927
33928 - pud = pud_offset(pgd, 0);
33929 -
33930 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33931 - pmd_t *pmd = pmds[i];
33932 +#ifdef CONFIG_X86_64
33933 + pyd = pyd_offset(mm, 0L);
33934 +#else
33935 + pyd = pyd_offset(pgd, 0L);
33936 +#endif
33937
33938 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33939 + pxd_t *pxd = pxds[i];
33940 if (i >= KERNEL_PGD_BOUNDARY)
33941 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33942 - sizeof(pmd_t) * PTRS_PER_PMD);
33943 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33944 + sizeof(pxd_t) * PTRS_PER_PMD);
33945
33946 - pud_populate(mm, pud, pmd);
33947 + pyd_populate(mm, pyd, pxd);
33948 }
33949 }
33950
33951 pgd_t *pgd_alloc(struct mm_struct *mm)
33952 {
33953 pgd_t *pgd;
33954 - pmd_t *pmds[PREALLOCATED_PMDS];
33955 + pxd_t *pxds[PREALLOCATED_PXDS];
33956
33957 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33958
33959 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33960
33961 mm->pgd = pgd;
33962
33963 - if (preallocate_pmds(pmds) != 0)
33964 + if (preallocate_pxds(pxds) != 0)
33965 goto out_free_pgd;
33966
33967 if (paravirt_pgd_alloc(mm) != 0)
33968 - goto out_free_pmds;
33969 + goto out_free_pxds;
33970
33971 /*
33972 * Make sure that pre-populating the pmds is atomic with
33973 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33974 spin_lock(&pgd_lock);
33975
33976 pgd_ctor(mm, pgd);
33977 - pgd_prepopulate_pmd(mm, pgd, pmds);
33978 + pgd_prepopulate_pxd(mm, pgd, pxds);
33979
33980 spin_unlock(&pgd_lock);
33981
33982 return pgd;
33983
33984 -out_free_pmds:
33985 - free_pmds(pmds);
33986 +out_free_pxds:
33987 + free_pxds(pxds);
33988 out_free_pgd:
33989 free_page((unsigned long)pgd);
33990 out:
33991 @@ -313,7 +380,7 @@ out:
33992
33993 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33994 {
33995 - pgd_mop_up_pmds(mm, pgd);
33996 + pgd_mop_up_pxds(mm, pgd);
33997 pgd_dtor(pgd);
33998 paravirt_pgd_free(mm, pgd);
33999 free_page((unsigned long)pgd);
34000 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34001 index 75cc097..79a097f 100644
34002 --- a/arch/x86/mm/pgtable_32.c
34003 +++ b/arch/x86/mm/pgtable_32.c
34004 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34005 return;
34006 }
34007 pte = pte_offset_kernel(pmd, vaddr);
34008 +
34009 + pax_open_kernel();
34010 if (pte_val(pteval))
34011 set_pte_at(&init_mm, vaddr, pte, pteval);
34012 else
34013 pte_clear(&init_mm, vaddr, pte);
34014 + pax_close_kernel();
34015
34016 /*
34017 * It's enough to flush this one mapping.
34018 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34019 index e666cbb..61788c45 100644
34020 --- a/arch/x86/mm/physaddr.c
34021 +++ b/arch/x86/mm/physaddr.c
34022 @@ -10,7 +10,7 @@
34023 #ifdef CONFIG_X86_64
34024
34025 #ifdef CONFIG_DEBUG_VIRTUAL
34026 -unsigned long __phys_addr(unsigned long x)
34027 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34028 {
34029 unsigned long y = x - __START_KERNEL_map;
34030
34031 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34032 #else
34033
34034 #ifdef CONFIG_DEBUG_VIRTUAL
34035 -unsigned long __phys_addr(unsigned long x)
34036 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34037 {
34038 unsigned long phys_addr = x - PAGE_OFFSET;
34039 /* VMALLOC_* aren't constants */
34040 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34041 index 90555bf..f5f1828 100644
34042 --- a/arch/x86/mm/setup_nx.c
34043 +++ b/arch/x86/mm/setup_nx.c
34044 @@ -5,8 +5,10 @@
34045 #include <asm/pgtable.h>
34046 #include <asm/proto.h>
34047
34048 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34049 static int disable_nx;
34050
34051 +#ifndef CONFIG_PAX_PAGEEXEC
34052 /*
34053 * noexec = on|off
34054 *
34055 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34056 return 0;
34057 }
34058 early_param("noexec", noexec_setup);
34059 +#endif
34060 +
34061 +#endif
34062
34063 void x86_configure_nx(void)
34064 {
34065 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34066 if (cpu_has_nx && !disable_nx)
34067 __supported_pte_mask |= _PAGE_NX;
34068 else
34069 +#endif
34070 __supported_pte_mask &= ~_PAGE_NX;
34071 }
34072
34073 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34074 index ee61c36..e6fedeb 100644
34075 --- a/arch/x86/mm/tlb.c
34076 +++ b/arch/x86/mm/tlb.c
34077 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
34078 BUG();
34079 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34080 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34081 +
34082 +#ifndef CONFIG_PAX_PER_CPU_PGD
34083 load_cr3(swapper_pg_dir);
34084 +#endif
34085 +
34086 /*
34087 * This gets called in the idle path where RCU
34088 * functions differently. Tracing normally
34089 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34090 new file mode 100644
34091 index 0000000..dace51c
34092 --- /dev/null
34093 +++ b/arch/x86/mm/uderef_64.c
34094 @@ -0,0 +1,37 @@
34095 +#include <linux/mm.h>
34096 +#include <asm/pgtable.h>
34097 +#include <asm/uaccess.h>
34098 +
34099 +#ifdef CONFIG_PAX_MEMORY_UDEREF
34100 +/* PaX: due to the special call convention these functions must
34101 + * - remain leaf functions under all configurations,
34102 + * - never be called directly, only dereferenced from the wrappers.
34103 + */
34104 +void __pax_open_userland(void)
34105 +{
34106 + unsigned int cpu;
34107 +
34108 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34109 + return;
34110 +
34111 + cpu = raw_get_cpu();
34112 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34113 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34114 + raw_put_cpu_no_resched();
34115 +}
34116 +EXPORT_SYMBOL(__pax_open_userland);
34117 +
34118 +void __pax_close_userland(void)
34119 +{
34120 + unsigned int cpu;
34121 +
34122 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34123 + return;
34124 +
34125 + cpu = raw_get_cpu();
34126 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34127 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34128 + raw_put_cpu_no_resched();
34129 +}
34130 +EXPORT_SYMBOL(__pax_close_userland);
34131 +#endif
34132 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34133 index 6440221..f84b5c7 100644
34134 --- a/arch/x86/net/bpf_jit.S
34135 +++ b/arch/x86/net/bpf_jit.S
34136 @@ -9,6 +9,7 @@
34137 */
34138 #include <linux/linkage.h>
34139 #include <asm/dwarf2.h>
34140 +#include <asm/alternative-asm.h>
34141
34142 /*
34143 * Calling convention :
34144 @@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34145 jle bpf_slow_path_word
34146 mov (SKBDATA,%rsi),%eax
34147 bswap %eax /* ntohl() */
34148 + pax_force_retaddr
34149 ret
34150
34151 sk_load_half:
34152 @@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34153 jle bpf_slow_path_half
34154 movzwl (SKBDATA,%rsi),%eax
34155 rol $8,%ax # ntohs()
34156 + pax_force_retaddr
34157 ret
34158
34159 sk_load_byte:
34160 @@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34161 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34162 jle bpf_slow_path_byte
34163 movzbl (SKBDATA,%rsi),%eax
34164 + pax_force_retaddr
34165 ret
34166
34167 /* rsi contains offset and can be scratched */
34168 @@ -90,6 +94,7 @@ bpf_slow_path_word:
34169 js bpf_error
34170 mov - MAX_BPF_STACK + 32(%rbp),%eax
34171 bswap %eax
34172 + pax_force_retaddr
34173 ret
34174
34175 bpf_slow_path_half:
34176 @@ -98,12 +103,14 @@ bpf_slow_path_half:
34177 mov - MAX_BPF_STACK + 32(%rbp),%ax
34178 rol $8,%ax
34179 movzwl %ax,%eax
34180 + pax_force_retaddr
34181 ret
34182
34183 bpf_slow_path_byte:
34184 bpf_slow_path_common(1)
34185 js bpf_error
34186 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34187 + pax_force_retaddr
34188 ret
34189
34190 #define sk_negative_common(SIZE) \
34191 @@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34192 sk_negative_common(4)
34193 mov (%rax), %eax
34194 bswap %eax
34195 + pax_force_retaddr
34196 ret
34197
34198 bpf_slow_path_half_neg:
34199 @@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34200 mov (%rax),%ax
34201 rol $8,%ax
34202 movzwl %ax,%eax
34203 + pax_force_retaddr
34204 ret
34205
34206 bpf_slow_path_byte_neg:
34207 @@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34208 .globl sk_load_byte_negative_offset
34209 sk_negative_common(1)
34210 movzbl (%rax), %eax
34211 + pax_force_retaddr
34212 ret
34213
34214 bpf_error:
34215 @@ -156,4 +166,5 @@ bpf_error:
34216 mov - MAX_BPF_STACK + 16(%rbp),%r14
34217 mov - MAX_BPF_STACK + 24(%rbp),%r15
34218 leaveq
34219 + pax_force_retaddr
34220 ret
34221 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34222 index 3f62734..a57894f 100644
34223 --- a/arch/x86/net/bpf_jit_comp.c
34224 +++ b/arch/x86/net/bpf_jit_comp.c
34225 @@ -13,7 +13,11 @@
34226 #include <linux/if_vlan.h>
34227 #include <asm/cacheflush.h>
34228
34229 +#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34230 +int bpf_jit_enable __read_only;
34231 +#else
34232 int bpf_jit_enable __read_mostly;
34233 +#endif
34234
34235 /*
34236 * assembly code in arch/x86/net/bpf_jit.S
34237 @@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34238 static void jit_fill_hole(void *area, unsigned int size)
34239 {
34240 /* fill whole space with int3 instructions */
34241 + pax_open_kernel();
34242 memset(area, 0xcc, size);
34243 + pax_close_kernel();
34244 }
34245
34246 struct jit_context {
34247 @@ -894,7 +900,9 @@ common_load:
34248 pr_err("bpf_jit_compile fatal error\n");
34249 return -EFAULT;
34250 }
34251 + pax_open_kernel();
34252 memcpy(image + proglen, temp, ilen);
34253 + pax_close_kernel();
34254 }
34255 proglen += ilen;
34256 addrs[i] = proglen;
34257 @@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34258
34259 if (image) {
34260 bpf_flush_icache(header, image + proglen);
34261 - set_memory_ro((unsigned long)header, header->pages);
34262 prog->bpf_func = (void *)image;
34263 prog->jited = true;
34264 }
34265 @@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34266 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34267 struct bpf_binary_header *header = (void *)addr;
34268
34269 - if (!fp->jited)
34270 - goto free_filter;
34271 + if (fp->jited)
34272 + bpf_jit_binary_free(header);
34273
34274 - set_memory_rw(addr, header->pages);
34275 - bpf_jit_binary_free(header);
34276 -
34277 -free_filter:
34278 bpf_prog_unlock_free(fp);
34279 }
34280 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34281 index 5d04be5..2beeaa2 100644
34282 --- a/arch/x86/oprofile/backtrace.c
34283 +++ b/arch/x86/oprofile/backtrace.c
34284 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34285 struct stack_frame_ia32 *fp;
34286 unsigned long bytes;
34287
34288 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34289 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34290 if (bytes != 0)
34291 return NULL;
34292
34293 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34294 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34295
34296 oprofile_add_trace(bufhead[0].return_address);
34297
34298 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34299 struct stack_frame bufhead[2];
34300 unsigned long bytes;
34301
34302 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34303 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34304 if (bytes != 0)
34305 return NULL;
34306
34307 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34308 {
34309 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34310
34311 - if (!user_mode_vm(regs)) {
34312 + if (!user_mode(regs)) {
34313 unsigned long stack = kernel_stack_pointer(regs);
34314 if (depth)
34315 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34316 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34317 index 1d2e639..f6ef82a 100644
34318 --- a/arch/x86/oprofile/nmi_int.c
34319 +++ b/arch/x86/oprofile/nmi_int.c
34320 @@ -23,6 +23,7 @@
34321 #include <asm/nmi.h>
34322 #include <asm/msr.h>
34323 #include <asm/apic.h>
34324 +#include <asm/pgtable.h>
34325
34326 #include "op_counter.h"
34327 #include "op_x86_model.h"
34328 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34329 if (ret)
34330 return ret;
34331
34332 - if (!model->num_virt_counters)
34333 - model->num_virt_counters = model->num_counters;
34334 + if (!model->num_virt_counters) {
34335 + pax_open_kernel();
34336 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34337 + pax_close_kernel();
34338 + }
34339
34340 mux_init(ops);
34341
34342 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34343 index 50d86c0..7985318 100644
34344 --- a/arch/x86/oprofile/op_model_amd.c
34345 +++ b/arch/x86/oprofile/op_model_amd.c
34346 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34347 num_counters = AMD64_NUM_COUNTERS;
34348 }
34349
34350 - op_amd_spec.num_counters = num_counters;
34351 - op_amd_spec.num_controls = num_counters;
34352 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34353 + pax_open_kernel();
34354 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34355 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34356 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34357 + pax_close_kernel();
34358
34359 return 0;
34360 }
34361 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34362 index d90528e..0127e2b 100644
34363 --- a/arch/x86/oprofile/op_model_ppro.c
34364 +++ b/arch/x86/oprofile/op_model_ppro.c
34365 @@ -19,6 +19,7 @@
34366 #include <asm/msr.h>
34367 #include <asm/apic.h>
34368 #include <asm/nmi.h>
34369 +#include <asm/pgtable.h>
34370
34371 #include "op_x86_model.h"
34372 #include "op_counter.h"
34373 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34374
34375 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34376
34377 - op_arch_perfmon_spec.num_counters = num_counters;
34378 - op_arch_perfmon_spec.num_controls = num_counters;
34379 + pax_open_kernel();
34380 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34381 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34382 + pax_close_kernel();
34383 }
34384
34385 static int arch_perfmon_init(struct oprofile_operations *ignore)
34386 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34387 index 71e8a67..6a313bb 100644
34388 --- a/arch/x86/oprofile/op_x86_model.h
34389 +++ b/arch/x86/oprofile/op_x86_model.h
34390 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34391 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34392 struct op_msrs const * const msrs);
34393 #endif
34394 -};
34395 +} __do_const;
34396
34397 struct op_counter_config;
34398
34399 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34400 index b9958c3..24229ab 100644
34401 --- a/arch/x86/pci/intel_mid_pci.c
34402 +++ b/arch/x86/pci/intel_mid_pci.c
34403 @@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34404 pci_mmcfg_late_init();
34405 pcibios_enable_irq = intel_mid_pci_irq_enable;
34406 pcibios_disable_irq = intel_mid_pci_irq_disable;
34407 - pci_root_ops = intel_mid_pci_ops;
34408 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34409 pci_soc_mode = 1;
34410 /* Continue with standard init */
34411 return 1;
34412 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34413 index eb500c2..eab9e70 100644
34414 --- a/arch/x86/pci/irq.c
34415 +++ b/arch/x86/pci/irq.c
34416 @@ -51,7 +51,7 @@ struct irq_router {
34417 struct irq_router_handler {
34418 u16 vendor;
34419 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34420 -};
34421 +} __do_const;
34422
34423 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34424 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34425 @@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34426 return 0;
34427 }
34428
34429 -static __initdata struct irq_router_handler pirq_routers[] = {
34430 +static __initconst const struct irq_router_handler pirq_routers[] = {
34431 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34432 { PCI_VENDOR_ID_AL, ali_router_probe },
34433 { PCI_VENDOR_ID_ITE, ite_router_probe },
34434 @@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34435 static void __init pirq_find_router(struct irq_router *r)
34436 {
34437 struct irq_routing_table *rt = pirq_table;
34438 - struct irq_router_handler *h;
34439 + const struct irq_router_handler *h;
34440
34441 #ifdef CONFIG_PCI_BIOS
34442 if (!rt->signature) {
34443 @@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34444 return 0;
34445 }
34446
34447 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34448 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34449 {
34450 .callback = fix_broken_hp_bios_irq9,
34451 .ident = "HP Pavilion N5400 Series Laptop",
34452 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34453 index 9b83b90..4112152 100644
34454 --- a/arch/x86/pci/pcbios.c
34455 +++ b/arch/x86/pci/pcbios.c
34456 @@ -79,7 +79,7 @@ union bios32 {
34457 static struct {
34458 unsigned long address;
34459 unsigned short segment;
34460 -} bios32_indirect __initdata = { 0, __KERNEL_CS };
34461 +} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34462
34463 /*
34464 * Returns the entry point for the given service, NULL on error
34465 @@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34466 unsigned long length; /* %ecx */
34467 unsigned long entry; /* %edx */
34468 unsigned long flags;
34469 + struct desc_struct d, *gdt;
34470
34471 local_irq_save(flags);
34472 - __asm__("lcall *(%%edi); cld"
34473 +
34474 + gdt = get_cpu_gdt_table(smp_processor_id());
34475 +
34476 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34477 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34478 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34479 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34480 +
34481 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34482 : "=a" (return_code),
34483 "=b" (address),
34484 "=c" (length),
34485 "=d" (entry)
34486 : "0" (service),
34487 "1" (0),
34488 - "D" (&bios32_indirect));
34489 + "D" (&bios32_indirect),
34490 + "r"(__PCIBIOS_DS)
34491 + : "memory");
34492 +
34493 + pax_open_kernel();
34494 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34495 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34496 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34497 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34498 + pax_close_kernel();
34499 +
34500 local_irq_restore(flags);
34501
34502 switch (return_code) {
34503 - case 0:
34504 - return address + entry;
34505 - case 0x80: /* Not present */
34506 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34507 - return 0;
34508 - default: /* Shouldn't happen */
34509 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34510 - service, return_code);
34511 + case 0: {
34512 + int cpu;
34513 + unsigned char flags;
34514 +
34515 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34516 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34517 + printk(KERN_WARNING "bios32_service: not valid\n");
34518 return 0;
34519 + }
34520 + address = address + PAGE_OFFSET;
34521 + length += 16UL; /* some BIOSs underreport this... */
34522 + flags = 4;
34523 + if (length >= 64*1024*1024) {
34524 + length >>= PAGE_SHIFT;
34525 + flags |= 8;
34526 + }
34527 +
34528 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34529 + gdt = get_cpu_gdt_table(cpu);
34530 + pack_descriptor(&d, address, length, 0x9b, flags);
34531 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34532 + pack_descriptor(&d, address, length, 0x93, flags);
34533 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34534 + }
34535 + return entry;
34536 + }
34537 + case 0x80: /* Not present */
34538 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34539 + return 0;
34540 + default: /* Shouldn't happen */
34541 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34542 + service, return_code);
34543 + return 0;
34544 }
34545 }
34546
34547 static struct {
34548 unsigned long address;
34549 unsigned short segment;
34550 -} pci_indirect = { 0, __KERNEL_CS };
34551 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34552
34553 -static int pci_bios_present;
34554 +static int pci_bios_present __read_only;
34555
34556 static int __init check_pcibios(void)
34557 {
34558 @@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34559 unsigned long flags, pcibios_entry;
34560
34561 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34562 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34563 + pci_indirect.address = pcibios_entry;
34564
34565 local_irq_save(flags);
34566 - __asm__(
34567 - "lcall *(%%edi); cld\n\t"
34568 + __asm__("movw %w6, %%ds\n\t"
34569 + "lcall *%%ss:(%%edi); 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 @@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34576 "=b" (ebx),
34577 "=c" (ecx)
34578 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34579 - "D" (&pci_indirect)
34580 + "D" (&pci_indirect),
34581 + "r" (__PCIBIOS_DS)
34582 : "memory");
34583 local_irq_restore(flags);
34584
34585 @@ -189,7 +235,10 @@ static int pci_bios_read(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 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34598 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34599 "b" (bx),
34600 "D" ((long)reg),
34601 - "S" (&pci_indirect));
34602 + "S" (&pci_indirect),
34603 + "r" (__PCIBIOS_DS));
34604 /*
34605 * Zero-extend the result beyond 8 bits, do not trust the
34606 * BIOS having done it:
34607 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34608 *value &= 0xff;
34609 break;
34610 case 2:
34611 - __asm__("lcall *(%%esi); cld\n\t"
34612 + __asm__("movw %w6, %%ds\n\t"
34613 + "lcall *%%ss:(%%esi); cld\n\t"
34614 + "push %%ss\n\t"
34615 + "pop %%ds\n\t"
34616 "jc 1f\n\t"
34617 "xor %%ah, %%ah\n"
34618 "1:"
34619 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34620 : "1" (PCIBIOS_READ_CONFIG_WORD),
34621 "b" (bx),
34622 "D" ((long)reg),
34623 - "S" (&pci_indirect));
34624 + "S" (&pci_indirect),
34625 + "r" (__PCIBIOS_DS));
34626 /*
34627 * Zero-extend the result beyond 16 bits, do not trust the
34628 * BIOS having done it:
34629 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34630 *value &= 0xffff;
34631 break;
34632 case 4:
34633 - __asm__("lcall *(%%esi); cld\n\t"
34634 + __asm__("movw %w6, %%ds\n\t"
34635 + "lcall *%%ss:(%%esi); cld\n\t"
34636 + "push %%ss\n\t"
34637 + "pop %%ds\n\t"
34638 "jc 1f\n\t"
34639 "xor %%ah, %%ah\n"
34640 "1:"
34641 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34642 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34643 "b" (bx),
34644 "D" ((long)reg),
34645 - "S" (&pci_indirect));
34646 + "S" (&pci_indirect),
34647 + "r" (__PCIBIOS_DS));
34648 break;
34649 }
34650
34651 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34652
34653 switch (len) {
34654 case 1:
34655 - __asm__("lcall *(%%esi); cld\n\t"
34656 + __asm__("movw %w6, %%ds\n\t"
34657 + "lcall *%%ss:(%%esi); cld\n\t"
34658 + "push %%ss\n\t"
34659 + "pop %%ds\n\t"
34660 "jc 1f\n\t"
34661 "xor %%ah, %%ah\n"
34662 "1:"
34663 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34664 "c" (value),
34665 "b" (bx),
34666 "D" ((long)reg),
34667 - "S" (&pci_indirect));
34668 + "S" (&pci_indirect),
34669 + "r" (__PCIBIOS_DS));
34670 break;
34671 case 2:
34672 - __asm__("lcall *(%%esi); cld\n\t"
34673 + __asm__("movw %w6, %%ds\n\t"
34674 + "lcall *%%ss:(%%esi); cld\n\t"
34675 + "push %%ss\n\t"
34676 + "pop %%ds\n\t"
34677 "jc 1f\n\t"
34678 "xor %%ah, %%ah\n"
34679 "1:"
34680 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34681 "c" (value),
34682 "b" (bx),
34683 "D" ((long)reg),
34684 - "S" (&pci_indirect));
34685 + "S" (&pci_indirect),
34686 + "r" (__PCIBIOS_DS));
34687 break;
34688 case 4:
34689 - __asm__("lcall *(%%esi); cld\n\t"
34690 + __asm__("movw %w6, %%ds\n\t"
34691 + "lcall *%%ss:(%%esi); cld\n\t"
34692 + "push %%ss\n\t"
34693 + "pop %%ds\n\t"
34694 "jc 1f\n\t"
34695 "xor %%ah, %%ah\n"
34696 "1:"
34697 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34698 "c" (value),
34699 "b" (bx),
34700 "D" ((long)reg),
34701 - "S" (&pci_indirect));
34702 + "S" (&pci_indirect),
34703 + "r" (__PCIBIOS_DS));
34704 break;
34705 }
34706
34707 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34708
34709 DBG("PCI: Fetching IRQ routing table... ");
34710 __asm__("push %%es\n\t"
34711 + "movw %w8, %%ds\n\t"
34712 "push %%ds\n\t"
34713 "pop %%es\n\t"
34714 - "lcall *(%%esi); cld\n\t"
34715 + "lcall *%%ss:(%%esi); cld\n\t"
34716 "pop %%es\n\t"
34717 + "push %%ss\n\t"
34718 + "pop %%ds\n"
34719 "jc 1f\n\t"
34720 "xor %%ah, %%ah\n"
34721 "1:"
34722 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34723 "1" (0),
34724 "D" ((long) &opt),
34725 "S" (&pci_indirect),
34726 - "m" (opt)
34727 + "m" (opt),
34728 + "r" (__PCIBIOS_DS)
34729 : "memory");
34730 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34731 if (ret & 0xff00)
34732 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34733 {
34734 int ret;
34735
34736 - __asm__("lcall *(%%esi); cld\n\t"
34737 + __asm__("movw %w5, %%ds\n\t"
34738 + "lcall *%%ss:(%%esi); cld\n\t"
34739 + "push %%ss\n\t"
34740 + "pop %%ds\n"
34741 "jc 1f\n\t"
34742 "xor %%ah, %%ah\n"
34743 "1:"
34744 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34745 : "0" (PCIBIOS_SET_PCI_HW_INT),
34746 "b" ((dev->bus->number << 8) | dev->devfn),
34747 "c" ((irq << 8) | (pin + 10)),
34748 - "S" (&pci_indirect));
34749 + "S" (&pci_indirect),
34750 + "r" (__PCIBIOS_DS));
34751 return !(ret & 0xff00);
34752 }
34753 EXPORT_SYMBOL(pcibios_set_irq_routing);
34754 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34755 index 40e7cda..c7e6672 100644
34756 --- a/arch/x86/platform/efi/efi_32.c
34757 +++ b/arch/x86/platform/efi/efi_32.c
34758 @@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34759 {
34760 struct desc_ptr gdt_descr;
34761
34762 +#ifdef CONFIG_PAX_KERNEXEC
34763 + struct desc_struct d;
34764 +#endif
34765 +
34766 local_irq_save(efi_rt_eflags);
34767
34768 load_cr3(initial_page_table);
34769 __flush_tlb_all();
34770
34771 +#ifdef CONFIG_PAX_KERNEXEC
34772 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34773 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34774 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34775 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34776 +#endif
34777 +
34778 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34779 gdt_descr.size = GDT_SIZE - 1;
34780 load_gdt(&gdt_descr);
34781 @@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34782 {
34783 struct desc_ptr gdt_descr;
34784
34785 +#ifdef CONFIG_PAX_KERNEXEC
34786 + struct desc_struct d;
34787 +
34788 + memset(&d, 0, sizeof d);
34789 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34790 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34791 +#endif
34792 +
34793 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34794 gdt_descr.size = GDT_SIZE - 1;
34795 load_gdt(&gdt_descr);
34796
34797 +#ifdef CONFIG_PAX_PER_CPU_PGD
34798 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34799 +#else
34800 load_cr3(swapper_pg_dir);
34801 +#endif
34802 +
34803 __flush_tlb_all();
34804
34805 local_irq_restore(efi_rt_eflags);
34806 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34807 index 35aecb6..46177db 100644
34808 --- a/arch/x86/platform/efi/efi_64.c
34809 +++ b/arch/x86/platform/efi/efi_64.c
34810 @@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34811 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34812 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34813 }
34814 +
34815 +#ifdef CONFIG_PAX_PER_CPU_PGD
34816 + load_cr3(swapper_pg_dir);
34817 +#endif
34818 +
34819 __flush_tlb_all();
34820 }
34821
34822 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34823 for (pgd = 0; pgd < n_pgds; pgd++)
34824 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34825 kfree(save_pgd);
34826 +
34827 +#ifdef CONFIG_PAX_PER_CPU_PGD
34828 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34829 +#endif
34830 +
34831 __flush_tlb_all();
34832 local_irq_restore(efi_flags);
34833 early_code_mapping_set_exec(0);
34834 @@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34835 unsigned npages;
34836 pgd_t *pgd;
34837
34838 - if (efi_enabled(EFI_OLD_MEMMAP))
34839 + if (efi_enabled(EFI_OLD_MEMMAP)) {
34840 + /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34841 + * able to execute the EFI services.
34842 + */
34843 + if (__supported_pte_mask & _PAGE_NX) {
34844 + unsigned long addr = (unsigned long) __va(0);
34845 + pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34846 +
34847 + pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34848 +#ifdef CONFIG_PAX_PER_CPU_PGD
34849 + set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34850 +#endif
34851 + set_pgd(pgd_offset_k(addr), pe);
34852 + }
34853 +
34854 return 0;
34855 + }
34856
34857 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34858 pgd = __va(efi_scratch.efi_pgt);
34859 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34860 index 040192b..7d3300f 100644
34861 --- a/arch/x86/platform/efi/efi_stub_32.S
34862 +++ b/arch/x86/platform/efi/efi_stub_32.S
34863 @@ -6,7 +6,9 @@
34864 */
34865
34866 #include <linux/linkage.h>
34867 +#include <linux/init.h>
34868 #include <asm/page_types.h>
34869 +#include <asm/segment.h>
34870
34871 /*
34872 * efi_call_phys(void *, ...) is a function with variable parameters.
34873 @@ -20,7 +22,7 @@
34874 * service functions will comply with gcc calling convention, too.
34875 */
34876
34877 -.text
34878 +__INIT
34879 ENTRY(efi_call_phys)
34880 /*
34881 * 0. The function can only be called in Linux kernel. So CS has been
34882 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34883 * The mapping of lower virtual memory has been created in prolog and
34884 * epilog.
34885 */
34886 - movl $1f, %edx
34887 - subl $__PAGE_OFFSET, %edx
34888 - jmp *%edx
34889 +#ifdef CONFIG_PAX_KERNEXEC
34890 + movl $(__KERNEXEC_EFI_DS), %edx
34891 + mov %edx, %ds
34892 + mov %edx, %es
34893 + mov %edx, %ss
34894 + addl $2f,(1f)
34895 + ljmp *(1f)
34896 +
34897 +__INITDATA
34898 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34899 +.previous
34900 +
34901 +2:
34902 + subl $2b,(1b)
34903 +#else
34904 + jmp 1f-__PAGE_OFFSET
34905 1:
34906 +#endif
34907
34908 /*
34909 * 2. Now on the top of stack is the return
34910 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34911 * parameter 2, ..., param n. To make things easy, we save the return
34912 * address of efi_call_phys in a global variable.
34913 */
34914 - popl %edx
34915 - movl %edx, saved_return_addr
34916 - /* get the function pointer into ECX*/
34917 - popl %ecx
34918 - movl %ecx, efi_rt_function_ptr
34919 - movl $2f, %edx
34920 - subl $__PAGE_OFFSET, %edx
34921 - pushl %edx
34922 + popl (saved_return_addr)
34923 + popl (efi_rt_function_ptr)
34924
34925 /*
34926 * 3. Clear PG bit in %CR0.
34927 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34928 /*
34929 * 5. Call the physical function.
34930 */
34931 - jmp *%ecx
34932 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34933
34934 -2:
34935 /*
34936 * 6. After EFI runtime service returns, control will return to
34937 * following instruction. We'd better readjust stack pointer first.
34938 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34939 movl %cr0, %edx
34940 orl $0x80000000, %edx
34941 movl %edx, %cr0
34942 - jmp 1f
34943 -1:
34944 +
34945 /*
34946 * 8. Now restore the virtual mode from flat mode by
34947 * adding EIP with PAGE_OFFSET.
34948 */
34949 - movl $1f, %edx
34950 - jmp *%edx
34951 +#ifdef CONFIG_PAX_KERNEXEC
34952 + movl $(__KERNEL_DS), %edx
34953 + mov %edx, %ds
34954 + mov %edx, %es
34955 + mov %edx, %ss
34956 + ljmp $(__KERNEL_CS),$1f
34957 +#else
34958 + jmp 1f+__PAGE_OFFSET
34959 +#endif
34960 1:
34961
34962 /*
34963 * 9. Balance the stack. And because EAX contain the return value,
34964 * we'd better not clobber it.
34965 */
34966 - leal efi_rt_function_ptr, %edx
34967 - movl (%edx), %ecx
34968 - pushl %ecx
34969 + pushl (efi_rt_function_ptr)
34970
34971 /*
34972 - * 10. Push the saved return address onto the stack and return.
34973 + * 10. Return to the saved return address.
34974 */
34975 - leal saved_return_addr, %edx
34976 - movl (%edx), %ecx
34977 - pushl %ecx
34978 - ret
34979 + jmpl *(saved_return_addr)
34980 ENDPROC(efi_call_phys)
34981 .previous
34982
34983 -.data
34984 +__INITDATA
34985 saved_return_addr:
34986 .long 0
34987 efi_rt_function_ptr:
34988 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34989 index 86d0f9e..6d499f4 100644
34990 --- a/arch/x86/platform/efi/efi_stub_64.S
34991 +++ b/arch/x86/platform/efi/efi_stub_64.S
34992 @@ -11,6 +11,7 @@
34993 #include <asm/msr.h>
34994 #include <asm/processor-flags.h>
34995 #include <asm/page_types.h>
34996 +#include <asm/alternative-asm.h>
34997
34998 #define SAVE_XMM \
34999 mov %rsp, %rax; \
35000 @@ -88,6 +89,7 @@ ENTRY(efi_call)
35001 RESTORE_PGT
35002 addq $48, %rsp
35003 RESTORE_XMM
35004 + pax_force_retaddr 0, 1
35005 ret
35006 ENDPROC(efi_call)
35007
35008 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35009 index 1bbedc4..eb795b5 100644
35010 --- a/arch/x86/platform/intel-mid/intel-mid.c
35011 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35012 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35013 {
35014 };
35015
35016 -static void intel_mid_reboot(void)
35017 +static void __noreturn intel_mid_reboot(void)
35018 {
35019 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35020 + BUG();
35021 }
35022
35023 static unsigned long __init intel_mid_calibrate_tsc(void)
35024 diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35025 index 3c1c386..59a68ed 100644
35026 --- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35027 +++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35028 @@ -13,6 +13,6 @@
35029 /* For every CPU addition a new get_<cpuname>_ops interface needs
35030 * to be added.
35031 */
35032 -extern void *get_penwell_ops(void);
35033 -extern void *get_cloverview_ops(void);
35034 -extern void *get_tangier_ops(void);
35035 +extern const void *get_penwell_ops(void);
35036 +extern const void *get_cloverview_ops(void);
35037 +extern const void *get_tangier_ops(void);
35038 diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35039 index 23381d2..8ddc10e 100644
35040 --- a/arch/x86/platform/intel-mid/mfld.c
35041 +++ b/arch/x86/platform/intel-mid/mfld.c
35042 @@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35043 pm_power_off = mfld_power_off;
35044 }
35045
35046 -void *get_penwell_ops(void)
35047 +const void *get_penwell_ops(void)
35048 {
35049 return &penwell_ops;
35050 }
35051
35052 -void *get_cloverview_ops(void)
35053 +const void *get_cloverview_ops(void)
35054 {
35055 return &penwell_ops;
35056 }
35057 diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35058 index aaca917..66eadbc 100644
35059 --- a/arch/x86/platform/intel-mid/mrfl.c
35060 +++ b/arch/x86/platform/intel-mid/mrfl.c
35061 @@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35062 .arch_setup = tangier_arch_setup,
35063 };
35064
35065 -void *get_tangier_ops(void)
35066 +const void *get_tangier_ops(void)
35067 {
35068 return &tangier_ops;
35069 }
35070 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35071 index d6ee929..3637cb5 100644
35072 --- a/arch/x86/platform/olpc/olpc_dt.c
35073 +++ b/arch/x86/platform/olpc/olpc_dt.c
35074 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35075 return res;
35076 }
35077
35078 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35079 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35080 .nextprop = olpc_dt_nextprop,
35081 .getproplen = olpc_dt_getproplen,
35082 .getproperty = olpc_dt_getproperty,
35083 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35084 index 6ec7910..ecdbb11 100644
35085 --- a/arch/x86/power/cpu.c
35086 +++ b/arch/x86/power/cpu.c
35087 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35088 static void fix_processor_context(void)
35089 {
35090 int cpu = smp_processor_id();
35091 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35092 -#ifdef CONFIG_X86_64
35093 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35094 - tss_desc tss;
35095 -#endif
35096 + struct tss_struct *t = init_tss + cpu;
35097 +
35098 set_tss_desc(cpu, t); /*
35099 * This just modifies memory; should not be
35100 * necessary. But... This is necessary, because
35101 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35102 */
35103
35104 #ifdef CONFIG_X86_64
35105 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35106 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35107 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35108 -
35109 syscall_init(); /* This sets MSR_*STAR and related */
35110 #endif
35111 load_TR_desc(); /* This does ltr */
35112 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35113 index bad628a..a102610 100644
35114 --- a/arch/x86/realmode/init.c
35115 +++ b/arch/x86/realmode/init.c
35116 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35117 __va(real_mode_header->trampoline_header);
35118
35119 #ifdef CONFIG_X86_32
35120 - trampoline_header->start = __pa_symbol(startup_32_smp);
35121 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35122 +
35123 +#ifdef CONFIG_PAX_KERNEXEC
35124 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35125 +#endif
35126 +
35127 + trampoline_header->boot_cs = __BOOT_CS;
35128 trampoline_header->gdt_limit = __BOOT_DS + 7;
35129 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35130 #else
35131 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35132 *trampoline_cr4_features = read_cr4();
35133
35134 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35135 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35136 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35137 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35138 #endif
35139 }
35140 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35141 index 7c0d7be..d24dc88 100644
35142 --- a/arch/x86/realmode/rm/Makefile
35143 +++ b/arch/x86/realmode/rm/Makefile
35144 @@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35145
35146 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35147 -I$(srctree)/arch/x86/boot
35148 +ifdef CONSTIFY_PLUGIN
35149 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35150 +endif
35151 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35152 GCOV_PROFILE := n
35153 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35154 index a28221d..93c40f1 100644
35155 --- a/arch/x86/realmode/rm/header.S
35156 +++ b/arch/x86/realmode/rm/header.S
35157 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35158 #endif
35159 /* APM/BIOS reboot */
35160 .long pa_machine_real_restart_asm
35161 -#ifdef CONFIG_X86_64
35162 +#ifdef CONFIG_X86_32
35163 + .long __KERNEL_CS
35164 +#else
35165 .long __KERNEL32_CS
35166 #endif
35167 END(real_mode_header)
35168 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35169 index 48ddd76..c26749f 100644
35170 --- a/arch/x86/realmode/rm/trampoline_32.S
35171 +++ b/arch/x86/realmode/rm/trampoline_32.S
35172 @@ -24,6 +24,12 @@
35173 #include <asm/page_types.h>
35174 #include "realmode.h"
35175
35176 +#ifdef CONFIG_PAX_KERNEXEC
35177 +#define ta(X) (X)
35178 +#else
35179 +#define ta(X) (pa_ ## X)
35180 +#endif
35181 +
35182 .text
35183 .code16
35184
35185 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35186
35187 cli # We should be safe anyway
35188
35189 - movl tr_start, %eax # where we need to go
35190 -
35191 movl $0xA5A5A5A5, trampoline_status
35192 # write marker for master knows we're running
35193
35194 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35195 movw $1, %dx # protected mode (PE) bit
35196 lmsw %dx # into protected mode
35197
35198 - ljmpl $__BOOT_CS, $pa_startup_32
35199 + ljmpl *(trampoline_header)
35200
35201 .section ".text32","ax"
35202 .code32
35203 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35204 .balign 8
35205 GLOBAL(trampoline_header)
35206 tr_start: .space 4
35207 - tr_gdt_pad: .space 2
35208 + tr_boot_cs: .space 2
35209 tr_gdt: .space 6
35210 END(trampoline_header)
35211
35212 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35213 index dac7b20..72dbaca 100644
35214 --- a/arch/x86/realmode/rm/trampoline_64.S
35215 +++ b/arch/x86/realmode/rm/trampoline_64.S
35216 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35217 movl %edx, %gs
35218
35219 movl pa_tr_cr4, %eax
35220 + andl $~X86_CR4_PCIDE, %eax
35221 movl %eax, %cr4 # Enable PAE mode
35222
35223 # Setup trampoline 4 level pagetables
35224 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35225 wrmsr
35226
35227 # Enable paging and in turn activate Long Mode
35228 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35229 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35230 movl %eax, %cr0
35231
35232 /*
35233 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35234 index 9e7e147..25a4158 100644
35235 --- a/arch/x86/realmode/rm/wakeup_asm.S
35236 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35237 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35238 lgdtl pmode_gdt
35239
35240 /* This really couldn't... */
35241 - movl pmode_entry, %eax
35242 movl pmode_cr0, %ecx
35243 movl %ecx, %cr0
35244 - ljmpl $__KERNEL_CS, $pa_startup_32
35245 - /* -> jmp *%eax in trampoline_32.S */
35246 +
35247 + ljmpl *pmode_entry
35248 #else
35249 jmp trampoline_start
35250 #endif
35251 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35252 index 604a37e..e49702a 100644
35253 --- a/arch/x86/tools/Makefile
35254 +++ b/arch/x86/tools/Makefile
35255 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35256
35257 $(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
35258
35259 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35260 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35261 hostprogs-y += relocs
35262 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35263 PHONY += relocs
35264 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35265 index a5efb21..97490e9 100644
35266 --- a/arch/x86/tools/relocs.c
35267 +++ b/arch/x86/tools/relocs.c
35268 @@ -1,5 +1,7 @@
35269 /* This is included from relocs_32/64.c */
35270
35271 +#include "../../../include/generated/autoconf.h"
35272 +
35273 #define ElfW(type) _ElfW(ELF_BITS, type)
35274 #define _ElfW(bits, type) __ElfW(bits, type)
35275 #define __ElfW(bits, type) Elf##bits##_##type
35276 @@ -11,6 +13,7 @@
35277 #define Elf_Sym ElfW(Sym)
35278
35279 static Elf_Ehdr ehdr;
35280 +static Elf_Phdr *phdr;
35281
35282 struct relocs {
35283 uint32_t *offset;
35284 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35285 }
35286 }
35287
35288 +static void read_phdrs(FILE *fp)
35289 +{
35290 + unsigned int i;
35291 +
35292 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35293 + if (!phdr) {
35294 + die("Unable to allocate %d program headers\n",
35295 + ehdr.e_phnum);
35296 + }
35297 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35298 + die("Seek to %d failed: %s\n",
35299 + ehdr.e_phoff, strerror(errno));
35300 + }
35301 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35302 + die("Cannot read ELF program headers: %s\n",
35303 + strerror(errno));
35304 + }
35305 + for(i = 0; i < ehdr.e_phnum; i++) {
35306 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35307 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35308 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35309 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35310 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35311 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35312 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35313 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35314 + }
35315 +
35316 +}
35317 +
35318 static void read_shdrs(FILE *fp)
35319 {
35320 - int i;
35321 + unsigned int i;
35322 Elf_Shdr shdr;
35323
35324 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35325 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35326
35327 static void read_strtabs(FILE *fp)
35328 {
35329 - int i;
35330 + unsigned int i;
35331 for (i = 0; i < ehdr.e_shnum; i++) {
35332 struct section *sec = &secs[i];
35333 if (sec->shdr.sh_type != SHT_STRTAB) {
35334 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35335
35336 static void read_symtabs(FILE *fp)
35337 {
35338 - int i,j;
35339 + unsigned int i,j;
35340 for (i = 0; i < ehdr.e_shnum; i++) {
35341 struct section *sec = &secs[i];
35342 if (sec->shdr.sh_type != SHT_SYMTAB) {
35343 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35344 }
35345
35346
35347 -static void read_relocs(FILE *fp)
35348 +static void read_relocs(FILE *fp, int use_real_mode)
35349 {
35350 - int i,j;
35351 + unsigned int i,j;
35352 + uint32_t base;
35353 +
35354 for (i = 0; i < ehdr.e_shnum; i++) {
35355 struct section *sec = &secs[i];
35356 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35357 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35358 die("Cannot read symbol table: %s\n",
35359 strerror(errno));
35360 }
35361 + base = 0;
35362 +
35363 +#ifdef CONFIG_X86_32
35364 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35365 + if (phdr[j].p_type != PT_LOAD )
35366 + continue;
35367 + 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)
35368 + continue;
35369 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35370 + break;
35371 + }
35372 +#endif
35373 +
35374 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35375 Elf_Rel *rel = &sec->reltab[j];
35376 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35377 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35378 rel->r_info = elf_xword_to_cpu(rel->r_info);
35379 #if (SHT_REL_TYPE == SHT_RELA)
35380 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35381 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35382
35383 static void print_absolute_symbols(void)
35384 {
35385 - int i;
35386 + unsigned int i;
35387 const char *format;
35388
35389 if (ELF_BITS == 64)
35390 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35391 for (i = 0; i < ehdr.e_shnum; i++) {
35392 struct section *sec = &secs[i];
35393 char *sym_strtab;
35394 - int j;
35395 + unsigned int j;
35396
35397 if (sec->shdr.sh_type != SHT_SYMTAB) {
35398 continue;
35399 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35400
35401 static void print_absolute_relocs(void)
35402 {
35403 - int i, printed = 0;
35404 + unsigned int i, printed = 0;
35405 const char *format;
35406
35407 if (ELF_BITS == 64)
35408 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35409 struct section *sec_applies, *sec_symtab;
35410 char *sym_strtab;
35411 Elf_Sym *sh_symtab;
35412 - int j;
35413 + unsigned int j;
35414 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35415 continue;
35416 }
35417 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35418 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35419 Elf_Sym *sym, const char *symname))
35420 {
35421 - int i;
35422 + unsigned int i;
35423 /* Walk through the relocations */
35424 for (i = 0; i < ehdr.e_shnum; i++) {
35425 char *sym_strtab;
35426 Elf_Sym *sh_symtab;
35427 struct section *sec_applies, *sec_symtab;
35428 - int j;
35429 + unsigned int j;
35430 struct section *sec = &secs[i];
35431
35432 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35433 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35434 {
35435 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35436 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35437 + char *sym_strtab = sec->link->link->strtab;
35438 +
35439 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35440 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35441 + return 0;
35442 +
35443 +#ifdef CONFIG_PAX_KERNEXEC
35444 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35445 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35446 + return 0;
35447 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35448 + return 0;
35449 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35450 + return 0;
35451 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35452 + return 0;
35453 +#endif
35454
35455 switch (r_type) {
35456 case R_386_NONE:
35457 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35458
35459 static void emit_relocs(int as_text, int use_real_mode)
35460 {
35461 - int i;
35462 + unsigned int i;
35463 int (*write_reloc)(uint32_t, FILE *) = write32;
35464 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35465 const char *symname);
35466 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35467 {
35468 regex_init(use_real_mode);
35469 read_ehdr(fp);
35470 + read_phdrs(fp);
35471 read_shdrs(fp);
35472 read_strtabs(fp);
35473 read_symtabs(fp);
35474 - read_relocs(fp);
35475 + read_relocs(fp, use_real_mode);
35476 if (ELF_BITS == 64)
35477 percpu_init();
35478 if (show_absolute_syms) {
35479 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35480 index f40281e..92728c9 100644
35481 --- a/arch/x86/um/mem_32.c
35482 +++ b/arch/x86/um/mem_32.c
35483 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35484 gate_vma.vm_start = FIXADDR_USER_START;
35485 gate_vma.vm_end = FIXADDR_USER_END;
35486 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35487 - gate_vma.vm_page_prot = __P101;
35488 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35489
35490 return 0;
35491 }
35492 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35493 index 80ffa5b..a33bd15 100644
35494 --- a/arch/x86/um/tls_32.c
35495 +++ b/arch/x86/um/tls_32.c
35496 @@ -260,7 +260,7 @@ out:
35497 if (unlikely(task == current &&
35498 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35499 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35500 - "without flushed TLS.", current->pid);
35501 + "without flushed TLS.", task_pid_nr(current));
35502 }
35503
35504 return 0;
35505 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35506 index 5a4affe..9e2d522 100644
35507 --- a/arch/x86/vdso/Makefile
35508 +++ b/arch/x86/vdso/Makefile
35509 @@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35510 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35511 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35512
35513 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35514 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35515 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35516 GCOV_PROFILE := n
35517
35518 diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35519 index 0224987..c7d65a5 100644
35520 --- a/arch/x86/vdso/vdso2c.h
35521 +++ b/arch/x86/vdso/vdso2c.h
35522 @@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35523 unsigned long load_size = -1; /* Work around bogus warning */
35524 unsigned long mapping_size;
35525 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35526 - int i;
35527 + unsigned int i;
35528 unsigned long j;
35529 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35530 *alt_sec = NULL;
35531 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35532 index e904c27..b9eaa03 100644
35533 --- a/arch/x86/vdso/vdso32-setup.c
35534 +++ b/arch/x86/vdso/vdso32-setup.c
35535 @@ -14,6 +14,7 @@
35536 #include <asm/cpufeature.h>
35537 #include <asm/processor.h>
35538 #include <asm/vdso.h>
35539 +#include <asm/mman.h>
35540
35541 #ifdef CONFIG_COMPAT_VDSO
35542 #define VDSO_DEFAULT 0
35543 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35544 index 208c220..54f1447 100644
35545 --- a/arch/x86/vdso/vma.c
35546 +++ b/arch/x86/vdso/vma.c
35547 @@ -16,10 +16,9 @@
35548 #include <asm/vdso.h>
35549 #include <asm/page.h>
35550 #include <asm/hpet.h>
35551 +#include <asm/mman.h>
35552
35553 #if defined(CONFIG_X86_64)
35554 -unsigned int __read_mostly vdso64_enabled = 1;
35555 -
35556 extern unsigned short vdso_sync_cpuid;
35557 #endif
35558
35559 @@ -114,6 +113,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35560 .pages = no_pages,
35561 };
35562
35563 +#ifdef CONFIG_PAX_RANDMMAP
35564 + if (mm->pax_flags & MF_PAX_RANDMMAP)
35565 + calculate_addr = false;
35566 +#endif
35567 +
35568 if (calculate_addr) {
35569 addr = vdso_addr(current->mm->start_stack,
35570 image->size - image->sym_vvar_start);
35571 @@ -124,14 +128,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35572 down_write(&mm->mmap_sem);
35573
35574 addr = get_unmapped_area(NULL, addr,
35575 - image->size - image->sym_vvar_start, 0, 0);
35576 + image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35577 if (IS_ERR_VALUE(addr)) {
35578 ret = addr;
35579 goto up_fail;
35580 }
35581
35582 text_start = addr - image->sym_vvar_start;
35583 - current->mm->context.vdso = (void __user *)text_start;
35584 + mm->context.vdso = text_start;
35585
35586 /*
35587 * MAYWRITE to allow gdb to COW and set breakpoints
35588 @@ -176,15 +180,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35589 hpet_address >> PAGE_SHIFT,
35590 PAGE_SIZE,
35591 pgprot_noncached(PAGE_READONLY));
35592 -
35593 - if (ret)
35594 - goto up_fail;
35595 }
35596 #endif
35597
35598 up_fail:
35599 if (ret)
35600 - current->mm->context.vdso = NULL;
35601 + current->mm->context.vdso = 0;
35602
35603 up_write(&mm->mmap_sem);
35604 return ret;
35605 @@ -204,8 +205,8 @@ static int load_vdso32(void)
35606
35607 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35608 current_thread_info()->sysenter_return =
35609 - current->mm->context.vdso +
35610 - selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35611 + (void __force_user *)(current->mm->context.vdso +
35612 + selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35613
35614 return 0;
35615 }
35616 @@ -214,9 +215,6 @@ static int load_vdso32(void)
35617 #ifdef CONFIG_X86_64
35618 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35619 {
35620 - if (!vdso64_enabled)
35621 - return 0;
35622 -
35623 return map_vdso(&vdso_image_64, true);
35624 }
35625
35626 @@ -225,12 +223,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35627 int uses_interp)
35628 {
35629 #ifdef CONFIG_X86_X32_ABI
35630 - if (test_thread_flag(TIF_X32)) {
35631 - if (!vdso64_enabled)
35632 - return 0;
35633 -
35634 + if (test_thread_flag(TIF_X32))
35635 return map_vdso(&vdso_image_x32, true);
35636 - }
35637 #endif
35638
35639 return load_vdso32();
35640 @@ -242,12 +236,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35641 return load_vdso32();
35642 }
35643 #endif
35644 -
35645 -#ifdef CONFIG_X86_64
35646 -static __init int vdso_setup(char *s)
35647 -{
35648 - vdso64_enabled = simple_strtoul(s, NULL, 0);
35649 - return 0;
35650 -}
35651 -__setup("vdso=", vdso_setup);
35652 -#endif
35653 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35654 index e88fda8..76ce7ce 100644
35655 --- a/arch/x86/xen/Kconfig
35656 +++ b/arch/x86/xen/Kconfig
35657 @@ -9,6 +9,7 @@ config XEN
35658 select XEN_HAVE_PVMMU
35659 depends on X86_64 || (X86_32 && X86_PAE)
35660 depends on X86_TSC
35661 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35662 help
35663 This is the Linux Xen port. Enabling this will allow the
35664 kernel to boot in a paravirtualized environment under the
35665 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35666 index fac5e4f..89c3525 100644
35667 --- a/arch/x86/xen/enlighten.c
35668 +++ b/arch/x86/xen/enlighten.c
35669 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35670
35671 struct shared_info xen_dummy_shared_info;
35672
35673 -void *xen_initial_gdt;
35674 -
35675 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35676 __read_mostly int xen_have_vector_callback;
35677 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35678 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35679 {
35680 unsigned long va = dtr->address;
35681 unsigned int size = dtr->size + 1;
35682 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35683 - unsigned long frames[pages];
35684 + unsigned long frames[65536 / PAGE_SIZE];
35685 int f;
35686
35687 /*
35688 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35689 {
35690 unsigned long va = dtr->address;
35691 unsigned int size = dtr->size + 1;
35692 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35693 - unsigned long frames[pages];
35694 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35695 int f;
35696
35697 /*
35698 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35699 * 8-byte entries, or 16 4k pages..
35700 */
35701
35702 - BUG_ON(size > 65536);
35703 + BUG_ON(size > GDT_SIZE);
35704 BUG_ON(va & ~PAGE_MASK);
35705
35706 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35707 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35708 return 0;
35709 }
35710
35711 -static void set_xen_basic_apic_ops(void)
35712 +static void __init set_xen_basic_apic_ops(void)
35713 {
35714 apic->read = xen_apic_read;
35715 apic->write = xen_apic_write;
35716 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35717 #endif
35718 };
35719
35720 -static void xen_reboot(int reason)
35721 +static __noreturn void xen_reboot(int reason)
35722 {
35723 struct sched_shutdown r = { .reason = reason };
35724
35725 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35726 - BUG();
35727 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35728 + BUG();
35729 }
35730
35731 -static void xen_restart(char *msg)
35732 +static __noreturn void xen_restart(char *msg)
35733 {
35734 xen_reboot(SHUTDOWN_reboot);
35735 }
35736
35737 -static void xen_emergency_restart(void)
35738 +static __noreturn void xen_emergency_restart(void)
35739 {
35740 xen_reboot(SHUTDOWN_reboot);
35741 }
35742
35743 -static void xen_machine_halt(void)
35744 +static __noreturn void xen_machine_halt(void)
35745 {
35746 xen_reboot(SHUTDOWN_poweroff);
35747 }
35748
35749 -static void xen_machine_power_off(void)
35750 +static __noreturn void xen_machine_power_off(void)
35751 {
35752 if (pm_power_off)
35753 pm_power_off();
35754 @@ -1456,8 +1452,11 @@ static void __ref xen_setup_gdt(int cpu)
35755 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
35756 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
35757
35758 - setup_stack_canary_segment(0);
35759 - switch_to_new_gdt(0);
35760 + setup_stack_canary_segment(cpu);
35761 +#ifdef CONFIG_X86_64
35762 + load_percpu_segment(cpu);
35763 +#endif
35764 + switch_to_new_gdt(cpu);
35765
35766 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
35767 pv_cpu_ops.load_gdt = xen_load_gdt;
35768 @@ -1573,7 +1572,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35769 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35770
35771 /* Work out if we support NX */
35772 - x86_configure_nx();
35773 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35774 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35775 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35776 + unsigned l, h;
35777 +
35778 + __supported_pte_mask |= _PAGE_NX;
35779 + rdmsr(MSR_EFER, l, h);
35780 + l |= EFER_NX;
35781 + wrmsr(MSR_EFER, l, h);
35782 + }
35783 +#endif
35784
35785 /* Get mfn list */
35786 xen_build_dynamic_phys_to_machine();
35787 @@ -1601,13 +1610,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35788
35789 machine_ops = xen_machine_ops;
35790
35791 - /*
35792 - * The only reliable way to retain the initial address of the
35793 - * percpu gdt_page is to remember it here, so we can go and
35794 - * mark it RW later, when the initial percpu area is freed.
35795 - */
35796 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35797 -
35798 xen_smp_init();
35799
35800 #ifdef CONFIG_ACPI_NUMA
35801 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35802 index a8a1a3d..8216142 100644
35803 --- a/arch/x86/xen/mmu.c
35804 +++ b/arch/x86/xen/mmu.c
35805 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35806 return val;
35807 }
35808
35809 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35810 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35811 {
35812 if (val & _PAGE_PRESENT) {
35813 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35814 @@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35815 * L3_k[511] -> level2_fixmap_pgt */
35816 convert_pfn_mfn(level3_kernel_pgt);
35817
35818 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35819 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35820 + convert_pfn_mfn(level3_vmemmap_pgt);
35821 /* L3_k[511][506] -> level1_fixmap_pgt */
35822 + /* L3_k[511][507] -> level1_vsyscall_pgt */
35823 convert_pfn_mfn(level2_fixmap_pgt);
35824 }
35825 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35826 @@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35827 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35828 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35829 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35830 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35831 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35832 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35833 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35834 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35835 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35836 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35837 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35838 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35839 + set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35840
35841 /* Pin down new L4 */
35842 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35843 @@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35844 pv_mmu_ops.set_pud = xen_set_pud;
35845 #if PAGETABLE_LEVELS == 4
35846 pv_mmu_ops.set_pgd = xen_set_pgd;
35847 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35848 #endif
35849
35850 /* This will work as long as patching hasn't happened yet
35851 @@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35852 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35853 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35854 .set_pgd = xen_set_pgd_hyper,
35855 + .set_pgd_batched = xen_set_pgd_hyper,
35856
35857 .alloc_pud = xen_alloc_pmd_init,
35858 .release_pud = xen_release_pmd_init,
35859 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35860 index 4c071ae..00e7049 100644
35861 --- a/arch/x86/xen/smp.c
35862 +++ b/arch/x86/xen/smp.c
35863 @@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35864
35865 if (xen_pv_domain()) {
35866 if (!xen_feature(XENFEAT_writable_page_tables))
35867 - /* We've switched to the "real" per-cpu gdt, so make
35868 - * sure the old memory can be recycled. */
35869 - make_lowmem_page_readwrite(xen_initial_gdt);
35870 -
35871 #ifdef CONFIG_X86_32
35872 /*
35873 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35874 * expects __USER_DS
35875 */
35876 - loadsegment(ds, __USER_DS);
35877 - loadsegment(es, __USER_DS);
35878 + loadsegment(ds, __KERNEL_DS);
35879 + loadsegment(es, __KERNEL_DS);
35880 #endif
35881
35882 xen_filter_cpu_maps();
35883 @@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35884 #ifdef CONFIG_X86_32
35885 /* Note: PVH is not yet supported on x86_32. */
35886 ctxt->user_regs.fs = __KERNEL_PERCPU;
35887 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35888 + savesegment(gs, ctxt->user_regs.gs);
35889 #endif
35890 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35891
35892 @@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35893 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35894 ctxt->flags = VGCF_IN_KERNEL;
35895 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35896 - ctxt->user_regs.ds = __USER_DS;
35897 - ctxt->user_regs.es = __USER_DS;
35898 + ctxt->user_regs.ds = __KERNEL_DS;
35899 + ctxt->user_regs.es = __KERNEL_DS;
35900 ctxt->user_regs.ss = __KERNEL_DS;
35901
35902 xen_copy_trap_info(ctxt->trap_ctxt);
35903 @@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35904 int rc;
35905
35906 per_cpu(current_task, cpu) = idle;
35907 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35908 #ifdef CONFIG_X86_32
35909 irq_ctx_init(cpu);
35910 #else
35911 clear_tsk_thread_flag(idle, TIF_FORK);
35912 #endif
35913 - per_cpu(kernel_stack, cpu) =
35914 - (unsigned long)task_stack_page(idle) -
35915 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35916 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35917
35918 xen_setup_runstate_info(cpu);
35919 xen_setup_timer(cpu);
35920 @@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35921
35922 void __init xen_smp_init(void)
35923 {
35924 - smp_ops = xen_smp_ops;
35925 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35926 xen_fill_possible_map();
35927 }
35928
35929 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35930 index fd92a64..1f72641 100644
35931 --- a/arch/x86/xen/xen-asm_32.S
35932 +++ b/arch/x86/xen/xen-asm_32.S
35933 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35934 pushw %fs
35935 movl $(__KERNEL_PERCPU), %eax
35936 movl %eax, %fs
35937 - movl %fs:xen_vcpu, %eax
35938 + mov PER_CPU_VAR(xen_vcpu), %eax
35939 POP_FS
35940 #else
35941 movl %ss:xen_vcpu, %eax
35942 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35943 index 674b2225..f1f5dc1 100644
35944 --- a/arch/x86/xen/xen-head.S
35945 +++ b/arch/x86/xen/xen-head.S
35946 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35947 #ifdef CONFIG_X86_32
35948 mov %esi,xen_start_info
35949 mov $init_thread_union+THREAD_SIZE,%esp
35950 +#ifdef CONFIG_SMP
35951 + movl $cpu_gdt_table,%edi
35952 + movl $__per_cpu_load,%eax
35953 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35954 + rorl $16,%eax
35955 + movb %al,__KERNEL_PERCPU + 4(%edi)
35956 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35957 + movl $__per_cpu_end - 1,%eax
35958 + subl $__per_cpu_start,%eax
35959 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35960 +#endif
35961 #else
35962 mov %rsi,xen_start_info
35963 mov $init_thread_union+THREAD_SIZE,%rsp
35964 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35965 index 28c7e0b..2acfec7 100644
35966 --- a/arch/x86/xen/xen-ops.h
35967 +++ b/arch/x86/xen/xen-ops.h
35968 @@ -10,8 +10,6 @@
35969 extern const char xen_hypervisor_callback[];
35970 extern const char xen_failsafe_callback[];
35971
35972 -extern void *xen_initial_gdt;
35973 -
35974 struct trap_info;
35975 void xen_copy_trap_info(struct trap_info *traps);
35976
35977 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35978 index 525bd3d..ef888b1 100644
35979 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35980 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35981 @@ -119,9 +119,9 @@
35982 ----------------------------------------------------------------------*/
35983
35984 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35985 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35986 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35987 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35988 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35989
35990 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35991 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35992 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35993 index 2f33760..835e50a 100644
35994 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35995 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35996 @@ -11,6 +11,7 @@
35997 #ifndef _XTENSA_CORE_H
35998 #define _XTENSA_CORE_H
35999
36000 +#include <linux/const.h>
36001
36002 /****************************************************************************
36003 Parameters Useful for Any Code, USER or PRIVILEGED
36004 @@ -112,9 +113,9 @@
36005 ----------------------------------------------------------------------*/
36006
36007 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36008 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36009 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36010 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36011 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36012
36013 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36014 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36015 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36016 index af00795..2bb8105 100644
36017 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36018 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36019 @@ -11,6 +11,7 @@
36020 #ifndef _XTENSA_CORE_CONFIGURATION_H
36021 #define _XTENSA_CORE_CONFIGURATION_H
36022
36023 +#include <linux/const.h>
36024
36025 /****************************************************************************
36026 Parameters Useful for Any Code, USER or PRIVILEGED
36027 @@ -118,9 +119,9 @@
36028 ----------------------------------------------------------------------*/
36029
36030 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36031 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36032 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36033 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36034 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36035
36036 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36037 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36038 diff --git a/block/bio.c b/block/bio.c
36039 index 3e6e198..5c65199 100644
36040 --- a/block/bio.c
36041 +++ b/block/bio.c
36042 @@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36043 /*
36044 * Overflow, abort
36045 */
36046 - if (end < start)
36047 + if (end < start || end - start > INT_MAX - nr_pages)
36048 return ERR_PTR(-EINVAL);
36049
36050 nr_pages += end - start;
36051 @@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36052 /*
36053 * Overflow, abort
36054 */
36055 - if (end < start)
36056 + if (end < start || end - start > INT_MAX - nr_pages)
36057 return ERR_PTR(-EINVAL);
36058
36059 nr_pages += end - start;
36060 @@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36061 const int read = bio_data_dir(bio) == READ;
36062 struct bio_map_data *bmd = bio->bi_private;
36063 int i;
36064 - char *p = bmd->sgvecs[0].iov_base;
36065 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36066
36067 bio_for_each_segment_all(bvec, bio, i) {
36068 char *addr = page_address(bvec->bv_page);
36069 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36070 index 0736729..2ec3b48 100644
36071 --- a/block/blk-iopoll.c
36072 +++ b/block/blk-iopoll.c
36073 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36074 }
36075 EXPORT_SYMBOL(blk_iopoll_complete);
36076
36077 -static void blk_iopoll_softirq(struct softirq_action *h)
36078 +static __latent_entropy void blk_iopoll_softirq(void)
36079 {
36080 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36081 int rearm = 0, budget = blk_iopoll_budget;
36082 diff --git a/block/blk-map.c b/block/blk-map.c
36083 index f890d43..97b0482 100644
36084 --- a/block/blk-map.c
36085 +++ b/block/blk-map.c
36086 @@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36087 if (!len || !kbuf)
36088 return -EINVAL;
36089
36090 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36091 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36092 if (do_copy)
36093 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36094 else
36095 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36096 index 53b1737..08177d2e 100644
36097 --- a/block/blk-softirq.c
36098 +++ b/block/blk-softirq.c
36099 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36100 * Softirq action handler - move entries to local list and loop over them
36101 * while passing them to the queue registered handler.
36102 */
36103 -static void blk_done_softirq(struct softirq_action *h)
36104 +static __latent_entropy void blk_done_softirq(void)
36105 {
36106 struct list_head *cpu_list, local_list;
36107
36108 diff --git a/block/bsg.c b/block/bsg.c
36109 index 276e869..6fe4c61 100644
36110 --- a/block/bsg.c
36111 +++ b/block/bsg.c
36112 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36113 struct sg_io_v4 *hdr, struct bsg_device *bd,
36114 fmode_t has_write_perm)
36115 {
36116 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36117 + unsigned char *cmdptr;
36118 +
36119 if (hdr->request_len > BLK_MAX_CDB) {
36120 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36121 if (!rq->cmd)
36122 return -ENOMEM;
36123 - }
36124 + cmdptr = rq->cmd;
36125 + } else
36126 + cmdptr = tmpcmd;
36127
36128 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36129 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36130 hdr->request_len))
36131 return -EFAULT;
36132
36133 + if (cmdptr != rq->cmd)
36134 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36135 +
36136 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36137 if (blk_verify_command(rq->cmd, has_write_perm))
36138 return -EPERM;
36139 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36140 index f678c73..f35aa18 100644
36141 --- a/block/compat_ioctl.c
36142 +++ b/block/compat_ioctl.c
36143 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36144 cgc = compat_alloc_user_space(sizeof(*cgc));
36145 cgc32 = compat_ptr(arg);
36146
36147 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36148 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36149 get_user(data, &cgc32->buffer) ||
36150 put_user(compat_ptr(data), &cgc->buffer) ||
36151 copy_in_user(&cgc->buflen, &cgc32->buflen,
36152 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36153 err |= __get_user(f->spec1, &uf->spec1);
36154 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36155 err |= __get_user(name, &uf->name);
36156 - f->name = compat_ptr(name);
36157 + f->name = (void __force_kernel *)compat_ptr(name);
36158 if (err) {
36159 err = -EFAULT;
36160 goto out;
36161 diff --git a/block/genhd.c b/block/genhd.c
36162 index 0a536dc..b8f7aca 100644
36163 --- a/block/genhd.c
36164 +++ b/block/genhd.c
36165 @@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36166
36167 /*
36168 * Register device numbers dev..(dev+range-1)
36169 - * range must be nonzero
36170 + * Noop if @range is zero.
36171 * The hash chain is sorted on range, so that subranges can override.
36172 */
36173 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36174 struct kobject *(*probe)(dev_t, int *, void *),
36175 int (*lock)(dev_t, void *), void *data)
36176 {
36177 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36178 + if (range)
36179 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36180 }
36181
36182 EXPORT_SYMBOL(blk_register_region);
36183
36184 +/* undo blk_register_region(), noop if @range is zero */
36185 void blk_unregister_region(dev_t devt, unsigned long range)
36186 {
36187 - kobj_unmap(bdev_map, devt, range);
36188 + if (range)
36189 + kobj_unmap(bdev_map, devt, range);
36190 }
36191
36192 EXPORT_SYMBOL(blk_unregister_region);
36193 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36194 index 56d08fd..2e07090 100644
36195 --- a/block/partitions/efi.c
36196 +++ b/block/partitions/efi.c
36197 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36198 if (!gpt)
36199 return NULL;
36200
36201 + if (!le32_to_cpu(gpt->num_partition_entries))
36202 + return NULL;
36203 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36204 + if (!pte)
36205 + return NULL;
36206 +
36207 count = le32_to_cpu(gpt->num_partition_entries) *
36208 le32_to_cpu(gpt->sizeof_partition_entry);
36209 - if (!count)
36210 - return NULL;
36211 - pte = kmalloc(count, GFP_KERNEL);
36212 - if (!pte)
36213 - return NULL;
36214 -
36215 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36216 (u8 *) pte, count) < count) {
36217 kfree(pte);
36218 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36219 index b0c2a61..10bb6ec 100644
36220 --- a/block/scsi_ioctl.c
36221 +++ b/block/scsi_ioctl.c
36222 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36223 return put_user(0, p);
36224 }
36225
36226 -static int sg_get_timeout(struct request_queue *q)
36227 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36228 {
36229 return jiffies_to_clock_t(q->sg_timeout);
36230 }
36231 @@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36232 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36233 struct sg_io_hdr *hdr, fmode_t mode)
36234 {
36235 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36236 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36237 + unsigned char *cmdptr;
36238 +
36239 + if (rq->cmd != rq->__cmd)
36240 + cmdptr = rq->cmd;
36241 + else
36242 + cmdptr = tmpcmd;
36243 +
36244 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36245 return -EFAULT;
36246 +
36247 + if (cmdptr != rq->cmd)
36248 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36249 +
36250 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36251 return -EPERM;
36252
36253 @@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36254 int err;
36255 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36256 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36257 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36258 + unsigned char *cmdptr;
36259
36260 if (!sic)
36261 return -EINVAL;
36262 @@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36263 */
36264 err = -EFAULT;
36265 rq->cmd_len = cmdlen;
36266 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36267 +
36268 + if (rq->cmd != rq->__cmd)
36269 + cmdptr = rq->cmd;
36270 + else
36271 + cmdptr = tmpcmd;
36272 +
36273 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36274 goto error;
36275
36276 + if (rq->cmd != cmdptr)
36277 + memcpy(rq->cmd, cmdptr, cmdlen);
36278 +
36279 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36280 goto error;
36281
36282 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36283 index 650afac1..f3307de 100644
36284 --- a/crypto/cryptd.c
36285 +++ b/crypto/cryptd.c
36286 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36287
36288 struct cryptd_blkcipher_request_ctx {
36289 crypto_completion_t complete;
36290 -};
36291 +} __no_const;
36292
36293 struct cryptd_hash_ctx {
36294 struct crypto_shash *child;
36295 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36296
36297 struct cryptd_aead_request_ctx {
36298 crypto_completion_t complete;
36299 -};
36300 +} __no_const;
36301
36302 static void cryptd_queue_worker(struct work_struct *work);
36303
36304 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36305 index c305d41..a96de79 100644
36306 --- a/crypto/pcrypt.c
36307 +++ b/crypto/pcrypt.c
36308 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36309 int ret;
36310
36311 pinst->kobj.kset = pcrypt_kset;
36312 - ret = kobject_add(&pinst->kobj, NULL, name);
36313 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36314 if (!ret)
36315 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36316
36317 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36318 index 6921c7f..78e1af7 100644
36319 --- a/drivers/acpi/acpica/hwxfsleep.c
36320 +++ b/drivers/acpi/acpica/hwxfsleep.c
36321 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36322 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36323
36324 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36325 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36326 - acpi_hw_extended_sleep},
36327 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36328 - acpi_hw_extended_wake_prep},
36329 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36330 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36331 + .extended_function = acpi_hw_extended_sleep},
36332 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36333 + .extended_function = acpi_hw_extended_wake_prep},
36334 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36335 + .extended_function = acpi_hw_extended_wake}
36336 };
36337
36338 /*
36339 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36340 index 16129c7..8b675cd 100644
36341 --- a/drivers/acpi/apei/apei-internal.h
36342 +++ b/drivers/acpi/apei/apei-internal.h
36343 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36344 struct apei_exec_ins_type {
36345 u32 flags;
36346 apei_exec_ins_func_t run;
36347 -};
36348 +} __do_const;
36349
36350 struct apei_exec_context {
36351 u32 ip;
36352 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36353 index fc5f780..e5ac91a 100644
36354 --- a/drivers/acpi/apei/ghes.c
36355 +++ b/drivers/acpi/apei/ghes.c
36356 @@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36357 const struct acpi_hest_generic *generic,
36358 const struct acpi_hest_generic_status *estatus)
36359 {
36360 - static atomic_t seqno;
36361 + static atomic_unchecked_t seqno;
36362 unsigned int curr_seqno;
36363 char pfx_seq[64];
36364
36365 @@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36366 else
36367 pfx = KERN_ERR;
36368 }
36369 - curr_seqno = atomic_inc_return(&seqno);
36370 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36371 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36372 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36373 pfx_seq, generic->header.source_id);
36374 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36375 index a83e3c6..c3d617f 100644
36376 --- a/drivers/acpi/bgrt.c
36377 +++ b/drivers/acpi/bgrt.c
36378 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36379 if (!bgrt_image)
36380 return -ENODEV;
36381
36382 - bin_attr_image.private = bgrt_image;
36383 - bin_attr_image.size = bgrt_image_size;
36384 + pax_open_kernel();
36385 + *(void **)&bin_attr_image.private = bgrt_image;
36386 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36387 + pax_close_kernel();
36388
36389 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36390 if (!bgrt_kobj)
36391 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36392 index 7556e7c..89a96bd 100644
36393 --- a/drivers/acpi/blacklist.c
36394 +++ b/drivers/acpi/blacklist.c
36395 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36396 u32 is_critical_error;
36397 };
36398
36399 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36400 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36401
36402 /*
36403 * POLICY: If *anything* doesn't work, put it on the blacklist.
36404 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36405 return 0;
36406 }
36407
36408 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36409 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36410 {
36411 .callback = dmi_disable_osi_vista,
36412 .ident = "Fujitsu Siemens",
36413 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36414 index c68e724..e863008 100644
36415 --- a/drivers/acpi/custom_method.c
36416 +++ b/drivers/acpi/custom_method.c
36417 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36418 struct acpi_table_header table;
36419 acpi_status status;
36420
36421 +#ifdef CONFIG_GRKERNSEC_KMEM
36422 + return -EPERM;
36423 +#endif
36424 +
36425 if (!(*ppos)) {
36426 /* parse the table header to get the table length */
36427 if (count <= sizeof(struct acpi_table_header))
36428 diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36429 index 6341e66..ebcf59c 100644
36430 --- a/drivers/acpi/device_pm.c
36431 +++ b/drivers/acpi/device_pm.c
36432 @@ -1029,6 +1029,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36433
36434 #endif /* CONFIG_PM_SLEEP */
36435
36436 +static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36437 +
36438 static struct dev_pm_domain acpi_general_pm_domain = {
36439 .ops = {
36440 #ifdef CONFIG_PM_RUNTIME
36441 @@ -1047,6 +1049,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36442 .restore_early = acpi_subsys_resume_early,
36443 #endif
36444 },
36445 + .detach = acpi_dev_pm_detach
36446 };
36447
36448 /**
36449 @@ -1116,7 +1119,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36450 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36451 }
36452
36453 - dev->pm_domain->detach = acpi_dev_pm_detach;
36454 return 0;
36455 }
36456 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36457 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36458 index 17f9ec5..d9a455e 100644
36459 --- a/drivers/acpi/processor_idle.c
36460 +++ b/drivers/acpi/processor_idle.c
36461 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36462 {
36463 int i, count = CPUIDLE_DRIVER_STATE_START;
36464 struct acpi_processor_cx *cx;
36465 - struct cpuidle_state *state;
36466 + cpuidle_state_no_const *state;
36467 struct cpuidle_driver *drv = &acpi_idle_driver;
36468
36469 if (!pr->flags.power_setup_done)
36470 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36471 index 13e577c..cef11ee 100644
36472 --- a/drivers/acpi/sysfs.c
36473 +++ b/drivers/acpi/sysfs.c
36474 @@ -423,11 +423,11 @@ static u32 num_counters;
36475 static struct attribute **all_attrs;
36476 static u32 acpi_gpe_count;
36477
36478 -static struct attribute_group interrupt_stats_attr_group = {
36479 +static attribute_group_no_const interrupt_stats_attr_group = {
36480 .name = "interrupts",
36481 };
36482
36483 -static struct kobj_attribute *counter_attrs;
36484 +static kobj_attribute_no_const *counter_attrs;
36485
36486 static void delete_gpe_attr_array(void)
36487 {
36488 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36489 index 97683e4..655f6ba 100644
36490 --- a/drivers/ata/libahci.c
36491 +++ b/drivers/ata/libahci.c
36492 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36493 }
36494 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36495
36496 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36497 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36498 struct ata_taskfile *tf, int is_cmd, u16 flags,
36499 unsigned long timeout_msec)
36500 {
36501 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36502 index 485f7ea..9a8df4a 100644
36503 --- a/drivers/ata/libata-core.c
36504 +++ b/drivers/ata/libata-core.c
36505 @@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36506 static void ata_dev_xfermask(struct ata_device *dev);
36507 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36508
36509 -atomic_t ata_print_id = ATOMIC_INIT(0);
36510 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36511
36512 struct ata_force_param {
36513 const char *name;
36514 @@ -4800,7 +4800,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36515 struct ata_port *ap;
36516 unsigned int tag;
36517
36518 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36519 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36520 ap = qc->ap;
36521
36522 qc->flags = 0;
36523 @@ -4816,7 +4816,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36524 struct ata_port *ap;
36525 struct ata_link *link;
36526
36527 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36528 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36529 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36530 ap = qc->ap;
36531 link = qc->dev->link;
36532 @@ -5920,6 +5920,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36533 return;
36534
36535 spin_lock(&lock);
36536 + pax_open_kernel();
36537
36538 for (cur = ops->inherits; cur; cur = cur->inherits) {
36539 void **inherit = (void **)cur;
36540 @@ -5933,8 +5934,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36541 if (IS_ERR(*pp))
36542 *pp = NULL;
36543
36544 - ops->inherits = NULL;
36545 + *(struct ata_port_operations **)&ops->inherits = NULL;
36546
36547 + pax_close_kernel();
36548 spin_unlock(&lock);
36549 }
36550
36551 @@ -6130,7 +6132,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36552
36553 /* give ports names and add SCSI hosts */
36554 for (i = 0; i < host->n_ports; i++) {
36555 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36556 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36557 host->ports[i]->local_port_no = i + 1;
36558 }
36559
36560 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36561 index 0586f66..1a8f74a 100644
36562 --- a/drivers/ata/libata-scsi.c
36563 +++ b/drivers/ata/libata-scsi.c
36564 @@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36565
36566 if (rc)
36567 return rc;
36568 - ap->print_id = atomic_inc_return(&ata_print_id);
36569 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36570 return 0;
36571 }
36572 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36573 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36574 index 5f4e0cc..ff2c347 100644
36575 --- a/drivers/ata/libata.h
36576 +++ b/drivers/ata/libata.h
36577 @@ -53,7 +53,7 @@ enum {
36578 ATA_DNXFER_QUIET = (1 << 31),
36579 };
36580
36581 -extern atomic_t ata_print_id;
36582 +extern atomic_unchecked_t ata_print_id;
36583 extern int atapi_passthru16;
36584 extern int libata_fua;
36585 extern int libata_noacpi;
36586 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36587 index 38216b9..4ec6aeb 100644
36588 --- a/drivers/ata/pata_arasan_cf.c
36589 +++ b/drivers/ata/pata_arasan_cf.c
36590 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36591 /* Handle platform specific quirks */
36592 if (quirk) {
36593 if (quirk & CF_BROKEN_PIO) {
36594 - ap->ops->set_piomode = NULL;
36595 + pax_open_kernel();
36596 + *(void **)&ap->ops->set_piomode = NULL;
36597 + pax_close_kernel();
36598 ap->pio_mask = 0;
36599 }
36600 if (quirk & CF_BROKEN_MWDMA)
36601 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36602 index f9b983a..887b9d8 100644
36603 --- a/drivers/atm/adummy.c
36604 +++ b/drivers/atm/adummy.c
36605 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36606 vcc->pop(vcc, skb);
36607 else
36608 dev_kfree_skb_any(skb);
36609 - atomic_inc(&vcc->stats->tx);
36610 + atomic_inc_unchecked(&vcc->stats->tx);
36611
36612 return 0;
36613 }
36614 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36615 index f1a9198..f466a4a 100644
36616 --- a/drivers/atm/ambassador.c
36617 +++ b/drivers/atm/ambassador.c
36618 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36619 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36620
36621 // VC layer stats
36622 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36623 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36624
36625 // free the descriptor
36626 kfree (tx_descr);
36627 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36628 dump_skb ("<<<", vc, skb);
36629
36630 // VC layer stats
36631 - atomic_inc(&atm_vcc->stats->rx);
36632 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36633 __net_timestamp(skb);
36634 // end of our responsibility
36635 atm_vcc->push (atm_vcc, skb);
36636 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36637 } else {
36638 PRINTK (KERN_INFO, "dropped over-size frame");
36639 // should we count this?
36640 - atomic_inc(&atm_vcc->stats->rx_drop);
36641 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36642 }
36643
36644 } else {
36645 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36646 }
36647
36648 if (check_area (skb->data, skb->len)) {
36649 - atomic_inc(&atm_vcc->stats->tx_err);
36650 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36651 return -ENOMEM; // ?
36652 }
36653
36654 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36655 index 480fa6f..947067c 100644
36656 --- a/drivers/atm/atmtcp.c
36657 +++ b/drivers/atm/atmtcp.c
36658 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36659 if (vcc->pop) vcc->pop(vcc,skb);
36660 else dev_kfree_skb(skb);
36661 if (dev_data) return 0;
36662 - atomic_inc(&vcc->stats->tx_err);
36663 + atomic_inc_unchecked(&vcc->stats->tx_err);
36664 return -ENOLINK;
36665 }
36666 size = skb->len+sizeof(struct atmtcp_hdr);
36667 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36668 if (!new_skb) {
36669 if (vcc->pop) vcc->pop(vcc,skb);
36670 else dev_kfree_skb(skb);
36671 - atomic_inc(&vcc->stats->tx_err);
36672 + atomic_inc_unchecked(&vcc->stats->tx_err);
36673 return -ENOBUFS;
36674 }
36675 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36676 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36677 if (vcc->pop) vcc->pop(vcc,skb);
36678 else dev_kfree_skb(skb);
36679 out_vcc->push(out_vcc,new_skb);
36680 - atomic_inc(&vcc->stats->tx);
36681 - atomic_inc(&out_vcc->stats->rx);
36682 + atomic_inc_unchecked(&vcc->stats->tx);
36683 + atomic_inc_unchecked(&out_vcc->stats->rx);
36684 return 0;
36685 }
36686
36687 @@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36688 read_unlock(&vcc_sklist_lock);
36689 if (!out_vcc) {
36690 result = -EUNATCH;
36691 - atomic_inc(&vcc->stats->tx_err);
36692 + atomic_inc_unchecked(&vcc->stats->tx_err);
36693 goto done;
36694 }
36695 skb_pull(skb,sizeof(struct atmtcp_hdr));
36696 @@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36697 __net_timestamp(new_skb);
36698 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36699 out_vcc->push(out_vcc,new_skb);
36700 - atomic_inc(&vcc->stats->tx);
36701 - atomic_inc(&out_vcc->stats->rx);
36702 + atomic_inc_unchecked(&vcc->stats->tx);
36703 + atomic_inc_unchecked(&out_vcc->stats->rx);
36704 done:
36705 if (vcc->pop) vcc->pop(vcc,skb);
36706 else dev_kfree_skb(skb);
36707 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36708 index d65975a..0b87e20 100644
36709 --- a/drivers/atm/eni.c
36710 +++ b/drivers/atm/eni.c
36711 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36712 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36713 vcc->dev->number);
36714 length = 0;
36715 - atomic_inc(&vcc->stats->rx_err);
36716 + atomic_inc_unchecked(&vcc->stats->rx_err);
36717 }
36718 else {
36719 length = ATM_CELL_SIZE-1; /* no HEC */
36720 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36721 size);
36722 }
36723 eff = length = 0;
36724 - atomic_inc(&vcc->stats->rx_err);
36725 + atomic_inc_unchecked(&vcc->stats->rx_err);
36726 }
36727 else {
36728 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36729 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36730 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36731 vcc->dev->number,vcc->vci,length,size << 2,descr);
36732 length = eff = 0;
36733 - atomic_inc(&vcc->stats->rx_err);
36734 + atomic_inc_unchecked(&vcc->stats->rx_err);
36735 }
36736 }
36737 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36738 @@ -767,7 +767,7 @@ rx_dequeued++;
36739 vcc->push(vcc,skb);
36740 pushed++;
36741 }
36742 - atomic_inc(&vcc->stats->rx);
36743 + atomic_inc_unchecked(&vcc->stats->rx);
36744 }
36745 wake_up(&eni_dev->rx_wait);
36746 }
36747 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36748 PCI_DMA_TODEVICE);
36749 if (vcc->pop) vcc->pop(vcc,skb);
36750 else dev_kfree_skb_irq(skb);
36751 - atomic_inc(&vcc->stats->tx);
36752 + atomic_inc_unchecked(&vcc->stats->tx);
36753 wake_up(&eni_dev->tx_wait);
36754 dma_complete++;
36755 }
36756 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36757 index 82f2ae0..f205c02 100644
36758 --- a/drivers/atm/firestream.c
36759 +++ b/drivers/atm/firestream.c
36760 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36761 }
36762 }
36763
36764 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36765 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36766
36767 fs_dprintk (FS_DEBUG_TXMEM, "i");
36768 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36769 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36770 #endif
36771 skb_put (skb, qe->p1 & 0xffff);
36772 ATM_SKB(skb)->vcc = atm_vcc;
36773 - atomic_inc(&atm_vcc->stats->rx);
36774 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36775 __net_timestamp(skb);
36776 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36777 atm_vcc->push (atm_vcc, skb);
36778 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36779 kfree (pe);
36780 }
36781 if (atm_vcc)
36782 - atomic_inc(&atm_vcc->stats->rx_drop);
36783 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36784 break;
36785 case 0x1f: /* Reassembly abort: no buffers. */
36786 /* Silently increment error counter. */
36787 if (atm_vcc)
36788 - atomic_inc(&atm_vcc->stats->rx_drop);
36789 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36790 break;
36791 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36792 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36793 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36794 index d4725fc..2d4ea65 100644
36795 --- a/drivers/atm/fore200e.c
36796 +++ b/drivers/atm/fore200e.c
36797 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36798 #endif
36799 /* check error condition */
36800 if (*entry->status & STATUS_ERROR)
36801 - atomic_inc(&vcc->stats->tx_err);
36802 + atomic_inc_unchecked(&vcc->stats->tx_err);
36803 else
36804 - atomic_inc(&vcc->stats->tx);
36805 + atomic_inc_unchecked(&vcc->stats->tx);
36806 }
36807 }
36808
36809 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36810 if (skb == NULL) {
36811 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36812
36813 - atomic_inc(&vcc->stats->rx_drop);
36814 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36815 return -ENOMEM;
36816 }
36817
36818 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36819
36820 dev_kfree_skb_any(skb);
36821
36822 - atomic_inc(&vcc->stats->rx_drop);
36823 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36824 return -ENOMEM;
36825 }
36826
36827 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36828
36829 vcc->push(vcc, skb);
36830 - atomic_inc(&vcc->stats->rx);
36831 + atomic_inc_unchecked(&vcc->stats->rx);
36832
36833 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36834
36835 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36836 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36837 fore200e->atm_dev->number,
36838 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36839 - atomic_inc(&vcc->stats->rx_err);
36840 + atomic_inc_unchecked(&vcc->stats->rx_err);
36841 }
36842 }
36843
36844 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36845 goto retry_here;
36846 }
36847
36848 - atomic_inc(&vcc->stats->tx_err);
36849 + atomic_inc_unchecked(&vcc->stats->tx_err);
36850
36851 fore200e->tx_sat++;
36852 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36853 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36854 index c39702b..785b73b 100644
36855 --- a/drivers/atm/he.c
36856 +++ b/drivers/atm/he.c
36857 @@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36858
36859 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36860 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36861 - atomic_inc(&vcc->stats->rx_drop);
36862 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36863 goto return_host_buffers;
36864 }
36865
36866 @@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36867 RBRQ_LEN_ERR(he_dev->rbrq_head)
36868 ? "LEN_ERR" : "",
36869 vcc->vpi, vcc->vci);
36870 - atomic_inc(&vcc->stats->rx_err);
36871 + atomic_inc_unchecked(&vcc->stats->rx_err);
36872 goto return_host_buffers;
36873 }
36874
36875 @@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36876 vcc->push(vcc, skb);
36877 spin_lock(&he_dev->global_lock);
36878
36879 - atomic_inc(&vcc->stats->rx);
36880 + atomic_inc_unchecked(&vcc->stats->rx);
36881
36882 return_host_buffers:
36883 ++pdus_assembled;
36884 @@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36885 tpd->vcc->pop(tpd->vcc, tpd->skb);
36886 else
36887 dev_kfree_skb_any(tpd->skb);
36888 - atomic_inc(&tpd->vcc->stats->tx_err);
36889 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36890 }
36891 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36892 return;
36893 @@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36894 vcc->pop(vcc, skb);
36895 else
36896 dev_kfree_skb_any(skb);
36897 - atomic_inc(&vcc->stats->tx_err);
36898 + atomic_inc_unchecked(&vcc->stats->tx_err);
36899 return -EINVAL;
36900 }
36901
36902 @@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36903 vcc->pop(vcc, skb);
36904 else
36905 dev_kfree_skb_any(skb);
36906 - atomic_inc(&vcc->stats->tx_err);
36907 + atomic_inc_unchecked(&vcc->stats->tx_err);
36908 return -EINVAL;
36909 }
36910 #endif
36911 @@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36912 vcc->pop(vcc, skb);
36913 else
36914 dev_kfree_skb_any(skb);
36915 - atomic_inc(&vcc->stats->tx_err);
36916 + atomic_inc_unchecked(&vcc->stats->tx_err);
36917 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36918 return -ENOMEM;
36919 }
36920 @@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36921 vcc->pop(vcc, skb);
36922 else
36923 dev_kfree_skb_any(skb);
36924 - atomic_inc(&vcc->stats->tx_err);
36925 + atomic_inc_unchecked(&vcc->stats->tx_err);
36926 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36927 return -ENOMEM;
36928 }
36929 @@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36930 __enqueue_tpd(he_dev, tpd, cid);
36931 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36932
36933 - atomic_inc(&vcc->stats->tx);
36934 + atomic_inc_unchecked(&vcc->stats->tx);
36935
36936 return 0;
36937 }
36938 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36939 index 1dc0519..1aadaf7 100644
36940 --- a/drivers/atm/horizon.c
36941 +++ b/drivers/atm/horizon.c
36942 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36943 {
36944 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36945 // VC layer stats
36946 - atomic_inc(&vcc->stats->rx);
36947 + atomic_inc_unchecked(&vcc->stats->rx);
36948 __net_timestamp(skb);
36949 // end of our responsibility
36950 vcc->push (vcc, skb);
36951 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36952 dev->tx_iovec = NULL;
36953
36954 // VC layer stats
36955 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36956 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36957
36958 // free the skb
36959 hrz_kfree_skb (skb);
36960 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36961 index 2b24ed0..b3d6acc 100644
36962 --- a/drivers/atm/idt77252.c
36963 +++ b/drivers/atm/idt77252.c
36964 @@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36965 else
36966 dev_kfree_skb(skb);
36967
36968 - atomic_inc(&vcc->stats->tx);
36969 + atomic_inc_unchecked(&vcc->stats->tx);
36970 }
36971
36972 atomic_dec(&scq->used);
36973 @@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36974 if ((sb = dev_alloc_skb(64)) == NULL) {
36975 printk("%s: Can't allocate buffers for aal0.\n",
36976 card->name);
36977 - atomic_add(i, &vcc->stats->rx_drop);
36978 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36979 break;
36980 }
36981 if (!atm_charge(vcc, sb->truesize)) {
36982 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36983 card->name);
36984 - atomic_add(i - 1, &vcc->stats->rx_drop);
36985 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36986 dev_kfree_skb(sb);
36987 break;
36988 }
36989 @@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36990 ATM_SKB(sb)->vcc = vcc;
36991 __net_timestamp(sb);
36992 vcc->push(vcc, sb);
36993 - atomic_inc(&vcc->stats->rx);
36994 + atomic_inc_unchecked(&vcc->stats->rx);
36995
36996 cell += ATM_CELL_PAYLOAD;
36997 }
36998 @@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36999 "(CDC: %08x)\n",
37000 card->name, len, rpp->len, readl(SAR_REG_CDC));
37001 recycle_rx_pool_skb(card, rpp);
37002 - atomic_inc(&vcc->stats->rx_err);
37003 + atomic_inc_unchecked(&vcc->stats->rx_err);
37004 return;
37005 }
37006 if (stat & SAR_RSQE_CRC) {
37007 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37008 recycle_rx_pool_skb(card, rpp);
37009 - atomic_inc(&vcc->stats->rx_err);
37010 + atomic_inc_unchecked(&vcc->stats->rx_err);
37011 return;
37012 }
37013 if (skb_queue_len(&rpp->queue) > 1) {
37014 @@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37015 RXPRINTK("%s: Can't alloc RX skb.\n",
37016 card->name);
37017 recycle_rx_pool_skb(card, rpp);
37018 - atomic_inc(&vcc->stats->rx_err);
37019 + atomic_inc_unchecked(&vcc->stats->rx_err);
37020 return;
37021 }
37022 if (!atm_charge(vcc, skb->truesize)) {
37023 @@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37024 __net_timestamp(skb);
37025
37026 vcc->push(vcc, skb);
37027 - atomic_inc(&vcc->stats->rx);
37028 + atomic_inc_unchecked(&vcc->stats->rx);
37029
37030 return;
37031 }
37032 @@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37033 __net_timestamp(skb);
37034
37035 vcc->push(vcc, skb);
37036 - atomic_inc(&vcc->stats->rx);
37037 + atomic_inc_unchecked(&vcc->stats->rx);
37038
37039 if (skb->truesize > SAR_FB_SIZE_3)
37040 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37041 @@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37042 if (vcc->qos.aal != ATM_AAL0) {
37043 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37044 card->name, vpi, vci);
37045 - atomic_inc(&vcc->stats->rx_drop);
37046 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37047 goto drop;
37048 }
37049
37050 if ((sb = dev_alloc_skb(64)) == NULL) {
37051 printk("%s: Can't allocate buffers for AAL0.\n",
37052 card->name);
37053 - atomic_inc(&vcc->stats->rx_err);
37054 + atomic_inc_unchecked(&vcc->stats->rx_err);
37055 goto drop;
37056 }
37057
37058 @@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37059 ATM_SKB(sb)->vcc = vcc;
37060 __net_timestamp(sb);
37061 vcc->push(vcc, sb);
37062 - atomic_inc(&vcc->stats->rx);
37063 + atomic_inc_unchecked(&vcc->stats->rx);
37064
37065 drop:
37066 skb_pull(queue, 64);
37067 @@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37068
37069 if (vc == NULL) {
37070 printk("%s: NULL connection in send().\n", card->name);
37071 - atomic_inc(&vcc->stats->tx_err);
37072 + atomic_inc_unchecked(&vcc->stats->tx_err);
37073 dev_kfree_skb(skb);
37074 return -EINVAL;
37075 }
37076 if (!test_bit(VCF_TX, &vc->flags)) {
37077 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37078 - atomic_inc(&vcc->stats->tx_err);
37079 + atomic_inc_unchecked(&vcc->stats->tx_err);
37080 dev_kfree_skb(skb);
37081 return -EINVAL;
37082 }
37083 @@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37084 break;
37085 default:
37086 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37087 - atomic_inc(&vcc->stats->tx_err);
37088 + atomic_inc_unchecked(&vcc->stats->tx_err);
37089 dev_kfree_skb(skb);
37090 return -EINVAL;
37091 }
37092
37093 if (skb_shinfo(skb)->nr_frags != 0) {
37094 printk("%s: No scatter-gather yet.\n", card->name);
37095 - atomic_inc(&vcc->stats->tx_err);
37096 + atomic_inc_unchecked(&vcc->stats->tx_err);
37097 dev_kfree_skb(skb);
37098 return -EINVAL;
37099 }
37100 @@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37101
37102 err = queue_skb(card, vc, skb, oam);
37103 if (err) {
37104 - atomic_inc(&vcc->stats->tx_err);
37105 + atomic_inc_unchecked(&vcc->stats->tx_err);
37106 dev_kfree_skb(skb);
37107 return err;
37108 }
37109 @@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37110 skb = dev_alloc_skb(64);
37111 if (!skb) {
37112 printk("%s: Out of memory in send_oam().\n", card->name);
37113 - atomic_inc(&vcc->stats->tx_err);
37114 + atomic_inc_unchecked(&vcc->stats->tx_err);
37115 return -ENOMEM;
37116 }
37117 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37118 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37119 index 4217f29..88f547a 100644
37120 --- a/drivers/atm/iphase.c
37121 +++ b/drivers/atm/iphase.c
37122 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37123 status = (u_short) (buf_desc_ptr->desc_mode);
37124 if (status & (RX_CER | RX_PTE | RX_OFL))
37125 {
37126 - atomic_inc(&vcc->stats->rx_err);
37127 + atomic_inc_unchecked(&vcc->stats->rx_err);
37128 IF_ERR(printk("IA: bad packet, dropping it");)
37129 if (status & RX_CER) {
37130 IF_ERR(printk(" cause: packet CRC error\n");)
37131 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37132 len = dma_addr - buf_addr;
37133 if (len > iadev->rx_buf_sz) {
37134 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37135 - atomic_inc(&vcc->stats->rx_err);
37136 + atomic_inc_unchecked(&vcc->stats->rx_err);
37137 goto out_free_desc;
37138 }
37139
37140 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37141 ia_vcc = INPH_IA_VCC(vcc);
37142 if (ia_vcc == NULL)
37143 {
37144 - atomic_inc(&vcc->stats->rx_err);
37145 + atomic_inc_unchecked(&vcc->stats->rx_err);
37146 atm_return(vcc, skb->truesize);
37147 dev_kfree_skb_any(skb);
37148 goto INCR_DLE;
37149 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37150 if ((length > iadev->rx_buf_sz) || (length >
37151 (skb->len - sizeof(struct cpcs_trailer))))
37152 {
37153 - atomic_inc(&vcc->stats->rx_err);
37154 + atomic_inc_unchecked(&vcc->stats->rx_err);
37155 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37156 length, skb->len);)
37157 atm_return(vcc, skb->truesize);
37158 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37159
37160 IF_RX(printk("rx_dle_intr: skb push");)
37161 vcc->push(vcc,skb);
37162 - atomic_inc(&vcc->stats->rx);
37163 + atomic_inc_unchecked(&vcc->stats->rx);
37164 iadev->rx_pkt_cnt++;
37165 }
37166 INCR_DLE:
37167 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37168 {
37169 struct k_sonet_stats *stats;
37170 stats = &PRIV(_ia_dev[board])->sonet_stats;
37171 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37172 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37173 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37174 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37175 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37176 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37177 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37178 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37179 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37180 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37181 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37182 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37183 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37184 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37185 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37186 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37187 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37188 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37189 }
37190 ia_cmds.status = 0;
37191 break;
37192 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37193 if ((desc == 0) || (desc > iadev->num_tx_desc))
37194 {
37195 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37196 - atomic_inc(&vcc->stats->tx);
37197 + atomic_inc_unchecked(&vcc->stats->tx);
37198 if (vcc->pop)
37199 vcc->pop(vcc, skb);
37200 else
37201 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37202 ATM_DESC(skb) = vcc->vci;
37203 skb_queue_tail(&iadev->tx_dma_q, skb);
37204
37205 - atomic_inc(&vcc->stats->tx);
37206 + atomic_inc_unchecked(&vcc->stats->tx);
37207 iadev->tx_pkt_cnt++;
37208 /* Increment transaction counter */
37209 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37210
37211 #if 0
37212 /* add flow control logic */
37213 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37214 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37215 if (iavcc->vc_desc_cnt > 10) {
37216 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37217 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37218 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37219 index 93eaf8d..b4ca7da 100644
37220 --- a/drivers/atm/lanai.c
37221 +++ b/drivers/atm/lanai.c
37222 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37223 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37224 lanai_endtx(lanai, lvcc);
37225 lanai_free_skb(lvcc->tx.atmvcc, skb);
37226 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37227 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37228 }
37229
37230 /* Try to fill the buffer - don't call unless there is backlog */
37231 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37232 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37233 __net_timestamp(skb);
37234 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37235 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37236 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37237 out:
37238 lvcc->rx.buf.ptr = end;
37239 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37240 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37241 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37242 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37243 lanai->stats.service_rxnotaal5++;
37244 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37245 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37246 return 0;
37247 }
37248 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37249 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37250 int bytes;
37251 read_unlock(&vcc_sklist_lock);
37252 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37253 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37254 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37255 lvcc->stats.x.aal5.service_trash++;
37256 bytes = (SERVICE_GET_END(s) * 16) -
37257 (((unsigned long) lvcc->rx.buf.ptr) -
37258 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37259 }
37260 if (s & SERVICE_STREAM) {
37261 read_unlock(&vcc_sklist_lock);
37262 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37263 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37264 lvcc->stats.x.aal5.service_stream++;
37265 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37266 "PDU on VCI %d!\n", lanai->number, vci);
37267 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37268 return 0;
37269 }
37270 DPRINTK("got rx crc error on vci %d\n", vci);
37271 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37272 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37273 lvcc->stats.x.aal5.service_rxcrc++;
37274 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37275 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37276 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37277 index 9988ac9..7c52585 100644
37278 --- a/drivers/atm/nicstar.c
37279 +++ b/drivers/atm/nicstar.c
37280 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37281 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37282 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37283 card->index);
37284 - atomic_inc(&vcc->stats->tx_err);
37285 + atomic_inc_unchecked(&vcc->stats->tx_err);
37286 dev_kfree_skb_any(skb);
37287 return -EINVAL;
37288 }
37289 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37290 if (!vc->tx) {
37291 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37292 card->index);
37293 - atomic_inc(&vcc->stats->tx_err);
37294 + atomic_inc_unchecked(&vcc->stats->tx_err);
37295 dev_kfree_skb_any(skb);
37296 return -EINVAL;
37297 }
37298 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37299 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37300 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37301 card->index);
37302 - atomic_inc(&vcc->stats->tx_err);
37303 + atomic_inc_unchecked(&vcc->stats->tx_err);
37304 dev_kfree_skb_any(skb);
37305 return -EINVAL;
37306 }
37307
37308 if (skb_shinfo(skb)->nr_frags != 0) {
37309 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37310 - atomic_inc(&vcc->stats->tx_err);
37311 + atomic_inc_unchecked(&vcc->stats->tx_err);
37312 dev_kfree_skb_any(skb);
37313 return -EINVAL;
37314 }
37315 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37316 }
37317
37318 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37319 - atomic_inc(&vcc->stats->tx_err);
37320 + atomic_inc_unchecked(&vcc->stats->tx_err);
37321 dev_kfree_skb_any(skb);
37322 return -EIO;
37323 }
37324 - atomic_inc(&vcc->stats->tx);
37325 + atomic_inc_unchecked(&vcc->stats->tx);
37326
37327 return 0;
37328 }
37329 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37330 printk
37331 ("nicstar%d: Can't allocate buffers for aal0.\n",
37332 card->index);
37333 - atomic_add(i, &vcc->stats->rx_drop);
37334 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37335 break;
37336 }
37337 if (!atm_charge(vcc, sb->truesize)) {
37338 RXPRINTK
37339 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37340 card->index);
37341 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37342 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37343 dev_kfree_skb_any(sb);
37344 break;
37345 }
37346 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37347 ATM_SKB(sb)->vcc = vcc;
37348 __net_timestamp(sb);
37349 vcc->push(vcc, sb);
37350 - atomic_inc(&vcc->stats->rx);
37351 + atomic_inc_unchecked(&vcc->stats->rx);
37352 cell += ATM_CELL_PAYLOAD;
37353 }
37354
37355 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37356 if (iovb == NULL) {
37357 printk("nicstar%d: Out of iovec buffers.\n",
37358 card->index);
37359 - atomic_inc(&vcc->stats->rx_drop);
37360 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37361 recycle_rx_buf(card, skb);
37362 return;
37363 }
37364 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37365 small or large buffer itself. */
37366 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37367 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37368 - atomic_inc(&vcc->stats->rx_err);
37369 + atomic_inc_unchecked(&vcc->stats->rx_err);
37370 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37371 NS_MAX_IOVECS);
37372 NS_PRV_IOVCNT(iovb) = 0;
37373 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37374 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37375 card->index);
37376 which_list(card, skb);
37377 - atomic_inc(&vcc->stats->rx_err);
37378 + atomic_inc_unchecked(&vcc->stats->rx_err);
37379 recycle_rx_buf(card, skb);
37380 vc->rx_iov = NULL;
37381 recycle_iov_buf(card, iovb);
37382 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37383 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37384 card->index);
37385 which_list(card, skb);
37386 - atomic_inc(&vcc->stats->rx_err);
37387 + atomic_inc_unchecked(&vcc->stats->rx_err);
37388 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37389 NS_PRV_IOVCNT(iovb));
37390 vc->rx_iov = NULL;
37391 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37392 printk(" - PDU size mismatch.\n");
37393 else
37394 printk(".\n");
37395 - atomic_inc(&vcc->stats->rx_err);
37396 + atomic_inc_unchecked(&vcc->stats->rx_err);
37397 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37398 NS_PRV_IOVCNT(iovb));
37399 vc->rx_iov = NULL;
37400 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37401 /* skb points to a small buffer */
37402 if (!atm_charge(vcc, skb->truesize)) {
37403 push_rxbufs(card, skb);
37404 - atomic_inc(&vcc->stats->rx_drop);
37405 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37406 } else {
37407 skb_put(skb, len);
37408 dequeue_sm_buf(card, skb);
37409 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37410 ATM_SKB(skb)->vcc = vcc;
37411 __net_timestamp(skb);
37412 vcc->push(vcc, skb);
37413 - atomic_inc(&vcc->stats->rx);
37414 + atomic_inc_unchecked(&vcc->stats->rx);
37415 }
37416 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37417 struct sk_buff *sb;
37418 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37419 if (len <= NS_SMBUFSIZE) {
37420 if (!atm_charge(vcc, sb->truesize)) {
37421 push_rxbufs(card, sb);
37422 - atomic_inc(&vcc->stats->rx_drop);
37423 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37424 } else {
37425 skb_put(sb, len);
37426 dequeue_sm_buf(card, sb);
37427 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37428 ATM_SKB(sb)->vcc = vcc;
37429 __net_timestamp(sb);
37430 vcc->push(vcc, sb);
37431 - atomic_inc(&vcc->stats->rx);
37432 + atomic_inc_unchecked(&vcc->stats->rx);
37433 }
37434
37435 push_rxbufs(card, skb);
37436 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37437
37438 if (!atm_charge(vcc, skb->truesize)) {
37439 push_rxbufs(card, skb);
37440 - atomic_inc(&vcc->stats->rx_drop);
37441 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37442 } else {
37443 dequeue_lg_buf(card, skb);
37444 #ifdef NS_USE_DESTRUCTORS
37445 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37446 ATM_SKB(skb)->vcc = vcc;
37447 __net_timestamp(skb);
37448 vcc->push(vcc, skb);
37449 - atomic_inc(&vcc->stats->rx);
37450 + atomic_inc_unchecked(&vcc->stats->rx);
37451 }
37452
37453 push_rxbufs(card, sb);
37454 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37455 printk
37456 ("nicstar%d: Out of huge buffers.\n",
37457 card->index);
37458 - atomic_inc(&vcc->stats->rx_drop);
37459 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37460 recycle_iovec_rx_bufs(card,
37461 (struct iovec *)
37462 iovb->data,
37463 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37464 card->hbpool.count++;
37465 } else
37466 dev_kfree_skb_any(hb);
37467 - atomic_inc(&vcc->stats->rx_drop);
37468 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37469 } else {
37470 /* Copy the small buffer to the huge buffer */
37471 sb = (struct sk_buff *)iov->iov_base;
37472 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37473 #endif /* NS_USE_DESTRUCTORS */
37474 __net_timestamp(hb);
37475 vcc->push(vcc, hb);
37476 - atomic_inc(&vcc->stats->rx);
37477 + atomic_inc_unchecked(&vcc->stats->rx);
37478 }
37479 }
37480
37481 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37482 index 21b0bc6..b5f40ba 100644
37483 --- a/drivers/atm/solos-pci.c
37484 +++ b/drivers/atm/solos-pci.c
37485 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37486 }
37487 atm_charge(vcc, skb->truesize);
37488 vcc->push(vcc, skb);
37489 - atomic_inc(&vcc->stats->rx);
37490 + atomic_inc_unchecked(&vcc->stats->rx);
37491 break;
37492
37493 case PKT_STATUS:
37494 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37495 vcc = SKB_CB(oldskb)->vcc;
37496
37497 if (vcc) {
37498 - atomic_inc(&vcc->stats->tx);
37499 + atomic_inc_unchecked(&vcc->stats->tx);
37500 solos_pop(vcc, oldskb);
37501 } else {
37502 dev_kfree_skb_irq(oldskb);
37503 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37504 index 0215934..ce9f5b1 100644
37505 --- a/drivers/atm/suni.c
37506 +++ b/drivers/atm/suni.c
37507 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37508
37509
37510 #define ADD_LIMITED(s,v) \
37511 - atomic_add((v),&stats->s); \
37512 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37513 + atomic_add_unchecked((v),&stats->s); \
37514 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37515
37516
37517 static void suni_hz(unsigned long from_timer)
37518 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37519 index 5120a96..e2572bd 100644
37520 --- a/drivers/atm/uPD98402.c
37521 +++ b/drivers/atm/uPD98402.c
37522 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37523 struct sonet_stats tmp;
37524 int error = 0;
37525
37526 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37527 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37528 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37529 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37530 if (zero && !error) {
37531 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37532
37533
37534 #define ADD_LIMITED(s,v) \
37535 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37536 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37537 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37538 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37539 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37540 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37541
37542
37543 static void stat_event(struct atm_dev *dev)
37544 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37545 if (reason & uPD98402_INT_PFM) stat_event(dev);
37546 if (reason & uPD98402_INT_PCO) {
37547 (void) GET(PCOCR); /* clear interrupt cause */
37548 - atomic_add(GET(HECCT),
37549 + atomic_add_unchecked(GET(HECCT),
37550 &PRIV(dev)->sonet_stats.uncorr_hcs);
37551 }
37552 if ((reason & uPD98402_INT_RFO) &&
37553 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37554 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37555 uPD98402_INT_LOS),PIMR); /* enable them */
37556 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37557 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37558 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37559 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37560 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37561 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37562 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37563 return 0;
37564 }
37565
37566 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37567 index 969c3c2..9b72956 100644
37568 --- a/drivers/atm/zatm.c
37569 +++ b/drivers/atm/zatm.c
37570 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37571 }
37572 if (!size) {
37573 dev_kfree_skb_irq(skb);
37574 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37575 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37576 continue;
37577 }
37578 if (!atm_charge(vcc,skb->truesize)) {
37579 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37580 skb->len = size;
37581 ATM_SKB(skb)->vcc = vcc;
37582 vcc->push(vcc,skb);
37583 - atomic_inc(&vcc->stats->rx);
37584 + atomic_inc_unchecked(&vcc->stats->rx);
37585 }
37586 zout(pos & 0xffff,MTA(mbx));
37587 #if 0 /* probably a stupid idea */
37588 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37589 skb_queue_head(&zatm_vcc->backlog,skb);
37590 break;
37591 }
37592 - atomic_inc(&vcc->stats->tx);
37593 + atomic_inc_unchecked(&vcc->stats->tx);
37594 wake_up(&zatm_vcc->tx_wait);
37595 }
37596
37597 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37598 index 876bae5..8978785 100644
37599 --- a/drivers/base/bus.c
37600 +++ b/drivers/base/bus.c
37601 @@ -1126,7 +1126,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37602 return -EINVAL;
37603
37604 mutex_lock(&subsys->p->mutex);
37605 - list_add_tail(&sif->node, &subsys->p->interfaces);
37606 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37607 if (sif->add_dev) {
37608 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37609 while ((dev = subsys_dev_iter_next(&iter)))
37610 @@ -1151,7 +1151,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37611 subsys = sif->subsys;
37612
37613 mutex_lock(&subsys->p->mutex);
37614 - list_del_init(&sif->node);
37615 + pax_list_del_init((struct list_head *)&sif->node);
37616 if (sif->remove_dev) {
37617 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37618 while ((dev = subsys_dev_iter_next(&iter)))
37619 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37620 index 25798db..15f130e 100644
37621 --- a/drivers/base/devtmpfs.c
37622 +++ b/drivers/base/devtmpfs.c
37623 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37624 if (!thread)
37625 return 0;
37626
37627 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37628 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37629 if (err)
37630 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37631 else
37632 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37633 *err = sys_unshare(CLONE_NEWNS);
37634 if (*err)
37635 goto out;
37636 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37637 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37638 if (*err)
37639 goto out;
37640 - sys_chdir("/.."); /* will traverse into overmounted root */
37641 - sys_chroot(".");
37642 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37643 + sys_chroot((char __force_user *)".");
37644 complete(&setup_done);
37645 while (1) {
37646 spin_lock(&req_lock);
37647 diff --git a/drivers/base/node.c b/drivers/base/node.c
37648 index 472168c..4af587e 100644
37649 --- a/drivers/base/node.c
37650 +++ b/drivers/base/node.c
37651 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37652 struct node_attr {
37653 struct device_attribute attr;
37654 enum node_states state;
37655 -};
37656 +} __do_const;
37657
37658 static ssize_t show_node_state(struct device *dev,
37659 struct device_attribute *attr, char *buf)
37660 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37661 index fb83d4a..e1797b3 100644
37662 --- a/drivers/base/power/domain.c
37663 +++ b/drivers/base/power/domain.c
37664 @@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37665 {
37666 struct cpuidle_driver *cpuidle_drv;
37667 struct gpd_cpuidle_data *cpuidle_data;
37668 - struct cpuidle_state *idle_state;
37669 + cpuidle_state_no_const *idle_state;
37670 int ret = 0;
37671
37672 if (IS_ERR_OR_NULL(genpd) || state < 0)
37673 @@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37674 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37675 {
37676 struct gpd_cpuidle_data *cpuidle_data;
37677 - struct cpuidle_state *idle_state;
37678 + cpuidle_state_no_const *idle_state;
37679 int ret = 0;
37680
37681 if (IS_ERR_OR_NULL(genpd))
37682 @@ -2215,7 +2215,9 @@ int genpd_dev_pm_attach(struct device *dev)
37683 return ret;
37684 }
37685
37686 - dev->pm_domain->detach = genpd_dev_pm_detach;
37687 + pax_open_kernel();
37688 + *(void **)&dev->pm_domain->detach = genpd_dev_pm_detach;
37689 + pax_close_kernel();
37690
37691 return 0;
37692 }
37693 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37694 index a9d26ed..74b8405 100644
37695 --- a/drivers/base/power/sysfs.c
37696 +++ b/drivers/base/power/sysfs.c
37697 @@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37698 return -EIO;
37699 }
37700 }
37701 - return sprintf(buf, p);
37702 + return sprintf(buf, "%s", p);
37703 }
37704
37705 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37706 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37707 index c2744b3..08fac19 100644
37708 --- a/drivers/base/power/wakeup.c
37709 +++ b/drivers/base/power/wakeup.c
37710 @@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37711 * They need to be modified together atomically, so it's better to use one
37712 * atomic variable to hold them both.
37713 */
37714 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37715 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37716
37717 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37718 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37719
37720 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37721 {
37722 - unsigned int comb = atomic_read(&combined_event_count);
37723 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37724
37725 *cnt = (comb >> IN_PROGRESS_BITS);
37726 *inpr = comb & MAX_IN_PROGRESS;
37727 @@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37728 ws->start_prevent_time = ws->last_time;
37729
37730 /* Increment the counter of events in progress. */
37731 - cec = atomic_inc_return(&combined_event_count);
37732 + cec = atomic_inc_return_unchecked(&combined_event_count);
37733
37734 trace_wakeup_source_activate(ws->name, cec);
37735 }
37736 @@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37737 * Increment the counter of registered wakeup events and decrement the
37738 * couter of wakeup events in progress simultaneously.
37739 */
37740 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37741 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37742 trace_wakeup_source_deactivate(ws->name, cec);
37743
37744 split_counters(&cnt, &inpr);
37745 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37746 index 8d98a32..61d3165 100644
37747 --- a/drivers/base/syscore.c
37748 +++ b/drivers/base/syscore.c
37749 @@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37750 void register_syscore_ops(struct syscore_ops *ops)
37751 {
37752 mutex_lock(&syscore_ops_lock);
37753 - list_add_tail(&ops->node, &syscore_ops_list);
37754 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37755 mutex_unlock(&syscore_ops_lock);
37756 }
37757 EXPORT_SYMBOL_GPL(register_syscore_ops);
37758 @@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37759 void unregister_syscore_ops(struct syscore_ops *ops)
37760 {
37761 mutex_lock(&syscore_ops_lock);
37762 - list_del(&ops->node);
37763 + pax_list_del((struct list_head *)&ops->node);
37764 mutex_unlock(&syscore_ops_lock);
37765 }
37766 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37767 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37768 index ff20f19..018f1da 100644
37769 --- a/drivers/block/cciss.c
37770 +++ b/drivers/block/cciss.c
37771 @@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37772 while (!list_empty(&h->reqQ)) {
37773 c = list_entry(h->reqQ.next, CommandList_struct, list);
37774 /* can't do anything if fifo is full */
37775 - if ((h->access.fifo_full(h))) {
37776 + if ((h->access->fifo_full(h))) {
37777 dev_warn(&h->pdev->dev, "fifo full\n");
37778 break;
37779 }
37780 @@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37781 h->Qdepth--;
37782
37783 /* Tell the controller execute command */
37784 - h->access.submit_command(h, c);
37785 + h->access->submit_command(h, c);
37786
37787 /* Put job onto the completed Q */
37788 addQ(&h->cmpQ, c);
37789 @@ -3444,17 +3444,17 @@ startio:
37790
37791 static inline unsigned long get_next_completion(ctlr_info_t *h)
37792 {
37793 - return h->access.command_completed(h);
37794 + return h->access->command_completed(h);
37795 }
37796
37797 static inline int interrupt_pending(ctlr_info_t *h)
37798 {
37799 - return h->access.intr_pending(h);
37800 + return h->access->intr_pending(h);
37801 }
37802
37803 static inline long interrupt_not_for_us(ctlr_info_t *h)
37804 {
37805 - return ((h->access.intr_pending(h) == 0) ||
37806 + return ((h->access->intr_pending(h) == 0) ||
37807 (h->interrupts_enabled == 0));
37808 }
37809
37810 @@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37811 u32 a;
37812
37813 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37814 - return h->access.command_completed(h);
37815 + return h->access->command_completed(h);
37816
37817 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37818 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37819 @@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37820 trans_support & CFGTBL_Trans_use_short_tags);
37821
37822 /* Change the access methods to the performant access methods */
37823 - h->access = SA5_performant_access;
37824 + h->access = &SA5_performant_access;
37825 h->transMethod = CFGTBL_Trans_Performant;
37826
37827 return;
37828 @@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37829 if (prod_index < 0)
37830 return -ENODEV;
37831 h->product_name = products[prod_index].product_name;
37832 - h->access = *(products[prod_index].access);
37833 + h->access = products[prod_index].access;
37834
37835 if (cciss_board_disabled(h)) {
37836 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37837 @@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37838 }
37839
37840 /* make sure the board interrupts are off */
37841 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37842 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37843 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37844 if (rc)
37845 goto clean2;
37846 @@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37847 * fake ones to scoop up any residual completions.
37848 */
37849 spin_lock_irqsave(&h->lock, flags);
37850 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37851 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37852 spin_unlock_irqrestore(&h->lock, flags);
37853 free_irq(h->intr[h->intr_mode], h);
37854 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37855 @@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37856 dev_info(&h->pdev->dev, "Board READY.\n");
37857 dev_info(&h->pdev->dev,
37858 "Waiting for stale completions to drain.\n");
37859 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37860 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37861 msleep(10000);
37862 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37863 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37864
37865 rc = controller_reset_failed(h->cfgtable);
37866 if (rc)
37867 @@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37868 cciss_scsi_setup(h);
37869
37870 /* Turn the interrupts on so we can service requests */
37871 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37872 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37873
37874 /* Get the firmware version */
37875 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37876 @@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37877 kfree(flush_buf);
37878 if (return_code != IO_OK)
37879 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37880 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37881 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37882 free_irq(h->intr[h->intr_mode], h);
37883 }
37884
37885 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37886 index 7fda30e..2f27946 100644
37887 --- a/drivers/block/cciss.h
37888 +++ b/drivers/block/cciss.h
37889 @@ -101,7 +101,7 @@ struct ctlr_info
37890 /* information about each logical volume */
37891 drive_info_struct *drv[CISS_MAX_LUN];
37892
37893 - struct access_method access;
37894 + struct access_method *access;
37895
37896 /* queue and queue Info */
37897 struct list_head reqQ;
37898 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37899 }
37900
37901 static struct access_method SA5_access = {
37902 - SA5_submit_command,
37903 - SA5_intr_mask,
37904 - SA5_fifo_full,
37905 - SA5_intr_pending,
37906 - SA5_completed,
37907 + .submit_command = SA5_submit_command,
37908 + .set_intr_mask = SA5_intr_mask,
37909 + .fifo_full = SA5_fifo_full,
37910 + .intr_pending = SA5_intr_pending,
37911 + .command_completed = SA5_completed,
37912 };
37913
37914 static struct access_method SA5B_access = {
37915 - SA5_submit_command,
37916 - SA5B_intr_mask,
37917 - SA5_fifo_full,
37918 - SA5B_intr_pending,
37919 - SA5_completed,
37920 + .submit_command = SA5_submit_command,
37921 + .set_intr_mask = SA5B_intr_mask,
37922 + .fifo_full = SA5_fifo_full,
37923 + .intr_pending = SA5B_intr_pending,
37924 + .command_completed = SA5_completed,
37925 };
37926
37927 static struct access_method SA5_performant_access = {
37928 - SA5_submit_command,
37929 - SA5_performant_intr_mask,
37930 - SA5_fifo_full,
37931 - SA5_performant_intr_pending,
37932 - SA5_performant_completed,
37933 + .submit_command = SA5_submit_command,
37934 + .set_intr_mask = SA5_performant_intr_mask,
37935 + .fifo_full = SA5_fifo_full,
37936 + .intr_pending = SA5_performant_intr_pending,
37937 + .command_completed = SA5_performant_completed,
37938 };
37939
37940 struct board_type {
37941 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37942 index 2b94403..fd6ad1f 100644
37943 --- a/drivers/block/cpqarray.c
37944 +++ b/drivers/block/cpqarray.c
37945 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37946 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37947 goto Enomem4;
37948 }
37949 - hba[i]->access.set_intr_mask(hba[i], 0);
37950 + hba[i]->access->set_intr_mask(hba[i], 0);
37951 if (request_irq(hba[i]->intr, do_ida_intr,
37952 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37953 {
37954 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37955 add_timer(&hba[i]->timer);
37956
37957 /* Enable IRQ now that spinlock and rate limit timer are set up */
37958 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37959 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37960
37961 for(j=0; j<NWD; j++) {
37962 struct gendisk *disk = ida_gendisk[i][j];
37963 @@ -694,7 +694,7 @@ DBGINFO(
37964 for(i=0; i<NR_PRODUCTS; i++) {
37965 if (board_id == products[i].board_id) {
37966 c->product_name = products[i].product_name;
37967 - c->access = *(products[i].access);
37968 + c->access = products[i].access;
37969 break;
37970 }
37971 }
37972 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37973 hba[ctlr]->intr = intr;
37974 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37975 hba[ctlr]->product_name = products[j].product_name;
37976 - hba[ctlr]->access = *(products[j].access);
37977 + hba[ctlr]->access = products[j].access;
37978 hba[ctlr]->ctlr = ctlr;
37979 hba[ctlr]->board_id = board_id;
37980 hba[ctlr]->pci_dev = NULL; /* not PCI */
37981 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37982
37983 while((c = h->reqQ) != NULL) {
37984 /* Can't do anything if we're busy */
37985 - if (h->access.fifo_full(h) == 0)
37986 + if (h->access->fifo_full(h) == 0)
37987 return;
37988
37989 /* Get the first entry from the request Q */
37990 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37991 h->Qdepth--;
37992
37993 /* Tell the controller to do our bidding */
37994 - h->access.submit_command(h, c);
37995 + h->access->submit_command(h, c);
37996
37997 /* Get onto the completion Q */
37998 addQ(&h->cmpQ, c);
37999 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38000 unsigned long flags;
38001 __u32 a,a1;
38002
38003 - istat = h->access.intr_pending(h);
38004 + istat = h->access->intr_pending(h);
38005 /* Is this interrupt for us? */
38006 if (istat == 0)
38007 return IRQ_NONE;
38008 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38009 */
38010 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38011 if (istat & FIFO_NOT_EMPTY) {
38012 - while((a = h->access.command_completed(h))) {
38013 + while((a = h->access->command_completed(h))) {
38014 a1 = a; a &= ~3;
38015 if ((c = h->cmpQ) == NULL)
38016 {
38017 @@ -1448,11 +1448,11 @@ static int sendcmd(
38018 /*
38019 * Disable interrupt
38020 */
38021 - info_p->access.set_intr_mask(info_p, 0);
38022 + info_p->access->set_intr_mask(info_p, 0);
38023 /* Make sure there is room in the command FIFO */
38024 /* Actually it should be completely empty at this time. */
38025 for (i = 200000; i > 0; i--) {
38026 - temp = info_p->access.fifo_full(info_p);
38027 + temp = info_p->access->fifo_full(info_p);
38028 if (temp != 0) {
38029 break;
38030 }
38031 @@ -1465,7 +1465,7 @@ DBG(
38032 /*
38033 * Send the cmd
38034 */
38035 - info_p->access.submit_command(info_p, c);
38036 + info_p->access->submit_command(info_p, c);
38037 complete = pollcomplete(ctlr);
38038
38039 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38040 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38041 * we check the new geometry. Then turn interrupts back on when
38042 * we're done.
38043 */
38044 - host->access.set_intr_mask(host, 0);
38045 + host->access->set_intr_mask(host, 0);
38046 getgeometry(ctlr);
38047 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38048 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38049
38050 for(i=0; i<NWD; i++) {
38051 struct gendisk *disk = ida_gendisk[ctlr][i];
38052 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38053 /* Wait (up to 2 seconds) for a command to complete */
38054
38055 for (i = 200000; i > 0; i--) {
38056 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38057 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38058 if (done == 0) {
38059 udelay(10); /* a short fixed delay */
38060 } else
38061 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38062 index be73e9d..7fbf140 100644
38063 --- a/drivers/block/cpqarray.h
38064 +++ b/drivers/block/cpqarray.h
38065 @@ -99,7 +99,7 @@ struct ctlr_info {
38066 drv_info_t drv[NWD];
38067 struct proc_dir_entry *proc;
38068
38069 - struct access_method access;
38070 + struct access_method *access;
38071
38072 cmdlist_t *reqQ;
38073 cmdlist_t *cmpQ;
38074 diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38075 index 434c77d..6d3219a 100644
38076 --- a/drivers/block/drbd/drbd_bitmap.c
38077 +++ b/drivers/block/drbd/drbd_bitmap.c
38078 @@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38079 submit_bio(rw, bio);
38080 /* this should not count as user activity and cause the
38081 * resync to throttle -- see drbd_rs_should_slow_down(). */
38082 - atomic_add(len >> 9, &device->rs_sect_ev);
38083 + atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38084 }
38085 }
38086
38087 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38088 index 9b22f8f..f2932af 100644
38089 --- a/drivers/block/drbd/drbd_int.h
38090 +++ b/drivers/block/drbd/drbd_int.h
38091 @@ -385,7 +385,7 @@ struct drbd_epoch {
38092 struct drbd_connection *connection;
38093 struct list_head list;
38094 unsigned int barrier_nr;
38095 - atomic_t epoch_size; /* increased on every request added. */
38096 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38097 atomic_t active; /* increased on every req. added, and dec on every finished. */
38098 unsigned long flags;
38099 };
38100 @@ -946,7 +946,7 @@ struct drbd_device {
38101 unsigned int al_tr_number;
38102 int al_tr_cycle;
38103 wait_queue_head_t seq_wait;
38104 - atomic_t packet_seq;
38105 + atomic_unchecked_t packet_seq;
38106 unsigned int peer_seq;
38107 spinlock_t peer_seq_lock;
38108 unsigned long comm_bm_set; /* communicated number of set bits. */
38109 @@ -955,8 +955,8 @@ struct drbd_device {
38110 struct mutex own_state_mutex;
38111 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38112 char congestion_reason; /* Why we where congested... */
38113 - atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38114 - atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38115 + atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38116 + atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38117 int rs_last_sect_ev; /* counter to compare with */
38118 int rs_last_events; /* counter of read or write "events" (unit sectors)
38119 * on the lower level device when we last looked. */
38120 @@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38121 char __user *uoptval;
38122 int err;
38123
38124 - uoptval = (char __user __force *)optval;
38125 + uoptval = (char __force_user *)optval;
38126
38127 set_fs(KERNEL_DS);
38128 if (level == SOL_SOCKET)
38129 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38130 index 973c185..05d8b1a 100644
38131 --- a/drivers/block/drbd/drbd_main.c
38132 +++ b/drivers/block/drbd/drbd_main.c
38133 @@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38134 p->sector = sector;
38135 p->block_id = block_id;
38136 p->blksize = blksize;
38137 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38138 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38139 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38140 }
38141
38142 @@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38143 return -EIO;
38144 p->sector = cpu_to_be64(req->i.sector);
38145 p->block_id = (unsigned long)req;
38146 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38147 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38148 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38149 if (device->state.conn >= C_SYNC_SOURCE &&
38150 device->state.conn <= C_PAUSED_SYNC_T)
38151 @@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38152 atomic_set(&device->unacked_cnt, 0);
38153 atomic_set(&device->local_cnt, 0);
38154 atomic_set(&device->pp_in_use_by_net, 0);
38155 - atomic_set(&device->rs_sect_in, 0);
38156 - atomic_set(&device->rs_sect_ev, 0);
38157 + atomic_set_unchecked(&device->rs_sect_in, 0);
38158 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38159 atomic_set(&device->ap_in_flight, 0);
38160 atomic_set(&device->md_io.in_use, 0);
38161
38162 @@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38163 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38164 struct drbd_resource *resource = connection->resource;
38165
38166 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38167 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38168 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38169 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38170 kfree(connection->current_epoch);
38171
38172 idr_destroy(&connection->peer_devices);
38173 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38174 index 1cd47df..57c53c0 100644
38175 --- a/drivers/block/drbd/drbd_nl.c
38176 +++ b/drivers/block/drbd/drbd_nl.c
38177 @@ -3645,13 +3645,13 @@ finish:
38178
38179 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38180 {
38181 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38182 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38183 struct sk_buff *msg;
38184 struct drbd_genlmsghdr *d_out;
38185 unsigned seq;
38186 int err = -ENOMEM;
38187
38188 - seq = atomic_inc_return(&drbd_genl_seq);
38189 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38190 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38191 if (!msg)
38192 goto failed;
38193 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38194 index 6960fb0..215d76b 100644
38195 --- a/drivers/block/drbd/drbd_receiver.c
38196 +++ b/drivers/block/drbd/drbd_receiver.c
38197 @@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38198 struct drbd_device *device = peer_device->device;
38199 int err;
38200
38201 - atomic_set(&device->packet_seq, 0);
38202 + atomic_set_unchecked(&device->packet_seq, 0);
38203 device->peer_seq = 0;
38204
38205 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38206 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38207 do {
38208 next_epoch = NULL;
38209
38210 - epoch_size = atomic_read(&epoch->epoch_size);
38211 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38212
38213 switch (ev & ~EV_CLEANUP) {
38214 case EV_PUT:
38215 @@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38216 rv = FE_DESTROYED;
38217 } else {
38218 epoch->flags = 0;
38219 - atomic_set(&epoch->epoch_size, 0);
38220 + atomic_set_unchecked(&epoch->epoch_size, 0);
38221 /* atomic_set(&epoch->active, 0); is already zero */
38222 if (rv == FE_STILL_LIVE)
38223 rv = FE_RECYCLED;
38224 @@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38225 conn_wait_active_ee_empty(connection);
38226 drbd_flush(connection);
38227
38228 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38229 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38230 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38231 if (epoch)
38232 break;
38233 @@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38234 }
38235
38236 epoch->flags = 0;
38237 - atomic_set(&epoch->epoch_size, 0);
38238 + atomic_set_unchecked(&epoch->epoch_size, 0);
38239 atomic_set(&epoch->active, 0);
38240
38241 spin_lock(&connection->epoch_lock);
38242 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38243 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38244 list_add(&epoch->list, &connection->current_epoch->list);
38245 connection->current_epoch = epoch;
38246 connection->epochs++;
38247 @@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38248 list_add_tail(&peer_req->w.list, &device->sync_ee);
38249 spin_unlock_irq(&device->resource->req_lock);
38250
38251 - atomic_add(pi->size >> 9, &device->rs_sect_ev);
38252 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38253 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38254 return 0;
38255
38256 @@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38257 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38258 }
38259
38260 - atomic_add(pi->size >> 9, &device->rs_sect_in);
38261 + atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38262
38263 return err;
38264 }
38265 @@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38266
38267 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38268 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38269 - atomic_inc(&connection->current_epoch->epoch_size);
38270 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38271 err2 = drbd_drain_block(peer_device, pi->size);
38272 if (!err)
38273 err = err2;
38274 @@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38275
38276 spin_lock(&connection->epoch_lock);
38277 peer_req->epoch = connection->current_epoch;
38278 - atomic_inc(&peer_req->epoch->epoch_size);
38279 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38280 atomic_inc(&peer_req->epoch->active);
38281 spin_unlock(&connection->epoch_lock);
38282
38283 @@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38284
38285 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38286 (int)part_stat_read(&disk->part0, sectors[1]) -
38287 - atomic_read(&device->rs_sect_ev);
38288 + atomic_read_unchecked(&device->rs_sect_ev);
38289
38290 if (atomic_read(&device->ap_actlog_cnt)
38291 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38292 @@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38293 device->use_csums = true;
38294 } else if (pi->cmd == P_OV_REPLY) {
38295 /* track progress, we may need to throttle */
38296 - atomic_add(size >> 9, &device->rs_sect_in);
38297 + atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38298 peer_req->w.cb = w_e_end_ov_reply;
38299 dec_rs_pending(device);
38300 /* drbd_rs_begin_io done when we sent this request,
38301 @@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38302 goto out_free_e;
38303
38304 submit_for_resync:
38305 - atomic_add(size >> 9, &device->rs_sect_ev);
38306 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38307
38308 submit:
38309 update_receiver_timing_details(connection, drbd_submit_peer_request);
38310 @@ -4564,7 +4564,7 @@ struct data_cmd {
38311 int expect_payload;
38312 size_t pkt_size;
38313 int (*fn)(struct drbd_connection *, struct packet_info *);
38314 -};
38315 +} __do_const;
38316
38317 static struct data_cmd drbd_cmd_handler[] = {
38318 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38319 @@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38320 if (!list_empty(&connection->current_epoch->list))
38321 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38322 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38323 - atomic_set(&connection->current_epoch->epoch_size, 0);
38324 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38325 connection->send.seen_any_write_yet = false;
38326
38327 drbd_info(connection, "Connection closed\n");
38328 @@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38329 put_ldev(device);
38330 }
38331 dec_rs_pending(device);
38332 - atomic_add(blksize >> 9, &device->rs_sect_in);
38333 + atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38334
38335 return 0;
38336 }
38337 @@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38338 struct asender_cmd {
38339 size_t pkt_size;
38340 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38341 -};
38342 +} __do_const;
38343
38344 static struct asender_cmd asender_tbl[] = {
38345 [P_PING] = { 0, got_Ping },
38346 diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38347 index d2d1f97..6a1188f 100644
38348 --- a/drivers/block/drbd/drbd_worker.c
38349 +++ b/drivers/block/drbd/drbd_worker.c
38350 @@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38351 list_add_tail(&peer_req->w.list, &device->read_ee);
38352 spin_unlock_irq(&device->resource->req_lock);
38353
38354 - atomic_add(size >> 9, &device->rs_sect_ev);
38355 + atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38356 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38357 return 0;
38358
38359 @@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38360 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38361 int number, mxb;
38362
38363 - sect_in = atomic_xchg(&device->rs_sect_in, 0);
38364 + sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38365 device->rs_in_flight -= sect_in;
38366
38367 rcu_read_lock();
38368 @@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38369 {
38370 struct fifo_buffer *plan;
38371
38372 - atomic_set(&device->rs_sect_in, 0);
38373 - atomic_set(&device->rs_sect_ev, 0);
38374 + atomic_set_unchecked(&device->rs_sect_in, 0);
38375 + atomic_set_unchecked(&device->rs_sect_ev, 0);
38376 device->rs_in_flight = 0;
38377
38378 /* Updating the RCU protected object in place is necessary since
38379 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38380 index 6cb1beb..bf490f7 100644
38381 --- a/drivers/block/loop.c
38382 +++ b/drivers/block/loop.c
38383 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38384
38385 file_start_write(file);
38386 set_fs(get_ds());
38387 - bw = file->f_op->write(file, buf, len, &pos);
38388 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38389 set_fs(old_fs);
38390 file_end_write(file);
38391 if (likely(bw == len))
38392 diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38393 index e2bb8af..44b8aef 100644
38394 --- a/drivers/block/nvme-core.c
38395 +++ b/drivers/block/nvme-core.c
38396 @@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38397 static struct task_struct *nvme_thread;
38398 static struct workqueue_struct *nvme_workq;
38399 static wait_queue_head_t nvme_kthread_wait;
38400 -static struct notifier_block nvme_nb;
38401
38402 static void nvme_reset_failed_dev(struct work_struct *ws);
38403
38404 @@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38405 .err_handler = &nvme_err_handler,
38406 };
38407
38408 +static struct notifier_block nvme_nb = {
38409 + .notifier_call = &nvme_cpu_notify,
38410 +};
38411 +
38412 static int __init nvme_init(void)
38413 {
38414 int result;
38415 @@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38416 else if (result > 0)
38417 nvme_major = result;
38418
38419 - nvme_nb.notifier_call = &nvme_cpu_notify;
38420 result = register_hotcpu_notifier(&nvme_nb);
38421 if (result)
38422 goto unregister_blkdev;
38423 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38424 index 09e628da..7607aaa 100644
38425 --- a/drivers/block/pktcdvd.c
38426 +++ b/drivers/block/pktcdvd.c
38427 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38428
38429 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38430 {
38431 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38432 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38433 }
38434
38435 /*
38436 @@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38437 return -EROFS;
38438 }
38439 pd->settings.fp = ti.fp;
38440 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38441 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38442
38443 if (ti.nwa_v) {
38444 pd->nwa = be32_to_cpu(ti.next_writable);
38445 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38446 index e5565fb..71be10b4 100644
38447 --- a/drivers/block/smart1,2.h
38448 +++ b/drivers/block/smart1,2.h
38449 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38450 }
38451
38452 static struct access_method smart4_access = {
38453 - smart4_submit_command,
38454 - smart4_intr_mask,
38455 - smart4_fifo_full,
38456 - smart4_intr_pending,
38457 - smart4_completed,
38458 + .submit_command = smart4_submit_command,
38459 + .set_intr_mask = smart4_intr_mask,
38460 + .fifo_full = smart4_fifo_full,
38461 + .intr_pending = smart4_intr_pending,
38462 + .command_completed = smart4_completed,
38463 };
38464
38465 /*
38466 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38467 }
38468
38469 static struct access_method smart2_access = {
38470 - smart2_submit_command,
38471 - smart2_intr_mask,
38472 - smart2_fifo_full,
38473 - smart2_intr_pending,
38474 - smart2_completed,
38475 + .submit_command = smart2_submit_command,
38476 + .set_intr_mask = smart2_intr_mask,
38477 + .fifo_full = smart2_fifo_full,
38478 + .intr_pending = smart2_intr_pending,
38479 + .command_completed = smart2_completed,
38480 };
38481
38482 /*
38483 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38484 }
38485
38486 static struct access_method smart2e_access = {
38487 - smart2e_submit_command,
38488 - smart2e_intr_mask,
38489 - smart2e_fifo_full,
38490 - smart2e_intr_pending,
38491 - smart2e_completed,
38492 + .submit_command = smart2e_submit_command,
38493 + .set_intr_mask = smart2e_intr_mask,
38494 + .fifo_full = smart2e_fifo_full,
38495 + .intr_pending = smart2e_intr_pending,
38496 + .command_completed = smart2e_completed,
38497 };
38498
38499 /*
38500 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38501 }
38502
38503 static struct access_method smart1_access = {
38504 - smart1_submit_command,
38505 - smart1_intr_mask,
38506 - smart1_fifo_full,
38507 - smart1_intr_pending,
38508 - smart1_completed,
38509 + .submit_command = smart1_submit_command,
38510 + .set_intr_mask = smart1_intr_mask,
38511 + .fifo_full = smart1_fifo_full,
38512 + .intr_pending = smart1_intr_pending,
38513 + .command_completed = smart1_completed,
38514 };
38515 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38516 index f038dba..bb74c08 100644
38517 --- a/drivers/bluetooth/btwilink.c
38518 +++ b/drivers/bluetooth/btwilink.c
38519 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38520
38521 static int bt_ti_probe(struct platform_device *pdev)
38522 {
38523 - static struct ti_st *hst;
38524 + struct ti_st *hst;
38525 struct hci_dev *hdev;
38526 int err;
38527
38528 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38529 index 5d28a45..a538f90 100644
38530 --- a/drivers/cdrom/cdrom.c
38531 +++ b/drivers/cdrom/cdrom.c
38532 @@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38533 ENSURE(reset, CDC_RESET);
38534 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38535 cdi->mc_flags = 0;
38536 - cdo->n_minors = 0;
38537 cdi->options = CDO_USE_FFLAGS;
38538
38539 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38540 @@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38541 else
38542 cdi->cdda_method = CDDA_OLD;
38543
38544 - if (!cdo->generic_packet)
38545 - cdo->generic_packet = cdrom_dummy_generic_packet;
38546 + if (!cdo->generic_packet) {
38547 + pax_open_kernel();
38548 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38549 + pax_close_kernel();
38550 + }
38551
38552 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38553 mutex_lock(&cdrom_mutex);
38554 @@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38555 if (cdi->exit)
38556 cdi->exit(cdi);
38557
38558 - cdi->ops->n_minors--;
38559 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38560 }
38561
38562 @@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38563 */
38564 nr = nframes;
38565 do {
38566 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38567 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38568 if (cgc.buffer)
38569 break;
38570
38571 @@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38572 struct cdrom_device_info *cdi;
38573 int ret;
38574
38575 - ret = scnprintf(info + *pos, max_size - *pos, header);
38576 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38577 if (!ret)
38578 return 1;
38579
38580 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38581 index 584bc31..e64a12c 100644
38582 --- a/drivers/cdrom/gdrom.c
38583 +++ b/drivers/cdrom/gdrom.c
38584 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38585 .audio_ioctl = gdrom_audio_ioctl,
38586 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38587 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38588 - .n_minors = 1,
38589 };
38590
38591 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38592 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38593 index efefd12..4f1d494 100644
38594 --- a/drivers/char/Kconfig
38595 +++ b/drivers/char/Kconfig
38596 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38597
38598 config DEVKMEM
38599 bool "/dev/kmem virtual device support"
38600 - default y
38601 + default n
38602 + depends on !GRKERNSEC_KMEM
38603 help
38604 Say Y here if you want to support the /dev/kmem device. The
38605 /dev/kmem device is rarely used, but can be used for certain
38606 @@ -577,6 +578,7 @@ config DEVPORT
38607 bool
38608 depends on !M68K
38609 depends on ISA || PCI
38610 + depends on !GRKERNSEC_KMEM
38611 default y
38612
38613 source "drivers/s390/char/Kconfig"
38614 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38615 index a48e05b..6bac831 100644
38616 --- a/drivers/char/agp/compat_ioctl.c
38617 +++ b/drivers/char/agp/compat_ioctl.c
38618 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38619 return -ENOMEM;
38620 }
38621
38622 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38623 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38624 sizeof(*usegment) * ureserve.seg_count)) {
38625 kfree(usegment);
38626 kfree(ksegment);
38627 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38628 index 09f17eb..8531d2f 100644
38629 --- a/drivers/char/agp/frontend.c
38630 +++ b/drivers/char/agp/frontend.c
38631 @@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38632 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38633 return -EFAULT;
38634
38635 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38636 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38637 return -EFAULT;
38638
38639 client = agp_find_client_by_pid(reserve.pid);
38640 @@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38641 if (segment == NULL)
38642 return -ENOMEM;
38643
38644 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38645 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38646 sizeof(struct agp_segment) * reserve.seg_count)) {
38647 kfree(segment);
38648 return -EFAULT;
38649 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38650 index 4f94375..413694e 100644
38651 --- a/drivers/char/genrtc.c
38652 +++ b/drivers/char/genrtc.c
38653 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38654 switch (cmd) {
38655
38656 case RTC_PLL_GET:
38657 + memset(&pll, 0, sizeof(pll));
38658 if (get_rtc_pll(&pll))
38659 return -EINVAL;
38660 else
38661 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38662 index d5d4cd8..22d561d 100644
38663 --- a/drivers/char/hpet.c
38664 +++ b/drivers/char/hpet.c
38665 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38666 }
38667
38668 static int
38669 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38670 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38671 struct hpet_info *info)
38672 {
38673 struct hpet_timer __iomem *timer;
38674 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38675 index f816211..89eadea 100644
38676 --- a/drivers/char/ipmi/ipmi_msghandler.c
38677 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38678 @@ -438,7 +438,7 @@ struct ipmi_smi {
38679 struct proc_dir_entry *proc_dir;
38680 char proc_dir_name[10];
38681
38682 - atomic_t stats[IPMI_NUM_STATS];
38683 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38684
38685 /*
38686 * run_to_completion duplicate of smb_info, smi_info
38687 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38688 static DEFINE_MUTEX(smi_watchers_mutex);
38689
38690 #define ipmi_inc_stat(intf, stat) \
38691 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38692 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38693 #define ipmi_get_stat(intf, stat) \
38694 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38695 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38696
38697 static int is_lan_addr(struct ipmi_addr *addr)
38698 {
38699 @@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38700 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38701 init_waitqueue_head(&intf->waitq);
38702 for (i = 0; i < IPMI_NUM_STATS; i++)
38703 - atomic_set(&intf->stats[i], 0);
38704 + atomic_set_unchecked(&intf->stats[i], 0);
38705
38706 intf->proc_dir = NULL;
38707
38708 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38709 index 5c4e1f6..0ea58f9 100644
38710 --- a/drivers/char/ipmi/ipmi_si_intf.c
38711 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38712 @@ -285,7 +285,7 @@ struct smi_info {
38713 unsigned char slave_addr;
38714
38715 /* Counters and things for the proc filesystem. */
38716 - atomic_t stats[SI_NUM_STATS];
38717 + atomic_unchecked_t stats[SI_NUM_STATS];
38718
38719 struct task_struct *thread;
38720
38721 @@ -294,9 +294,9 @@ struct smi_info {
38722 };
38723
38724 #define smi_inc_stat(smi, stat) \
38725 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38726 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38727 #define smi_get_stat(smi, stat) \
38728 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38729 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38730
38731 #define SI_MAX_PARMS 4
38732
38733 @@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38734 atomic_set(&new_smi->req_events, 0);
38735 new_smi->run_to_completion = false;
38736 for (i = 0; i < SI_NUM_STATS; i++)
38737 - atomic_set(&new_smi->stats[i], 0);
38738 + atomic_set_unchecked(&new_smi->stats[i], 0);
38739
38740 new_smi->interrupt_disabled = true;
38741 atomic_set(&new_smi->stop_operation, 0);
38742 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38743 index 524b707..62a3d70 100644
38744 --- a/drivers/char/mem.c
38745 +++ b/drivers/char/mem.c
38746 @@ -18,6 +18,7 @@
38747 #include <linux/raw.h>
38748 #include <linux/tty.h>
38749 #include <linux/capability.h>
38750 +#include <linux/security.h>
38751 #include <linux/ptrace.h>
38752 #include <linux/device.h>
38753 #include <linux/highmem.h>
38754 @@ -36,6 +37,10 @@
38755
38756 #define DEVPORT_MINOR 4
38757
38758 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38759 +extern const struct file_operations grsec_fops;
38760 +#endif
38761 +
38762 static inline unsigned long size_inside_page(unsigned long start,
38763 unsigned long size)
38764 {
38765 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38766
38767 while (cursor < to) {
38768 if (!devmem_is_allowed(pfn)) {
38769 +#ifdef CONFIG_GRKERNSEC_KMEM
38770 + gr_handle_mem_readwrite(from, to);
38771 +#else
38772 printk(KERN_INFO
38773 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38774 current->comm, from, to);
38775 +#endif
38776 return 0;
38777 }
38778 cursor += PAGE_SIZE;
38779 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38780 }
38781 return 1;
38782 }
38783 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38784 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38785 +{
38786 + return 0;
38787 +}
38788 #else
38789 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38790 {
38791 @@ -121,7 +135,8 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38792 #endif
38793
38794 while (count > 0) {
38795 - unsigned long remaining;
38796 + unsigned long remaining = 0;
38797 + char *temp;
38798
38799 sz = size_inside_page(p, count);
38800
38801 @@ -137,7 +152,24 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38802 if (!ptr)
38803 return -EFAULT;
38804
38805 - remaining = copy_to_user(buf, ptr, sz);
38806 +#ifdef CONFIG_PAX_USERCOPY
38807 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38808 + if (!temp) {
38809 + unxlate_dev_mem_ptr(p, ptr);
38810 + return -ENOMEM;
38811 + }
38812 + remaining = probe_kernel_read(temp, ptr, sz);
38813 +#else
38814 + temp = ptr;
38815 +#endif
38816 +
38817 + if (!remaining)
38818 + remaining = copy_to_user(buf, temp, sz);
38819 +
38820 +#ifdef CONFIG_PAX_USERCOPY
38821 + kfree(temp);
38822 +#endif
38823 +
38824 unxlate_dev_mem_ptr(p, ptr);
38825 if (remaining)
38826 return -EFAULT;
38827 @@ -369,9 +401,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38828 size_t count, loff_t *ppos)
38829 {
38830 unsigned long p = *ppos;
38831 - ssize_t low_count, read, sz;
38832 + ssize_t low_count, read, sz, err = 0;
38833 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38834 - int err = 0;
38835
38836 read = 0;
38837 if (p < (unsigned long) high_memory) {
38838 @@ -393,6 +424,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38839 }
38840 #endif
38841 while (low_count > 0) {
38842 + char *temp;
38843 +
38844 sz = size_inside_page(p, low_count);
38845
38846 /*
38847 @@ -402,7 +435,23 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38848 */
38849 kbuf = xlate_dev_kmem_ptr((char *)p);
38850
38851 - if (copy_to_user(buf, kbuf, sz))
38852 +#ifdef CONFIG_PAX_USERCOPY
38853 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38854 + if (!temp)
38855 + return -ENOMEM;
38856 + err = probe_kernel_read(temp, kbuf, sz);
38857 +#else
38858 + temp = kbuf;
38859 +#endif
38860 +
38861 + if (!err)
38862 + err = copy_to_user(buf, temp, sz);
38863 +
38864 +#ifdef CONFIG_PAX_USERCOPY
38865 + kfree(temp);
38866 +#endif
38867 +
38868 + if (err)
38869 return -EFAULT;
38870 buf += sz;
38871 p += sz;
38872 @@ -797,6 +846,9 @@ static const struct memdev {
38873 #ifdef CONFIG_PRINTK
38874 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38875 #endif
38876 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38877 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38878 +#endif
38879 };
38880
38881 static int memory_open(struct inode *inode, struct file *filp)
38882 @@ -868,7 +920,7 @@ static int __init chr_dev_init(void)
38883 continue;
38884
38885 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38886 - NULL, devlist[minor].name);
38887 + NULL, "%s", devlist[minor].name);
38888 }
38889
38890 return tty_init();
38891 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38892 index 9df78e2..01ba9ae 100644
38893 --- a/drivers/char/nvram.c
38894 +++ b/drivers/char/nvram.c
38895 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38896
38897 spin_unlock_irq(&rtc_lock);
38898
38899 - if (copy_to_user(buf, contents, tmp - contents))
38900 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38901 return -EFAULT;
38902
38903 *ppos = i;
38904 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38905 index 0ea9986..e7b07e4 100644
38906 --- a/drivers/char/pcmcia/synclink_cs.c
38907 +++ b/drivers/char/pcmcia/synclink_cs.c
38908 @@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38909
38910 if (debug_level >= DEBUG_LEVEL_INFO)
38911 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38912 - __FILE__, __LINE__, info->device_name, port->count);
38913 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38914
38915 if (tty_port_close_start(port, tty, filp) == 0)
38916 goto cleanup;
38917 @@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38918 cleanup:
38919 if (debug_level >= DEBUG_LEVEL_INFO)
38920 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38921 - tty->driver->name, port->count);
38922 + tty->driver->name, atomic_read(&port->count));
38923 }
38924
38925 /* Wait until the transmitter is empty.
38926 @@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38927
38928 if (debug_level >= DEBUG_LEVEL_INFO)
38929 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38930 - __FILE__, __LINE__, tty->driver->name, port->count);
38931 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38932
38933 /* If port is closing, signal caller to try again */
38934 if (port->flags & ASYNC_CLOSING){
38935 @@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38936 goto cleanup;
38937 }
38938 spin_lock(&port->lock);
38939 - port->count++;
38940 + atomic_inc(&port->count);
38941 spin_unlock(&port->lock);
38942 spin_unlock_irqrestore(&info->netlock, flags);
38943
38944 - if (port->count == 1) {
38945 + if (atomic_read(&port->count) == 1) {
38946 /* 1st open on this device, init hardware */
38947 retval = startup(info, tty);
38948 if (retval < 0)
38949 @@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38950 unsigned short new_crctype;
38951
38952 /* return error if TTY interface open */
38953 - if (info->port.count)
38954 + if (atomic_read(&info->port.count))
38955 return -EBUSY;
38956
38957 switch (encoding)
38958 @@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38959
38960 /* arbitrate between network and tty opens */
38961 spin_lock_irqsave(&info->netlock, flags);
38962 - if (info->port.count != 0 || info->netcount != 0) {
38963 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38964 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38965 spin_unlock_irqrestore(&info->netlock, flags);
38966 return -EBUSY;
38967 @@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38968 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38969
38970 /* return error if TTY interface open */
38971 - if (info->port.count)
38972 + if (atomic_read(&info->port.count))
38973 return -EBUSY;
38974
38975 if (cmd != SIOCWANDEV)
38976 diff --git a/drivers/char/random.c b/drivers/char/random.c
38977 index 9cd6968..6416f00 100644
38978 --- a/drivers/char/random.c
38979 +++ b/drivers/char/random.c
38980 @@ -289,9 +289,6 @@
38981 /*
38982 * To allow fractional bits to be tracked, the entropy_count field is
38983 * denominated in units of 1/8th bits.
38984 - *
38985 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38986 - * credit_entropy_bits() needs to be 64 bits wide.
38987 */
38988 #define ENTROPY_SHIFT 3
38989 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38990 @@ -439,9 +436,9 @@ struct entropy_store {
38991 };
38992
38993 static void push_to_pool(struct work_struct *work);
38994 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38995 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38996 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38997 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38998 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38999 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39000
39001 static struct entropy_store input_pool = {
39002 .poolinfo = &poolinfo_table[0],
39003 @@ -635,7 +632,7 @@ retry:
39004 /* The +2 corresponds to the /4 in the denominator */
39005
39006 do {
39007 - unsigned int anfrac = min(pnfrac, pool_size/2);
39008 + u64 anfrac = min(pnfrac, pool_size/2);
39009 unsigned int add =
39010 ((pool_size - entropy_count)*anfrac*3) >> s;
39011
39012 @@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39013
39014 extract_buf(r, tmp);
39015 i = min_t(int, nbytes, EXTRACT_SIZE);
39016 - if (copy_to_user(buf, tmp, i)) {
39017 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39018 ret = -EFAULT;
39019 break;
39020 }
39021 @@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39022 static int proc_do_uuid(struct ctl_table *table, int write,
39023 void __user *buffer, size_t *lenp, loff_t *ppos)
39024 {
39025 - struct ctl_table fake_table;
39026 + ctl_table_no_const fake_table;
39027 unsigned char buf[64], tmp_uuid[16], *uuid;
39028
39029 uuid = table->data;
39030 @@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39031 static int proc_do_entropy(struct ctl_table *table, int write,
39032 void __user *buffer, size_t *lenp, loff_t *ppos)
39033 {
39034 - struct ctl_table fake_table;
39035 + ctl_table_no_const fake_table;
39036 int entropy_count;
39037
39038 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39039 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39040 index 7cc1fe22..b602d6b 100644
39041 --- a/drivers/char/sonypi.c
39042 +++ b/drivers/char/sonypi.c
39043 @@ -54,6 +54,7 @@
39044
39045 #include <asm/uaccess.h>
39046 #include <asm/io.h>
39047 +#include <asm/local.h>
39048
39049 #include <linux/sonypi.h>
39050
39051 @@ -490,7 +491,7 @@ static struct sonypi_device {
39052 spinlock_t fifo_lock;
39053 wait_queue_head_t fifo_proc_list;
39054 struct fasync_struct *fifo_async;
39055 - int open_count;
39056 + local_t open_count;
39057 int model;
39058 struct input_dev *input_jog_dev;
39059 struct input_dev *input_key_dev;
39060 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39061 static int sonypi_misc_release(struct inode *inode, struct file *file)
39062 {
39063 mutex_lock(&sonypi_device.lock);
39064 - sonypi_device.open_count--;
39065 + local_dec(&sonypi_device.open_count);
39066 mutex_unlock(&sonypi_device.lock);
39067 return 0;
39068 }
39069 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39070 {
39071 mutex_lock(&sonypi_device.lock);
39072 /* Flush input queue on first open */
39073 - if (!sonypi_device.open_count)
39074 + if (!local_read(&sonypi_device.open_count))
39075 kfifo_reset(&sonypi_device.fifo);
39076 - sonypi_device.open_count++;
39077 + local_inc(&sonypi_device.open_count);
39078 mutex_unlock(&sonypi_device.lock);
39079
39080 return 0;
39081 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39082 index 565a947..dcdc06e 100644
39083 --- a/drivers/char/tpm/tpm_acpi.c
39084 +++ b/drivers/char/tpm/tpm_acpi.c
39085 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39086 virt = acpi_os_map_iomem(start, len);
39087 if (!virt) {
39088 kfree(log->bios_event_log);
39089 + log->bios_event_log = NULL;
39090 printk("%s: ERROR - Unable to map memory\n", __func__);
39091 return -EIO;
39092 }
39093
39094 - memcpy_fromio(log->bios_event_log, virt, len);
39095 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39096
39097 acpi_os_unmap_iomem(virt, len);
39098 return 0;
39099 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39100 index 3a56a13..f8cbd25 100644
39101 --- a/drivers/char/tpm/tpm_eventlog.c
39102 +++ b/drivers/char/tpm/tpm_eventlog.c
39103 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39104 event = addr;
39105
39106 if ((event->event_type == 0 && event->event_size == 0) ||
39107 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39108 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39109 return NULL;
39110
39111 return addr;
39112 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39113 return NULL;
39114
39115 if ((event->event_type == 0 && event->event_size == 0) ||
39116 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39117 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39118 return NULL;
39119
39120 (*pos)++;
39121 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39122 int i;
39123
39124 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39125 - seq_putc(m, data[i]);
39126 + if (!seq_putc(m, data[i]))
39127 + return -EFAULT;
39128
39129 return 0;
39130 }
39131 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39132 index cf7a561..c319ce0 100644
39133 --- a/drivers/char/virtio_console.c
39134 +++ b/drivers/char/virtio_console.c
39135 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39136 if (to_user) {
39137 ssize_t ret;
39138
39139 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39140 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39141 if (ret)
39142 return -EFAULT;
39143 } else {
39144 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39145 if (!port_has_data(port) && !port->host_connected)
39146 return 0;
39147
39148 - return fill_readbuf(port, ubuf, count, true);
39149 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39150 }
39151
39152 static int wait_port_writable(struct port *port, bool nonblock)
39153 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39154 index b9355da..9611f4e 100644
39155 --- a/drivers/clk/clk-composite.c
39156 +++ b/drivers/clk/clk-composite.c
39157 @@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39158 struct clk *clk;
39159 struct clk_init_data init;
39160 struct clk_composite *composite;
39161 - struct clk_ops *clk_composite_ops;
39162 + clk_ops_no_const *clk_composite_ops;
39163
39164 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39165 if (!composite) {
39166 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39167 index dd3a78c..386d49c 100644
39168 --- a/drivers/clk/socfpga/clk-gate.c
39169 +++ b/drivers/clk/socfpga/clk-gate.c
39170 @@ -22,6 +22,7 @@
39171 #include <linux/mfd/syscon.h>
39172 #include <linux/of.h>
39173 #include <linux/regmap.h>
39174 +#include <asm/pgtable.h>
39175
39176 #include "clk.h"
39177
39178 @@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39179 return 0;
39180 }
39181
39182 -static struct clk_ops gateclk_ops = {
39183 +static clk_ops_no_const gateclk_ops __read_only = {
39184 .prepare = socfpga_clk_prepare,
39185 .recalc_rate = socfpga_clk_recalc_rate,
39186 .get_parent = socfpga_clk_get_parent,
39187 @@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39188 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39189 socfpga_clk->hw.bit_idx = clk_gate[1];
39190
39191 - gateclk_ops.enable = clk_gate_ops.enable;
39192 - gateclk_ops.disable = clk_gate_ops.disable;
39193 + pax_open_kernel();
39194 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39195 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39196 + pax_close_kernel();
39197 }
39198
39199 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39200 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39201 index de6da95..c98278b 100644
39202 --- a/drivers/clk/socfpga/clk-pll.c
39203 +++ b/drivers/clk/socfpga/clk-pll.c
39204 @@ -21,6 +21,7 @@
39205 #include <linux/io.h>
39206 #include <linux/of.h>
39207 #include <linux/of_address.h>
39208 +#include <asm/pgtable.h>
39209
39210 #include "clk.h"
39211
39212 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39213 CLK_MGR_PLL_CLK_SRC_MASK;
39214 }
39215
39216 -static struct clk_ops clk_pll_ops = {
39217 +static clk_ops_no_const clk_pll_ops __read_only = {
39218 .recalc_rate = clk_pll_recalc_rate,
39219 .get_parent = clk_pll_get_parent,
39220 };
39221 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39222 pll_clk->hw.hw.init = &init;
39223
39224 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39225 - clk_pll_ops.enable = clk_gate_ops.enable;
39226 - clk_pll_ops.disable = clk_gate_ops.disable;
39227 + pax_open_kernel();
39228 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39229 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39230 + pax_close_kernel();
39231
39232 clk = clk_register(NULL, &pll_clk->hw.hw);
39233 if (WARN_ON(IS_ERR(clk))) {
39234 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39235 index b0c18ed..1713a80 100644
39236 --- a/drivers/cpufreq/acpi-cpufreq.c
39237 +++ b/drivers/cpufreq/acpi-cpufreq.c
39238 @@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39239 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39240 per_cpu(acfreq_data, cpu) = data;
39241
39242 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39243 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39244 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39245 + pax_open_kernel();
39246 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39247 + pax_close_kernel();
39248 + }
39249
39250 result = acpi_processor_register_performance(data->acpi_data, cpu);
39251 if (result)
39252 @@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39253 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39254 break;
39255 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39256 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39257 + pax_open_kernel();
39258 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39259 + pax_close_kernel();
39260 break;
39261 default:
39262 break;
39263 @@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39264 if (!msrs)
39265 return;
39266
39267 - acpi_cpufreq_driver.boost_supported = true;
39268 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39269 + pax_open_kernel();
39270 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39271 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39272 + pax_close_kernel();
39273
39274 cpu_notifier_register_begin();
39275
39276 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39277 index f657c57..31d97ae 100644
39278 --- a/drivers/cpufreq/cpufreq-dt.c
39279 +++ b/drivers/cpufreq/cpufreq-dt.c
39280 @@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39281 if (!IS_ERR(cpu_reg))
39282 regulator_put(cpu_reg);
39283
39284 - dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39285 + pax_open_kernel();
39286 + *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39287 + pax_close_kernel();
39288
39289 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39290 if (ret)
39291 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39292 index e3bf702..4dbf06c 100644
39293 --- a/drivers/cpufreq/cpufreq.c
39294 +++ b/drivers/cpufreq/cpufreq.c
39295 @@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39296 }
39297
39298 mutex_lock(&cpufreq_governor_mutex);
39299 - list_del(&governor->governor_list);
39300 + pax_list_del(&governor->governor_list);
39301 mutex_unlock(&cpufreq_governor_mutex);
39302 return;
39303 }
39304 @@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39305 return NOTIFY_OK;
39306 }
39307
39308 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39309 +static struct notifier_block cpufreq_cpu_notifier = {
39310 .notifier_call = cpufreq_cpu_callback,
39311 };
39312
39313 @@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39314 return 0;
39315
39316 write_lock_irqsave(&cpufreq_driver_lock, flags);
39317 - cpufreq_driver->boost_enabled = state;
39318 + pax_open_kernel();
39319 + *(bool *)&cpufreq_driver->boost_enabled = state;
39320 + pax_close_kernel();
39321 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39322
39323 ret = cpufreq_driver->set_boost(state);
39324 if (ret) {
39325 write_lock_irqsave(&cpufreq_driver_lock, flags);
39326 - cpufreq_driver->boost_enabled = !state;
39327 + pax_open_kernel();
39328 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39329 + pax_close_kernel();
39330 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39331
39332 pr_err("%s: Cannot %s BOOST\n",
39333 @@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39334
39335 pr_debug("trying to register driver %s\n", driver_data->name);
39336
39337 - if (driver_data->setpolicy)
39338 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39339 + if (driver_data->setpolicy) {
39340 + pax_open_kernel();
39341 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39342 + pax_close_kernel();
39343 + }
39344
39345 write_lock_irqsave(&cpufreq_driver_lock, flags);
39346 if (cpufreq_driver) {
39347 @@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39348 * Check if driver provides function to enable boost -
39349 * if not, use cpufreq_boost_set_sw as default
39350 */
39351 - if (!cpufreq_driver->set_boost)
39352 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39353 + if (!cpufreq_driver->set_boost) {
39354 + pax_open_kernel();
39355 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39356 + pax_close_kernel();
39357 + }
39358
39359 ret = cpufreq_sysfs_create_file(&boost.attr);
39360 if (ret) {
39361 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39362 index 1b44496..b80ff5e 100644
39363 --- a/drivers/cpufreq/cpufreq_governor.c
39364 +++ b/drivers/cpufreq/cpufreq_governor.c
39365 @@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39366 struct dbs_data *dbs_data;
39367 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39368 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39369 - struct od_ops *od_ops = NULL;
39370 + const struct od_ops *od_ops = NULL;
39371 struct od_dbs_tuners *od_tuners = NULL;
39372 struct cs_dbs_tuners *cs_tuners = NULL;
39373 struct cpu_dbs_common_info *cpu_cdbs;
39374 @@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39375
39376 if ((cdata->governor == GOV_CONSERVATIVE) &&
39377 (!policy->governor->initialized)) {
39378 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39379 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39380
39381 cpufreq_register_notifier(cs_ops->notifier_block,
39382 CPUFREQ_TRANSITION_NOTIFIER);
39383 @@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39384
39385 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39386 (policy->governor->initialized == 1)) {
39387 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39388 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39389
39390 cpufreq_unregister_notifier(cs_ops->notifier_block,
39391 CPUFREQ_TRANSITION_NOTIFIER);
39392 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39393 index cc401d1..8197340 100644
39394 --- a/drivers/cpufreq/cpufreq_governor.h
39395 +++ b/drivers/cpufreq/cpufreq_governor.h
39396 @@ -212,7 +212,7 @@ struct common_dbs_data {
39397 void (*exit)(struct dbs_data *dbs_data);
39398
39399 /* Governor specific ops, see below */
39400 - void *gov_ops;
39401 + const void *gov_ops;
39402 };
39403
39404 /* Governor Per policy data */
39405 @@ -232,7 +232,7 @@ struct od_ops {
39406 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39407 unsigned int freq_next, unsigned int relation);
39408 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39409 -};
39410 +} __no_const;
39411
39412 struct cs_ops {
39413 struct notifier_block *notifier_block;
39414 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39415 index ad3f38f..8f086cd 100644
39416 --- a/drivers/cpufreq/cpufreq_ondemand.c
39417 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39418 @@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39419
39420 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39421
39422 -static struct od_ops od_ops = {
39423 +static struct od_ops od_ops __read_only = {
39424 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39425 .powersave_bias_target = generic_powersave_bias_target,
39426 .freq_increase = dbs_freq_increase,
39427 @@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39428 (struct cpufreq_policy *, unsigned int, unsigned int),
39429 unsigned int powersave_bias)
39430 {
39431 - od_ops.powersave_bias_target = f;
39432 + pax_open_kernel();
39433 + *(void **)&od_ops.powersave_bias_target = f;
39434 + pax_close_kernel();
39435 od_set_powersave_bias(powersave_bias);
39436 }
39437 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39438
39439 void od_unregister_powersave_bias_handler(void)
39440 {
39441 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39442 + pax_open_kernel();
39443 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39444 + pax_close_kernel();
39445 od_set_powersave_bias(0);
39446 }
39447 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39448 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39449 index 27bb6d3..4cf595c 100644
39450 --- a/drivers/cpufreq/intel_pstate.c
39451 +++ b/drivers/cpufreq/intel_pstate.c
39452 @@ -133,10 +133,10 @@ struct pstate_funcs {
39453 struct cpu_defaults {
39454 struct pstate_adjust_policy pid_policy;
39455 struct pstate_funcs funcs;
39456 -};
39457 +} __do_const;
39458
39459 static struct pstate_adjust_policy pid_params;
39460 -static struct pstate_funcs pstate_funcs;
39461 +static struct pstate_funcs *pstate_funcs;
39462
39463 struct perf_limits {
39464 int no_turbo;
39465 @@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39466
39467 cpu->pstate.current_pstate = pstate;
39468
39469 - pstate_funcs.set(cpu, pstate);
39470 + pstate_funcs->set(cpu, pstate);
39471 }
39472
39473 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39474 {
39475 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39476 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39477 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39478 - cpu->pstate.scaling = pstate_funcs.get_scaling();
39479 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39480 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39481 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39482 + cpu->pstate.scaling = pstate_funcs->get_scaling();
39483
39484 - if (pstate_funcs.get_vid)
39485 - pstate_funcs.get_vid(cpu);
39486 + if (pstate_funcs->get_vid)
39487 + pstate_funcs->get_vid(cpu);
39488 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39489 }
39490
39491 @@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39492 rdmsrl(MSR_IA32_APERF, aperf);
39493 rdmsrl(MSR_IA32_MPERF, mperf);
39494
39495 - if (!pstate_funcs.get_max() ||
39496 - !pstate_funcs.get_min() ||
39497 - !pstate_funcs.get_turbo())
39498 + if (!pstate_funcs->get_max() ||
39499 + !pstate_funcs->get_min() ||
39500 + !pstate_funcs->get_turbo())
39501 return -ENODEV;
39502
39503 rdmsrl(MSR_IA32_APERF, tmp);
39504 @@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39505 return 0;
39506 }
39507
39508 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39509 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39510 {
39511 pid_params.sample_rate_ms = policy->sample_rate_ms;
39512 pid_params.p_gain_pct = policy->p_gain_pct;
39513 @@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39514
39515 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39516 {
39517 - pstate_funcs.get_max = funcs->get_max;
39518 - pstate_funcs.get_min = funcs->get_min;
39519 - pstate_funcs.get_turbo = funcs->get_turbo;
39520 - pstate_funcs.get_scaling = funcs->get_scaling;
39521 - pstate_funcs.set = funcs->set;
39522 - pstate_funcs.get_vid = funcs->get_vid;
39523 + pstate_funcs = funcs;
39524 }
39525
39526 #if IS_ENABLED(CONFIG_ACPI)
39527 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39528 index 529cfd9..0e28fff 100644
39529 --- a/drivers/cpufreq/p4-clockmod.c
39530 +++ b/drivers/cpufreq/p4-clockmod.c
39531 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39532 case 0x0F: /* Core Duo */
39533 case 0x16: /* Celeron Core */
39534 case 0x1C: /* Atom */
39535 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39536 + pax_open_kernel();
39537 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39538 + pax_close_kernel();
39539 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39540 case 0x0D: /* Pentium M (Dothan) */
39541 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39542 + pax_open_kernel();
39543 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39544 + pax_close_kernel();
39545 /* fall through */
39546 case 0x09: /* Pentium M (Banias) */
39547 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39548 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39549
39550 /* on P-4s, the TSC runs with constant frequency independent whether
39551 * throttling is active or not. */
39552 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39553 + pax_open_kernel();
39554 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39555 + pax_close_kernel();
39556
39557 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39558 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39559 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39560 index 9bb42ba..b01b4a2 100644
39561 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39562 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39563 @@ -18,14 +18,12 @@
39564 #include <asm/head.h>
39565 #include <asm/timer.h>
39566
39567 -static struct cpufreq_driver *cpufreq_us3_driver;
39568 -
39569 struct us3_freq_percpu_info {
39570 struct cpufreq_frequency_table table[4];
39571 };
39572
39573 /* Indexed by cpu number. */
39574 -static struct us3_freq_percpu_info *us3_freq_table;
39575 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39576
39577 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39578 * in the Safari config register.
39579 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39580
39581 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39582 {
39583 - if (cpufreq_us3_driver)
39584 - us3_freq_target(policy, 0);
39585 + us3_freq_target(policy, 0);
39586
39587 return 0;
39588 }
39589
39590 +static int __init us3_freq_init(void);
39591 +static void __exit us3_freq_exit(void);
39592 +
39593 +static struct cpufreq_driver cpufreq_us3_driver = {
39594 + .init = us3_freq_cpu_init,
39595 + .verify = cpufreq_generic_frequency_table_verify,
39596 + .target_index = us3_freq_target,
39597 + .get = us3_freq_get,
39598 + .exit = us3_freq_cpu_exit,
39599 + .name = "UltraSPARC-III",
39600 +
39601 +};
39602 +
39603 static int __init us3_freq_init(void)
39604 {
39605 unsigned long manuf, impl, ver;
39606 - int ret;
39607
39608 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39609 return -ENODEV;
39610 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39611 (impl == CHEETAH_IMPL ||
39612 impl == CHEETAH_PLUS_IMPL ||
39613 impl == JAGUAR_IMPL ||
39614 - impl == PANTHER_IMPL)) {
39615 - struct cpufreq_driver *driver;
39616 -
39617 - ret = -ENOMEM;
39618 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39619 - if (!driver)
39620 - goto err_out;
39621 -
39622 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39623 - GFP_KERNEL);
39624 - if (!us3_freq_table)
39625 - goto err_out;
39626 -
39627 - driver->init = us3_freq_cpu_init;
39628 - driver->verify = cpufreq_generic_frequency_table_verify;
39629 - driver->target_index = us3_freq_target;
39630 - driver->get = us3_freq_get;
39631 - driver->exit = us3_freq_cpu_exit;
39632 - strcpy(driver->name, "UltraSPARC-III");
39633 -
39634 - cpufreq_us3_driver = driver;
39635 - ret = cpufreq_register_driver(driver);
39636 - if (ret)
39637 - goto err_out;
39638 -
39639 - return 0;
39640 -
39641 -err_out:
39642 - if (driver) {
39643 - kfree(driver);
39644 - cpufreq_us3_driver = NULL;
39645 - }
39646 - kfree(us3_freq_table);
39647 - us3_freq_table = NULL;
39648 - return ret;
39649 - }
39650 + impl == PANTHER_IMPL))
39651 + return cpufreq_register_driver(&cpufreq_us3_driver);
39652
39653 return -ENODEV;
39654 }
39655
39656 static void __exit us3_freq_exit(void)
39657 {
39658 - if (cpufreq_us3_driver) {
39659 - cpufreq_unregister_driver(cpufreq_us3_driver);
39660 - kfree(cpufreq_us3_driver);
39661 - cpufreq_us3_driver = NULL;
39662 - kfree(us3_freq_table);
39663 - us3_freq_table = NULL;
39664 - }
39665 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39666 }
39667
39668 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39669 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39670 index 7d4a315..21bb886 100644
39671 --- a/drivers/cpufreq/speedstep-centrino.c
39672 +++ b/drivers/cpufreq/speedstep-centrino.c
39673 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39674 !cpu_has(cpu, X86_FEATURE_EST))
39675 return -ENODEV;
39676
39677 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39678 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39679 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39680 + pax_open_kernel();
39681 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39682 + pax_close_kernel();
39683 + }
39684
39685 if (policy->cpu != 0)
39686 return -ENODEV;
39687 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39688 index e431d11..d0b997e 100644
39689 --- a/drivers/cpuidle/driver.c
39690 +++ b/drivers/cpuidle/driver.c
39691 @@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39692
39693 static void poll_idle_init(struct cpuidle_driver *drv)
39694 {
39695 - struct cpuidle_state *state = &drv->states[0];
39696 + cpuidle_state_no_const *state = &drv->states[0];
39697
39698 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39699 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39700 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39701 index fb9f511..213e6cc 100644
39702 --- a/drivers/cpuidle/governor.c
39703 +++ b/drivers/cpuidle/governor.c
39704 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39705 mutex_lock(&cpuidle_lock);
39706 if (__cpuidle_find_governor(gov->name) == NULL) {
39707 ret = 0;
39708 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39709 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39710 if (!cpuidle_curr_governor ||
39711 cpuidle_curr_governor->rating < gov->rating)
39712 cpuidle_switch_governor(gov);
39713 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39714 index 97c5903..023ad23 100644
39715 --- a/drivers/cpuidle/sysfs.c
39716 +++ b/drivers/cpuidle/sysfs.c
39717 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39718 NULL
39719 };
39720
39721 -static struct attribute_group cpuidle_attr_group = {
39722 +static attribute_group_no_const cpuidle_attr_group = {
39723 .attrs = cpuidle_default_attrs,
39724 .name = "cpuidle",
39725 };
39726 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39727 index 8d2a772..33826c9 100644
39728 --- a/drivers/crypto/hifn_795x.c
39729 +++ b/drivers/crypto/hifn_795x.c
39730 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39731 MODULE_PARM_DESC(hifn_pll_ref,
39732 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39733
39734 -static atomic_t hifn_dev_number;
39735 +static atomic_unchecked_t hifn_dev_number;
39736
39737 #define ACRYPTO_OP_DECRYPT 0
39738 #define ACRYPTO_OP_ENCRYPT 1
39739 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39740 goto err_out_disable_pci_device;
39741
39742 snprintf(name, sizeof(name), "hifn%d",
39743 - atomic_inc_return(&hifn_dev_number)-1);
39744 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39745
39746 err = pci_request_regions(pdev, name);
39747 if (err)
39748 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39749 index 30b538d8..1610d75 100644
39750 --- a/drivers/devfreq/devfreq.c
39751 +++ b/drivers/devfreq/devfreq.c
39752 @@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39753 goto err_out;
39754 }
39755
39756 - list_add(&governor->node, &devfreq_governor_list);
39757 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39758
39759 list_for_each_entry(devfreq, &devfreq_list, node) {
39760 int ret = 0;
39761 @@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39762 }
39763 }
39764
39765 - list_del(&governor->node);
39766 + pax_list_del((struct list_head *)&governor->node);
39767 err_out:
39768 mutex_unlock(&devfreq_list_lock);
39769
39770 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39771 index 42d4974..2714f36 100644
39772 --- a/drivers/dma/sh/shdma-base.c
39773 +++ b/drivers/dma/sh/shdma-base.c
39774 @@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39775 schan->slave_id = -EINVAL;
39776 }
39777
39778 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39779 - sdev->desc_size, GFP_KERNEL);
39780 + schan->desc = kcalloc(sdev->desc_size,
39781 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39782 if (!schan->desc) {
39783 ret = -ENOMEM;
39784 goto edescalloc;
39785 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39786 index 58eb857..d7e42c8 100644
39787 --- a/drivers/dma/sh/shdmac.c
39788 +++ b/drivers/dma/sh/shdmac.c
39789 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39790 return ret;
39791 }
39792
39793 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39794 +static struct notifier_block sh_dmae_nmi_notifier = {
39795 .notifier_call = sh_dmae_nmi_handler,
39796
39797 /* Run before NMI debug handler and KGDB */
39798 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39799 index 592af5f..bb1d583 100644
39800 --- a/drivers/edac/edac_device.c
39801 +++ b/drivers/edac/edac_device.c
39802 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39803 */
39804 int edac_device_alloc_index(void)
39805 {
39806 - static atomic_t device_indexes = ATOMIC_INIT(0);
39807 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39808
39809 - return atomic_inc_return(&device_indexes) - 1;
39810 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39811 }
39812 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39813
39814 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39815 index a6cd361..7bdbf53 100644
39816 --- a/drivers/edac/edac_mc_sysfs.c
39817 +++ b/drivers/edac/edac_mc_sysfs.c
39818 @@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39819 struct dev_ch_attribute {
39820 struct device_attribute attr;
39821 int channel;
39822 -};
39823 +} __do_const;
39824
39825 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39826 struct dev_ch_attribute dev_attr_legacy_##_name = \
39827 @@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39828 }
39829
39830 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39831 + pax_open_kernel();
39832 if (mci->get_sdram_scrub_rate) {
39833 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39834 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39835 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39836 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39837 }
39838 if (mci->set_sdram_scrub_rate) {
39839 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39840 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39841 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39842 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39843 }
39844 + pax_close_kernel();
39845 err = device_create_file(&mci->dev,
39846 &dev_attr_sdram_scrub_rate);
39847 if (err) {
39848 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39849 index 2cf44b4d..6dd2dc7 100644
39850 --- a/drivers/edac/edac_pci.c
39851 +++ b/drivers/edac/edac_pci.c
39852 @@ -29,7 +29,7 @@
39853
39854 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39855 static LIST_HEAD(edac_pci_list);
39856 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39857 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39858
39859 /*
39860 * edac_pci_alloc_ctl_info
39861 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39862 */
39863 int edac_pci_alloc_index(void)
39864 {
39865 - return atomic_inc_return(&pci_indexes) - 1;
39866 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39867 }
39868 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39869
39870 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39871 index e8658e4..22746d6 100644
39872 --- a/drivers/edac/edac_pci_sysfs.c
39873 +++ b/drivers/edac/edac_pci_sysfs.c
39874 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39875 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39876 static int edac_pci_poll_msec = 1000; /* one second workq period */
39877
39878 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39879 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39880 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39881 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39882
39883 static struct kobject *edac_pci_top_main_kobj;
39884 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39885 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39886 void *value;
39887 ssize_t(*show) (void *, char *);
39888 ssize_t(*store) (void *, const char *, size_t);
39889 -};
39890 +} __do_const;
39891
39892 /* Set of show/store abstract level functions for PCI Parity object */
39893 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39894 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39895 edac_printk(KERN_CRIT, EDAC_PCI,
39896 "Signaled System Error on %s\n",
39897 pci_name(dev));
39898 - atomic_inc(&pci_nonparity_count);
39899 + atomic_inc_unchecked(&pci_nonparity_count);
39900 }
39901
39902 if (status & (PCI_STATUS_PARITY)) {
39903 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39904 "Master Data Parity Error on %s\n",
39905 pci_name(dev));
39906
39907 - atomic_inc(&pci_parity_count);
39908 + atomic_inc_unchecked(&pci_parity_count);
39909 }
39910
39911 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39912 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39913 "Detected Parity Error on %s\n",
39914 pci_name(dev));
39915
39916 - atomic_inc(&pci_parity_count);
39917 + atomic_inc_unchecked(&pci_parity_count);
39918 }
39919 }
39920
39921 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39922 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39923 "Signaled System Error on %s\n",
39924 pci_name(dev));
39925 - atomic_inc(&pci_nonparity_count);
39926 + atomic_inc_unchecked(&pci_nonparity_count);
39927 }
39928
39929 if (status & (PCI_STATUS_PARITY)) {
39930 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39931 "Master Data Parity Error on "
39932 "%s\n", pci_name(dev));
39933
39934 - atomic_inc(&pci_parity_count);
39935 + atomic_inc_unchecked(&pci_parity_count);
39936 }
39937
39938 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39939 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39940 "Detected Parity Error on %s\n",
39941 pci_name(dev));
39942
39943 - atomic_inc(&pci_parity_count);
39944 + atomic_inc_unchecked(&pci_parity_count);
39945 }
39946 }
39947 }
39948 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39949 if (!check_pci_errors)
39950 return;
39951
39952 - before_count = atomic_read(&pci_parity_count);
39953 + before_count = atomic_read_unchecked(&pci_parity_count);
39954
39955 /* scan all PCI devices looking for a Parity Error on devices and
39956 * bridges.
39957 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39958 /* Only if operator has selected panic on PCI Error */
39959 if (edac_pci_get_panic_on_pe()) {
39960 /* If the count is different 'after' from 'before' */
39961 - if (before_count != atomic_read(&pci_parity_count))
39962 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39963 panic("EDAC: PCI Parity Error");
39964 }
39965 }
39966 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39967 index 51b7e3a..aa8a3e8 100644
39968 --- a/drivers/edac/mce_amd.h
39969 +++ b/drivers/edac/mce_amd.h
39970 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39971 bool (*mc0_mce)(u16, u8);
39972 bool (*mc1_mce)(u16, u8);
39973 bool (*mc2_mce)(u16, u8);
39974 -};
39975 +} __no_const;
39976
39977 void amd_report_gart_errors(bool);
39978 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39979 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39980 index 57ea7f4..af06b76 100644
39981 --- a/drivers/firewire/core-card.c
39982 +++ b/drivers/firewire/core-card.c
39983 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39984 const struct fw_card_driver *driver,
39985 struct device *device)
39986 {
39987 - static atomic_t index = ATOMIC_INIT(-1);
39988 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39989
39990 - card->index = atomic_inc_return(&index);
39991 + card->index = atomic_inc_return_unchecked(&index);
39992 card->driver = driver;
39993 card->device = device;
39994 card->current_tlabel = 0;
39995 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39996
39997 void fw_core_remove_card(struct fw_card *card)
39998 {
39999 - struct fw_card_driver dummy_driver = dummy_driver_template;
40000 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40001
40002 card->driver->update_phy_reg(card, 4,
40003 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40004 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40005 index 2c6d5e1..a2cca6b 100644
40006 --- a/drivers/firewire/core-device.c
40007 +++ b/drivers/firewire/core-device.c
40008 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40009 struct config_rom_attribute {
40010 struct device_attribute attr;
40011 u32 key;
40012 -};
40013 +} __do_const;
40014
40015 static ssize_t show_immediate(struct device *dev,
40016 struct device_attribute *dattr, char *buf)
40017 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40018 index eb6935c..3cc2bfa 100644
40019 --- a/drivers/firewire/core-transaction.c
40020 +++ b/drivers/firewire/core-transaction.c
40021 @@ -38,6 +38,7 @@
40022 #include <linux/timer.h>
40023 #include <linux/types.h>
40024 #include <linux/workqueue.h>
40025 +#include <linux/sched.h>
40026
40027 #include <asm/byteorder.h>
40028
40029 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40030 index e1480ff6..1a429bd 100644
40031 --- a/drivers/firewire/core.h
40032 +++ b/drivers/firewire/core.h
40033 @@ -111,6 +111,7 @@ struct fw_card_driver {
40034
40035 int (*stop_iso)(struct fw_iso_context *ctx);
40036 };
40037 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40038
40039 void fw_card_initialize(struct fw_card *card,
40040 const struct fw_card_driver *driver, struct device *device);
40041 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40042 index a66a321..f6caf20 100644
40043 --- a/drivers/firewire/ohci.c
40044 +++ b/drivers/firewire/ohci.c
40045 @@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40046 be32_to_cpu(ohci->next_header));
40047 }
40048
40049 +#ifndef CONFIG_GRKERNSEC
40050 if (param_remote_dma) {
40051 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40052 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40053 }
40054 +#endif
40055
40056 spin_unlock_irq(&ohci->lock);
40057
40058 @@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40059 unsigned long flags;
40060 int n, ret = 0;
40061
40062 +#ifndef CONFIG_GRKERNSEC
40063 if (param_remote_dma)
40064 return 0;
40065 +#endif
40066
40067 /*
40068 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40069 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40070 index 94a58a0..f5eba42 100644
40071 --- a/drivers/firmware/dmi-id.c
40072 +++ b/drivers/firmware/dmi-id.c
40073 @@ -16,7 +16,7 @@
40074 struct dmi_device_attribute{
40075 struct device_attribute dev_attr;
40076 int field;
40077 -};
40078 +} __do_const;
40079 #define to_dmi_dev_attr(_dev_attr) \
40080 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40081
40082 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40083 index 17afc51..0ef90cd 100644
40084 --- a/drivers/firmware/dmi_scan.c
40085 +++ b/drivers/firmware/dmi_scan.c
40086 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40087 if (buf == NULL)
40088 return -1;
40089
40090 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40091 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40092
40093 dmi_unmap(buf);
40094 return 0;
40095 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40096 index 5b53d61..72cee96 100644
40097 --- a/drivers/firmware/efi/cper.c
40098 +++ b/drivers/firmware/efi/cper.c
40099 @@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40100 */
40101 u64 cper_next_record_id(void)
40102 {
40103 - static atomic64_t seq;
40104 + static atomic64_unchecked_t seq;
40105
40106 - if (!atomic64_read(&seq))
40107 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40108 + if (!atomic64_read_unchecked(&seq))
40109 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40110
40111 - return atomic64_inc_return(&seq);
40112 + return atomic64_inc_return_unchecked(&seq);
40113 }
40114 EXPORT_SYMBOL_GPL(cper_next_record_id);
40115
40116 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40117 index 8590099..d83627a 100644
40118 --- a/drivers/firmware/efi/efi.c
40119 +++ b/drivers/firmware/efi/efi.c
40120 @@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40121 };
40122
40123 static struct efivars generic_efivars;
40124 -static struct efivar_operations generic_ops;
40125 +static efivar_operations_no_const generic_ops __read_only;
40126
40127 static int generic_ops_register(void)
40128 {
40129 - generic_ops.get_variable = efi.get_variable;
40130 - generic_ops.set_variable = efi.set_variable;
40131 - generic_ops.get_next_variable = efi.get_next_variable;
40132 - generic_ops.query_variable_store = efi_query_variable_store;
40133 + pax_open_kernel();
40134 + *(void **)&generic_ops.get_variable = efi.get_variable;
40135 + *(void **)&generic_ops.set_variable = efi.set_variable;
40136 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40137 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40138 + pax_close_kernel();
40139
40140 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40141 }
40142 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40143 index f256ecd..387dcb1 100644
40144 --- a/drivers/firmware/efi/efivars.c
40145 +++ b/drivers/firmware/efi/efivars.c
40146 @@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40147 static int
40148 create_efivars_bin_attributes(void)
40149 {
40150 - struct bin_attribute *attr;
40151 + bin_attribute_no_const *attr;
40152 int error;
40153
40154 /* new_var */
40155 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40156 index 2f569aa..c95f4fb 100644
40157 --- a/drivers/firmware/google/memconsole.c
40158 +++ b/drivers/firmware/google/memconsole.c
40159 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40160 if (!found_memconsole())
40161 return -ENODEV;
40162
40163 - memconsole_bin_attr.size = memconsole_length;
40164 + pax_open_kernel();
40165 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40166 + pax_close_kernel();
40167 +
40168 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40169 }
40170
40171 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40172 index fe49ec3..1ade794 100644
40173 --- a/drivers/gpio/gpio-em.c
40174 +++ b/drivers/gpio/gpio-em.c
40175 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40176 struct em_gio_priv *p;
40177 struct resource *io[2], *irq[2];
40178 struct gpio_chip *gpio_chip;
40179 - struct irq_chip *irq_chip;
40180 + irq_chip_no_const *irq_chip;
40181 const char *name = dev_name(&pdev->dev);
40182 int ret;
40183
40184 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40185 index 3784e81..73637b5 100644
40186 --- a/drivers/gpio/gpio-ich.c
40187 +++ b/drivers/gpio/gpio-ich.c
40188 @@ -94,7 +94,7 @@ struct ichx_desc {
40189 * this option allows driver caching written output values
40190 */
40191 bool use_outlvl_cache;
40192 -};
40193 +} __do_const;
40194
40195 static struct {
40196 spinlock_t lock;
40197 diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
40198 index 415682f..08438b8 100644
40199 --- a/drivers/gpio/gpio-omap.c
40200 +++ b/drivers/gpio/gpio-omap.c
40201 @@ -1162,7 +1162,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
40202 const struct omap_gpio_platform_data *pdata;
40203 struct resource *res;
40204 struct gpio_bank *bank;
40205 - struct irq_chip *irqc;
40206 + irq_chip_no_const *irqc;
40207 int ret;
40208
40209 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
40210 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40211 index bf6c094..6573caf 100644
40212 --- a/drivers/gpio/gpio-rcar.c
40213 +++ b/drivers/gpio/gpio-rcar.c
40214 @@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40215 struct gpio_rcar_priv *p;
40216 struct resource *io, *irq;
40217 struct gpio_chip *gpio_chip;
40218 - struct irq_chip *irq_chip;
40219 + irq_chip_no_const *irq_chip;
40220 struct device *dev = &pdev->dev;
40221 const char *name = dev_name(dev);
40222 int ret;
40223 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40224 index dbf28fa..04dad4e 100644
40225 --- a/drivers/gpio/gpio-vr41xx.c
40226 +++ b/drivers/gpio/gpio-vr41xx.c
40227 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40228 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40229 maskl, pendl, maskh, pendh);
40230
40231 - atomic_inc(&irq_err_count);
40232 + atomic_inc_unchecked(&irq_err_count);
40233
40234 return -EINVAL;
40235 }
40236 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40237 index c81bda0..a8ccd9f 100644
40238 --- a/drivers/gpio/gpiolib.c
40239 +++ b/drivers/gpio/gpiolib.c
40240 @@ -539,8 +539,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40241 }
40242
40243 if (gpiochip->irqchip) {
40244 - gpiochip->irqchip->irq_request_resources = NULL;
40245 - gpiochip->irqchip->irq_release_resources = NULL;
40246 + pax_open_kernel();
40247 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40248 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40249 + pax_close_kernel();
40250 gpiochip->irqchip = NULL;
40251 }
40252 }
40253 @@ -606,8 +608,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40254 gpiochip->irqchip = NULL;
40255 return -EINVAL;
40256 }
40257 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40258 - irqchip->irq_release_resources = gpiochip_irq_relres;
40259 +
40260 + pax_open_kernel();
40261 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40262 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40263 + pax_close_kernel();
40264
40265 /*
40266 * Prepare the mapping since the irqchip shall be orthogonal to
40267 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40268 index e79c8d3..a9370bc 100644
40269 --- a/drivers/gpu/drm/drm_crtc.c
40270 +++ b/drivers/gpu/drm/drm_crtc.c
40271 @@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40272 goto done;
40273 }
40274
40275 - if (copy_to_user(&enum_ptr[copied].name,
40276 + if (copy_to_user(enum_ptr[copied].name,
40277 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40278 ret = -EFAULT;
40279 goto done;
40280 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40281 index bc3da32..7289357 100644
40282 --- a/drivers/gpu/drm/drm_drv.c
40283 +++ b/drivers/gpu/drm/drm_drv.c
40284 @@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40285
40286 drm_device_set_unplugged(dev);
40287
40288 - if (dev->open_count == 0) {
40289 + if (local_read(&dev->open_count) == 0) {
40290 drm_put_dev(dev);
40291 }
40292 mutex_unlock(&drm_global_mutex);
40293 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
40294 index e9a2827..5df4716 100644
40295 --- a/drivers/gpu/drm/drm_fb_helper.c
40296 +++ b/drivers/gpu/drm/drm_fb_helper.c
40297 @@ -771,7 +771,9 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
40298 int i, j, rc = 0;
40299 int start;
40300
40301 - drm_modeset_lock_all(dev);
40302 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40303 + return -EBUSY;
40304 + }
40305 if (!drm_fb_helper_is_bound(fb_helper)) {
40306 drm_modeset_unlock_all(dev);
40307 return -EBUSY;
40308 @@ -945,7 +947,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
40309 int ret = 0;
40310 int i;
40311
40312 - drm_modeset_lock_all(dev);
40313 + if (__drm_modeset_lock_all(dev, !!oops_in_progress)) {
40314 + return -EBUSY;
40315 + }
40316 if (!drm_fb_helper_is_bound(fb_helper)) {
40317 drm_modeset_unlock_all(dev);
40318 return -EBUSY;
40319 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40320 index ed7bc68..0d536af 100644
40321 --- a/drivers/gpu/drm/drm_fops.c
40322 +++ b/drivers/gpu/drm/drm_fops.c
40323 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40324 return PTR_ERR(minor);
40325
40326 dev = minor->dev;
40327 - if (!dev->open_count++)
40328 + if (local_inc_return(&dev->open_count) == 1)
40329 need_setup = 1;
40330
40331 /* share address_space across all char-devs of a single device */
40332 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40333 return 0;
40334
40335 err_undo:
40336 - dev->open_count--;
40337 + local_dec(&dev->open_count);
40338 drm_minor_release(minor);
40339 return retcode;
40340 }
40341 @@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40342
40343 mutex_lock(&drm_global_mutex);
40344
40345 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40346 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40347
40348 mutex_lock(&dev->struct_mutex);
40349 list_del(&file_priv->lhead);
40350 @@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40351 * Begin inline drm_release
40352 */
40353
40354 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40355 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40356 task_pid_nr(current),
40357 (long)old_encode_dev(file_priv->minor->kdev->devt),
40358 - dev->open_count);
40359 + local_read(&dev->open_count));
40360
40361 /* Release any auth tokens that might point to this file_priv,
40362 (do that under the drm_global_mutex) */
40363 @@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40364 * End inline drm_release
40365 */
40366
40367 - if (!--dev->open_count) {
40368 + if (local_dec_and_test(&dev->open_count)) {
40369 retcode = drm_lastclose(dev);
40370 if (drm_device_is_unplugged(dev))
40371 drm_put_dev(dev);
40372 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40373 index 3d2e91c..d31c4c9 100644
40374 --- a/drivers/gpu/drm/drm_global.c
40375 +++ b/drivers/gpu/drm/drm_global.c
40376 @@ -36,7 +36,7 @@
40377 struct drm_global_item {
40378 struct mutex mutex;
40379 void *object;
40380 - int refcount;
40381 + atomic_t refcount;
40382 };
40383
40384 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40385 @@ -49,7 +49,7 @@ void drm_global_init(void)
40386 struct drm_global_item *item = &glob[i];
40387 mutex_init(&item->mutex);
40388 item->object = NULL;
40389 - item->refcount = 0;
40390 + atomic_set(&item->refcount, 0);
40391 }
40392 }
40393
40394 @@ -59,7 +59,7 @@ void drm_global_release(void)
40395 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40396 struct drm_global_item *item = &glob[i];
40397 BUG_ON(item->object != NULL);
40398 - BUG_ON(item->refcount != 0);
40399 + BUG_ON(atomic_read(&item->refcount) != 0);
40400 }
40401 }
40402
40403 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40404 struct drm_global_item *item = &glob[ref->global_type];
40405
40406 mutex_lock(&item->mutex);
40407 - if (item->refcount == 0) {
40408 + if (atomic_read(&item->refcount) == 0) {
40409 item->object = kzalloc(ref->size, GFP_KERNEL);
40410 if (unlikely(item->object == NULL)) {
40411 ret = -ENOMEM;
40412 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40413 goto out_err;
40414
40415 }
40416 - ++item->refcount;
40417 + atomic_inc(&item->refcount);
40418 ref->object = item->object;
40419 mutex_unlock(&item->mutex);
40420 return 0;
40421 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40422 struct drm_global_item *item = &glob[ref->global_type];
40423
40424 mutex_lock(&item->mutex);
40425 - BUG_ON(item->refcount == 0);
40426 + BUG_ON(atomic_read(&item->refcount) == 0);
40427 BUG_ON(ref->object != item->object);
40428 - if (--item->refcount == 0) {
40429 + if (atomic_dec_and_test(&item->refcount)) {
40430 ref->release(ref);
40431 item->object = NULL;
40432 }
40433 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40434 index 51efebd..2b70935 100644
40435 --- a/drivers/gpu/drm/drm_info.c
40436 +++ b/drivers/gpu/drm/drm_info.c
40437 @@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40438 struct drm_local_map *map;
40439 struct drm_map_list *r_list;
40440
40441 - /* Hardcoded from _DRM_FRAME_BUFFER,
40442 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40443 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40444 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40445 + static const char * const types[] = {
40446 + [_DRM_FRAME_BUFFER] = "FB",
40447 + [_DRM_REGISTERS] = "REG",
40448 + [_DRM_SHM] = "SHM",
40449 + [_DRM_AGP] = "AGP",
40450 + [_DRM_SCATTER_GATHER] = "SG",
40451 + [_DRM_CONSISTENT] = "PCI"};
40452 const char *type;
40453 int i;
40454
40455 @@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40456 map = r_list->map;
40457 if (!map)
40458 continue;
40459 - if (map->type < 0 || map->type > 5)
40460 + if (map->type >= ARRAY_SIZE(types))
40461 type = "??";
40462 else
40463 type = types[map->type];
40464 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40465 index 2f4c4343..dd12cd2 100644
40466 --- a/drivers/gpu/drm/drm_ioc32.c
40467 +++ b/drivers/gpu/drm/drm_ioc32.c
40468 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40469 request = compat_alloc_user_space(nbytes);
40470 if (!access_ok(VERIFY_WRITE, request, nbytes))
40471 return -EFAULT;
40472 - list = (struct drm_buf_desc *) (request + 1);
40473 + list = (struct drm_buf_desc __user *) (request + 1);
40474
40475 if (__put_user(count, &request->count)
40476 || __put_user(list, &request->list))
40477 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40478 request = compat_alloc_user_space(nbytes);
40479 if (!access_ok(VERIFY_WRITE, request, nbytes))
40480 return -EFAULT;
40481 - list = (struct drm_buf_pub *) (request + 1);
40482 + list = (struct drm_buf_pub __user *) (request + 1);
40483
40484 if (__put_user(count, &request->count)
40485 || __put_user(list, &request->list))
40486 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40487 return 0;
40488 }
40489
40490 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40491 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40492 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40493 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40494 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40495 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40496 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40497 {
40498 unsigned int nr = DRM_IOCTL_NR(cmd);
40499 - drm_ioctl_compat_t *fn;
40500 int ret;
40501
40502 /* Assume that ioctls without an explicit compat routine will just
40503 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40504 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40505 return drm_ioctl(filp, cmd, arg);
40506
40507 - fn = drm_compat_ioctls[nr];
40508 -
40509 - if (fn != NULL)
40510 - ret = (*fn) (filp, cmd, arg);
40511 + if (drm_compat_ioctls[nr] != NULL)
40512 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40513 else
40514 ret = drm_ioctl(filp, cmd, arg);
40515
40516 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40517 index 00587a1..57a65ca 100644
40518 --- a/drivers/gpu/drm/drm_ioctl.c
40519 +++ b/drivers/gpu/drm/drm_ioctl.c
40520 @@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40521 struct drm_file *file_priv = filp->private_data;
40522 struct drm_device *dev;
40523 const struct drm_ioctl_desc *ioctl = NULL;
40524 - drm_ioctl_t *func;
40525 + drm_ioctl_no_const_t func;
40526 unsigned int nr = DRM_IOCTL_NR(cmd);
40527 int retcode = -EINVAL;
40528 char stack_kdata[128];
40529 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40530 index 93ec5dc..82acbaf 100644
40531 --- a/drivers/gpu/drm/i810/i810_drv.h
40532 +++ b/drivers/gpu/drm/i810/i810_drv.h
40533 @@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40534 int page_flipping;
40535
40536 wait_queue_head_t irq_queue;
40537 - atomic_t irq_received;
40538 - atomic_t irq_emitted;
40539 + atomic_unchecked_t irq_received;
40540 + atomic_unchecked_t irq_emitted;
40541
40542 int front_offset;
40543 } drm_i810_private_t;
40544 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40545 index 318ade9..1f5de55 100644
40546 --- a/drivers/gpu/drm/i915/i915_dma.c
40547 +++ b/drivers/gpu/drm/i915/i915_dma.c
40548 @@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40549 * locking inversion with the driver load path. And the access here is
40550 * completely racy anyway. So don't bother with locking for now.
40551 */
40552 - return dev->open_count == 0;
40553 + return local_read(&dev->open_count) == 0;
40554 }
40555
40556 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40557 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40558 index 1a0611b..dd1fbfc 100644
40559 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40560 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40561 @@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40562 static int
40563 validate_exec_list(struct drm_device *dev,
40564 struct drm_i915_gem_exec_object2 *exec,
40565 - int count)
40566 + unsigned int count)
40567 {
40568 unsigned relocs_total = 0;
40569 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40570 unsigned invalid_flags;
40571 - int i;
40572 + unsigned int i;
40573
40574 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40575 if (USES_FULL_PPGTT(dev))
40576 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40577 index 2e0613e..a8b94d9 100644
40578 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40579 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40580 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40581 (unsigned long)request);
40582 }
40583
40584 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40585 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40586 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40587 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40588 [DRM_I915_GETPARAM] = compat_i915_getparam,
40589 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40590 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40591 {
40592 unsigned int nr = DRM_IOCTL_NR(cmd);
40593 - drm_ioctl_compat_t *fn = NULL;
40594 int ret;
40595
40596 if (nr < DRM_COMMAND_BASE)
40597 return drm_compat_ioctl(filp, cmd, arg);
40598
40599 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40600 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40601 -
40602 - if (fn != NULL)
40603 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40604 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40605 ret = (*fn) (filp, cmd, arg);
40606 - else
40607 + } else
40608 ret = drm_ioctl(filp, cmd, arg);
40609
40610 return ret;
40611 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40612 index 31b9664..5d478d3 100644
40613 --- a/drivers/gpu/drm/i915/intel_display.c
40614 +++ b/drivers/gpu/drm/i915/intel_display.c
40615 @@ -12811,13 +12811,13 @@ struct intel_quirk {
40616 int subsystem_vendor;
40617 int subsystem_device;
40618 void (*hook)(struct drm_device *dev);
40619 -};
40620 +} __do_const;
40621
40622 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40623 struct intel_dmi_quirk {
40624 void (*hook)(struct drm_device *dev);
40625 const struct dmi_system_id (*dmi_id_list)[];
40626 -};
40627 +} __do_const;
40628
40629 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40630 {
40631 @@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40632 return 1;
40633 }
40634
40635 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40636 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40637 {
40638 - .dmi_id_list = &(const struct dmi_system_id[]) {
40639 - {
40640 - .callback = intel_dmi_reverse_brightness,
40641 - .ident = "NCR Corporation",
40642 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40643 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40644 - },
40645 - },
40646 - { } /* terminating entry */
40647 + .callback = intel_dmi_reverse_brightness,
40648 + .ident = "NCR Corporation",
40649 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40650 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40651 },
40652 + },
40653 + { } /* terminating entry */
40654 +};
40655 +
40656 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40657 + {
40658 + .dmi_id_list = &intel_dmi_quirks_table,
40659 .hook = quirk_invert_brightness,
40660 },
40661 };
40662 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40663 index b4a2014..219ab78 100644
40664 --- a/drivers/gpu/drm/mga/mga_drv.h
40665 +++ b/drivers/gpu/drm/mga/mga_drv.h
40666 @@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40667 u32 clear_cmd;
40668 u32 maccess;
40669
40670 - atomic_t vbl_received; /**< Number of vblanks received. */
40671 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40672 wait_queue_head_t fence_queue;
40673 - atomic_t last_fence_retired;
40674 + atomic_unchecked_t last_fence_retired;
40675 u32 next_fence_to_post;
40676
40677 unsigned int fb_cpp;
40678 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40679 index 729bfd5..ead8823 100644
40680 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40681 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40682 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40683 return 0;
40684 }
40685
40686 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40687 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40688 [DRM_MGA_INIT] = compat_mga_init,
40689 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40690 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40691 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40692 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40693 {
40694 unsigned int nr = DRM_IOCTL_NR(cmd);
40695 - drm_ioctl_compat_t *fn = NULL;
40696 int ret;
40697
40698 if (nr < DRM_COMMAND_BASE)
40699 return drm_compat_ioctl(filp, cmd, arg);
40700
40701 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40702 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40703 -
40704 - if (fn != NULL)
40705 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40706 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40707 ret = (*fn) (filp, cmd, arg);
40708 - else
40709 + } else
40710 ret = drm_ioctl(filp, cmd, arg);
40711
40712 return ret;
40713 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40714 index 1b071b8..de8601a 100644
40715 --- a/drivers/gpu/drm/mga/mga_irq.c
40716 +++ b/drivers/gpu/drm/mga/mga_irq.c
40717 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40718 if (crtc != 0)
40719 return 0;
40720
40721 - return atomic_read(&dev_priv->vbl_received);
40722 + return atomic_read_unchecked(&dev_priv->vbl_received);
40723 }
40724
40725
40726 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40727 /* VBLANK interrupt */
40728 if (status & MGA_VLINEPEN) {
40729 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40730 - atomic_inc(&dev_priv->vbl_received);
40731 + atomic_inc_unchecked(&dev_priv->vbl_received);
40732 drm_handle_vblank(dev, 0);
40733 handled = 1;
40734 }
40735 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40736 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40737 MGA_WRITE(MGA_PRIMEND, prim_end);
40738
40739 - atomic_inc(&dev_priv->last_fence_retired);
40740 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40741 wake_up(&dev_priv->fence_queue);
40742 handled = 1;
40743 }
40744 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40745 * using fences.
40746 */
40747 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40748 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40749 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40750 - *sequence) <= (1 << 23)));
40751
40752 *sequence = cur_fence;
40753 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40754 index dae2c96..324dbe4 100644
40755 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40756 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40757 @@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40758 struct bit_table {
40759 const char id;
40760 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40761 -};
40762 +} __no_const;
40763
40764 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40765
40766 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40767 index 8ae36f2..1147a30 100644
40768 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40769 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40770 @@ -121,7 +121,6 @@ struct nouveau_drm {
40771 struct drm_global_reference mem_global_ref;
40772 struct ttm_bo_global_ref bo_global_ref;
40773 struct ttm_bo_device bdev;
40774 - atomic_t validate_sequence;
40775 int (*move)(struct nouveau_channel *,
40776 struct ttm_buffer_object *,
40777 struct ttm_mem_reg *, struct ttm_mem_reg *);
40778 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40779 index 462679a..88e32a7 100644
40780 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40781 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40782 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40783 unsigned long arg)
40784 {
40785 unsigned int nr = DRM_IOCTL_NR(cmd);
40786 - drm_ioctl_compat_t *fn = NULL;
40787 + drm_ioctl_compat_t fn = NULL;
40788 int ret;
40789
40790 if (nr < DRM_COMMAND_BASE)
40791 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40792 index 3d1cfcb..0542700 100644
40793 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40794 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40795 @@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40796 }
40797
40798 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40799 - nouveau_vram_manager_init,
40800 - nouveau_vram_manager_fini,
40801 - nouveau_vram_manager_new,
40802 - nouveau_vram_manager_del,
40803 - nouveau_vram_manager_debug
40804 + .init = nouveau_vram_manager_init,
40805 + .takedown = nouveau_vram_manager_fini,
40806 + .get_node = nouveau_vram_manager_new,
40807 + .put_node = nouveau_vram_manager_del,
40808 + .debug = nouveau_vram_manager_debug
40809 };
40810
40811 static int
40812 @@ -195,11 +195,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40813 }
40814
40815 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40816 - nouveau_gart_manager_init,
40817 - nouveau_gart_manager_fini,
40818 - nouveau_gart_manager_new,
40819 - nouveau_gart_manager_del,
40820 - nouveau_gart_manager_debug
40821 + .init = nouveau_gart_manager_init,
40822 + .takedown = nouveau_gart_manager_fini,
40823 + .get_node = nouveau_gart_manager_new,
40824 + .put_node = nouveau_gart_manager_del,
40825 + .debug = nouveau_gart_manager_debug
40826 };
40827
40828 /*XXX*/
40829 @@ -268,11 +268,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40830 }
40831
40832 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40833 - nv04_gart_manager_init,
40834 - nv04_gart_manager_fini,
40835 - nv04_gart_manager_new,
40836 - nv04_gart_manager_del,
40837 - nv04_gart_manager_debug
40838 + .init = nv04_gart_manager_init,
40839 + .takedown = nv04_gart_manager_fini,
40840 + .get_node = nv04_gart_manager_new,
40841 + .put_node = nv04_gart_manager_del,
40842 + .debug = nv04_gart_manager_debug
40843 };
40844
40845 int
40846 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40847 index c7592ec..dd45ebc 100644
40848 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40849 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40850 @@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40851 * locking inversion with the driver load path. And the access here is
40852 * completely racy anyway. So don't bother with locking for now.
40853 */
40854 - return dev->open_count == 0;
40855 + return local_read(&dev->open_count) == 0;
40856 }
40857
40858 static const struct vga_switcheroo_client_ops
40859 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40860 index 9782364..89bd954 100644
40861 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40862 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40863 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40864 int ret;
40865
40866 mutex_lock(&qdev->async_io_mutex);
40867 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40868 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40869 if (qdev->last_sent_io_cmd > irq_num) {
40870 if (intr)
40871 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40872 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40873 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40874 else
40875 ret = wait_event_timeout(qdev->io_cmd_event,
40876 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40877 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40878 /* 0 is timeout, just bail the "hw" has gone away */
40879 if (ret <= 0)
40880 goto out;
40881 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40882 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40883 }
40884 outb(val, addr);
40885 qdev->last_sent_io_cmd = irq_num + 1;
40886 if (intr)
40887 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40888 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40889 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40890 else
40891 ret = wait_event_timeout(qdev->io_cmd_event,
40892 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40893 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40894 out:
40895 if (ret > 0)
40896 ret = 0;
40897 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40898 index 6911b8c..89d6867 100644
40899 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40900 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40901 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40902 struct drm_info_node *node = (struct drm_info_node *) m->private;
40903 struct qxl_device *qdev = node->minor->dev->dev_private;
40904
40905 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40906 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40907 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40908 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40909 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40910 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40911 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40912 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40913 seq_printf(m, "%d\n", qdev->irq_received_error);
40914 return 0;
40915 }
40916 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40917 index 7c6cafe..460f542 100644
40918 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40919 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40920 @@ -290,10 +290,10 @@ struct qxl_device {
40921 unsigned int last_sent_io_cmd;
40922
40923 /* interrupt handling */
40924 - atomic_t irq_received;
40925 - atomic_t irq_received_display;
40926 - atomic_t irq_received_cursor;
40927 - atomic_t irq_received_io_cmd;
40928 + atomic_unchecked_t irq_received;
40929 + atomic_unchecked_t irq_received_display;
40930 + atomic_unchecked_t irq_received_cursor;
40931 + atomic_unchecked_t irq_received_io_cmd;
40932 unsigned irq_received_error;
40933 wait_queue_head_t display_event;
40934 wait_queue_head_t cursor_event;
40935 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40936 index b110883..dd06418 100644
40937 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40938 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40939 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40940
40941 /* TODO copy slow path code from i915 */
40942 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40943 - 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);
40944 + 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);
40945
40946 {
40947 struct qxl_drawable *draw = fb_cmd;
40948 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40949 struct drm_qxl_reloc reloc;
40950
40951 if (copy_from_user(&reloc,
40952 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40953 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40954 sizeof(reloc))) {
40955 ret = -EFAULT;
40956 goto out_free_bos;
40957 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40958
40959 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40960
40961 - struct drm_qxl_command *commands =
40962 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40963 + struct drm_qxl_command __user *commands =
40964 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40965
40966 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40967 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40968 sizeof(user_cmd)))
40969 return -EFAULT;
40970
40971 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40972 index 0bf1e20..42a7310 100644
40973 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40974 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40975 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40976 if (!pending)
40977 return IRQ_NONE;
40978
40979 - atomic_inc(&qdev->irq_received);
40980 + atomic_inc_unchecked(&qdev->irq_received);
40981
40982 if (pending & QXL_INTERRUPT_DISPLAY) {
40983 - atomic_inc(&qdev->irq_received_display);
40984 + atomic_inc_unchecked(&qdev->irq_received_display);
40985 wake_up_all(&qdev->display_event);
40986 qxl_queue_garbage_collect(qdev, false);
40987 }
40988 if (pending & QXL_INTERRUPT_CURSOR) {
40989 - atomic_inc(&qdev->irq_received_cursor);
40990 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40991 wake_up_all(&qdev->cursor_event);
40992 }
40993 if (pending & QXL_INTERRUPT_IO_CMD) {
40994 - atomic_inc(&qdev->irq_received_io_cmd);
40995 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40996 wake_up_all(&qdev->io_cmd_event);
40997 }
40998 if (pending & QXL_INTERRUPT_ERROR) {
40999 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41000 init_waitqueue_head(&qdev->io_cmd_event);
41001 INIT_WORK(&qdev->client_monitors_config_work,
41002 qxl_client_monitors_config_work_func);
41003 - atomic_set(&qdev->irq_received, 0);
41004 - atomic_set(&qdev->irq_received_display, 0);
41005 - atomic_set(&qdev->irq_received_cursor, 0);
41006 - atomic_set(&qdev->irq_received_io_cmd, 0);
41007 + atomic_set_unchecked(&qdev->irq_received, 0);
41008 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41009 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41010 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41011 qdev->irq_received_error = 0;
41012 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41013 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41014 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41015 index 0cbc4c9..0e46686 100644
41016 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41017 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41018 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41019 }
41020 }
41021
41022 -static struct vm_operations_struct qxl_ttm_vm_ops;
41023 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41024 static const struct vm_operations_struct *ttm_vm_ops;
41025
41026 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41027 @@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41028 return r;
41029 if (unlikely(ttm_vm_ops == NULL)) {
41030 ttm_vm_ops = vma->vm_ops;
41031 + pax_open_kernel();
41032 qxl_ttm_vm_ops = *ttm_vm_ops;
41033 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41034 + pax_close_kernel();
41035 }
41036 vma->vm_ops = &qxl_ttm_vm_ops;
41037 return 0;
41038 @@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41039 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41040 {
41041 #if defined(CONFIG_DEBUG_FS)
41042 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41043 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41044 - unsigned i;
41045 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41046 + {
41047 + .name = "qxl_mem_mm",
41048 + .show = &qxl_mm_dump_table,
41049 + },
41050 + {
41051 + .name = "qxl_surf_mm",
41052 + .show = &qxl_mm_dump_table,
41053 + }
41054 + };
41055
41056 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41057 - if (i == 0)
41058 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41059 - else
41060 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41061 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41062 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41063 - qxl_mem_types_list[i].driver_features = 0;
41064 - if (i == 0)
41065 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41066 - else
41067 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41068 + pax_open_kernel();
41069 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41070 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41071 + pax_close_kernel();
41072
41073 - }
41074 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41075 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41076 #else
41077 return 0;
41078 #endif
41079 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41080 index 2c45ac9..5d740f8 100644
41081 --- a/drivers/gpu/drm/r128/r128_cce.c
41082 +++ b/drivers/gpu/drm/r128/r128_cce.c
41083 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41084
41085 /* GH: Simple idle check.
41086 */
41087 - atomic_set(&dev_priv->idle_count, 0);
41088 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41089
41090 /* We don't support anything other than bus-mastering ring mode,
41091 * but the ring can be in either AGP or PCI space for the ring
41092 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41093 index 723e5d6..102dbaf 100644
41094 --- a/drivers/gpu/drm/r128/r128_drv.h
41095 +++ b/drivers/gpu/drm/r128/r128_drv.h
41096 @@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41097 int is_pci;
41098 unsigned long cce_buffers_offset;
41099
41100 - atomic_t idle_count;
41101 + atomic_unchecked_t idle_count;
41102
41103 int page_flipping;
41104 int current_page;
41105 u32 crtc_offset;
41106 u32 crtc_offset_cntl;
41107
41108 - atomic_t vbl_received;
41109 + atomic_unchecked_t vbl_received;
41110
41111 u32 color_fmt;
41112 unsigned int front_offset;
41113 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41114 index 663f38c..c689495 100644
41115 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41116 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41117 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41118 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41119 }
41120
41121 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41122 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41123 [DRM_R128_INIT] = compat_r128_init,
41124 [DRM_R128_DEPTH] = compat_r128_depth,
41125 [DRM_R128_STIPPLE] = compat_r128_stipple,
41126 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41127 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41128 {
41129 unsigned int nr = DRM_IOCTL_NR(cmd);
41130 - drm_ioctl_compat_t *fn = NULL;
41131 int ret;
41132
41133 if (nr < DRM_COMMAND_BASE)
41134 return drm_compat_ioctl(filp, cmd, arg);
41135
41136 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41137 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41138 -
41139 - if (fn != NULL)
41140 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41141 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41142 ret = (*fn) (filp, cmd, arg);
41143 - else
41144 + } else
41145 ret = drm_ioctl(filp, cmd, arg);
41146
41147 return ret;
41148 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41149 index c2ae496..30b5993 100644
41150 --- a/drivers/gpu/drm/r128/r128_irq.c
41151 +++ b/drivers/gpu/drm/r128/r128_irq.c
41152 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41153 if (crtc != 0)
41154 return 0;
41155
41156 - return atomic_read(&dev_priv->vbl_received);
41157 + return atomic_read_unchecked(&dev_priv->vbl_received);
41158 }
41159
41160 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41161 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41162 /* VBLANK interrupt */
41163 if (status & R128_CRTC_VBLANK_INT) {
41164 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41165 - atomic_inc(&dev_priv->vbl_received);
41166 + atomic_inc_unchecked(&dev_priv->vbl_received);
41167 drm_handle_vblank(dev, 0);
41168 return IRQ_HANDLED;
41169 }
41170 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41171 index 575e986..66e62ca 100644
41172 --- a/drivers/gpu/drm/r128/r128_state.c
41173 +++ b/drivers/gpu/drm/r128/r128_state.c
41174 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41175
41176 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41177 {
41178 - if (atomic_read(&dev_priv->idle_count) == 0)
41179 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41180 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41181 else
41182 - atomic_set(&dev_priv->idle_count, 0);
41183 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41184 }
41185
41186 #endif
41187 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41188 index 4a85bb6..aaea819 100644
41189 --- a/drivers/gpu/drm/radeon/mkregtable.c
41190 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41191 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41192 regex_t mask_rex;
41193 regmatch_t match[4];
41194 char buf[1024];
41195 - size_t end;
41196 + long end;
41197 int len;
41198 int done = 0;
41199 int r;
41200 unsigned o;
41201 struct offset *offset;
41202 char last_reg_s[10];
41203 - int last_reg;
41204 + unsigned long last_reg;
41205
41206 if (regcomp
41207 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41208 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41209 index bdf263a..0305446 100644
41210 --- a/drivers/gpu/drm/radeon/radeon_device.c
41211 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41212 @@ -1216,7 +1216,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41213 * locking inversion with the driver load path. And the access here is
41214 * completely racy anyway. So don't bother with locking for now.
41215 */
41216 - return dev->open_count == 0;
41217 + return local_read(&dev->open_count) == 0;
41218 }
41219
41220 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41221 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41222 index 46bd393..6ae4719 100644
41223 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41224 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41225 @@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41226
41227 /* SW interrupt */
41228 wait_queue_head_t swi_queue;
41229 - atomic_t swi_emitted;
41230 + atomic_unchecked_t swi_emitted;
41231 int vblank_crtc;
41232 uint32_t irq_enable_reg;
41233 uint32_t r500_disp_irq_reg;
41234 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41235 index 0b98ea1..0881827 100644
41236 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41237 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41238 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41239 request = compat_alloc_user_space(sizeof(*request));
41240 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41241 || __put_user(req32.param, &request->param)
41242 - || __put_user((void __user *)(unsigned long)req32.value,
41243 + || __put_user((unsigned long)req32.value,
41244 &request->value))
41245 return -EFAULT;
41246
41247 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41248 #define compat_radeon_cp_setparam NULL
41249 #endif /* X86_64 || IA64 */
41250
41251 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41252 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41253 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41254 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41255 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41256 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41257 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41258 {
41259 unsigned int nr = DRM_IOCTL_NR(cmd);
41260 - drm_ioctl_compat_t *fn = NULL;
41261 int ret;
41262
41263 if (nr < DRM_COMMAND_BASE)
41264 return drm_compat_ioctl(filp, cmd, arg);
41265
41266 - if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41267 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41268 -
41269 - if (fn != NULL)
41270 + if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41271 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41272 ret = (*fn) (filp, cmd, arg);
41273 - else
41274 + } else
41275 ret = drm_ioctl(filp, cmd, arg);
41276
41277 return ret;
41278 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41279 index 244b19b..c19226d 100644
41280 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41281 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41282 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41283 unsigned int ret;
41284 RING_LOCALS;
41285
41286 - atomic_inc(&dev_priv->swi_emitted);
41287 - ret = atomic_read(&dev_priv->swi_emitted);
41288 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41289 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41290
41291 BEGIN_RING(4);
41292 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41293 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41294 drm_radeon_private_t *dev_priv =
41295 (drm_radeon_private_t *) dev->dev_private;
41296
41297 - atomic_set(&dev_priv->swi_emitted, 0);
41298 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41299 init_waitqueue_head(&dev_priv->swi_queue);
41300
41301 dev->max_vblank_count = 0x001fffff;
41302 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41303 index 535403e..5dd655b 100644
41304 --- a/drivers/gpu/drm/radeon/radeon_state.c
41305 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41306 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41307 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41308 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41309
41310 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41311 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41312 sarea_priv->nbox * sizeof(depth_boxes[0])))
41313 return -EFAULT;
41314
41315 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41316 {
41317 drm_radeon_private_t *dev_priv = dev->dev_private;
41318 drm_radeon_getparam_t *param = data;
41319 - int value;
41320 + int value = 0;
41321
41322 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41323
41324 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41325 index d2510cf..63bd4ed 100644
41326 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41327 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41328 @@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41329 man->size = size >> PAGE_SHIFT;
41330 }
41331
41332 -static struct vm_operations_struct radeon_ttm_vm_ops;
41333 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41334 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41335
41336 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41337 @@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41338 }
41339 if (unlikely(ttm_vm_ops == NULL)) {
41340 ttm_vm_ops = vma->vm_ops;
41341 + pax_open_kernel();
41342 radeon_ttm_vm_ops = *ttm_vm_ops;
41343 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41344 + pax_close_kernel();
41345 }
41346 vma->vm_ops = &radeon_ttm_vm_ops;
41347 return 0;
41348 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41349 index 054a79f..30d9ac4 100644
41350 --- a/drivers/gpu/drm/tegra/dc.c
41351 +++ b/drivers/gpu/drm/tegra/dc.c
41352 @@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41353 }
41354
41355 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41356 - dc->debugfs_files[i].data = dc;
41357 + *(void **)&dc->debugfs_files[i].data = dc;
41358
41359 err = drm_debugfs_create_files(dc->debugfs_files,
41360 ARRAY_SIZE(debugfs_files),
41361 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41362 index f787445..2df2c65 100644
41363 --- a/drivers/gpu/drm/tegra/dsi.c
41364 +++ b/drivers/gpu/drm/tegra/dsi.c
41365 @@ -41,7 +41,7 @@ struct tegra_dsi {
41366 struct clk *clk_lp;
41367 struct clk *clk;
41368
41369 - struct drm_info_list *debugfs_files;
41370 + drm_info_list_no_const *debugfs_files;
41371 struct drm_minor *minor;
41372 struct dentry *debugfs;
41373
41374 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41375 index ffe2654..03c7b1c 100644
41376 --- a/drivers/gpu/drm/tegra/hdmi.c
41377 +++ b/drivers/gpu/drm/tegra/hdmi.c
41378 @@ -60,7 +60,7 @@ struct tegra_hdmi {
41379 bool stereo;
41380 bool dvi;
41381
41382 - struct drm_info_list *debugfs_files;
41383 + drm_info_list_no_const *debugfs_files;
41384 struct drm_minor *minor;
41385 struct dentry *debugfs;
41386 };
41387 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41388 index 964387f..4eafc00 100644
41389 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41390 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41391 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41392 }
41393
41394 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41395 - ttm_bo_man_init,
41396 - ttm_bo_man_takedown,
41397 - ttm_bo_man_get_node,
41398 - ttm_bo_man_put_node,
41399 - ttm_bo_man_debug
41400 + .init = ttm_bo_man_init,
41401 + .takedown = ttm_bo_man_takedown,
41402 + .get_node = ttm_bo_man_get_node,
41403 + .put_node = ttm_bo_man_put_node,
41404 + .debug = ttm_bo_man_debug
41405 };
41406 EXPORT_SYMBOL(ttm_bo_manager_func);
41407 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41408 index a1803fb..c53f6b0 100644
41409 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41410 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41411 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41412 zone->glob = glob;
41413 glob->zone_kernel = zone;
41414 ret = kobject_init_and_add(
41415 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41416 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41417 if (unlikely(ret != 0)) {
41418 kobject_put(&zone->kobj);
41419 return ret;
41420 @@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41421 zone->glob = glob;
41422 glob->zone_dma32 = zone;
41423 ret = kobject_init_and_add(
41424 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41425 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41426 if (unlikely(ret != 0)) {
41427 kobject_put(&zone->kobj);
41428 return ret;
41429 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41430 index 025c429..314062f 100644
41431 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41432 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41433 @@ -54,7 +54,7 @@
41434
41435 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41436 #define SMALL_ALLOCATION 16
41437 -#define FREE_ALL_PAGES (~0U)
41438 +#define FREE_ALL_PAGES (~0UL)
41439 /* times are in msecs */
41440 #define PAGE_FREE_INTERVAL 1000
41441
41442 @@ -299,15 +299,14 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41443 * @free_all: If set to true will free all pages in pool
41444 * @use_static: Safe to use static buffer
41445 **/
41446 -static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41447 +static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41448 bool use_static)
41449 {
41450 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41451 unsigned long irq_flags;
41452 struct page *p;
41453 struct page **pages_to_free;
41454 - unsigned freed_pages = 0,
41455 - npages_to_free = nr_free;
41456 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41457
41458 if (NUM_PAGES_TO_ALLOC < nr_free)
41459 npages_to_free = NUM_PAGES_TO_ALLOC;
41460 @@ -371,7 +370,8 @@ restart:
41461 __list_del(&p->lru, &pool->list);
41462
41463 ttm_pool_update_free_locked(pool, freed_pages);
41464 - nr_free -= freed_pages;
41465 + if (likely(nr_free != FREE_ALL_PAGES))
41466 + nr_free -= freed_pages;
41467 }
41468
41469 spin_unlock_irqrestore(&pool->lock, irq_flags);
41470 @@ -399,7 +399,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41471 unsigned i;
41472 unsigned pool_offset;
41473 struct ttm_page_pool *pool;
41474 - int shrink_pages = sc->nr_to_scan;
41475 + unsigned long shrink_pages = sc->nr_to_scan;
41476 unsigned long freed = 0;
41477
41478 if (!mutex_trylock(&lock))
41479 @@ -407,7 +407,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41480 pool_offset = ++start_pool % NUM_POOLS;
41481 /* select start pool in round robin fashion */
41482 for (i = 0; i < NUM_POOLS; ++i) {
41483 - unsigned nr_free = shrink_pages;
41484 + unsigned long nr_free = shrink_pages;
41485 if (shrink_pages == 0)
41486 break;
41487 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41488 @@ -673,7 +673,7 @@ out:
41489 }
41490
41491 /* Put all pages in pages list to correct pool to wait for reuse */
41492 -static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41493 +static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41494 enum ttm_caching_state cstate)
41495 {
41496 unsigned long irq_flags;
41497 @@ -728,7 +728,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41498 struct list_head plist;
41499 struct page *p = NULL;
41500 gfp_t gfp_flags = GFP_USER;
41501 - unsigned count;
41502 + unsigned long count;
41503 int r;
41504
41505 /* set zero flag for page allocation if required */
41506 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41507 index 01e1d27..aaa018a 100644
41508 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41509 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41510 @@ -56,7 +56,7 @@
41511
41512 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41513 #define SMALL_ALLOCATION 4
41514 -#define FREE_ALL_PAGES (~0U)
41515 +#define FREE_ALL_PAGES (~0UL)
41516 /* times are in msecs */
41517 #define IS_UNDEFINED (0)
41518 #define IS_WC (1<<1)
41519 @@ -413,7 +413,7 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41520 * @nr_free: If set to true will free all pages in pool
41521 * @use_static: Safe to use static buffer
41522 **/
41523 -static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41524 +static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41525 bool use_static)
41526 {
41527 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
41528 @@ -421,8 +421,7 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41529 struct dma_page *dma_p, *tmp;
41530 struct page **pages_to_free;
41531 struct list_head d_pages;
41532 - unsigned freed_pages = 0,
41533 - npages_to_free = nr_free;
41534 + unsigned long freed_pages = 0, npages_to_free = nr_free;
41535
41536 if (NUM_PAGES_TO_ALLOC < nr_free)
41537 npages_to_free = NUM_PAGES_TO_ALLOC;
41538 @@ -499,7 +498,8 @@ restart:
41539 /* remove range of pages from the pool */
41540 if (freed_pages) {
41541 ttm_pool_update_free_locked(pool, freed_pages);
41542 - nr_free -= freed_pages;
41543 + if (likely(nr_free != FREE_ALL_PAGES))
41544 + nr_free -= freed_pages;
41545 }
41546
41547 spin_unlock_irqrestore(&pool->lock, irq_flags);
41548 @@ -936,7 +936,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41549 struct dma_page *d_page, *next;
41550 enum pool_type type;
41551 bool is_cached = false;
41552 - unsigned count = 0, i, npages = 0;
41553 + unsigned long count = 0, i, npages = 0;
41554 unsigned long irq_flags;
41555
41556 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41557 @@ -1012,7 +1012,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41558 static unsigned start_pool;
41559 unsigned idx = 0;
41560 unsigned pool_offset;
41561 - unsigned shrink_pages = sc->nr_to_scan;
41562 + unsigned long shrink_pages = sc->nr_to_scan;
41563 struct device_pools *p;
41564 unsigned long freed = 0;
41565
41566 @@ -1025,7 +1025,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41567 goto out;
41568 pool_offset = ++start_pool % _manager->npools;
41569 list_for_each_entry(p, &_manager->pools, pools) {
41570 - unsigned nr_free;
41571 + unsigned long nr_free;
41572
41573 if (!p->dev)
41574 continue;
41575 @@ -1039,7 +1039,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41576 shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
41577 freed += nr_free - shrink_pages;
41578
41579 - pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41580 + pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41581 p->pool->dev_name, p->pool->name, current->pid,
41582 nr_free, shrink_pages);
41583 }
41584 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41585 index 8cbcb45..a4d9cf7 100644
41586 --- a/drivers/gpu/drm/udl/udl_fb.c
41587 +++ b/drivers/gpu/drm/udl/udl_fb.c
41588 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41589 fb_deferred_io_cleanup(info);
41590 kfree(info->fbdefio);
41591 info->fbdefio = NULL;
41592 - info->fbops->fb_mmap = udl_fb_mmap;
41593 }
41594
41595 pr_warn("released /dev/fb%d user=%d count=%d\n",
41596 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41597 index ef8c500..01030c8 100644
41598 --- a/drivers/gpu/drm/via/via_drv.h
41599 +++ b/drivers/gpu/drm/via/via_drv.h
41600 @@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41601 typedef uint32_t maskarray_t[5];
41602
41603 typedef struct drm_via_irq {
41604 - atomic_t irq_received;
41605 + atomic_unchecked_t irq_received;
41606 uint32_t pending_mask;
41607 uint32_t enable_mask;
41608 wait_queue_head_t irq_queue;
41609 @@ -77,7 +77,7 @@ typedef struct drm_via_private {
41610 struct timeval last_vblank;
41611 int last_vblank_valid;
41612 unsigned usec_per_vblank;
41613 - atomic_t vbl_received;
41614 + atomic_unchecked_t vbl_received;
41615 drm_via_state_t hc_state;
41616 char pci_buf[VIA_PCI_BUF_SIZE];
41617 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41618 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41619 index 1319433..a993b0c 100644
41620 --- a/drivers/gpu/drm/via/via_irq.c
41621 +++ b/drivers/gpu/drm/via/via_irq.c
41622 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41623 if (crtc != 0)
41624 return 0;
41625
41626 - return atomic_read(&dev_priv->vbl_received);
41627 + return atomic_read_unchecked(&dev_priv->vbl_received);
41628 }
41629
41630 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41631 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41632
41633 status = VIA_READ(VIA_REG_INTERRUPT);
41634 if (status & VIA_IRQ_VBLANK_PENDING) {
41635 - atomic_inc(&dev_priv->vbl_received);
41636 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41637 + atomic_inc_unchecked(&dev_priv->vbl_received);
41638 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41639 do_gettimeofday(&cur_vblank);
41640 if (dev_priv->last_vblank_valid) {
41641 dev_priv->usec_per_vblank =
41642 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41643 dev_priv->last_vblank = cur_vblank;
41644 dev_priv->last_vblank_valid = 1;
41645 }
41646 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41647 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41648 DRM_DEBUG("US per vblank is: %u\n",
41649 dev_priv->usec_per_vblank);
41650 }
41651 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41652
41653 for (i = 0; i < dev_priv->num_irqs; ++i) {
41654 if (status & cur_irq->pending_mask) {
41655 - atomic_inc(&cur_irq->irq_received);
41656 + atomic_inc_unchecked(&cur_irq->irq_received);
41657 wake_up(&cur_irq->irq_queue);
41658 handled = 1;
41659 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41660 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41661 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41662 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41663 masks[irq][4]));
41664 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41665 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41666 } else {
41667 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41668 (((cur_irq_sequence =
41669 - atomic_read(&cur_irq->irq_received)) -
41670 + atomic_read_unchecked(&cur_irq->irq_received)) -
41671 *sequence) <= (1 << 23)));
41672 }
41673 *sequence = cur_irq_sequence;
41674 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41675 }
41676
41677 for (i = 0; i < dev_priv->num_irqs; ++i) {
41678 - atomic_set(&cur_irq->irq_received, 0);
41679 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41680 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41681 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41682 init_waitqueue_head(&cur_irq->irq_queue);
41683 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41684 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41685 case VIA_IRQ_RELATIVE:
41686 irqwait->request.sequence +=
41687 - atomic_read(&cur_irq->irq_received);
41688 + atomic_read_unchecked(&cur_irq->irq_received);
41689 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41690 case VIA_IRQ_ABSOLUTE:
41691 break;
41692 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41693 index d26a6da..5fa41ed 100644
41694 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41695 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41696 @@ -447,7 +447,7 @@ struct vmw_private {
41697 * Fencing and IRQs.
41698 */
41699
41700 - atomic_t marker_seq;
41701 + atomic_unchecked_t marker_seq;
41702 wait_queue_head_t fence_queue;
41703 wait_queue_head_t fifo_queue;
41704 spinlock_t waiter_lock;
41705 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41706 index 39f2b03..d1b0a64 100644
41707 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41708 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41709 @@ -152,7 +152,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41710 (unsigned int) min,
41711 (unsigned int) fifo->capabilities);
41712
41713 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41714 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41715 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41716 vmw_marker_queue_init(&fifo->marker_queue);
41717 return vmw_fifo_send_fence(dev_priv, &dummy);
41718 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41719 if (reserveable)
41720 iowrite32(bytes, fifo_mem +
41721 SVGA_FIFO_RESERVED);
41722 - return fifo_mem + (next_cmd >> 2);
41723 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41724 } else {
41725 need_bounce = true;
41726 }
41727 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41728
41729 fm = vmw_fifo_reserve(dev_priv, bytes);
41730 if (unlikely(fm == NULL)) {
41731 - *seqno = atomic_read(&dev_priv->marker_seq);
41732 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41733 ret = -ENOMEM;
41734 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41735 false, 3*HZ);
41736 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41737 }
41738
41739 do {
41740 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41741 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41742 } while (*seqno == 0);
41743
41744 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41745 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41746 index 170b61b..fec7348 100644
41747 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41748 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41749 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41750 }
41751
41752 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41753 - vmw_gmrid_man_init,
41754 - vmw_gmrid_man_takedown,
41755 - vmw_gmrid_man_get_node,
41756 - vmw_gmrid_man_put_node,
41757 - vmw_gmrid_man_debug
41758 + .init = vmw_gmrid_man_init,
41759 + .takedown = vmw_gmrid_man_takedown,
41760 + .get_node = vmw_gmrid_man_get_node,
41761 + .put_node = vmw_gmrid_man_put_node,
41762 + .debug = vmw_gmrid_man_debug
41763 };
41764 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41765 index 69c8ce2..cacb0ab 100644
41766 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41767 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41768 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41769 int ret;
41770
41771 num_clips = arg->num_clips;
41772 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41773 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41774
41775 if (unlikely(num_clips == 0))
41776 return 0;
41777 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41778 int ret;
41779
41780 num_clips = arg->num_clips;
41781 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41782 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41783
41784 if (unlikely(num_clips == 0))
41785 return 0;
41786 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41787 index 9fe9827..0aa2fc0 100644
41788 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41789 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41790 @@ -102,7 +102,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41791 * emitted. Then the fence is stale and signaled.
41792 */
41793
41794 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41795 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41796 > VMW_FENCE_WRAP);
41797
41798 return ret;
41799 @@ -133,7 +133,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41800
41801 if (fifo_idle)
41802 down_read(&fifo_state->rwsem);
41803 - signal_seq = atomic_read(&dev_priv->marker_seq);
41804 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41805 ret = 0;
41806
41807 for (;;) {
41808 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41809 index efd1ffd..0ae13ca 100644
41810 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41811 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41812 @@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41813 while (!vmw_lag_lt(queue, us)) {
41814 spin_lock(&queue->lock);
41815 if (list_empty(&queue->head))
41816 - seqno = atomic_read(&dev_priv->marker_seq);
41817 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41818 else {
41819 marker = list_first_entry(&queue->head,
41820 struct vmw_marker, head);
41821 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41822 index 37ac7b5..d52a5c9 100644
41823 --- a/drivers/gpu/vga/vga_switcheroo.c
41824 +++ b/drivers/gpu/vga/vga_switcheroo.c
41825 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41826
41827 /* this version is for the case where the power switch is separate
41828 to the device being powered down. */
41829 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41830 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41831 {
41832 /* copy over all the bus versions */
41833 if (dev->bus && dev->bus->pm) {
41834 @@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41835 return ret;
41836 }
41837
41838 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41839 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41840 {
41841 /* copy over all the bus versions */
41842 if (dev->bus && dev->bus->pm) {
41843 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41844 index dfaccfc..bfea740 100644
41845 --- a/drivers/hid/hid-core.c
41846 +++ b/drivers/hid/hid-core.c
41847 @@ -2507,7 +2507,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41848
41849 int hid_add_device(struct hid_device *hdev)
41850 {
41851 - static atomic_t id = ATOMIC_INIT(0);
41852 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41853 int ret;
41854
41855 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41856 @@ -2549,7 +2549,7 @@ int hid_add_device(struct hid_device *hdev)
41857 /* XXX hack, any other cleaner solution after the driver core
41858 * is converted to allow more than 20 bytes as the device name? */
41859 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41860 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41861 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41862
41863 hid_debug_register(hdev, dev_name(&hdev->dev));
41864 ret = device_add(&hdev->dev);
41865 diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41866 index 71f5692..147d3da 100644
41867 --- a/drivers/hid/hid-logitech-dj.c
41868 +++ b/drivers/hid/hid-logitech-dj.c
41869 @@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41870 * device (via hid_input_report() ) and return 1 so hid-core does not do
41871 * anything else with it.
41872 */
41873 + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41874 + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41875 + dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41876 + __func__, dj_report->device_index);
41877 + return false;
41878 + }
41879
41880 /* case 1) */
41881 if (data[0] != REPORT_ID_DJ_SHORT)
41882 diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41883 index bc4269e..b6e6102 100644
41884 --- a/drivers/hid/hid-sony.c
41885 +++ b/drivers/hid/hid-sony.c
41886 @@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41887 __u8 buf[36];
41888 };
41889
41890 +#define DS4_REPORT_0x02_SIZE 37
41891 +#define DS4_REPORT_0x05_SIZE 32
41892 +#define DS4_REPORT_0x11_SIZE 78
41893 +#define DS4_REPORT_0x81_SIZE 7
41894 +#define SIXAXIS_REPORT_0xF2_SIZE 18
41895 +
41896 static spinlock_t sony_dev_list_lock;
41897 static LIST_HEAD(sony_device_list);
41898 static DEFINE_IDA(sony_device_id_allocator);
41899 @@ -811,6 +817,7 @@ struct sony_sc {
41900 struct work_struct state_worker;
41901 struct power_supply battery;
41902 int device_id;
41903 + __u8 *output_report_dmabuf;
41904
41905 #ifdef CONFIG_SONY_FF
41906 __u8 left;
41907 @@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41908
41909 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41910 {
41911 - unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41912 - return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41913 + static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41914 + __u8 *buf;
41915 + int ret;
41916 +
41917 + buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41918 + if (!buf)
41919 + return -ENOMEM;
41920 +
41921 + ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41922 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41923 +
41924 + kfree(buf);
41925 +
41926 + return ret;
41927 }
41928
41929 /*
41930 @@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41931 */
41932 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41933 {
41934 - __u8 buf[37] = { 0 };
41935 + __u8 *buf;
41936 + int ret;
41937
41938 - return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41939 + buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41940 + if (!buf)
41941 + return -ENOMEM;
41942 +
41943 + ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41944 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41945 +
41946 + kfree(buf);
41947 +
41948 + return ret;
41949 }
41950
41951 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41952 @@ -1471,9 +1498,7 @@ error_leds:
41953
41954 static void sixaxis_state_worker(struct work_struct *work)
41955 {
41956 - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41957 - int n;
41958 - union sixaxis_output_report_01 report = {
41959 + static const union sixaxis_output_report_01 default_report = {
41960 .buf = {
41961 0x01,
41962 0x00, 0xff, 0x00, 0xff, 0x00,
41963 @@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41964 0x00, 0x00, 0x00, 0x00, 0x00
41965 }
41966 };
41967 + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41968 + struct sixaxis_output_report *report =
41969 + (struct sixaxis_output_report *)sc->output_report_dmabuf;
41970 + int n;
41971 +
41972 + /* Initialize the report with default values */
41973 + memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41974
41975 #ifdef CONFIG_SONY_FF
41976 - report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41977 - report.data.rumble.left_motor_force = sc->left;
41978 + report->rumble.right_motor_on = sc->right ? 1 : 0;
41979 + report->rumble.left_motor_force = sc->left;
41980 #endif
41981
41982 - report.data.leds_bitmap |= sc->led_state[0] << 1;
41983 - report.data.leds_bitmap |= sc->led_state[1] << 2;
41984 - report.data.leds_bitmap |= sc->led_state[2] << 3;
41985 - report.data.leds_bitmap |= sc->led_state[3] << 4;
41986 + report->leds_bitmap |= sc->led_state[0] << 1;
41987 + report->leds_bitmap |= sc->led_state[1] << 2;
41988 + report->leds_bitmap |= sc->led_state[2] << 3;
41989 + report->leds_bitmap |= sc->led_state[3] << 4;
41990
41991 /* Set flag for all leds off, required for 3rd party INTEC controller */
41992 - if ((report.data.leds_bitmap & 0x1E) == 0)
41993 - report.data.leds_bitmap |= 0x20;
41994 + if ((report->leds_bitmap & 0x1E) == 0)
41995 + report->leds_bitmap |= 0x20;
41996
41997 /*
41998 * The LEDs in the report are indexed in reverse order to their
41999 @@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
42000 */
42001 for (n = 0; n < 4; n++) {
42002 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
42003 - report.data.led[3 - n].duty_off = sc->led_delay_off[n];
42004 - report.data.led[3 - n].duty_on = sc->led_delay_on[n];
42005 + report->led[3 - n].duty_off = sc->led_delay_off[n];
42006 + report->led[3 - n].duty_on = sc->led_delay_on[n];
42007 }
42008 }
42009
42010 - hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
42011 - sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42012 + hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
42013 + sizeof(struct sixaxis_output_report),
42014 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42015 }
42016
42017 static void dualshock4_state_worker(struct work_struct *work)
42018 {
42019 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
42020 struct hid_device *hdev = sc->hdev;
42021 + __u8 *buf = sc->output_report_dmabuf;
42022 int offset;
42023
42024 - __u8 buf[78] = { 0 };
42025 -
42026 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42027 + memset(buf, 0, DS4_REPORT_0x05_SIZE);
42028 buf[0] = 0x05;
42029 buf[1] = 0xFF;
42030 offset = 4;
42031 } else {
42032 + memset(buf, 0, DS4_REPORT_0x11_SIZE);
42033 buf[0] = 0x11;
42034 buf[1] = 0xB0;
42035 buf[3] = 0x0F;
42036 @@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
42037 buf[offset++] = sc->led_delay_off[3];
42038
42039 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42040 - hid_hw_output_report(hdev, buf, 32);
42041 + hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42042 else
42043 - hid_hw_raw_request(hdev, 0x11, buf, 78,
42044 + hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42045 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42046 }
42047
42048 +static int sony_allocate_output_report(struct sony_sc *sc)
42049 +{
42050 + if (sc->quirks & SIXAXIS_CONTROLLER)
42051 + sc->output_report_dmabuf =
42052 + kmalloc(sizeof(union sixaxis_output_report_01),
42053 + GFP_KERNEL);
42054 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42055 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42056 + GFP_KERNEL);
42057 + else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42058 + sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42059 + GFP_KERNEL);
42060 + else
42061 + return 0;
42062 +
42063 + if (!sc->output_report_dmabuf)
42064 + return -ENOMEM;
42065 +
42066 + return 0;
42067 +}
42068 +
42069 #ifdef CONFIG_SONY_FF
42070 static int sony_play_effect(struct input_dev *dev, void *data,
42071 struct ff_effect *effect)
42072 @@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42073
42074 static int sony_check_add(struct sony_sc *sc)
42075 {
42076 + __u8 *buf = NULL;
42077 int n, ret;
42078
42079 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42080 @@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42081 return 0;
42082 }
42083 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42084 - __u8 buf[7];
42085 + buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42086 + if (!buf)
42087 + return -ENOMEM;
42088
42089 /*
42090 * The MAC address of a DS4 controller connected via USB can be
42091 * retrieved with feature report 0x81. The address begins at
42092 * offset 1.
42093 */
42094 - ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42095 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42096 + ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42097 + DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42098 + HID_REQ_GET_REPORT);
42099
42100 - if (ret != 7) {
42101 + if (ret != DS4_REPORT_0x81_SIZE) {
42102 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42103 - return ret < 0 ? ret : -EINVAL;
42104 + ret = ret < 0 ? ret : -EINVAL;
42105 + goto out_free;
42106 }
42107
42108 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42109 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42110 - __u8 buf[18];
42111 + buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42112 + if (!buf)
42113 + return -ENOMEM;
42114
42115 /*
42116 * The MAC address of a Sixaxis controller connected via USB can
42117 * be retrieved with feature report 0xf2. The address begins at
42118 * offset 4.
42119 */
42120 - ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42121 - HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42122 + ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42123 + SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42124 + HID_REQ_GET_REPORT);
42125
42126 - if (ret != 18) {
42127 + if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42128 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42129 - return ret < 0 ? ret : -EINVAL;
42130 + ret = ret < 0 ? ret : -EINVAL;
42131 + goto out_free;
42132 }
42133
42134 /*
42135 @@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42136 return 0;
42137 }
42138
42139 - return sony_check_add_dev_list(sc);
42140 + ret = sony_check_add_dev_list(sc);
42141 +
42142 +out_free:
42143 +
42144 + kfree(buf);
42145 +
42146 + return ret;
42147 }
42148
42149 static int sony_set_device_id(struct sony_sc *sc)
42150 @@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42151 return ret;
42152 }
42153
42154 + ret = sony_allocate_output_report(sc);
42155 + if (ret < 0) {
42156 + hid_err(hdev, "failed to allocate the output report buffer\n");
42157 + goto err_stop;
42158 + }
42159 +
42160 ret = sony_set_device_id(sc);
42161 if (ret < 0) {
42162 hid_err(hdev, "failed to allocate the device id\n");
42163 @@ -1984,6 +2060,7 @@ err_stop:
42164 if (sc->quirks & SONY_BATTERY_SUPPORT)
42165 sony_battery_remove(sc);
42166 sony_cancel_work_sync(sc);
42167 + kfree(sc->output_report_dmabuf);
42168 sony_remove_dev_list(sc);
42169 sony_release_device_id(sc);
42170 hid_hw_stop(hdev);
42171 @@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42172
42173 sony_cancel_work_sync(sc);
42174
42175 + kfree(sc->output_report_dmabuf);
42176 +
42177 sony_remove_dev_list(sc);
42178
42179 sony_release_device_id(sc);
42180 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42181 index c13fb5b..55a3802 100644
42182 --- a/drivers/hid/hid-wiimote-debug.c
42183 +++ b/drivers/hid/hid-wiimote-debug.c
42184 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42185 else if (size == 0)
42186 return -EIO;
42187
42188 - if (copy_to_user(u, buf, size))
42189 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
42190 return -EFAULT;
42191
42192 *off += size;
42193 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42194 index 433f72a..2926005 100644
42195 --- a/drivers/hv/channel.c
42196 +++ b/drivers/hv/channel.c
42197 @@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42198 unsigned long flags;
42199 int ret = 0;
42200
42201 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42202 - atomic_inc(&vmbus_connection.next_gpadl_handle);
42203 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42204 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42205
42206 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42207 if (ret)
42208 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42209 index 3e4235c..877d0e5 100644
42210 --- a/drivers/hv/hv.c
42211 +++ b/drivers/hv/hv.c
42212 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42213 u64 output_address = (output) ? virt_to_phys(output) : 0;
42214 u32 output_address_hi = output_address >> 32;
42215 u32 output_address_lo = output_address & 0xFFFFFFFF;
42216 - void *hypercall_page = hv_context.hypercall_page;
42217 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42218
42219 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42220 "=a"(hv_status_lo) : "d" (control_hi),
42221 @@ -156,7 +156,7 @@ int hv_init(void)
42222 /* See if the hypercall page is already set */
42223 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42224
42225 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42226 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42227
42228 if (!virtaddr)
42229 goto cleanup;
42230 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42231 index 5e90c5d..d8fcefb 100644
42232 --- a/drivers/hv/hv_balloon.c
42233 +++ b/drivers/hv/hv_balloon.c
42234 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42235
42236 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42237 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42238 -static atomic_t trans_id = ATOMIC_INIT(0);
42239 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42240
42241 static int dm_ring_size = (5 * PAGE_SIZE);
42242
42243 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42244 pr_info("Memory hot add failed\n");
42245
42246 dm->state = DM_INITIALIZED;
42247 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42248 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42249 vmbus_sendpacket(dm->dev->channel, &resp,
42250 sizeof(struct dm_hot_add_response),
42251 (unsigned long)NULL,
42252 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42253 memset(&status, 0, sizeof(struct dm_status));
42254 status.hdr.type = DM_STATUS_REPORT;
42255 status.hdr.size = sizeof(struct dm_status);
42256 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42257 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42258
42259 /*
42260 * The host expects the guest to report free memory.
42261 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42262 * send the status. This can happen if we were interrupted
42263 * after we picked our transaction ID.
42264 */
42265 - if (status.hdr.trans_id != atomic_read(&trans_id))
42266 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42267 return;
42268
42269 /*
42270 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42271 */
42272
42273 do {
42274 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42275 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42276 ret = vmbus_sendpacket(dm_device.dev->channel,
42277 bl_resp,
42278 bl_resp->hdr.size,
42279 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42280
42281 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42282 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42283 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42284 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42285 resp.hdr.size = sizeof(struct dm_unballoon_response);
42286
42287 vmbus_sendpacket(dm_device.dev->channel, &resp,
42288 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42289 memset(&version_req, 0, sizeof(struct dm_version_request));
42290 version_req.hdr.type = DM_VERSION_REQUEST;
42291 version_req.hdr.size = sizeof(struct dm_version_request);
42292 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42293 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42294 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42295 version_req.is_last_attempt = 1;
42296
42297 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42298 memset(&version_req, 0, sizeof(struct dm_version_request));
42299 version_req.hdr.type = DM_VERSION_REQUEST;
42300 version_req.hdr.size = sizeof(struct dm_version_request);
42301 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42302 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42303 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42304 version_req.is_last_attempt = 0;
42305
42306 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42307 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42308 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42309 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42310 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42311 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42312
42313 cap_msg.caps.cap_bits.balloon = 1;
42314 cap_msg.caps.cap_bits.hot_add = 1;
42315 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42316 index c386d8d..d6004c4 100644
42317 --- a/drivers/hv/hyperv_vmbus.h
42318 +++ b/drivers/hv/hyperv_vmbus.h
42319 @@ -611,7 +611,7 @@ enum vmbus_connect_state {
42320 struct vmbus_connection {
42321 enum vmbus_connect_state conn_state;
42322
42323 - atomic_t next_gpadl_handle;
42324 + atomic_unchecked_t next_gpadl_handle;
42325
42326 /*
42327 * Represents channel interrupts. Each bit position represents a
42328 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42329 index 4d6b269..2e23b86 100644
42330 --- a/drivers/hv/vmbus_drv.c
42331 +++ b/drivers/hv/vmbus_drv.c
42332 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42333 {
42334 int ret = 0;
42335
42336 - static atomic_t device_num = ATOMIC_INIT(0);
42337 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42338
42339 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42340 - atomic_inc_return(&device_num));
42341 + atomic_inc_return_unchecked(&device_num));
42342
42343 child_device_obj->device.bus = &hv_bus;
42344 child_device_obj->device.parent = &hv_acpi_dev->dev;
42345 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42346 index 579bdf9..75118b5 100644
42347 --- a/drivers/hwmon/acpi_power_meter.c
42348 +++ b/drivers/hwmon/acpi_power_meter.c
42349 @@ -116,7 +116,7 @@ struct sensor_template {
42350 struct device_attribute *devattr,
42351 const char *buf, size_t count);
42352 int index;
42353 -};
42354 +} __do_const;
42355
42356 /* Averaging interval */
42357 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42358 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42359 struct sensor_template *attrs)
42360 {
42361 struct device *dev = &resource->acpi_dev->dev;
42362 - struct sensor_device_attribute *sensors =
42363 + sensor_device_attribute_no_const *sensors =
42364 &resource->sensors[resource->num_sensors];
42365 int res = 0;
42366
42367 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42368 index 3288f13..71cfb4e 100644
42369 --- a/drivers/hwmon/applesmc.c
42370 +++ b/drivers/hwmon/applesmc.c
42371 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42372 {
42373 struct applesmc_node_group *grp;
42374 struct applesmc_dev_attr *node;
42375 - struct attribute *attr;
42376 + attribute_no_const *attr;
42377 int ret, i;
42378
42379 for (grp = groups; grp->format; grp++) {
42380 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42381 index cccef87..06ce8ec 100644
42382 --- a/drivers/hwmon/asus_atk0110.c
42383 +++ b/drivers/hwmon/asus_atk0110.c
42384 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42385 struct atk_sensor_data {
42386 struct list_head list;
42387 struct atk_data *data;
42388 - struct device_attribute label_attr;
42389 - struct device_attribute input_attr;
42390 - struct device_attribute limit1_attr;
42391 - struct device_attribute limit2_attr;
42392 + device_attribute_no_const label_attr;
42393 + device_attribute_no_const input_attr;
42394 + device_attribute_no_const limit1_attr;
42395 + device_attribute_no_const limit2_attr;
42396 char label_attr_name[ATTR_NAME_SIZE];
42397 char input_attr_name[ATTR_NAME_SIZE];
42398 char limit1_attr_name[ATTR_NAME_SIZE];
42399 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42400 static struct device_attribute atk_name_attr =
42401 __ATTR(name, 0444, atk_name_show, NULL);
42402
42403 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42404 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42405 sysfs_show_func show)
42406 {
42407 sysfs_attr_init(&attr->attr);
42408 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42409 index d76f0b7..55ae976 100644
42410 --- a/drivers/hwmon/coretemp.c
42411 +++ b/drivers/hwmon/coretemp.c
42412 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42413 return NOTIFY_OK;
42414 }
42415
42416 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42417 +static struct notifier_block coretemp_cpu_notifier = {
42418 .notifier_call = coretemp_cpu_callback,
42419 };
42420
42421 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42422 index 7a8a6fb..015c1fd 100644
42423 --- a/drivers/hwmon/ibmaem.c
42424 +++ b/drivers/hwmon/ibmaem.c
42425 @@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42426 struct aem_rw_sensor_template *rw)
42427 {
42428 struct device *dev = &data->pdev->dev;
42429 - struct sensor_device_attribute *sensors = data->sensors;
42430 + sensor_device_attribute_no_const *sensors = data->sensors;
42431 int err;
42432
42433 /* Set up read-only sensors */
42434 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42435 index 14c82da..09b25d7 100644
42436 --- a/drivers/hwmon/iio_hwmon.c
42437 +++ b/drivers/hwmon/iio_hwmon.c
42438 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42439 {
42440 struct device *dev = &pdev->dev;
42441 struct iio_hwmon_state *st;
42442 - struct sensor_device_attribute *a;
42443 + sensor_device_attribute_no_const *a;
42444 int ret, i;
42445 int in_i = 1, temp_i = 1, curr_i = 1;
42446 enum iio_chan_type type;
42447 diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42448 index 7710f46..427a28d 100644
42449 --- a/drivers/hwmon/nct6683.c
42450 +++ b/drivers/hwmon/nct6683.c
42451 @@ -397,11 +397,11 @@ static struct attribute_group *
42452 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42453 int repeat)
42454 {
42455 - struct sensor_device_attribute_2 *a2;
42456 - struct sensor_device_attribute *a;
42457 + sensor_device_attribute_2_no_const *a2;
42458 + sensor_device_attribute_no_const *a;
42459 struct sensor_device_template **t;
42460 struct sensor_device_attr_u *su;
42461 - struct attribute_group *group;
42462 + attribute_group_no_const *group;
42463 struct attribute **attrs;
42464 int i, j, count;
42465
42466 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42467 index 504cbdd..35d6f25 100644
42468 --- a/drivers/hwmon/nct6775.c
42469 +++ b/drivers/hwmon/nct6775.c
42470 @@ -943,10 +943,10 @@ static struct attribute_group *
42471 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42472 int repeat)
42473 {
42474 - struct attribute_group *group;
42475 + attribute_group_no_const *group;
42476 struct sensor_device_attr_u *su;
42477 - struct sensor_device_attribute *a;
42478 - struct sensor_device_attribute_2 *a2;
42479 + sensor_device_attribute_no_const *a;
42480 + sensor_device_attribute_2_no_const *a2;
42481 struct attribute **attrs;
42482 struct sensor_device_template **t;
42483 int i, count;
42484 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42485 index 291d11f..3f0dbbd 100644
42486 --- a/drivers/hwmon/pmbus/pmbus_core.c
42487 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42488 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42489 return 0;
42490 }
42491
42492 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42493 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42494 const char *name,
42495 umode_t mode,
42496 ssize_t (*show)(struct device *dev,
42497 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42498 dev_attr->store = store;
42499 }
42500
42501 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42502 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42503 const char *name,
42504 umode_t mode,
42505 ssize_t (*show)(struct device *dev,
42506 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42507 u16 reg, u8 mask)
42508 {
42509 struct pmbus_boolean *boolean;
42510 - struct sensor_device_attribute *a;
42511 + sensor_device_attribute_no_const *a;
42512
42513 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42514 if (!boolean)
42515 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42516 bool update, bool readonly)
42517 {
42518 struct pmbus_sensor *sensor;
42519 - struct device_attribute *a;
42520 + device_attribute_no_const *a;
42521
42522 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42523 if (!sensor)
42524 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42525 const char *lstring, int index)
42526 {
42527 struct pmbus_label *label;
42528 - struct device_attribute *a;
42529 + device_attribute_no_const *a;
42530
42531 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42532 if (!label)
42533 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42534 index 97cd45a..ac54d8b 100644
42535 --- a/drivers/hwmon/sht15.c
42536 +++ b/drivers/hwmon/sht15.c
42537 @@ -169,7 +169,7 @@ struct sht15_data {
42538 int supply_uv;
42539 bool supply_uv_valid;
42540 struct work_struct update_supply_work;
42541 - atomic_t interrupt_handled;
42542 + atomic_unchecked_t interrupt_handled;
42543 };
42544
42545 /**
42546 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42547 ret = gpio_direction_input(data->pdata->gpio_data);
42548 if (ret)
42549 return ret;
42550 - atomic_set(&data->interrupt_handled, 0);
42551 + atomic_set_unchecked(&data->interrupt_handled, 0);
42552
42553 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42554 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42555 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42556 /* Only relevant if the interrupt hasn't occurred. */
42557 - if (!atomic_read(&data->interrupt_handled))
42558 + if (!atomic_read_unchecked(&data->interrupt_handled))
42559 schedule_work(&data->read_work);
42560 }
42561 ret = wait_event_timeout(data->wait_queue,
42562 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42563
42564 /* First disable the interrupt */
42565 disable_irq_nosync(irq);
42566 - atomic_inc(&data->interrupt_handled);
42567 + atomic_inc_unchecked(&data->interrupt_handled);
42568 /* Then schedule a reading work struct */
42569 if (data->state != SHT15_READING_NOTHING)
42570 schedule_work(&data->read_work);
42571 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42572 * If not, then start the interrupt again - care here as could
42573 * have gone low in meantime so verify it hasn't!
42574 */
42575 - atomic_set(&data->interrupt_handled, 0);
42576 + atomic_set_unchecked(&data->interrupt_handled, 0);
42577 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42578 /* If still not occurred or another handler was scheduled */
42579 if (gpio_get_value(data->pdata->gpio_data)
42580 - || atomic_read(&data->interrupt_handled))
42581 + || atomic_read_unchecked(&data->interrupt_handled))
42582 return;
42583 }
42584
42585 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42586 index 8df43c5..b07b91d 100644
42587 --- a/drivers/hwmon/via-cputemp.c
42588 +++ b/drivers/hwmon/via-cputemp.c
42589 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42590 return NOTIFY_OK;
42591 }
42592
42593 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42594 +static struct notifier_block via_cputemp_cpu_notifier = {
42595 .notifier_call = via_cputemp_cpu_callback,
42596 };
42597
42598 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42599 index 65e3240..e6c511d 100644
42600 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42601 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42602 @@ -39,7 +39,7 @@
42603 extern struct i2c_adapter amd756_smbus;
42604
42605 static struct i2c_adapter *s4882_adapter;
42606 -static struct i2c_algorithm *s4882_algo;
42607 +static i2c_algorithm_no_const *s4882_algo;
42608
42609 /* Wrapper access functions for multiplexed SMBus */
42610 static DEFINE_MUTEX(amd756_lock);
42611 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42612 index b19a310..d6eece0 100644
42613 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42614 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42615 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42616 /* usb layer */
42617
42618 /* Send command to device, and get response. */
42619 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42620 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42621 {
42622 int ret = 0;
42623 int actual;
42624 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42625 index 88eda09..cf40434 100644
42626 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42627 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42628 @@ -37,7 +37,7 @@
42629 extern struct i2c_adapter *nforce2_smbus;
42630
42631 static struct i2c_adapter *s4985_adapter;
42632 -static struct i2c_algorithm *s4985_algo;
42633 +static i2c_algorithm_no_const *s4985_algo;
42634
42635 /* Wrapper access functions for multiplexed SMBus */
42636 static DEFINE_MUTEX(nforce2_lock);
42637 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42638 index 71c7a39..71dd3e0 100644
42639 --- a/drivers/i2c/i2c-dev.c
42640 +++ b/drivers/i2c/i2c-dev.c
42641 @@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42642 break;
42643 }
42644
42645 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42646 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42647 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42648 if (IS_ERR(rdwr_pa[i].buf)) {
42649 res = PTR_ERR(rdwr_pa[i].buf);
42650 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42651 index 0b510ba..4fbb5085 100644
42652 --- a/drivers/ide/ide-cd.c
42653 +++ b/drivers/ide/ide-cd.c
42654 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42655 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42656 if ((unsigned long)buf & alignment
42657 || blk_rq_bytes(rq) & q->dma_pad_mask
42658 - || object_is_on_stack(buf))
42659 + || object_starts_on_stack(buf))
42660 drive->dma = 0;
42661 }
42662 }
42663 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42664 index af3e76d..96dfe5e 100644
42665 --- a/drivers/iio/industrialio-core.c
42666 +++ b/drivers/iio/industrialio-core.c
42667 @@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42668 }
42669
42670 static
42671 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42672 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42673 const char *postfix,
42674 struct iio_chan_spec const *chan,
42675 ssize_t (*readfunc)(struct device *dev,
42676 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42677 index e28a494..f7c2671 100644
42678 --- a/drivers/infiniband/core/cm.c
42679 +++ b/drivers/infiniband/core/cm.c
42680 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42681
42682 struct cm_counter_group {
42683 struct kobject obj;
42684 - atomic_long_t counter[CM_ATTR_COUNT];
42685 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42686 };
42687
42688 struct cm_counter_attribute {
42689 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42690 struct ib_mad_send_buf *msg = NULL;
42691 int ret;
42692
42693 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42694 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42695 counter[CM_REQ_COUNTER]);
42696
42697 /* Quick state check to discard duplicate REQs. */
42698 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42699 if (!cm_id_priv)
42700 return;
42701
42702 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42703 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42704 counter[CM_REP_COUNTER]);
42705 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42706 if (ret)
42707 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42708 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42709 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42710 spin_unlock_irq(&cm_id_priv->lock);
42711 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42712 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42713 counter[CM_RTU_COUNTER]);
42714 goto out;
42715 }
42716 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42717 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42718 dreq_msg->local_comm_id);
42719 if (!cm_id_priv) {
42720 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42721 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42722 counter[CM_DREQ_COUNTER]);
42723 cm_issue_drep(work->port, work->mad_recv_wc);
42724 return -EINVAL;
42725 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42726 case IB_CM_MRA_REP_RCVD:
42727 break;
42728 case IB_CM_TIMEWAIT:
42729 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42730 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42731 counter[CM_DREQ_COUNTER]);
42732 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42733 goto unlock;
42734 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42735 cm_free_msg(msg);
42736 goto deref;
42737 case IB_CM_DREQ_RCVD:
42738 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42739 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42740 counter[CM_DREQ_COUNTER]);
42741 goto unlock;
42742 default:
42743 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42744 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42745 cm_id_priv->msg, timeout)) {
42746 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42747 - atomic_long_inc(&work->port->
42748 + atomic_long_inc_unchecked(&work->port->
42749 counter_group[CM_RECV_DUPLICATES].
42750 counter[CM_MRA_COUNTER]);
42751 goto out;
42752 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42753 break;
42754 case IB_CM_MRA_REQ_RCVD:
42755 case IB_CM_MRA_REP_RCVD:
42756 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42757 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42758 counter[CM_MRA_COUNTER]);
42759 /* fall through */
42760 default:
42761 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42762 case IB_CM_LAP_IDLE:
42763 break;
42764 case IB_CM_MRA_LAP_SENT:
42765 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42766 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42767 counter[CM_LAP_COUNTER]);
42768 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42769 goto unlock;
42770 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42771 cm_free_msg(msg);
42772 goto deref;
42773 case IB_CM_LAP_RCVD:
42774 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42775 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42776 counter[CM_LAP_COUNTER]);
42777 goto unlock;
42778 default:
42779 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42780 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42781 if (cur_cm_id_priv) {
42782 spin_unlock_irq(&cm.lock);
42783 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42784 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42785 counter[CM_SIDR_REQ_COUNTER]);
42786 goto out; /* Duplicate message. */
42787 }
42788 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42789 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42790 msg->retries = 1;
42791
42792 - atomic_long_add(1 + msg->retries,
42793 + atomic_long_add_unchecked(1 + msg->retries,
42794 &port->counter_group[CM_XMIT].counter[attr_index]);
42795 if (msg->retries)
42796 - atomic_long_add(msg->retries,
42797 + atomic_long_add_unchecked(msg->retries,
42798 &port->counter_group[CM_XMIT_RETRIES].
42799 counter[attr_index]);
42800
42801 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42802 }
42803
42804 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42805 - atomic_long_inc(&port->counter_group[CM_RECV].
42806 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42807 counter[attr_id - CM_ATTR_ID_OFFSET]);
42808
42809 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42810 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42811 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42812
42813 return sprintf(buf, "%ld\n",
42814 - atomic_long_read(&group->counter[cm_attr->index]));
42815 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42816 }
42817
42818 static const struct sysfs_ops cm_counter_ops = {
42819 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42820 index 9f5ad7c..588cd84 100644
42821 --- a/drivers/infiniband/core/fmr_pool.c
42822 +++ b/drivers/infiniband/core/fmr_pool.c
42823 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42824
42825 struct task_struct *thread;
42826
42827 - atomic_t req_ser;
42828 - atomic_t flush_ser;
42829 + atomic_unchecked_t req_ser;
42830 + atomic_unchecked_t flush_ser;
42831
42832 wait_queue_head_t force_wait;
42833 };
42834 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42835 struct ib_fmr_pool *pool = pool_ptr;
42836
42837 do {
42838 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42839 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42840 ib_fmr_batch_release(pool);
42841
42842 - atomic_inc(&pool->flush_ser);
42843 + atomic_inc_unchecked(&pool->flush_ser);
42844 wake_up_interruptible(&pool->force_wait);
42845
42846 if (pool->flush_function)
42847 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42848 }
42849
42850 set_current_state(TASK_INTERRUPTIBLE);
42851 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42852 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42853 !kthread_should_stop())
42854 schedule();
42855 __set_current_state(TASK_RUNNING);
42856 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42857 pool->dirty_watermark = params->dirty_watermark;
42858 pool->dirty_len = 0;
42859 spin_lock_init(&pool->pool_lock);
42860 - atomic_set(&pool->req_ser, 0);
42861 - atomic_set(&pool->flush_ser, 0);
42862 + atomic_set_unchecked(&pool->req_ser, 0);
42863 + atomic_set_unchecked(&pool->flush_ser, 0);
42864 init_waitqueue_head(&pool->force_wait);
42865
42866 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42867 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42868 }
42869 spin_unlock_irq(&pool->pool_lock);
42870
42871 - serial = atomic_inc_return(&pool->req_ser);
42872 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42873 wake_up_process(pool->thread);
42874
42875 if (wait_event_interruptible(pool->force_wait,
42876 - atomic_read(&pool->flush_ser) - serial >= 0))
42877 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42878 return -EINTR;
42879
42880 return 0;
42881 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42882 } else {
42883 list_add_tail(&fmr->list, &pool->dirty_list);
42884 if (++pool->dirty_len >= pool->dirty_watermark) {
42885 - atomic_inc(&pool->req_ser);
42886 + atomic_inc_unchecked(&pool->req_ser);
42887 wake_up_process(pool->thread);
42888 }
42889 }
42890 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42891 index ec7a298..8742e59 100644
42892 --- a/drivers/infiniband/hw/cxgb4/mem.c
42893 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42894 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42895 int err;
42896 struct fw_ri_tpte tpt;
42897 u32 stag_idx;
42898 - static atomic_t key;
42899 + static atomic_unchecked_t key;
42900
42901 if (c4iw_fatal_error(rdev))
42902 return -EIO;
42903 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42904 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42905 rdev->stats.stag.max = rdev->stats.stag.cur;
42906 mutex_unlock(&rdev->stats.lock);
42907 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42908 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42909 }
42910 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42911 __func__, stag_state, type, pdid, stag_idx);
42912 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42913 index 79b3dbc..96e5fcc 100644
42914 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42915 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42916 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42917 struct ib_atomic_eth *ateth;
42918 struct ipath_ack_entry *e;
42919 u64 vaddr;
42920 - atomic64_t *maddr;
42921 + atomic64_unchecked_t *maddr;
42922 u64 sdata;
42923 u32 rkey;
42924 u8 next;
42925 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42926 IB_ACCESS_REMOTE_ATOMIC)))
42927 goto nack_acc_unlck;
42928 /* Perform atomic OP and save result. */
42929 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42930 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42931 sdata = be64_to_cpu(ateth->swap_data);
42932 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42933 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42934 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42935 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42936 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42937 be64_to_cpu(ateth->compare_data),
42938 sdata);
42939 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42940 index 1f95bba..9530f87 100644
42941 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42942 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42943 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42944 unsigned long flags;
42945 struct ib_wc wc;
42946 u64 sdata;
42947 - atomic64_t *maddr;
42948 + atomic64_unchecked_t *maddr;
42949 enum ib_wc_status send_status;
42950
42951 /*
42952 @@ -382,11 +382,11 @@ again:
42953 IB_ACCESS_REMOTE_ATOMIC)))
42954 goto acc_err;
42955 /* Perform atomic OP and save result. */
42956 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42957 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42958 sdata = wqe->wr.wr.atomic.compare_add;
42959 *(u64 *) sqp->s_sge.sge.vaddr =
42960 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42961 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42962 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42963 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42964 sdata, wqe->wr.wr.atomic.swap);
42965 goto send_comp;
42966 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42967 index 82a7dd8..8fb6ba6 100644
42968 --- a/drivers/infiniband/hw/mlx4/mad.c
42969 +++ b/drivers/infiniband/hw/mlx4/mad.c
42970 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42971
42972 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42973 {
42974 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42975 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42976 cpu_to_be64(0xff00000000000000LL);
42977 }
42978
42979 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42980 index ed327e6..ca1739e0 100644
42981 --- a/drivers/infiniband/hw/mlx4/mcg.c
42982 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42983 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42984 {
42985 char name[20];
42986
42987 - atomic_set(&ctx->tid, 0);
42988 + atomic_set_unchecked(&ctx->tid, 0);
42989 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42990 ctx->mcg_wq = create_singlethread_workqueue(name);
42991 if (!ctx->mcg_wq)
42992 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42993 index 6eb743f..a7b0f6d 100644
42994 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42995 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42996 @@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42997 struct list_head mcg_mgid0_list;
42998 struct workqueue_struct *mcg_wq;
42999 struct mlx4_ib_demux_pv_ctx **tun;
43000 - atomic_t tid;
43001 + atomic_unchecked_t tid;
43002 int flushing; /* flushing the work queue */
43003 };
43004
43005 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43006 index 9d3e5c1..6f166df 100644
43007 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43008 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43009 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43010 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43011 }
43012
43013 -int mthca_QUERY_FW(struct mthca_dev *dev)
43014 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43015 {
43016 struct mthca_mailbox *mailbox;
43017 u32 *outbox;
43018 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43019 CMD_TIME_CLASS_B);
43020 }
43021
43022 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43023 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43024 int num_mtt)
43025 {
43026 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43027 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43028 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43029 }
43030
43031 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43032 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43033 int eq_num)
43034 {
43035 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43036 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43037 CMD_TIME_CLASS_B);
43038 }
43039
43040 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43041 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43042 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43043 void *in_mad, void *response_mad)
43044 {
43045 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43046 index ded76c1..0cf0a08 100644
43047 --- a/drivers/infiniband/hw/mthca/mthca_main.c
43048 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
43049 @@ -692,7 +692,7 @@ err_close:
43050 return err;
43051 }
43052
43053 -static int mthca_setup_hca(struct mthca_dev *dev)
43054 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43055 {
43056 int err;
43057
43058 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43059 index ed9a989..6aa5dc2 100644
43060 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
43061 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43062 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43063 * through the bitmaps)
43064 */
43065
43066 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43067 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43068 {
43069 int o;
43070 int m;
43071 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43072 return key;
43073 }
43074
43075 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43076 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43077 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43078 {
43079 struct mthca_mailbox *mailbox;
43080 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43081 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43082 }
43083
43084 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43085 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43086 u64 *buffer_list, int buffer_size_shift,
43087 int list_len, u64 iova, u64 total_size,
43088 u32 access, struct mthca_mr *mr)
43089 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43090 index 415f8e1..e34214e 100644
43091 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
43092 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43093 @@ -764,7 +764,7 @@ unlock:
43094 return 0;
43095 }
43096
43097 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43098 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43099 {
43100 struct mthca_dev *dev = to_mdev(ibcq->device);
43101 struct mthca_cq *cq = to_mcq(ibcq);
43102 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43103 index 3b2a6dc..bce26ff 100644
43104 --- a/drivers/infiniband/hw/nes/nes.c
43105 +++ b/drivers/infiniband/hw/nes/nes.c
43106 @@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43107 LIST_HEAD(nes_adapter_list);
43108 static LIST_HEAD(nes_dev_list);
43109
43110 -atomic_t qps_destroyed;
43111 +atomic_unchecked_t qps_destroyed;
43112
43113 static unsigned int ee_flsh_adapter;
43114 static unsigned int sysfs_nonidx_addr;
43115 @@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43116 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43117 struct nes_adapter *nesadapter = nesdev->nesadapter;
43118
43119 - atomic_inc(&qps_destroyed);
43120 + atomic_inc_unchecked(&qps_destroyed);
43121
43122 /* Free the control structures */
43123
43124 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43125 index bd9d132..70d84f4 100644
43126 --- a/drivers/infiniband/hw/nes/nes.h
43127 +++ b/drivers/infiniband/hw/nes/nes.h
43128 @@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43129 extern unsigned int wqm_quanta;
43130 extern struct list_head nes_adapter_list;
43131
43132 -extern atomic_t cm_connects;
43133 -extern atomic_t cm_accepts;
43134 -extern atomic_t cm_disconnects;
43135 -extern atomic_t cm_closes;
43136 -extern atomic_t cm_connecteds;
43137 -extern atomic_t cm_connect_reqs;
43138 -extern atomic_t cm_rejects;
43139 -extern atomic_t mod_qp_timouts;
43140 -extern atomic_t qps_created;
43141 -extern atomic_t qps_destroyed;
43142 -extern atomic_t sw_qps_destroyed;
43143 +extern atomic_unchecked_t cm_connects;
43144 +extern atomic_unchecked_t cm_accepts;
43145 +extern atomic_unchecked_t cm_disconnects;
43146 +extern atomic_unchecked_t cm_closes;
43147 +extern atomic_unchecked_t cm_connecteds;
43148 +extern atomic_unchecked_t cm_connect_reqs;
43149 +extern atomic_unchecked_t cm_rejects;
43150 +extern atomic_unchecked_t mod_qp_timouts;
43151 +extern atomic_unchecked_t qps_created;
43152 +extern atomic_unchecked_t qps_destroyed;
43153 +extern atomic_unchecked_t sw_qps_destroyed;
43154 extern u32 mh_detected;
43155 extern u32 mh_pauses_sent;
43156 extern u32 cm_packets_sent;
43157 @@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43158 extern u32 cm_packets_received;
43159 extern u32 cm_packets_dropped;
43160 extern u32 cm_packets_retrans;
43161 -extern atomic_t cm_listens_created;
43162 -extern atomic_t cm_listens_destroyed;
43163 +extern atomic_unchecked_t cm_listens_created;
43164 +extern atomic_unchecked_t cm_listens_destroyed;
43165 extern u32 cm_backlog_drops;
43166 -extern atomic_t cm_loopbacks;
43167 -extern atomic_t cm_nodes_created;
43168 -extern atomic_t cm_nodes_destroyed;
43169 -extern atomic_t cm_accel_dropped_pkts;
43170 -extern atomic_t cm_resets_recvd;
43171 -extern atomic_t pau_qps_created;
43172 -extern atomic_t pau_qps_destroyed;
43173 +extern atomic_unchecked_t cm_loopbacks;
43174 +extern atomic_unchecked_t cm_nodes_created;
43175 +extern atomic_unchecked_t cm_nodes_destroyed;
43176 +extern atomic_unchecked_t cm_accel_dropped_pkts;
43177 +extern atomic_unchecked_t cm_resets_recvd;
43178 +extern atomic_unchecked_t pau_qps_created;
43179 +extern atomic_unchecked_t pau_qps_destroyed;
43180
43181 extern u32 int_mod_timer_init;
43182 extern u32 int_mod_cq_depth_256;
43183 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43184 index 6f09a72..cf4399d 100644
43185 --- a/drivers/infiniband/hw/nes/nes_cm.c
43186 +++ b/drivers/infiniband/hw/nes/nes_cm.c
43187 @@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43188 u32 cm_packets_retrans;
43189 u32 cm_packets_created;
43190 u32 cm_packets_received;
43191 -atomic_t cm_listens_created;
43192 -atomic_t cm_listens_destroyed;
43193 +atomic_unchecked_t cm_listens_created;
43194 +atomic_unchecked_t cm_listens_destroyed;
43195 u32 cm_backlog_drops;
43196 -atomic_t cm_loopbacks;
43197 -atomic_t cm_nodes_created;
43198 -atomic_t cm_nodes_destroyed;
43199 -atomic_t cm_accel_dropped_pkts;
43200 -atomic_t cm_resets_recvd;
43201 +atomic_unchecked_t cm_loopbacks;
43202 +atomic_unchecked_t cm_nodes_created;
43203 +atomic_unchecked_t cm_nodes_destroyed;
43204 +atomic_unchecked_t cm_accel_dropped_pkts;
43205 +atomic_unchecked_t cm_resets_recvd;
43206
43207 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43208 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43209 @@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43210 /* instance of function pointers for client API */
43211 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43212 static struct nes_cm_ops nes_cm_api = {
43213 - mini_cm_accelerated,
43214 - mini_cm_listen,
43215 - mini_cm_del_listen,
43216 - mini_cm_connect,
43217 - mini_cm_close,
43218 - mini_cm_accept,
43219 - mini_cm_reject,
43220 - mini_cm_recv_pkt,
43221 - mini_cm_dealloc_core,
43222 - mini_cm_get,
43223 - mini_cm_set
43224 + .accelerated = mini_cm_accelerated,
43225 + .listen = mini_cm_listen,
43226 + .stop_listener = mini_cm_del_listen,
43227 + .connect = mini_cm_connect,
43228 + .close = mini_cm_close,
43229 + .accept = mini_cm_accept,
43230 + .reject = mini_cm_reject,
43231 + .recv_pkt = mini_cm_recv_pkt,
43232 + .destroy_cm_core = mini_cm_dealloc_core,
43233 + .get = mini_cm_get,
43234 + .set = mini_cm_set
43235 };
43236
43237 static struct nes_cm_core *g_cm_core;
43238
43239 -atomic_t cm_connects;
43240 -atomic_t cm_accepts;
43241 -atomic_t cm_disconnects;
43242 -atomic_t cm_closes;
43243 -atomic_t cm_connecteds;
43244 -atomic_t cm_connect_reqs;
43245 -atomic_t cm_rejects;
43246 +atomic_unchecked_t cm_connects;
43247 +atomic_unchecked_t cm_accepts;
43248 +atomic_unchecked_t cm_disconnects;
43249 +atomic_unchecked_t cm_closes;
43250 +atomic_unchecked_t cm_connecteds;
43251 +atomic_unchecked_t cm_connect_reqs;
43252 +atomic_unchecked_t cm_rejects;
43253
43254 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43255 {
43256 @@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43257 kfree(listener);
43258 listener = NULL;
43259 ret = 0;
43260 - atomic_inc(&cm_listens_destroyed);
43261 + atomic_inc_unchecked(&cm_listens_destroyed);
43262 } else {
43263 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43264 }
43265 @@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43266 cm_node->rem_mac);
43267
43268 add_hte_node(cm_core, cm_node);
43269 - atomic_inc(&cm_nodes_created);
43270 + atomic_inc_unchecked(&cm_nodes_created);
43271
43272 return cm_node;
43273 }
43274 @@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43275 }
43276
43277 atomic_dec(&cm_core->node_cnt);
43278 - atomic_inc(&cm_nodes_destroyed);
43279 + atomic_inc_unchecked(&cm_nodes_destroyed);
43280 nesqp = cm_node->nesqp;
43281 if (nesqp) {
43282 nesqp->cm_node = NULL;
43283 @@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43284
43285 static void drop_packet(struct sk_buff *skb)
43286 {
43287 - atomic_inc(&cm_accel_dropped_pkts);
43288 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43289 dev_kfree_skb_any(skb);
43290 }
43291
43292 @@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43293 {
43294
43295 int reset = 0; /* whether to send reset in case of err.. */
43296 - atomic_inc(&cm_resets_recvd);
43297 + atomic_inc_unchecked(&cm_resets_recvd);
43298 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43299 " refcnt=%d\n", cm_node, cm_node->state,
43300 atomic_read(&cm_node->ref_count));
43301 @@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43302 rem_ref_cm_node(cm_node->cm_core, cm_node);
43303 return NULL;
43304 }
43305 - atomic_inc(&cm_loopbacks);
43306 + atomic_inc_unchecked(&cm_loopbacks);
43307 loopbackremotenode->loopbackpartner = cm_node;
43308 loopbackremotenode->tcp_cntxt.rcv_wscale =
43309 NES_CM_DEFAULT_RCV_WND_SCALE;
43310 @@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43311 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43312 else {
43313 rem_ref_cm_node(cm_core, cm_node);
43314 - atomic_inc(&cm_accel_dropped_pkts);
43315 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43316 dev_kfree_skb_any(skb);
43317 }
43318 break;
43319 @@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43320
43321 if ((cm_id) && (cm_id->event_handler)) {
43322 if (issue_disconn) {
43323 - atomic_inc(&cm_disconnects);
43324 + atomic_inc_unchecked(&cm_disconnects);
43325 cm_event.event = IW_CM_EVENT_DISCONNECT;
43326 cm_event.status = disconn_status;
43327 cm_event.local_addr = cm_id->local_addr;
43328 @@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43329 }
43330
43331 if (issue_close) {
43332 - atomic_inc(&cm_closes);
43333 + atomic_inc_unchecked(&cm_closes);
43334 nes_disconnect(nesqp, 1);
43335
43336 cm_id->provider_data = nesqp;
43337 @@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43338
43339 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43340 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43341 - atomic_inc(&cm_accepts);
43342 + atomic_inc_unchecked(&cm_accepts);
43343
43344 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43345 netdev_refcnt_read(nesvnic->netdev));
43346 @@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43347 struct nes_cm_core *cm_core;
43348 u8 *start_buff;
43349
43350 - atomic_inc(&cm_rejects);
43351 + atomic_inc_unchecked(&cm_rejects);
43352 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43353 loopback = cm_node->loopbackpartner;
43354 cm_core = cm_node->cm_core;
43355 @@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43356 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43357 ntohs(laddr->sin_port));
43358
43359 - atomic_inc(&cm_connects);
43360 + atomic_inc_unchecked(&cm_connects);
43361 nesqp->active_conn = 1;
43362
43363 /* cache the cm_id in the qp */
43364 @@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43365 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43366 return err;
43367 }
43368 - atomic_inc(&cm_listens_created);
43369 + atomic_inc_unchecked(&cm_listens_created);
43370 }
43371
43372 cm_id->add_ref(cm_id);
43373 @@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43374
43375 if (nesqp->destroyed)
43376 return;
43377 - atomic_inc(&cm_connecteds);
43378 + atomic_inc_unchecked(&cm_connecteds);
43379 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43380 " local port 0x%04X. jiffies = %lu.\n",
43381 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43382 @@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43383
43384 cm_id->add_ref(cm_id);
43385 ret = cm_id->event_handler(cm_id, &cm_event);
43386 - atomic_inc(&cm_closes);
43387 + atomic_inc_unchecked(&cm_closes);
43388 cm_event.event = IW_CM_EVENT_CLOSE;
43389 cm_event.status = 0;
43390 cm_event.provider_data = cm_id->provider_data;
43391 @@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43392 return;
43393 cm_id = cm_node->cm_id;
43394
43395 - atomic_inc(&cm_connect_reqs);
43396 + atomic_inc_unchecked(&cm_connect_reqs);
43397 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43398 cm_node, cm_id, jiffies);
43399
43400 @@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43401 return;
43402 cm_id = cm_node->cm_id;
43403
43404 - atomic_inc(&cm_connect_reqs);
43405 + atomic_inc_unchecked(&cm_connect_reqs);
43406 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43407 cm_node, cm_id, jiffies);
43408
43409 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43410 index 4166452..fc952c3 100644
43411 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43412 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43413 @@ -40,8 +40,8 @@
43414 #include "nes.h"
43415 #include "nes_mgt.h"
43416
43417 -atomic_t pau_qps_created;
43418 -atomic_t pau_qps_destroyed;
43419 +atomic_unchecked_t pau_qps_created;
43420 +atomic_unchecked_t pau_qps_destroyed;
43421
43422 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43423 {
43424 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43425 {
43426 struct sk_buff *skb;
43427 unsigned long flags;
43428 - atomic_inc(&pau_qps_destroyed);
43429 + atomic_inc_unchecked(&pau_qps_destroyed);
43430
43431 /* Free packets that have not yet been forwarded */
43432 /* Lock is acquired by skb_dequeue when removing the skb */
43433 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43434 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43435 skb_queue_head_init(&nesqp->pau_list);
43436 spin_lock_init(&nesqp->pau_lock);
43437 - atomic_inc(&pau_qps_created);
43438 + atomic_inc_unchecked(&pau_qps_created);
43439 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43440 }
43441
43442 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43443 index 49eb511..a774366 100644
43444 --- a/drivers/infiniband/hw/nes/nes_nic.c
43445 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43446 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43447 target_stat_values[++index] = mh_detected;
43448 target_stat_values[++index] = mh_pauses_sent;
43449 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43450 - target_stat_values[++index] = atomic_read(&cm_connects);
43451 - target_stat_values[++index] = atomic_read(&cm_accepts);
43452 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43453 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43454 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43455 - target_stat_values[++index] = atomic_read(&cm_rejects);
43456 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43457 - target_stat_values[++index] = atomic_read(&qps_created);
43458 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43459 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43460 - target_stat_values[++index] = atomic_read(&cm_closes);
43461 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43462 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43463 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43464 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43465 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43466 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43467 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43468 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43469 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43470 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43471 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43472 target_stat_values[++index] = cm_packets_sent;
43473 target_stat_values[++index] = cm_packets_bounced;
43474 target_stat_values[++index] = cm_packets_created;
43475 target_stat_values[++index] = cm_packets_received;
43476 target_stat_values[++index] = cm_packets_dropped;
43477 target_stat_values[++index] = cm_packets_retrans;
43478 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43479 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43480 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43481 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43482 target_stat_values[++index] = cm_backlog_drops;
43483 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43484 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43485 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43486 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43487 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43488 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43489 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43490 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43491 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43492 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43493 target_stat_values[++index] = nesadapter->free_4kpbl;
43494 target_stat_values[++index] = nesadapter->free_256pbl;
43495 target_stat_values[++index] = int_mod_timer_init;
43496 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43497 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43498 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43499 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43500 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43501 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43502 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43503 }
43504
43505 /**
43506 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43507 index fef067c..6a25ccd 100644
43508 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43509 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43510 @@ -46,9 +46,9 @@
43511
43512 #include <rdma/ib_umem.h>
43513
43514 -atomic_t mod_qp_timouts;
43515 -atomic_t qps_created;
43516 -atomic_t sw_qps_destroyed;
43517 +atomic_unchecked_t mod_qp_timouts;
43518 +atomic_unchecked_t qps_created;
43519 +atomic_unchecked_t sw_qps_destroyed;
43520
43521 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43522
43523 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43524 if (init_attr->create_flags)
43525 return ERR_PTR(-EINVAL);
43526
43527 - atomic_inc(&qps_created);
43528 + atomic_inc_unchecked(&qps_created);
43529 switch (init_attr->qp_type) {
43530 case IB_QPT_RC:
43531 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43532 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43533 struct iw_cm_event cm_event;
43534 int ret = 0;
43535
43536 - atomic_inc(&sw_qps_destroyed);
43537 + atomic_inc_unchecked(&sw_qps_destroyed);
43538 nesqp->destroyed = 1;
43539
43540 /* Blow away the connection if it exists. */
43541 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43542 index c00ae09..04e91be 100644
43543 --- a/drivers/infiniband/hw/qib/qib.h
43544 +++ b/drivers/infiniband/hw/qib/qib.h
43545 @@ -52,6 +52,7 @@
43546 #include <linux/kref.h>
43547 #include <linux/sched.h>
43548 #include <linux/kthread.h>
43549 +#include <linux/slab.h>
43550
43551 #include "qib_common.h"
43552 #include "qib_verbs.h"
43553 diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43554 index cdc7df4..a2fdfdb 100644
43555 --- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43556 +++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43557 @@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43558 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43559 }
43560
43561 -static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43562 +static struct rtnl_link_ops ipoib_link_ops = {
43563 .kind = "ipoib",
43564 .maxtype = IFLA_IPOIB_MAX,
43565 .policy = ipoib_policy,
43566 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43567 index e29c04e..adbf68c 100644
43568 --- a/drivers/input/gameport/gameport.c
43569 +++ b/drivers/input/gameport/gameport.c
43570 @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43571 */
43572 static void gameport_init_port(struct gameport *gameport)
43573 {
43574 - static atomic_t gameport_no = ATOMIC_INIT(0);
43575 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43576
43577 __module_get(THIS_MODULE);
43578
43579 mutex_init(&gameport->drv_mutex);
43580 device_initialize(&gameport->dev);
43581 dev_set_name(&gameport->dev, "gameport%lu",
43582 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43583 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43584 gameport->dev.bus = &gameport_bus;
43585 gameport->dev.release = gameport_release_port;
43586 if (gameport->parent)
43587 diff --git a/drivers/input/input.c b/drivers/input/input.c
43588 index 0f175f5..4c481c0 100644
43589 --- a/drivers/input/input.c
43590 +++ b/drivers/input/input.c
43591 @@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43592 */
43593 struct input_dev *input_allocate_device(void)
43594 {
43595 - static atomic_t input_no = ATOMIC_INIT(0);
43596 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43597 struct input_dev *dev;
43598
43599 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43600 @@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43601 INIT_LIST_HEAD(&dev->node);
43602
43603 dev_set_name(&dev->dev, "input%lu",
43604 - (unsigned long) atomic_inc_return(&input_no) - 1);
43605 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43606
43607 __module_get(THIS_MODULE);
43608 }
43609 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43610 index 4a95b22..874c182 100644
43611 --- a/drivers/input/joystick/sidewinder.c
43612 +++ b/drivers/input/joystick/sidewinder.c
43613 @@ -30,6 +30,7 @@
43614 #include <linux/kernel.h>
43615 #include <linux/module.h>
43616 #include <linux/slab.h>
43617 +#include <linux/sched.h>
43618 #include <linux/input.h>
43619 #include <linux/gameport.h>
43620 #include <linux/jiffies.h>
43621 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43622 index fc55f0d..11e2aa6 100644
43623 --- a/drivers/input/joystick/xpad.c
43624 +++ b/drivers/input/joystick/xpad.c
43625 @@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43626
43627 static int xpad_led_probe(struct usb_xpad *xpad)
43628 {
43629 - static atomic_t led_seq = ATOMIC_INIT(0);
43630 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43631 long led_no;
43632 struct xpad_led *led;
43633 struct led_classdev *led_cdev;
43634 @@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43635 if (!led)
43636 return -ENOMEM;
43637
43638 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43639 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43640
43641 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43642 led->xpad = xpad;
43643 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43644 index afed8e2..3aa8a18 100644
43645 --- a/drivers/input/misc/ims-pcu.c
43646 +++ b/drivers/input/misc/ims-pcu.c
43647 @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43648
43649 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43650 {
43651 - static atomic_t device_no = ATOMIC_INIT(0);
43652 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43653
43654 const struct ims_pcu_device_info *info;
43655 int error;
43656 @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43657 }
43658
43659 /* Device appears to be operable, complete initialization */
43660 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43661 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43662
43663 /*
43664 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43665 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43666 index f4cf664..3204fda 100644
43667 --- a/drivers/input/mouse/psmouse.h
43668 +++ b/drivers/input/mouse/psmouse.h
43669 @@ -117,7 +117,7 @@ struct psmouse_attribute {
43670 ssize_t (*set)(struct psmouse *psmouse, void *data,
43671 const char *buf, size_t count);
43672 bool protect;
43673 -};
43674 +} __do_const;
43675 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43676
43677 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43678 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43679 index b604564..3f14ae4 100644
43680 --- a/drivers/input/mousedev.c
43681 +++ b/drivers/input/mousedev.c
43682 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43683
43684 spin_unlock_irq(&client->packet_lock);
43685
43686 - if (copy_to_user(buffer, data, count))
43687 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43688 return -EFAULT;
43689
43690 return count;
43691 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43692 index d399b8b..4913ede 100644
43693 --- a/drivers/input/serio/serio.c
43694 +++ b/drivers/input/serio/serio.c
43695 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43696 */
43697 static void serio_init_port(struct serio *serio)
43698 {
43699 - static atomic_t serio_no = ATOMIC_INIT(0);
43700 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43701
43702 __module_get(THIS_MODULE);
43703
43704 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43705 mutex_init(&serio->drv_mutex);
43706 device_initialize(&serio->dev);
43707 dev_set_name(&serio->dev, "serio%lu",
43708 - (unsigned long)atomic_inc_return(&serio_no) - 1);
43709 + (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43710 serio->dev.bus = &serio_bus;
43711 serio->dev.release = serio_release_port;
43712 serio->dev.groups = serio_device_attr_groups;
43713 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43714 index c9a02fe..0debc75 100644
43715 --- a/drivers/input/serio/serio_raw.c
43716 +++ b/drivers/input/serio/serio_raw.c
43717 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43718
43719 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43720 {
43721 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43722 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43723 struct serio_raw *serio_raw;
43724 int err;
43725
43726 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43727 }
43728
43729 snprintf(serio_raw->name, sizeof(serio_raw->name),
43730 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43731 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43732 kref_init(&serio_raw->kref);
43733 INIT_LIST_HEAD(&serio_raw->client_list);
43734 init_waitqueue_head(&serio_raw->wait);
43735 diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43736 index 505a9ad..356734c 100644
43737 --- a/drivers/iommu/amd_iommu.c
43738 +++ b/drivers/iommu/amd_iommu.c
43739 @@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43740
43741 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43742 {
43743 + phys_addr_t physaddr;
43744 WARN_ON(address & 0x7ULL);
43745
43746 memset(cmd, 0, sizeof(*cmd));
43747 - cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43748 - cmd->data[1] = upper_32_bits(__pa(address));
43749 +
43750 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43751 + if (object_starts_on_stack((void *)address)) {
43752 + void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43753 + physaddr = __pa((u64)adjbuf);
43754 + } else
43755 +#endif
43756 + physaddr = __pa(address);
43757 +
43758 + cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43759 + cmd->data[1] = upper_32_bits(physaddr);
43760 cmd->data[2] = 1;
43761 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43762 }
43763 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43764 index 60558f7..5a02369 100644
43765 --- a/drivers/iommu/arm-smmu.c
43766 +++ b/drivers/iommu/arm-smmu.c
43767 @@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43768 cfg->irptndx = cfg->cbndx;
43769 }
43770
43771 - ACCESS_ONCE(smmu_domain->smmu) = smmu;
43772 + ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43773 arm_smmu_init_context_bank(smmu_domain);
43774 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43775
43776 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43777 index ed8b048..7fbcc01 100644
43778 --- a/drivers/iommu/iommu.c
43779 +++ b/drivers/iommu/iommu.c
43780 @@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43781 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43782 {
43783 int err;
43784 - struct notifier_block *nb;
43785 + notifier_block_no_const *nb;
43786 struct iommu_callback_data cb = {
43787 .ops = ops,
43788 };
43789 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43790 index 74a1767..5a359e8 100644
43791 --- a/drivers/iommu/irq_remapping.c
43792 +++ b/drivers/iommu/irq_remapping.c
43793 @@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43794 void panic_if_irq_remap(const char *msg)
43795 {
43796 if (irq_remapping_enabled)
43797 - panic(msg);
43798 + panic("%s", msg);
43799 }
43800
43801 static void ir_ack_apic_edge(struct irq_data *data)
43802 @@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43803
43804 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43805 {
43806 - chip->irq_print_chip = ir_print_prefix;
43807 - chip->irq_ack = ir_ack_apic_edge;
43808 - chip->irq_eoi = ir_ack_apic_level;
43809 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43810 + pax_open_kernel();
43811 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43812 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43813 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43814 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43815 + pax_close_kernel();
43816 }
43817
43818 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43819 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43820 index 38493ff..001538b 100644
43821 --- a/drivers/irqchip/irq-gic.c
43822 +++ b/drivers/irqchip/irq-gic.c
43823 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43824 * Supported arch specific GIC irq extension.
43825 * Default make them NULL.
43826 */
43827 -struct irq_chip gic_arch_extn = {
43828 +irq_chip_no_const gic_arch_extn = {
43829 .irq_eoi = NULL,
43830 .irq_mask = NULL,
43831 .irq_unmask = NULL,
43832 @@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43833 chained_irq_exit(chip, desc);
43834 }
43835
43836 -static struct irq_chip gic_chip = {
43837 +static irq_chip_no_const gic_chip __read_only = {
43838 .name = "GIC",
43839 .irq_mask = gic_mask_irq,
43840 .irq_unmask = gic_unmask_irq,
43841 diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
43842 index 542e850..1bb094c 100644
43843 --- a/drivers/irqchip/irq-renesas-intc-irqpin.c
43844 +++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
43845 @@ -353,7 +353,7 @@ static int intc_irqpin_probe(struct platform_device *pdev)
43846 struct intc_irqpin_iomem *i;
43847 struct resource *io[INTC_IRQPIN_REG_NR];
43848 struct resource *irq;
43849 - struct irq_chip *irq_chip;
43850 + irq_chip_no_const *irq_chip;
43851 void (*enable_fn)(struct irq_data *d);
43852 void (*disable_fn)(struct irq_data *d);
43853 const char *name = dev_name(dev);
43854 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43855 index 8777065..a4a9967 100644
43856 --- a/drivers/irqchip/irq-renesas-irqc.c
43857 +++ b/drivers/irqchip/irq-renesas-irqc.c
43858 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43859 struct irqc_priv *p;
43860 struct resource *io;
43861 struct resource *irq;
43862 - struct irq_chip *irq_chip;
43863 + irq_chip_no_const *irq_chip;
43864 const char *name = dev_name(&pdev->dev);
43865 int ret;
43866 int k;
43867 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43868 index 6a2df32..dc962f1 100644
43869 --- a/drivers/isdn/capi/capi.c
43870 +++ b/drivers/isdn/capi/capi.c
43871 @@ -81,8 +81,8 @@ struct capiminor {
43872
43873 struct capi20_appl *ap;
43874 u32 ncci;
43875 - atomic_t datahandle;
43876 - atomic_t msgid;
43877 + atomic_unchecked_t datahandle;
43878 + atomic_unchecked_t msgid;
43879
43880 struct tty_port port;
43881 int ttyinstop;
43882 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43883 capimsg_setu16(s, 2, mp->ap->applid);
43884 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43885 capimsg_setu8 (s, 5, CAPI_RESP);
43886 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43887 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43888 capimsg_setu32(s, 8, mp->ncci);
43889 capimsg_setu16(s, 12, datahandle);
43890 }
43891 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43892 mp->outbytes -= len;
43893 spin_unlock_bh(&mp->outlock);
43894
43895 - datahandle = atomic_inc_return(&mp->datahandle);
43896 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43897 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43898 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43899 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43900 capimsg_setu16(skb->data, 2, mp->ap->applid);
43901 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43902 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43903 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43904 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43905 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43906 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43907 capimsg_setu16(skb->data, 16, len); /* Data length */
43908 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43909 index aecec6d..11e13c5 100644
43910 --- a/drivers/isdn/gigaset/bas-gigaset.c
43911 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43912 @@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43913
43914
43915 static const struct gigaset_ops gigops = {
43916 - gigaset_write_cmd,
43917 - gigaset_write_room,
43918 - gigaset_chars_in_buffer,
43919 - gigaset_brkchars,
43920 - gigaset_init_bchannel,
43921 - gigaset_close_bchannel,
43922 - gigaset_initbcshw,
43923 - gigaset_freebcshw,
43924 - gigaset_reinitbcshw,
43925 - gigaset_initcshw,
43926 - gigaset_freecshw,
43927 - gigaset_set_modem_ctrl,
43928 - gigaset_baud_rate,
43929 - gigaset_set_line_ctrl,
43930 - gigaset_isoc_send_skb,
43931 - gigaset_isoc_input,
43932 + .write_cmd = gigaset_write_cmd,
43933 + .write_room = gigaset_write_room,
43934 + .chars_in_buffer = gigaset_chars_in_buffer,
43935 + .brkchars = gigaset_brkchars,
43936 + .init_bchannel = gigaset_init_bchannel,
43937 + .close_bchannel = gigaset_close_bchannel,
43938 + .initbcshw = gigaset_initbcshw,
43939 + .freebcshw = gigaset_freebcshw,
43940 + .reinitbcshw = gigaset_reinitbcshw,
43941 + .initcshw = gigaset_initcshw,
43942 + .freecshw = gigaset_freecshw,
43943 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43944 + .baud_rate = gigaset_baud_rate,
43945 + .set_line_ctrl = gigaset_set_line_ctrl,
43946 + .send_skb = gigaset_isoc_send_skb,
43947 + .handle_input = gigaset_isoc_input,
43948 };
43949
43950 /* bas_gigaset_init
43951 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43952 index 600c79b..3752bab 100644
43953 --- a/drivers/isdn/gigaset/interface.c
43954 +++ b/drivers/isdn/gigaset/interface.c
43955 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43956 }
43957 tty->driver_data = cs;
43958
43959 - ++cs->port.count;
43960 + atomic_inc(&cs->port.count);
43961
43962 - if (cs->port.count == 1) {
43963 + if (atomic_read(&cs->port.count) == 1) {
43964 tty_port_tty_set(&cs->port, tty);
43965 cs->port.low_latency = 1;
43966 }
43967 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43968
43969 if (!cs->connected)
43970 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43971 - else if (!cs->port.count)
43972 + else if (!atomic_read(&cs->port.count))
43973 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43974 - else if (!--cs->port.count)
43975 + else if (!atomic_dec_return(&cs->port.count))
43976 tty_port_tty_set(&cs->port, NULL);
43977
43978 mutex_unlock(&cs->mutex);
43979 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43980 index 8c91fd5..14f13ce 100644
43981 --- a/drivers/isdn/gigaset/ser-gigaset.c
43982 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43983 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43984 }
43985
43986 static const struct gigaset_ops ops = {
43987 - gigaset_write_cmd,
43988 - gigaset_write_room,
43989 - gigaset_chars_in_buffer,
43990 - gigaset_brkchars,
43991 - gigaset_init_bchannel,
43992 - gigaset_close_bchannel,
43993 - gigaset_initbcshw,
43994 - gigaset_freebcshw,
43995 - gigaset_reinitbcshw,
43996 - gigaset_initcshw,
43997 - gigaset_freecshw,
43998 - gigaset_set_modem_ctrl,
43999 - gigaset_baud_rate,
44000 - gigaset_set_line_ctrl,
44001 - gigaset_m10x_send_skb, /* asyncdata.c */
44002 - gigaset_m10x_input, /* asyncdata.c */
44003 + .write_cmd = gigaset_write_cmd,
44004 + .write_room = gigaset_write_room,
44005 + .chars_in_buffer = gigaset_chars_in_buffer,
44006 + .brkchars = gigaset_brkchars,
44007 + .init_bchannel = gigaset_init_bchannel,
44008 + .close_bchannel = gigaset_close_bchannel,
44009 + .initbcshw = gigaset_initbcshw,
44010 + .freebcshw = gigaset_freebcshw,
44011 + .reinitbcshw = gigaset_reinitbcshw,
44012 + .initcshw = gigaset_initcshw,
44013 + .freecshw = gigaset_freecshw,
44014 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44015 + .baud_rate = gigaset_baud_rate,
44016 + .set_line_ctrl = gigaset_set_line_ctrl,
44017 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44018 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
44019 };
44020
44021
44022 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44023 index a8e652d..edadaa4 100644
44024 --- a/drivers/isdn/gigaset/usb-gigaset.c
44025 +++ b/drivers/isdn/gigaset/usb-gigaset.c
44026 @@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44027 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44028 memcpy(cs->hw.usb->bchars, buf, 6);
44029 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44030 - 0, 0, &buf, 6, 2000);
44031 + 0, 0, buf, 6, 2000);
44032 }
44033
44034 static void gigaset_freebcshw(struct bc_state *bcs)
44035 @@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44036 }
44037
44038 static const struct gigaset_ops ops = {
44039 - gigaset_write_cmd,
44040 - gigaset_write_room,
44041 - gigaset_chars_in_buffer,
44042 - gigaset_brkchars,
44043 - gigaset_init_bchannel,
44044 - gigaset_close_bchannel,
44045 - gigaset_initbcshw,
44046 - gigaset_freebcshw,
44047 - gigaset_reinitbcshw,
44048 - gigaset_initcshw,
44049 - gigaset_freecshw,
44050 - gigaset_set_modem_ctrl,
44051 - gigaset_baud_rate,
44052 - gigaset_set_line_ctrl,
44053 - gigaset_m10x_send_skb,
44054 - gigaset_m10x_input,
44055 + .write_cmd = gigaset_write_cmd,
44056 + .write_room = gigaset_write_room,
44057 + .chars_in_buffer = gigaset_chars_in_buffer,
44058 + .brkchars = gigaset_brkchars,
44059 + .init_bchannel = gigaset_init_bchannel,
44060 + .close_bchannel = gigaset_close_bchannel,
44061 + .initbcshw = gigaset_initbcshw,
44062 + .freebcshw = gigaset_freebcshw,
44063 + .reinitbcshw = gigaset_reinitbcshw,
44064 + .initcshw = gigaset_initcshw,
44065 + .freecshw = gigaset_freecshw,
44066 + .set_modem_ctrl = gigaset_set_modem_ctrl,
44067 + .baud_rate = gigaset_baud_rate,
44068 + .set_line_ctrl = gigaset_set_line_ctrl,
44069 + .send_skb = gigaset_m10x_send_skb,
44070 + .handle_input = gigaset_m10x_input,
44071 };
44072
44073 /*
44074 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44075 index 4d9b195..455075c 100644
44076 --- a/drivers/isdn/hardware/avm/b1.c
44077 +++ b/drivers/isdn/hardware/avm/b1.c
44078 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44079 }
44080 if (left) {
44081 if (t4file->user) {
44082 - if (copy_from_user(buf, dp, left))
44083 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44084 return -EFAULT;
44085 } else {
44086 memcpy(buf, dp, left);
44087 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44088 }
44089 if (left) {
44090 if (config->user) {
44091 - if (copy_from_user(buf, dp, left))
44092 + if (left > sizeof buf || copy_from_user(buf, dp, left))
44093 return -EFAULT;
44094 } else {
44095 memcpy(buf, dp, left);
44096 diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
44097 index a82e542..f766a79 100644
44098 --- a/drivers/isdn/hardware/eicon/message.c
44099 +++ b/drivers/isdn/hardware/eicon/message.c
44100 @@ -1474,7 +1474,7 @@ static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
44101 add_ai(plci, &parms[5]);
44102 sig_req(plci, REJECT, 0);
44103 }
44104 - else if (Reject == 1 || Reject > 9)
44105 + else if (Reject == 1 || Reject >= 9)
44106 {
44107 add_ai(plci, &parms[5]);
44108 sig_req(plci, HANGUP, 0);
44109 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44110 index 9b856e1..fa03c92 100644
44111 --- a/drivers/isdn/i4l/isdn_common.c
44112 +++ b/drivers/isdn/i4l/isdn_common.c
44113 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44114 } else
44115 return -EINVAL;
44116 case IIOCDBGVAR:
44117 + if (!capable(CAP_SYS_RAWIO))
44118 + return -EPERM;
44119 if (arg) {
44120 if (copy_to_user(argp, &dev, sizeof(ulong)))
44121 return -EFAULT;
44122 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44123 index 91d5730..336523e 100644
44124 --- a/drivers/isdn/i4l/isdn_concap.c
44125 +++ b/drivers/isdn/i4l/isdn_concap.c
44126 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44127 }
44128
44129 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44130 - &isdn_concap_dl_data_req,
44131 - &isdn_concap_dl_connect_req,
44132 - &isdn_concap_dl_disconn_req
44133 + .data_req = &isdn_concap_dl_data_req,
44134 + .connect_req = &isdn_concap_dl_connect_req,
44135 + .disconn_req = &isdn_concap_dl_disconn_req
44136 };
44137
44138 /* The following should better go into a dedicated source file such that
44139 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44140 index bc91261..2ef7e36 100644
44141 --- a/drivers/isdn/i4l/isdn_tty.c
44142 +++ b/drivers/isdn/i4l/isdn_tty.c
44143 @@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44144
44145 #ifdef ISDN_DEBUG_MODEM_OPEN
44146 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44147 - port->count);
44148 + atomic_read(&port->count));
44149 #endif
44150 - port->count++;
44151 + atomic_inc(&port->count);
44152 port->tty = tty;
44153 /*
44154 * Start up serial port
44155 @@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44156 #endif
44157 return;
44158 }
44159 - if ((tty->count == 1) && (port->count != 1)) {
44160 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44161 /*
44162 * Uh, oh. tty->count is 1, which means that the tty
44163 * structure will be freed. Info->count should always
44164 @@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44165 * serial port won't be shutdown.
44166 */
44167 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44168 - "info->count is %d\n", port->count);
44169 - port->count = 1;
44170 + "info->count is %d\n", atomic_read(&port->count));
44171 + atomic_set(&port->count, 1);
44172 }
44173 - if (--port->count < 0) {
44174 + if (atomic_dec_return(&port->count) < 0) {
44175 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44176 - info->line, port->count);
44177 - port->count = 0;
44178 + info->line, atomic_read(&port->count));
44179 + atomic_set(&port->count, 0);
44180 }
44181 - if (port->count) {
44182 + if (atomic_read(&port->count)) {
44183 #ifdef ISDN_DEBUG_MODEM_OPEN
44184 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44185 #endif
44186 @@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44187 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44188 return;
44189 isdn_tty_shutdown(info);
44190 - port->count = 0;
44191 + atomic_set(&port->count, 0);
44192 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44193 port->tty = NULL;
44194 wake_up_interruptible(&port->open_wait);
44195 @@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44196 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44197 modem_info *info = &dev->mdm.info[i];
44198
44199 - if (info->port.count == 0)
44200 + if (atomic_read(&info->port.count) == 0)
44201 continue;
44202 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44203 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44204 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44205 index e2d4e58..40cd045 100644
44206 --- a/drivers/isdn/i4l/isdn_x25iface.c
44207 +++ b/drivers/isdn/i4l/isdn_x25iface.c
44208 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44209
44210
44211 static struct concap_proto_ops ix25_pops = {
44212 - &isdn_x25iface_proto_new,
44213 - &isdn_x25iface_proto_del,
44214 - &isdn_x25iface_proto_restart,
44215 - &isdn_x25iface_proto_close,
44216 - &isdn_x25iface_xmit,
44217 - &isdn_x25iface_receive,
44218 - &isdn_x25iface_connect_ind,
44219 - &isdn_x25iface_disconn_ind
44220 + .proto_new = &isdn_x25iface_proto_new,
44221 + .proto_del = &isdn_x25iface_proto_del,
44222 + .restart = &isdn_x25iface_proto_restart,
44223 + .close = &isdn_x25iface_proto_close,
44224 + .encap_and_xmit = &isdn_x25iface_xmit,
44225 + .data_ind = &isdn_x25iface_receive,
44226 + .connect_ind = &isdn_x25iface_connect_ind,
44227 + .disconn_ind = &isdn_x25iface_disconn_ind
44228 };
44229
44230 /* error message helper function */
44231 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44232 index 6a7447c..cae33fe 100644
44233 --- a/drivers/isdn/icn/icn.c
44234 +++ b/drivers/isdn/icn/icn.c
44235 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44236 if (count > len)
44237 count = len;
44238 if (user) {
44239 - if (copy_from_user(msg, buf, count))
44240 + if (count > sizeof msg || copy_from_user(msg, buf, count))
44241 return -EFAULT;
44242 } else
44243 memcpy(msg, buf, count);
44244 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44245 index 87f7dff..7300125 100644
44246 --- a/drivers/isdn/mISDN/dsp_cmx.c
44247 +++ b/drivers/isdn/mISDN/dsp_cmx.c
44248 @@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44249 static u16 dsp_count; /* last sample count */
44250 static int dsp_count_valid; /* if we have last sample count */
44251
44252 -void
44253 +void __intentional_overflow(-1)
44254 dsp_cmx_send(void *arg)
44255 {
44256 struct dsp_conf *conf;
44257 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44258 index f58a354..fbae176 100644
44259 --- a/drivers/leds/leds-clevo-mail.c
44260 +++ b/drivers/leds/leds-clevo-mail.c
44261 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44262 * detected as working, but in reality it is not) as low as
44263 * possible.
44264 */
44265 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44266 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44267 {
44268 .callback = clevo_mail_led_dmi_callback,
44269 .ident = "Clevo D410J",
44270 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44271 index 046cb70..6b20d39 100644
44272 --- a/drivers/leds/leds-ss4200.c
44273 +++ b/drivers/leds/leds-ss4200.c
44274 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44275 * detected as working, but in reality it is not) as low as
44276 * possible.
44277 */
44278 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
44279 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
44280 {
44281 .callback = ss4200_led_dmi_callback,
44282 .ident = "Intel SS4200-E",
44283 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44284 index 6590558..a74c5dd 100644
44285 --- a/drivers/lguest/core.c
44286 +++ b/drivers/lguest/core.c
44287 @@ -96,9 +96,17 @@ static __init int map_switcher(void)
44288 * The end address needs +1 because __get_vm_area allocates an
44289 * extra guard page, so we need space for that.
44290 */
44291 +
44292 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44293 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44294 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44295 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44296 +#else
44297 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44298 VM_ALLOC, switcher_addr, switcher_addr
44299 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44300 +#endif
44301 +
44302 if (!switcher_vma) {
44303 err = -ENOMEM;
44304 printk("lguest: could not map switcher pages high\n");
44305 @@ -121,7 +129,7 @@ static __init int map_switcher(void)
44306 * Now the Switcher is mapped at the right address, we can't fail!
44307 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44308 */
44309 - memcpy(switcher_vma->addr, start_switcher_text,
44310 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44311 end_switcher_text - start_switcher_text);
44312
44313 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44314 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44315 index e8b55c3..3514c37 100644
44316 --- a/drivers/lguest/page_tables.c
44317 +++ b/drivers/lguest/page_tables.c
44318 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44319 /*:*/
44320
44321 #ifdef CONFIG_X86_PAE
44322 -static void release_pmd(pmd_t *spmd)
44323 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44324 {
44325 /* If the entry's not present, there's nothing to release. */
44326 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44327 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44328 index 922a1ac..9dd0c2a 100644
44329 --- a/drivers/lguest/x86/core.c
44330 +++ b/drivers/lguest/x86/core.c
44331 @@ -59,7 +59,7 @@ static struct {
44332 /* Offset from where switcher.S was compiled to where we've copied it */
44333 static unsigned long switcher_offset(void)
44334 {
44335 - return switcher_addr - (unsigned long)start_switcher_text;
44336 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44337 }
44338
44339 /* This cpu's struct lguest_pages (after the Switcher text page) */
44340 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44341 * These copies are pretty cheap, so we do them unconditionally: */
44342 /* Save the current Host top-level page directory.
44343 */
44344 +
44345 +#ifdef CONFIG_PAX_PER_CPU_PGD
44346 + pages->state.host_cr3 = read_cr3();
44347 +#else
44348 pages->state.host_cr3 = __pa(current->mm->pgd);
44349 +#endif
44350 +
44351 /*
44352 * Set up the Guest's page tables to see this CPU's pages (and no
44353 * other CPU's pages).
44354 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44355 * compiled-in switcher code and the high-mapped copy we just made.
44356 */
44357 for (i = 0; i < IDT_ENTRIES; i++)
44358 - default_idt_entries[i] += switcher_offset();
44359 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44360
44361 /*
44362 * Set up the Switcher's per-cpu areas.
44363 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44364 * it will be undisturbed when we switch. To change %cs and jump we
44365 * need this structure to feed to Intel's "lcall" instruction.
44366 */
44367 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44368 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44369 lguest_entry.segment = LGUEST_CS;
44370
44371 /*
44372 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44373 index 40634b0..4f5855e 100644
44374 --- a/drivers/lguest/x86/switcher_32.S
44375 +++ b/drivers/lguest/x86/switcher_32.S
44376 @@ -87,6 +87,7 @@
44377 #include <asm/page.h>
44378 #include <asm/segment.h>
44379 #include <asm/lguest.h>
44380 +#include <asm/processor-flags.h>
44381
44382 // We mark the start of the code to copy
44383 // It's placed in .text tho it's never run here
44384 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44385 // Changes type when we load it: damn Intel!
44386 // For after we switch over our page tables
44387 // That entry will be read-only: we'd crash.
44388 +
44389 +#ifdef CONFIG_PAX_KERNEXEC
44390 + mov %cr0, %edx
44391 + xor $X86_CR0_WP, %edx
44392 + mov %edx, %cr0
44393 +#endif
44394 +
44395 movl $(GDT_ENTRY_TSS*8), %edx
44396 ltr %dx
44397
44398 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44399 // Let's clear it again for our return.
44400 // The GDT descriptor of the Host
44401 // Points to the table after two "size" bytes
44402 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44403 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44404 // Clear "used" from type field (byte 5, bit 2)
44405 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44406 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44407 +
44408 +#ifdef CONFIG_PAX_KERNEXEC
44409 + mov %cr0, %eax
44410 + xor $X86_CR0_WP, %eax
44411 + mov %eax, %cr0
44412 +#endif
44413
44414 // Once our page table's switched, the Guest is live!
44415 // The Host fades as we run this final step.
44416 @@ -295,13 +309,12 @@ deliver_to_host:
44417 // I consulted gcc, and it gave
44418 // These instructions, which I gladly credit:
44419 leal (%edx,%ebx,8), %eax
44420 - movzwl (%eax),%edx
44421 - movl 4(%eax), %eax
44422 - xorw %ax, %ax
44423 - orl %eax, %edx
44424 + movl 4(%eax), %edx
44425 + movw (%eax), %dx
44426 // Now the address of the handler's in %edx
44427 // We call it now: its "iret" drops us home.
44428 - jmp *%edx
44429 + ljmp $__KERNEL_CS, $1f
44430 +1: jmp *%edx
44431
44432 // Every interrupt can come to us here
44433 // But we must truly tell each apart.
44434 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44435 index a08e3ee..df8ade2 100644
44436 --- a/drivers/md/bcache/closure.h
44437 +++ b/drivers/md/bcache/closure.h
44438 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44439 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44440 struct workqueue_struct *wq)
44441 {
44442 - BUG_ON(object_is_on_stack(cl));
44443 + BUG_ON(object_starts_on_stack(cl));
44444 closure_set_ip(cl);
44445 cl->fn = fn;
44446 cl->wq = wq;
44447 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44448 index da3604e..7789cb4c 100644
44449 --- a/drivers/md/bitmap.c
44450 +++ b/drivers/md/bitmap.c
44451 @@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44452 chunk_kb ? "KB" : "B");
44453 if (bitmap->storage.file) {
44454 seq_printf(seq, ", file: ");
44455 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44456 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44457 }
44458
44459 seq_printf(seq, "\n");
44460 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44461 index 0be9381..114262b 100644
44462 --- a/drivers/md/dm-ioctl.c
44463 +++ b/drivers/md/dm-ioctl.c
44464 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44465 cmd == DM_LIST_VERSIONS_CMD)
44466 return 0;
44467
44468 - if ((cmd == DM_DEV_CREATE_CMD)) {
44469 + if (cmd == DM_DEV_CREATE_CMD) {
44470 if (!*param->name) {
44471 DMWARN("name not supplied when creating device");
44472 return -EINVAL;
44473 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44474 index 7dfdb5c..4caada6 100644
44475 --- a/drivers/md/dm-raid1.c
44476 +++ b/drivers/md/dm-raid1.c
44477 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44478
44479 struct mirror {
44480 struct mirror_set *ms;
44481 - atomic_t error_count;
44482 + atomic_unchecked_t error_count;
44483 unsigned long error_type;
44484 struct dm_dev *dev;
44485 sector_t offset;
44486 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44487 struct mirror *m;
44488
44489 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44490 - if (!atomic_read(&m->error_count))
44491 + if (!atomic_read_unchecked(&m->error_count))
44492 return m;
44493
44494 return NULL;
44495 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44496 * simple way to tell if a device has encountered
44497 * errors.
44498 */
44499 - atomic_inc(&m->error_count);
44500 + atomic_inc_unchecked(&m->error_count);
44501
44502 if (test_and_set_bit(error_type, &m->error_type))
44503 return;
44504 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44505 struct mirror *m = get_default_mirror(ms);
44506
44507 do {
44508 - if (likely(!atomic_read(&m->error_count)))
44509 + if (likely(!atomic_read_unchecked(&m->error_count)))
44510 return m;
44511
44512 if (m-- == ms->mirror)
44513 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44514 {
44515 struct mirror *default_mirror = get_default_mirror(m->ms);
44516
44517 - return !atomic_read(&default_mirror->error_count);
44518 + return !atomic_read_unchecked(&default_mirror->error_count);
44519 }
44520
44521 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44522 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44523 */
44524 if (likely(region_in_sync(ms, region, 1)))
44525 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44526 - else if (m && atomic_read(&m->error_count))
44527 + else if (m && atomic_read_unchecked(&m->error_count))
44528 m = NULL;
44529
44530 if (likely(m))
44531 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44532 }
44533
44534 ms->mirror[mirror].ms = ms;
44535 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44536 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44537 ms->mirror[mirror].error_type = 0;
44538 ms->mirror[mirror].offset = offset;
44539
44540 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44541 */
44542 static char device_status_char(struct mirror *m)
44543 {
44544 - if (!atomic_read(&(m->error_count)))
44545 + if (!atomic_read_unchecked(&(m->error_count)))
44546 return 'A';
44547
44548 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44549 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44550 index 87f86c7..a1a4100 100644
44551 --- a/drivers/md/dm-stats.c
44552 +++ b/drivers/md/dm-stats.c
44553 @@ -382,7 +382,7 @@ do_sync_free:
44554 synchronize_rcu_expedited();
44555 dm_stat_free(&s->rcu_head);
44556 } else {
44557 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44558 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44559 call_rcu(&s->rcu_head, dm_stat_free);
44560 }
44561 return 0;
44562 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44563 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44564 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44565 ));
44566 - ACCESS_ONCE(last->last_sector) = end_sector;
44567 - ACCESS_ONCE(last->last_rw) = bi_rw;
44568 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44569 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44570 }
44571
44572 rcu_read_lock();
44573 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44574 index f8b37d4..5c5cafd 100644
44575 --- a/drivers/md/dm-stripe.c
44576 +++ b/drivers/md/dm-stripe.c
44577 @@ -21,7 +21,7 @@ struct stripe {
44578 struct dm_dev *dev;
44579 sector_t physical_start;
44580
44581 - atomic_t error_count;
44582 + atomic_unchecked_t error_count;
44583 };
44584
44585 struct stripe_c {
44586 @@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44587 kfree(sc);
44588 return r;
44589 }
44590 - atomic_set(&(sc->stripe[i].error_count), 0);
44591 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44592 }
44593
44594 ti->private = sc;
44595 @@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44596 DMEMIT("%d ", sc->stripes);
44597 for (i = 0; i < sc->stripes; i++) {
44598 DMEMIT("%s ", sc->stripe[i].dev->name);
44599 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44600 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44601 'D' : 'A';
44602 }
44603 buffer[i] = '\0';
44604 @@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44605 */
44606 for (i = 0; i < sc->stripes; i++)
44607 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44608 - atomic_inc(&(sc->stripe[i].error_count));
44609 - if (atomic_read(&(sc->stripe[i].error_count)) <
44610 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44611 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44612 DM_IO_ERROR_THRESHOLD)
44613 schedule_work(&sc->trigger_event);
44614 }
44615 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44616 index b2bd1eb..38f7a44 100644
44617 --- a/drivers/md/dm-table.c
44618 +++ b/drivers/md/dm-table.c
44619 @@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44620 if (!dev_size)
44621 return 0;
44622
44623 - if ((start >= dev_size) || (start + len > dev_size)) {
44624 + if ((start >= dev_size) || (len > dev_size - start)) {
44625 DMWARN("%s: %s too small for target: "
44626 "start=%llu, len=%llu, dev_size=%llu",
44627 dm_device_name(ti->table->md), bdevname(bdev, b),
44628 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44629 index e9d33ad..dae9880d 100644
44630 --- a/drivers/md/dm-thin-metadata.c
44631 +++ b/drivers/md/dm-thin-metadata.c
44632 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44633 {
44634 pmd->info.tm = pmd->tm;
44635 pmd->info.levels = 2;
44636 - pmd->info.value_type.context = pmd->data_sm;
44637 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44638 pmd->info.value_type.size = sizeof(__le64);
44639 pmd->info.value_type.inc = data_block_inc;
44640 pmd->info.value_type.dec = data_block_dec;
44641 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44642
44643 pmd->bl_info.tm = pmd->tm;
44644 pmd->bl_info.levels = 1;
44645 - pmd->bl_info.value_type.context = pmd->data_sm;
44646 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44647 pmd->bl_info.value_type.size = sizeof(__le64);
44648 pmd->bl_info.value_type.inc = data_block_inc;
44649 pmd->bl_info.value_type.dec = data_block_dec;
44650 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44651 index 62c5136..aede7f1 100644
44652 --- a/drivers/md/dm.c
44653 +++ b/drivers/md/dm.c
44654 @@ -183,9 +183,9 @@ struct mapped_device {
44655 /*
44656 * Event handling.
44657 */
44658 - atomic_t event_nr;
44659 + atomic_unchecked_t event_nr;
44660 wait_queue_head_t eventq;
44661 - atomic_t uevent_seq;
44662 + atomic_unchecked_t uevent_seq;
44663 struct list_head uevent_list;
44664 spinlock_t uevent_lock; /* Protect access to uevent_list */
44665
44666 @@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44667 spin_lock_init(&md->deferred_lock);
44668 atomic_set(&md->holders, 1);
44669 atomic_set(&md->open_count, 0);
44670 - atomic_set(&md->event_nr, 0);
44671 - atomic_set(&md->uevent_seq, 0);
44672 + atomic_set_unchecked(&md->event_nr, 0);
44673 + atomic_set_unchecked(&md->uevent_seq, 0);
44674 INIT_LIST_HEAD(&md->uevent_list);
44675 INIT_LIST_HEAD(&md->table_devices);
44676 spin_lock_init(&md->uevent_lock);
44677 @@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44678
44679 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44680
44681 - atomic_inc(&md->event_nr);
44682 + atomic_inc_unchecked(&md->event_nr);
44683 wake_up(&md->eventq);
44684 }
44685
44686 @@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44687
44688 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44689 {
44690 - return atomic_add_return(1, &md->uevent_seq);
44691 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44692 }
44693
44694 uint32_t dm_get_event_nr(struct mapped_device *md)
44695 {
44696 - return atomic_read(&md->event_nr);
44697 + return atomic_read_unchecked(&md->event_nr);
44698 }
44699
44700 int dm_wait_event(struct mapped_device *md, int event_nr)
44701 {
44702 return wait_event_interruptible(md->eventq,
44703 - (event_nr != atomic_read(&md->event_nr)));
44704 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44705 }
44706
44707 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44708 diff --git a/drivers/md/md.c b/drivers/md/md.c
44709 index 9233c71..ed5243a 100644
44710 --- a/drivers/md/md.c
44711 +++ b/drivers/md/md.c
44712 @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44713 * start build, activate spare
44714 */
44715 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44716 -static atomic_t md_event_count;
44717 +static atomic_unchecked_t md_event_count;
44718 void md_new_event(struct mddev *mddev)
44719 {
44720 - atomic_inc(&md_event_count);
44721 + atomic_inc_unchecked(&md_event_count);
44722 wake_up(&md_event_waiters);
44723 }
44724 EXPORT_SYMBOL_GPL(md_new_event);
44725 @@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44726 */
44727 static void md_new_event_inintr(struct mddev *mddev)
44728 {
44729 - atomic_inc(&md_event_count);
44730 + atomic_inc_unchecked(&md_event_count);
44731 wake_up(&md_event_waiters);
44732 }
44733
44734 @@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44735 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44736 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44737 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44738 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44739 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44740
44741 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44742 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44743 @@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44744 else
44745 sb->resync_offset = cpu_to_le64(0);
44746
44747 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44748 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44749
44750 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44751 sb->size = cpu_to_le64(mddev->dev_sectors);
44752 @@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44753 static ssize_t
44754 errors_show(struct md_rdev *rdev, char *page)
44755 {
44756 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44757 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44758 }
44759
44760 static ssize_t
44761 @@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44762 char *e;
44763 unsigned long n = simple_strtoul(buf, &e, 10);
44764 if (*buf && (*e == 0 || *e == '\n')) {
44765 - atomic_set(&rdev->corrected_errors, n);
44766 + atomic_set_unchecked(&rdev->corrected_errors, n);
44767 return len;
44768 }
44769 return -EINVAL;
44770 @@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44771 rdev->sb_loaded = 0;
44772 rdev->bb_page = NULL;
44773 atomic_set(&rdev->nr_pending, 0);
44774 - atomic_set(&rdev->read_errors, 0);
44775 - atomic_set(&rdev->corrected_errors, 0);
44776 + atomic_set_unchecked(&rdev->read_errors, 0);
44777 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44778
44779 INIT_LIST_HEAD(&rdev->same_set);
44780 init_waitqueue_head(&rdev->blocked_wait);
44781 @@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44782
44783 spin_unlock(&pers_lock);
44784 seq_printf(seq, "\n");
44785 - seq->poll_event = atomic_read(&md_event_count);
44786 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44787 return 0;
44788 }
44789 if (v == (void*)2) {
44790 @@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44791 return error;
44792
44793 seq = file->private_data;
44794 - seq->poll_event = atomic_read(&md_event_count);
44795 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44796 return error;
44797 }
44798
44799 @@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44800 /* always allow read */
44801 mask = POLLIN | POLLRDNORM;
44802
44803 - if (seq->poll_event != atomic_read(&md_event_count))
44804 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44805 mask |= POLLERR | POLLPRI;
44806 return mask;
44807 }
44808 @@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44809 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44810 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44811 (int)part_stat_read(&disk->part0, sectors[1]) -
44812 - atomic_read(&disk->sync_io);
44813 + atomic_read_unchecked(&disk->sync_io);
44814 /* sync IO will cause sync_io to increase before the disk_stats
44815 * as sync_io is counted when a request starts, and
44816 * disk_stats is counted when it completes.
44817 diff --git a/drivers/md/md.h b/drivers/md/md.h
44818 index 03cec5b..0a658c1 100644
44819 --- a/drivers/md/md.h
44820 +++ b/drivers/md/md.h
44821 @@ -94,13 +94,13 @@ struct md_rdev {
44822 * only maintained for arrays that
44823 * support hot removal
44824 */
44825 - atomic_t read_errors; /* number of consecutive read errors that
44826 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44827 * we have tried to ignore.
44828 */
44829 struct timespec last_read_error; /* monotonic time since our
44830 * last read error
44831 */
44832 - atomic_t corrected_errors; /* number of corrected read errors,
44833 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44834 * for reporting to userspace and storing
44835 * in superblock.
44836 */
44837 @@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44838
44839 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44840 {
44841 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44842 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44843 }
44844
44845 struct md_personality
44846 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44847 index f4e22bc..8f83114 100644
44848 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44849 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44850 @@ -681,7 +681,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44851 * Flick into a mode where all blocks get allocated in the new area.
44852 */
44853 smm->begin = old_len;
44854 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44855 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44856
44857 /*
44858 * Extend.
44859 @@ -712,7 +712,7 @@ out:
44860 /*
44861 * Switch back to normal behaviour.
44862 */
44863 - memcpy(sm, &ops, sizeof(*sm));
44864 + memcpy((void *)sm, &ops, sizeof(*sm));
44865 return r;
44866 }
44867
44868 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44869 index 3e6d115..ffecdeb 100644
44870 --- a/drivers/md/persistent-data/dm-space-map.h
44871 +++ b/drivers/md/persistent-data/dm-space-map.h
44872 @@ -71,6 +71,7 @@ struct dm_space_map {
44873 dm_sm_threshold_fn fn,
44874 void *context);
44875 };
44876 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44877
44878 /*----------------------------------------------------------------*/
44879
44880 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44881 index 2f2f38f..f6a8ebe 100644
44882 --- a/drivers/md/raid1.c
44883 +++ b/drivers/md/raid1.c
44884 @@ -1932,7 +1932,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44885 if (r1_sync_page_io(rdev, sect, s,
44886 bio->bi_io_vec[idx].bv_page,
44887 READ) != 0)
44888 - atomic_add(s, &rdev->corrected_errors);
44889 + atomic_add_unchecked(s, &rdev->corrected_errors);
44890 }
44891 sectors -= s;
44892 sect += s;
44893 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44894 !test_bit(Faulty, &rdev->flags)) {
44895 if (r1_sync_page_io(rdev, sect, s,
44896 conf->tmppage, READ)) {
44897 - atomic_add(s, &rdev->corrected_errors);
44898 + atomic_add_unchecked(s, &rdev->corrected_errors);
44899 printk(KERN_INFO
44900 "md/raid1:%s: read error corrected "
44901 "(%d sectors at %llu on %s)\n",
44902 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44903 index 32e282f..5cec803 100644
44904 --- a/drivers/md/raid10.c
44905 +++ b/drivers/md/raid10.c
44906 @@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44907 /* The write handler will notice the lack of
44908 * R10BIO_Uptodate and record any errors etc
44909 */
44910 - atomic_add(r10_bio->sectors,
44911 + atomic_add_unchecked(r10_bio->sectors,
44912 &conf->mirrors[d].rdev->corrected_errors);
44913
44914 /* for reconstruct, we always reschedule after a read.
44915 @@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44916 {
44917 struct timespec cur_time_mon;
44918 unsigned long hours_since_last;
44919 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44920 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44921
44922 ktime_get_ts(&cur_time_mon);
44923
44924 @@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44925 * overflowing the shift of read_errors by hours_since_last.
44926 */
44927 if (hours_since_last >= 8 * sizeof(read_errors))
44928 - atomic_set(&rdev->read_errors, 0);
44929 + atomic_set_unchecked(&rdev->read_errors, 0);
44930 else
44931 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44932 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44933 }
44934
44935 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44936 @@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44937 return;
44938
44939 check_decay_read_errors(mddev, rdev);
44940 - atomic_inc(&rdev->read_errors);
44941 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44942 + atomic_inc_unchecked(&rdev->read_errors);
44943 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44944 char b[BDEVNAME_SIZE];
44945 bdevname(rdev->bdev, b);
44946
44947 @@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44948 "md/raid10:%s: %s: Raid device exceeded "
44949 "read_error threshold [cur %d:max %d]\n",
44950 mdname(mddev), b,
44951 - atomic_read(&rdev->read_errors), max_read_errors);
44952 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44953 printk(KERN_NOTICE
44954 "md/raid10:%s: %s: Failing raid device\n",
44955 mdname(mddev), b);
44956 @@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44957 sect +
44958 choose_data_offset(r10_bio, rdev)),
44959 bdevname(rdev->bdev, b));
44960 - atomic_add(s, &rdev->corrected_errors);
44961 + atomic_add_unchecked(s, &rdev->corrected_errors);
44962 }
44963
44964 rdev_dec_pending(rdev, mddev);
44965 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44966 index 8577cc7..e80e05d 100644
44967 --- a/drivers/md/raid5.c
44968 +++ b/drivers/md/raid5.c
44969 @@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44970 return 1;
44971 }
44972
44973 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44974 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44975 +#endif
44976 +
44977 static int grow_stripes(struct r5conf *conf, int num)
44978 {
44979 struct kmem_cache *sc;
44980 @@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44981 "raid%d-%s", conf->level, mdname(conf->mddev));
44982 else
44983 sprintf(conf->cache_name[0],
44984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44985 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44986 +#else
44987 "raid%d-%p", conf->level, conf->mddev);
44988 +#endif
44989 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44990
44991 conf->active_name = 0;
44992 @@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44993 mdname(conf->mddev), STRIPE_SECTORS,
44994 (unsigned long long)s,
44995 bdevname(rdev->bdev, b));
44996 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44997 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44998 clear_bit(R5_ReadError, &sh->dev[i].flags);
44999 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45000 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45001 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45002
45003 - if (atomic_read(&rdev->read_errors))
45004 - atomic_set(&rdev->read_errors, 0);
45005 + if (atomic_read_unchecked(&rdev->read_errors))
45006 + atomic_set_unchecked(&rdev->read_errors, 0);
45007 } else {
45008 const char *bdn = bdevname(rdev->bdev, b);
45009 int retry = 0;
45010 int set_bad = 0;
45011
45012 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45013 - atomic_inc(&rdev->read_errors);
45014 + atomic_inc_unchecked(&rdev->read_errors);
45015 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45016 printk_ratelimited(
45017 KERN_WARNING
45018 @@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45019 mdname(conf->mddev),
45020 (unsigned long long)s,
45021 bdn);
45022 - } else if (atomic_read(&rdev->read_errors)
45023 + } else if (atomic_read_unchecked(&rdev->read_errors)
45024 > conf->max_nr_stripes)
45025 printk(KERN_WARNING
45026 "md/raid:%s: Too many read errors, failing device %s.\n",
45027 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45028 index 983db75..ef9248c 100644
45029 --- a/drivers/media/dvb-core/dvbdev.c
45030 +++ b/drivers/media/dvb-core/dvbdev.c
45031 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45032 const struct dvb_device *template, void *priv, int type)
45033 {
45034 struct dvb_device *dvbdev;
45035 - struct file_operations *dvbdevfops;
45036 + file_operations_no_const *dvbdevfops;
45037 struct device *clsdev;
45038 int minor;
45039 int id;
45040 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45041 index 6ad22b6..6e90e2a 100644
45042 --- a/drivers/media/dvb-frontends/af9033.h
45043 +++ b/drivers/media/dvb-frontends/af9033.h
45044 @@ -96,6 +96,6 @@ struct af9033_ops {
45045 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45046 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45047 int onoff);
45048 -};
45049 +} __no_const;
45050
45051 #endif /* AF9033_H */
45052 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45053 index 9b6c3bb..baeb5c7 100644
45054 --- a/drivers/media/dvb-frontends/dib3000.h
45055 +++ b/drivers/media/dvb-frontends/dib3000.h
45056 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45057 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45058 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45059 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45060 -};
45061 +} __no_const;
45062
45063 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45064 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45065 diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45066 index 1fea0e9..321ce8f 100644
45067 --- a/drivers/media/dvb-frontends/dib7000p.h
45068 +++ b/drivers/media/dvb-frontends/dib7000p.h
45069 @@ -64,7 +64,7 @@ struct dib7000p_ops {
45070 int (*get_adc_power)(struct dvb_frontend *fe);
45071 int (*slave_reset)(struct dvb_frontend *fe);
45072 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45073 -};
45074 +} __no_const;
45075
45076 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45077 void *dib7000p_attach(struct dib7000p_ops *ops);
45078 diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45079 index 84cc103..5780c54 100644
45080 --- a/drivers/media/dvb-frontends/dib8000.h
45081 +++ b/drivers/media/dvb-frontends/dib8000.h
45082 @@ -61,7 +61,7 @@ struct dib8000_ops {
45083 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45084 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45085 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45086 -};
45087 +} __no_const;
45088
45089 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45090 void *dib8000_attach(struct dib8000_ops *ops);
45091 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45092 index ce27e6d..b70435a 100644
45093 --- a/drivers/media/pci/cx88/cx88-video.c
45094 +++ b/drivers/media/pci/cx88/cx88-video.c
45095 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45096
45097 /* ------------------------------------------------------------------ */
45098
45099 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45100 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45101 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45102 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45103 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45104 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45105
45106 module_param_array(video_nr, int, NULL, 0444);
45107 module_param_array(vbi_nr, int, NULL, 0444);
45108 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45109 index 802642d..5534900 100644
45110 --- a/drivers/media/pci/ivtv/ivtv-driver.c
45111 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
45112 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45113 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45114
45115 /* ivtv instance counter */
45116 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
45117 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45118
45119 /* Parameter declarations */
45120 static int cardtype[IVTV_MAX_CARDS];
45121 diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45122 index 8cbe6b4..ea3601c 100644
45123 --- a/drivers/media/pci/solo6x10/solo6x10-core.c
45124 +++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45125 @@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45126
45127 static int solo_sysfs_init(struct solo_dev *solo_dev)
45128 {
45129 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45130 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45131 struct device *dev = &solo_dev->dev;
45132 const char *driver;
45133 int i;
45134 diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45135 index c7141f2..5301fec 100644
45136 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45137 +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45138 @@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45139
45140 int solo_g723_init(struct solo_dev *solo_dev)
45141 {
45142 - static struct snd_device_ops ops = { NULL };
45143 + static struct snd_device_ops ops = { };
45144 struct snd_card *card;
45145 struct snd_kcontrol_new kctl;
45146 char name[32];
45147 diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45148 index 8c84846..27b4f83 100644
45149 --- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45150 +++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45151 @@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45152
45153 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45154 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45155 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45156 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45157 if (p2m_id < 0)
45158 p2m_id = -p2m_id;
45159 }
45160 diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45161 index 72017b7..dd37ae6 100644
45162 --- a/drivers/media/pci/solo6x10/solo6x10.h
45163 +++ b/drivers/media/pci/solo6x10/solo6x10.h
45164 @@ -219,7 +219,7 @@ struct solo_dev {
45165
45166 /* P2M DMA Engine */
45167 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45168 - atomic_t p2m_count;
45169 + atomic_unchecked_t p2m_count;
45170 int p2m_jiffies;
45171 unsigned int p2m_timeouts;
45172
45173 diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45174 index 63f0b64..a017c1c 100644
45175 --- a/drivers/media/pci/tw68/tw68-core.c
45176 +++ b/drivers/media/pci/tw68/tw68-core.c
45177 @@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45178 module_param_array(card, int, NULL, 0444);
45179 MODULE_PARM_DESC(card, "card type");
45180
45181 -static atomic_t tw68_instance = ATOMIC_INIT(0);
45182 +static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45183
45184 /* ------------------------------------------------------------------ */
45185
45186 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45187 index 64ab6fb..ef4a8b9 100644
45188 --- a/drivers/media/platform/omap/omap_vout.c
45189 +++ b/drivers/media/platform/omap/omap_vout.c
45190 @@ -63,7 +63,6 @@ enum omap_vout_channels {
45191 OMAP_VIDEO2,
45192 };
45193
45194 -static struct videobuf_queue_ops video_vbq_ops;
45195 /* Variables configurable through module params*/
45196 static u32 video1_numbuffers = 3;
45197 static u32 video2_numbuffers = 3;
45198 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45199 {
45200 struct videobuf_queue *q;
45201 struct omap_vout_device *vout = NULL;
45202 + static struct videobuf_queue_ops video_vbq_ops = {
45203 + .buf_setup = omap_vout_buffer_setup,
45204 + .buf_prepare = omap_vout_buffer_prepare,
45205 + .buf_release = omap_vout_buffer_release,
45206 + .buf_queue = omap_vout_buffer_queue,
45207 + };
45208
45209 vout = video_drvdata(file);
45210 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45211 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45212 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45213
45214 q = &vout->vbq;
45215 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45216 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45217 - video_vbq_ops.buf_release = omap_vout_buffer_release;
45218 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45219 spin_lock_init(&vout->vbq_lock);
45220
45221 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45222 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45223 index fb2acc5..a2fcbdc4 100644
45224 --- a/drivers/media/platform/s5p-tv/mixer.h
45225 +++ b/drivers/media/platform/s5p-tv/mixer.h
45226 @@ -156,7 +156,7 @@ struct mxr_layer {
45227 /** layer index (unique identifier) */
45228 int idx;
45229 /** callbacks for layer methods */
45230 - struct mxr_layer_ops ops;
45231 + struct mxr_layer_ops *ops;
45232 /** format array */
45233 const struct mxr_format **fmt_array;
45234 /** size of format array */
45235 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45236 index 74344c7..a39e70e 100644
45237 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45238 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45239 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45240 {
45241 struct mxr_layer *layer;
45242 int ret;
45243 - struct mxr_layer_ops ops = {
45244 + static struct mxr_layer_ops ops = {
45245 .release = mxr_graph_layer_release,
45246 .buffer_set = mxr_graph_buffer_set,
45247 .stream_set = mxr_graph_stream_set,
45248 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45249 index b713403..53cb5ad 100644
45250 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
45251 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45252 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45253 layer->update_buf = next;
45254 }
45255
45256 - layer->ops.buffer_set(layer, layer->update_buf);
45257 + layer->ops->buffer_set(layer, layer->update_buf);
45258
45259 if (done && done != layer->shadow_buf)
45260 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45261 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45262 index b4d2696..91df48e 100644
45263 --- a/drivers/media/platform/s5p-tv/mixer_video.c
45264 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
45265 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45266 layer->geo.src.height = layer->geo.src.full_height;
45267
45268 mxr_geometry_dump(mdev, &layer->geo);
45269 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45270 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45271 mxr_geometry_dump(mdev, &layer->geo);
45272 }
45273
45274 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45275 layer->geo.dst.full_width = mbus_fmt.width;
45276 layer->geo.dst.full_height = mbus_fmt.height;
45277 layer->geo.dst.field = mbus_fmt.field;
45278 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45279 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45280
45281 mxr_geometry_dump(mdev, &layer->geo);
45282 }
45283 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45284 /* set source size to highest accepted value */
45285 geo->src.full_width = max(geo->dst.full_width, pix->width);
45286 geo->src.full_height = max(geo->dst.full_height, pix->height);
45287 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45288 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45289 mxr_geometry_dump(mdev, &layer->geo);
45290 /* set cropping to total visible screen */
45291 geo->src.width = pix->width;
45292 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45293 geo->src.x_offset = 0;
45294 geo->src.y_offset = 0;
45295 /* assure consistency of geometry */
45296 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45297 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45298 mxr_geometry_dump(mdev, &layer->geo);
45299 /* set full size to lowest possible value */
45300 geo->src.full_width = 0;
45301 geo->src.full_height = 0;
45302 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45303 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45304 mxr_geometry_dump(mdev, &layer->geo);
45305
45306 /* returning results */
45307 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45308 target->width = s->r.width;
45309 target->height = s->r.height;
45310
45311 - layer->ops.fix_geometry(layer, stage, s->flags);
45312 + layer->ops->fix_geometry(layer, stage, s->flags);
45313
45314 /* retrieve update selection rectangle */
45315 res.left = target->x_offset;
45316 @@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45317 mxr_output_get(mdev);
45318
45319 mxr_layer_update_output(layer);
45320 - layer->ops.format_set(layer);
45321 + layer->ops->format_set(layer);
45322 /* enabling layer in hardware */
45323 spin_lock_irqsave(&layer->enq_slock, flags);
45324 layer->state = MXR_LAYER_STREAMING;
45325 spin_unlock_irqrestore(&layer->enq_slock, flags);
45326
45327 - layer->ops.stream_set(layer, MXR_ENABLE);
45328 + layer->ops->stream_set(layer, MXR_ENABLE);
45329 mxr_streamer_get(mdev);
45330
45331 return 0;
45332 @@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45333 spin_unlock_irqrestore(&layer->enq_slock, flags);
45334
45335 /* disabling layer in hardware */
45336 - layer->ops.stream_set(layer, MXR_DISABLE);
45337 + layer->ops->stream_set(layer, MXR_DISABLE);
45338 /* remove one streamer */
45339 mxr_streamer_put(mdev);
45340 /* allow changes in output configuration */
45341 @@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45342
45343 void mxr_layer_release(struct mxr_layer *layer)
45344 {
45345 - if (layer->ops.release)
45346 - layer->ops.release(layer);
45347 + if (layer->ops->release)
45348 + layer->ops->release(layer);
45349 }
45350
45351 void mxr_base_layer_release(struct mxr_layer *layer)
45352 @@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45353
45354 layer->mdev = mdev;
45355 layer->idx = idx;
45356 - layer->ops = *ops;
45357 + layer->ops = ops;
45358
45359 spin_lock_init(&layer->enq_slock);
45360 INIT_LIST_HEAD(&layer->enq_list);
45361 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45362 index c9388c4..ce71ece 100644
45363 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45364 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45365 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45366 {
45367 struct mxr_layer *layer;
45368 int ret;
45369 - struct mxr_layer_ops ops = {
45370 + static struct mxr_layer_ops ops = {
45371 .release = mxr_vp_layer_release,
45372 .buffer_set = mxr_vp_buffer_set,
45373 .stream_set = mxr_vp_stream_set,
45374 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45375 index 82affae..42833ec 100644
45376 --- a/drivers/media/radio/radio-cadet.c
45377 +++ b/drivers/media/radio/radio-cadet.c
45378 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45379 unsigned char readbuf[RDS_BUFFER];
45380 int i = 0;
45381
45382 + if (count > RDS_BUFFER)
45383 + return -EFAULT;
45384 mutex_lock(&dev->lock);
45385 if (dev->rdsstat == 0)
45386 cadet_start_rds(dev);
45387 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45388 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45389 mutex_unlock(&dev->lock);
45390
45391 - if (i && copy_to_user(data, readbuf, i))
45392 - return -EFAULT;
45393 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45394 + i = -EFAULT;
45395 +
45396 return i;
45397 }
45398
45399 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45400 index 5236035..c622c74 100644
45401 --- a/drivers/media/radio/radio-maxiradio.c
45402 +++ b/drivers/media/radio/radio-maxiradio.c
45403 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45404 /* TEA5757 pin mappings */
45405 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45406
45407 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45408 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45409
45410 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45411 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45412 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45413 index 050b3bb..79f62b9 100644
45414 --- a/drivers/media/radio/radio-shark.c
45415 +++ b/drivers/media/radio/radio-shark.c
45416 @@ -79,7 +79,7 @@ struct shark_device {
45417 u32 last_val;
45418 };
45419
45420 -static atomic_t shark_instance = ATOMIC_INIT(0);
45421 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45422
45423 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45424 {
45425 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45426 index 8654e0d..0608a64 100644
45427 --- a/drivers/media/radio/radio-shark2.c
45428 +++ b/drivers/media/radio/radio-shark2.c
45429 @@ -74,7 +74,7 @@ struct shark_device {
45430 u8 *transfer_buffer;
45431 };
45432
45433 -static atomic_t shark_instance = ATOMIC_INIT(0);
45434 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45435
45436 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45437 {
45438 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45439 index 633022b..7f10754 100644
45440 --- a/drivers/media/radio/radio-si476x.c
45441 +++ b/drivers/media/radio/radio-si476x.c
45442 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45443 struct si476x_radio *radio;
45444 struct v4l2_ctrl *ctrl;
45445
45446 - static atomic_t instance = ATOMIC_INIT(0);
45447 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45448
45449 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45450 if (!radio)
45451 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45452 index 9fd1527..8927230 100644
45453 --- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45454 +++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45455 @@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45456
45457 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45458 {
45459 - char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45460 - char result[64];
45461 - return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45462 - sizeof(result), 0);
45463 + char *buf;
45464 + char *result;
45465 + int retval;
45466 +
45467 + buf = kmalloc(2, GFP_KERNEL);
45468 + if (buf == NULL)
45469 + return -ENOMEM;
45470 + result = kmalloc(64, GFP_KERNEL);
45471 + if (result == NULL) {
45472 + kfree(buf);
45473 + return -ENOMEM;
45474 + }
45475 +
45476 + buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45477 + buf[1] = enable ? 1 : 0;
45478 +
45479 + retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45480 +
45481 + kfree(buf);
45482 + kfree(result);
45483 + return retval;
45484 }
45485
45486 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45487 {
45488 - char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45489 - char state[3];
45490 - return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45491 + char *buf;
45492 + char *state;
45493 + int retval;
45494 +
45495 + buf = kmalloc(2, GFP_KERNEL);
45496 + if (buf == NULL)
45497 + return -ENOMEM;
45498 + state = kmalloc(3, GFP_KERNEL);
45499 + if (state == NULL) {
45500 + kfree(buf);
45501 + return -ENOMEM;
45502 + }
45503 +
45504 + buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45505 + buf[1] = enable ? 1 : 0;
45506 +
45507 + retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45508 +
45509 + kfree(buf);
45510 + kfree(state);
45511 + return retval;
45512 }
45513
45514 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45515 {
45516 - char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45517 - char state[3];
45518 + char *query;
45519 + char *state;
45520 int ret;
45521 + query = kmalloc(1, GFP_KERNEL);
45522 + if (query == NULL)
45523 + return -ENOMEM;
45524 + state = kmalloc(3, GFP_KERNEL);
45525 + if (state == NULL) {
45526 + kfree(query);
45527 + return -ENOMEM;
45528 + }
45529 +
45530 + query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45531
45532 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45533
45534 - ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45535 - sizeof(state), 0);
45536 + ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45537 if (ret < 0) {
45538 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45539 "state info\n");
45540 @@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45541
45542 /* Copy this pointer as we are gonna need it in the release phase */
45543 cinergyt2_usb_device = adap->dev;
45544 -
45545 + kfree(query);
45546 + kfree(state);
45547 return 0;
45548 }
45549
45550 @@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45551 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45552 {
45553 struct cinergyt2_state *st = d->priv;
45554 - u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45555 + u8 *key, *cmd;
45556 int i;
45557
45558 + cmd = kmalloc(1, GFP_KERNEL);
45559 + if (cmd == NULL)
45560 + return -EINVAL;
45561 + key = kzalloc(5, GFP_KERNEL);
45562 + if (key == NULL) {
45563 + kfree(cmd);
45564 + return -EINVAL;
45565 + }
45566 +
45567 + cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45568 +
45569 *state = REMOTE_NO_KEY_PRESSED;
45570
45571 - dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45572 + dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45573 if (key[4] == 0xff) {
45574 /* key repeat */
45575 st->rc_counter++;
45576 @@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45577 *event = d->last_event;
45578 deb_rc("repeat key, event %x\n",
45579 *event);
45580 - return 0;
45581 + goto out;
45582 }
45583 }
45584 deb_rc("repeated key (non repeatable)\n");
45585 }
45586 - return 0;
45587 + goto out;
45588 }
45589
45590 /* hack to pass checksum on the custom field */
45591 @@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45592
45593 deb_rc("key: %*ph\n", 5, key);
45594 }
45595 +out:
45596 + kfree(cmd);
45597 + kfree(key);
45598 return 0;
45599 }
45600
45601 diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45602 index c890fe4..f9b2ae6 100644
45603 --- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45604 +++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45605 @@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45606 fe_status_t *status)
45607 {
45608 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45609 - struct dvbt_get_status_msg result;
45610 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45611 + struct dvbt_get_status_msg *result;
45612 + u8 *cmd;
45613 int ret;
45614
45615 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45616 - sizeof(result), 0);
45617 + cmd = kmalloc(1, GFP_KERNEL);
45618 + if (cmd == NULL)
45619 + return -ENOMEM;
45620 + result = kmalloc(sizeof(*result), GFP_KERNEL);
45621 + if (result == NULL) {
45622 + kfree(cmd);
45623 + return -ENOMEM;
45624 + }
45625 +
45626 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45627 +
45628 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45629 + sizeof(*result), 0);
45630 if (ret < 0)
45631 - return ret;
45632 + goto out;
45633
45634 *status = 0;
45635
45636 - if (0xffff - le16_to_cpu(result.gain) > 30)
45637 + if (0xffff - le16_to_cpu(result->gain) > 30)
45638 *status |= FE_HAS_SIGNAL;
45639 - if (result.lock_bits & (1 << 6))
45640 + if (result->lock_bits & (1 << 6))
45641 *status |= FE_HAS_LOCK;
45642 - if (result.lock_bits & (1 << 5))
45643 + if (result->lock_bits & (1 << 5))
45644 *status |= FE_HAS_SYNC;
45645 - if (result.lock_bits & (1 << 4))
45646 + if (result->lock_bits & (1 << 4))
45647 *status |= FE_HAS_CARRIER;
45648 - if (result.lock_bits & (1 << 1))
45649 + if (result->lock_bits & (1 << 1))
45650 *status |= FE_HAS_VITERBI;
45651
45652 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45653 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45654 *status &= ~FE_HAS_LOCK;
45655
45656 - return 0;
45657 +out:
45658 + kfree(cmd);
45659 + kfree(result);
45660 + return ret;
45661 }
45662
45663 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45664 {
45665 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45666 - struct dvbt_get_status_msg status;
45667 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45668 + struct dvbt_get_status_msg *status;
45669 + char *cmd;
45670 int ret;
45671
45672 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45673 - sizeof(status), 0);
45674 + cmd = kmalloc(1, GFP_KERNEL);
45675 + if (cmd == NULL)
45676 + return -ENOMEM;
45677 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45678 + if (status == NULL) {
45679 + kfree(cmd);
45680 + return -ENOMEM;
45681 + }
45682 +
45683 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45684 +
45685 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45686 + sizeof(*status), 0);
45687 if (ret < 0)
45688 - return ret;
45689 + goto out;
45690
45691 - *ber = le32_to_cpu(status.viterbi_error_rate);
45692 + *ber = le32_to_cpu(status->viterbi_error_rate);
45693 +out:
45694 + kfree(cmd);
45695 + kfree(status);
45696 return 0;
45697 }
45698
45699 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45700 {
45701 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45702 - struct dvbt_get_status_msg status;
45703 - u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45704 + struct dvbt_get_status_msg *status;
45705 + u8 *cmd;
45706 int ret;
45707
45708 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45709 - sizeof(status), 0);
45710 + cmd = kmalloc(1, GFP_KERNEL);
45711 + if (cmd == NULL)
45712 + return -ENOMEM;
45713 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45714 + if (status == NULL) {
45715 + kfree(cmd);
45716 + return -ENOMEM;
45717 + }
45718 +
45719 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45720 +
45721 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45722 + sizeof(*status), 0);
45723 if (ret < 0) {
45724 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45725 ret);
45726 - return ret;
45727 + goto out;
45728 }
45729 - *unc = le32_to_cpu(status.uncorrected_block_count);
45730 - return 0;
45731 + *unc = le32_to_cpu(status->uncorrected_block_count);
45732 +
45733 +out:
45734 + kfree(cmd);
45735 + kfree(status);
45736 + return ret;
45737 }
45738
45739 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45740 u16 *strength)
45741 {
45742 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45743 - struct dvbt_get_status_msg status;
45744 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45745 + struct dvbt_get_status_msg *status;
45746 + char *cmd;
45747 int ret;
45748
45749 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45750 - sizeof(status), 0);
45751 + cmd = kmalloc(1, GFP_KERNEL);
45752 + if (cmd == NULL)
45753 + return -ENOMEM;
45754 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45755 + if (status == NULL) {
45756 + kfree(cmd);
45757 + return -ENOMEM;
45758 + }
45759 +
45760 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45761 +
45762 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45763 + sizeof(*status), 0);
45764 if (ret < 0) {
45765 err("cinergyt2_fe_read_signal_strength() Failed!"
45766 " (Error=%d)\n", ret);
45767 - return ret;
45768 + goto out;
45769 }
45770 - *strength = (0xffff - le16_to_cpu(status.gain));
45771 + *strength = (0xffff - le16_to_cpu(status->gain));
45772 +
45773 +out:
45774 + kfree(cmd);
45775 + kfree(status);
45776 return 0;
45777 }
45778
45779 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45780 {
45781 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45782 - struct dvbt_get_status_msg status;
45783 - char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45784 + struct dvbt_get_status_msg *status;
45785 + char *cmd;
45786 int ret;
45787
45788 - ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45789 - sizeof(status), 0);
45790 + cmd = kmalloc(1, GFP_KERNEL);
45791 + if (cmd == NULL)
45792 + return -ENOMEM;
45793 + status = kmalloc(sizeof(*status), GFP_KERNEL);
45794 + if (status == NULL) {
45795 + kfree(cmd);
45796 + return -ENOMEM;
45797 + }
45798 +
45799 + cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45800 +
45801 + ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45802 + sizeof(*status), 0);
45803 if (ret < 0) {
45804 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45805 - return ret;
45806 + goto out;
45807 }
45808 - *snr = (status.snr << 8) | status.snr;
45809 - return 0;
45810 + *snr = (status->snr << 8) | status->snr;
45811 +
45812 +out:
45813 + kfree(cmd);
45814 + kfree(status);
45815 + return ret;
45816 }
45817
45818 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45819 @@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45820 {
45821 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45822 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45823 - struct dvbt_set_parameters_msg param;
45824 - char result[2];
45825 + struct dvbt_set_parameters_msg *param;
45826 + char *result;
45827 int err;
45828
45829 - param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45830 - param.tps = cpu_to_le16(compute_tps(fep));
45831 - param.freq = cpu_to_le32(fep->frequency / 1000);
45832 - param.flags = 0;
45833 + result = kmalloc(2, GFP_KERNEL);
45834 + if (result == NULL)
45835 + return -ENOMEM;
45836 + param = kmalloc(sizeof(*param), GFP_KERNEL);
45837 + if (param == NULL) {
45838 + kfree(result);
45839 + return -ENOMEM;
45840 + }
45841 +
45842 + param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45843 + param->tps = cpu_to_le16(compute_tps(fep));
45844 + param->freq = cpu_to_le32(fep->frequency / 1000);
45845 + param->flags = 0;
45846
45847 switch (fep->bandwidth_hz) {
45848 default:
45849 case 8000000:
45850 - param.bandwidth = 8;
45851 + param->bandwidth = 8;
45852 break;
45853 case 7000000:
45854 - param.bandwidth = 7;
45855 + param->bandwidth = 7;
45856 break;
45857 case 6000000:
45858 - param.bandwidth = 6;
45859 + param->bandwidth = 6;
45860 break;
45861 }
45862
45863 err = dvb_usb_generic_rw(state->d,
45864 - (char *)&param, sizeof(param),
45865 - result, sizeof(result), 0);
45866 + (char *)param, sizeof(*param),
45867 + result, 2, 0);
45868 if (err < 0)
45869 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45870
45871 - return (err < 0) ? err : 0;
45872 + kfree(result);
45873 + kfree(param);
45874 + return err;
45875 }
45876
45877 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45878 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45879 index 733a7ff..f8b52e3 100644
45880 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45881 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45882 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45883
45884 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45885 {
45886 - struct hexline hx;
45887 - u8 reset;
45888 + struct hexline *hx;
45889 + u8 *reset;
45890 int ret,pos=0;
45891
45892 + reset = kmalloc(1, GFP_KERNEL);
45893 + if (reset == NULL)
45894 + return -ENOMEM;
45895 +
45896 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45897 + if (hx == NULL) {
45898 + kfree(reset);
45899 + return -ENOMEM;
45900 + }
45901 +
45902 /* stop the CPU */
45903 - reset = 1;
45904 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45905 + reset[0] = 1;
45906 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45907 err("could not stop the USB controller CPU.");
45908
45909 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45910 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45911 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45912 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45913 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45914 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45915
45916 - if (ret != hx.len) {
45917 + if (ret != hx->len) {
45918 err("error while transferring firmware "
45919 "(transferred size: %d, block size: %d)",
45920 - ret,hx.len);
45921 + ret,hx->len);
45922 ret = -EINVAL;
45923 break;
45924 }
45925 }
45926 if (ret < 0) {
45927 err("firmware download failed at %d with %d",pos,ret);
45928 + kfree(reset);
45929 + kfree(hx);
45930 return ret;
45931 }
45932
45933 if (ret == 0) {
45934 /* restart the CPU */
45935 - reset = 0;
45936 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45937 + reset[0] = 0;
45938 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45939 err("could not restart the USB controller CPU.");
45940 ret = -EINVAL;
45941 }
45942 } else
45943 ret = -EIO;
45944
45945 + kfree(reset);
45946 + kfree(hx);
45947 +
45948 return ret;
45949 }
45950 EXPORT_SYMBOL(usb_cypress_load_firmware);
45951 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45952 index 1a3df10..57997a5 100644
45953 --- a/drivers/media/usb/dvb-usb/dw2102.c
45954 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45955 @@ -118,7 +118,7 @@ struct su3000_state {
45956
45957 struct s6x0_state {
45958 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45959 -};
45960 +} __no_const;
45961
45962 /* debug */
45963 static int dvb_usb_dw2102_debug;
45964 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45965 index 6b0b8b6b..4038398 100644
45966 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45967 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45968 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
45969 static int technisat_usb2_i2c_access(struct usb_device *udev,
45970 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45971 {
45972 - u8 b[64];
45973 - int ret, actual_length;
45974 + u8 *b = kmalloc(64, GFP_KERNEL);
45975 + int ret, actual_length, error = 0;
45976 +
45977 + if (b == NULL)
45978 + return -ENOMEM;
45979
45980 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45981 debug_dump(tx, txlen, deb_i2c);
45982 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45983
45984 if (ret < 0) {
45985 err("i2c-error: out failed %02x = %d", device_addr, ret);
45986 - return -ENODEV;
45987 + error = -ENODEV;
45988 + goto out;
45989 }
45990
45991 ret = usb_bulk_msg(udev,
45992 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45993 b, 64, &actual_length, 1000);
45994 if (ret < 0) {
45995 err("i2c-error: in failed %02x = %d", device_addr, ret);
45996 - return -ENODEV;
45997 + error = -ENODEV;
45998 + goto out;
45999 }
46000
46001 if (b[0] != I2C_STATUS_OK) {
46002 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46003 /* handle tuner-i2c-nak */
46004 if (!(b[0] == I2C_STATUS_NAK &&
46005 device_addr == 0x60
46006 - /* && device_is_technisat_usb2 */))
46007 - return -ENODEV;
46008 + /* && device_is_technisat_usb2 */)) {
46009 + error = -ENODEV;
46010 + goto out;
46011 + }
46012 }
46013
46014 deb_i2c("status: %d, ", b[0]);
46015 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46016
46017 deb_i2c("\n");
46018
46019 - return 0;
46020 +out:
46021 + kfree(b);
46022 + return error;
46023 }
46024
46025 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46026 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46027 {
46028 int ret;
46029
46030 - u8 led[8] = {
46031 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46032 - 0
46033 - };
46034 + u8 *led = kzalloc(8, GFP_KERNEL);
46035 +
46036 + if (led == NULL)
46037 + return -ENOMEM;
46038
46039 if (disable_led_control && state != TECH_LED_OFF)
46040 return 0;
46041
46042 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46043 +
46044 switch (state) {
46045 case TECH_LED_ON:
46046 led[1] = 0x82;
46047 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46048 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46049 USB_TYPE_VENDOR | USB_DIR_OUT,
46050 0, 0,
46051 - led, sizeof(led), 500);
46052 + led, 8, 500);
46053
46054 mutex_unlock(&d->i2c_mutex);
46055 +
46056 + kfree(led);
46057 +
46058 return ret;
46059 }
46060
46061 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46062 {
46063 int ret;
46064 - u8 b = 0;
46065 + u8 *b = kzalloc(1, GFP_KERNEL);
46066 +
46067 + if (b == NULL)
46068 + return -ENOMEM;
46069
46070 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46071 return -EAGAIN;
46072 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46073 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46074 USB_TYPE_VENDOR | USB_DIR_OUT,
46075 (red << 8) | green, 0,
46076 - &b, 1, 500);
46077 + b, 1, 500);
46078
46079 mutex_unlock(&d->i2c_mutex);
46080
46081 + kfree(b);
46082 +
46083 return ret;
46084 }
46085
46086 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46087 struct dvb_usb_device_description **desc, int *cold)
46088 {
46089 int ret;
46090 - u8 version[3];
46091 + u8 *version = kmalloc(3, GFP_KERNEL);
46092
46093 /* first select the interface */
46094 if (usb_set_interface(udev, 0, 1) != 0)
46095 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46096
46097 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46098
46099 + if (version == NULL)
46100 + return 0;
46101 +
46102 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46103 GET_VERSION_INFO_VENDOR_REQUEST,
46104 USB_TYPE_VENDOR | USB_DIR_IN,
46105 0, 0,
46106 - version, sizeof(version), 500);
46107 + version, 3, 500);
46108
46109 if (ret < 0)
46110 *cold = 1;
46111 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46112 *cold = 0;
46113 }
46114
46115 + kfree(version);
46116 +
46117 return 0;
46118 }
46119
46120 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46121
46122 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46123 {
46124 - u8 buf[62], *b;
46125 + u8 *buf, *b;
46126 int ret;
46127 struct ir_raw_event ev;
46128
46129 + buf = kmalloc(62, GFP_KERNEL);
46130 +
46131 + if (buf == NULL)
46132 + return -ENOMEM;
46133 +
46134 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46135 buf[1] = 0x08;
46136 buf[2] = 0x8f;
46137 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46138 GET_IR_DATA_VENDOR_REQUEST,
46139 USB_TYPE_VENDOR | USB_DIR_IN,
46140 0x8080, 0,
46141 - buf, sizeof(buf), 500);
46142 + buf, 62, 500);
46143
46144 unlock:
46145 mutex_unlock(&d->i2c_mutex);
46146
46147 - if (ret < 0)
46148 + if (ret < 0) {
46149 + kfree(buf);
46150 return ret;
46151 + }
46152
46153 - if (ret == 1)
46154 + if (ret == 1) {
46155 + kfree(buf);
46156 return 0; /* no key pressed */
46157 + }
46158
46159 /* decoding */
46160 b = buf+1;
46161 @@ -653,6 +686,8 @@ unlock:
46162
46163 ir_raw_event_handle(d->rc_dev);
46164
46165 + kfree(buf);
46166 +
46167 return 1;
46168 }
46169
46170 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46171 index e502a5f..2a27f40 100644
46172 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46173 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46174 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46175 * by passing a very big num_planes value */
46176 uplane = compat_alloc_user_space(num_planes *
46177 sizeof(struct v4l2_plane));
46178 - kp->m.planes = (__force struct v4l2_plane *)uplane;
46179 + kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46180
46181 while (--num_planes >= 0) {
46182 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46183 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46184 if (num_planes == 0)
46185 return 0;
46186
46187 - uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46188 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46189 if (get_user(p, &up->m.planes))
46190 return -EFAULT;
46191 uplane32 = compat_ptr(p);
46192 @@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46193 get_user(kp->flags, &up->flags) ||
46194 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46195 return -EFAULT;
46196 - kp->base = (__force void *)compat_ptr(tmp);
46197 + kp->base = (__force_kernel void *)compat_ptr(tmp);
46198 return 0;
46199 }
46200
46201 @@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46202 n * sizeof(struct v4l2_ext_control32)))
46203 return -EFAULT;
46204 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46205 - kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46206 + kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46207 while (--n >= 0) {
46208 u32 id;
46209
46210 @@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46211 {
46212 struct v4l2_ext_control32 __user *ucontrols;
46213 struct v4l2_ext_control __user *kcontrols =
46214 - (__force struct v4l2_ext_control __user *)kp->controls;
46215 + (struct v4l2_ext_control __force_user *)kp->controls;
46216 int n = kp->count;
46217 compat_caddr_t p;
46218
46219 @@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46220 get_user(tmp, &up->edid) ||
46221 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46222 return -EFAULT;
46223 - kp->edid = (__force u8 *)compat_ptr(tmp);
46224 + kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46225 return 0;
46226 }
46227
46228 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46229 index 015f92a..59e311e 100644
46230 --- a/drivers/media/v4l2-core/v4l2-device.c
46231 +++ b/drivers/media/v4l2-core/v4l2-device.c
46232 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46233 EXPORT_SYMBOL_GPL(v4l2_device_put);
46234
46235 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46236 - atomic_t *instance)
46237 + atomic_unchecked_t *instance)
46238 {
46239 - int num = atomic_inc_return(instance) - 1;
46240 + int num = atomic_inc_return_unchecked(instance) - 1;
46241 int len = strlen(basename);
46242
46243 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46244 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46245 index 9ccb19a..d131468 100644
46246 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
46247 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46248 @@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46249 struct file *file, void *fh, void *p);
46250 } u;
46251 void (*debug)(const void *arg, bool write_only);
46252 -};
46253 +} __do_const;
46254 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46255
46256 /* This control needs a priority check */
46257 #define INFO_FL_PRIO (1 << 0)
46258 @@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46259 struct video_device *vfd = video_devdata(file);
46260 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46261 bool write_only = false;
46262 - struct v4l2_ioctl_info default_info;
46263 + v4l2_ioctl_info_no_const default_info;
46264 const struct v4l2_ioctl_info *info;
46265 void *fh = file->private_data;
46266 struct v4l2_fh *vfh = NULL;
46267 @@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46268 ret = -EINVAL;
46269 break;
46270 }
46271 - *user_ptr = (void __user *)buf->m.planes;
46272 + *user_ptr = (void __force_user *)buf->m.planes;
46273 *kernel_ptr = (void **)&buf->m.planes;
46274 *array_size = sizeof(struct v4l2_plane) * buf->length;
46275 ret = 1;
46276 @@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46277 ret = -EINVAL;
46278 break;
46279 }
46280 - *user_ptr = (void __user *)edid->edid;
46281 + *user_ptr = (void __force_user *)edid->edid;
46282 *kernel_ptr = (void **)&edid->edid;
46283 *array_size = edid->blocks * 128;
46284 ret = 1;
46285 @@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46286 ret = -EINVAL;
46287 break;
46288 }
46289 - *user_ptr = (void __user *)ctrls->controls;
46290 + *user_ptr = (void __force_user *)ctrls->controls;
46291 *kernel_ptr = (void **)&ctrls->controls;
46292 *array_size = sizeof(struct v4l2_ext_control)
46293 * ctrls->count;
46294 @@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46295 }
46296
46297 if (has_array_args) {
46298 - *kernel_ptr = (void __force *)user_ptr;
46299 + *kernel_ptr = (void __force_kernel *)user_ptr;
46300 if (copy_to_user(user_ptr, mbuf, array_size))
46301 err = -EFAULT;
46302 goto out_array_args;
46303 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46304 index 187f836..679544b 100644
46305 --- a/drivers/message/fusion/mptbase.c
46306 +++ b/drivers/message/fusion/mptbase.c
46307 @@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46308 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46309 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46310
46311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46312 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46313 +#else
46314 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46315 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46316 +#endif
46317 +
46318 /*
46319 * Rounding UP to nearest 4-kB boundary here...
46320 */
46321 @@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46322 ioc->facts.GlobalCredits);
46323
46324 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46325 +#ifdef CONFIG_GRKERNSEC_HIDESYM
46326 + NULL, NULL);
46327 +#else
46328 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46329 +#endif
46330 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46331 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46332 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46333 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46334 index 0707fa2..70ca794 100644
46335 --- a/drivers/message/fusion/mptsas.c
46336 +++ b/drivers/message/fusion/mptsas.c
46337 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46338 return 0;
46339 }
46340
46341 +static inline void
46342 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46343 +{
46344 + if (phy_info->port_details) {
46345 + phy_info->port_details->rphy = rphy;
46346 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46347 + ioc->name, rphy));
46348 + }
46349 +
46350 + if (rphy) {
46351 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46352 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46353 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46354 + ioc->name, rphy, rphy->dev.release));
46355 + }
46356 +}
46357 +
46358 /* no mutex */
46359 static void
46360 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46361 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46362 return NULL;
46363 }
46364
46365 -static inline void
46366 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46367 -{
46368 - if (phy_info->port_details) {
46369 - phy_info->port_details->rphy = rphy;
46370 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46371 - ioc->name, rphy));
46372 - }
46373 -
46374 - if (rphy) {
46375 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46376 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46377 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46378 - ioc->name, rphy, rphy->dev.release));
46379 - }
46380 -}
46381 -
46382 static inline struct sas_port *
46383 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46384 {
46385 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46386 index b7d87cd..3fb36da 100644
46387 --- a/drivers/message/i2o/i2o_proc.c
46388 +++ b/drivers/message/i2o/i2o_proc.c
46389 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46390 "Array Controller Device"
46391 };
46392
46393 -static char *chtostr(char *tmp, u8 *chars, int n)
46394 -{
46395 - tmp[0] = 0;
46396 - return strncat(tmp, (char *)chars, n);
46397 -}
46398 -
46399 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46400 char *group)
46401 {
46402 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46403 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46404 {
46405 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46406 - static u32 work32[5];
46407 - static u8 *work8 = (u8 *) work32;
46408 - static u16 *work16 = (u16 *) work32;
46409 + u32 work32[5];
46410 + u8 *work8 = (u8 *) work32;
46411 + u16 *work16 = (u16 *) work32;
46412 int token;
46413 u32 hwcap;
46414
46415 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46416 } *result;
46417
46418 i2o_exec_execute_ddm_table ddm_table;
46419 - char tmp[28 + 1];
46420
46421 result = kmalloc(sizeof(*result), GFP_KERNEL);
46422 if (!result)
46423 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46424
46425 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46426 seq_printf(seq, "%-#8x", ddm_table.module_id);
46427 - seq_printf(seq, "%-29s",
46428 - chtostr(tmp, ddm_table.module_name_version, 28));
46429 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46430 seq_printf(seq, "%9d ", ddm_table.data_size);
46431 seq_printf(seq, "%8d", ddm_table.code_size);
46432
46433 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46434
46435 i2o_driver_result_table *result;
46436 i2o_driver_store_table *dst;
46437 - char tmp[28 + 1];
46438
46439 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46440 if (result == NULL)
46441 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46442
46443 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46444 seq_printf(seq, "%-#8x", dst->module_id);
46445 - seq_printf(seq, "%-29s",
46446 - chtostr(tmp, dst->module_name_version, 28));
46447 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46448 + seq_printf(seq, "%-.28s", dst->module_name_version);
46449 + seq_printf(seq, "%-.8s", dst->date);
46450 seq_printf(seq, "%8d ", dst->module_size);
46451 seq_printf(seq, "%8d ", dst->mpb_size);
46452 seq_printf(seq, "0x%04x", dst->module_flags);
46453 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46454 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46455 {
46456 struct i2o_device *d = (struct i2o_device *)seq->private;
46457 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46458 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46459 // == (allow) 512d bytes (max)
46460 - static u16 *work16 = (u16 *) work32;
46461 + u16 *work16 = (u16 *) work32;
46462 int token;
46463 - char tmp[16 + 1];
46464
46465 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46466
46467 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46468 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46469 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46470 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46471 - seq_printf(seq, "Vendor info : %s\n",
46472 - chtostr(tmp, (u8 *) (work32 + 2), 16));
46473 - seq_printf(seq, "Product info : %s\n",
46474 - chtostr(tmp, (u8 *) (work32 + 6), 16));
46475 - seq_printf(seq, "Description : %s\n",
46476 - chtostr(tmp, (u8 *) (work32 + 10), 16));
46477 - seq_printf(seq, "Product rev. : %s\n",
46478 - chtostr(tmp, (u8 *) (work32 + 14), 8));
46479 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46480 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46481 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46482 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46483
46484 seq_printf(seq, "Serial number : ");
46485 print_serial_number(seq, (u8 *) (work32 + 16),
46486 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46487 u8 pad[256]; // allow up to 256 byte (max) serial number
46488 } result;
46489
46490 - char tmp[24 + 1];
46491 -
46492 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46493
46494 if (token < 0) {
46495 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46496 }
46497
46498 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46499 - seq_printf(seq, "Module name : %s\n",
46500 - chtostr(tmp, result.module_name, 24));
46501 - seq_printf(seq, "Module revision : %s\n",
46502 - chtostr(tmp, result.module_rev, 8));
46503 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
46504 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46505
46506 seq_printf(seq, "Serial number : ");
46507 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46508 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46509 u8 instance_number[4];
46510 } result;
46511
46512 - char tmp[64 + 1];
46513 -
46514 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46515
46516 if (token < 0) {
46517 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46518 return 0;
46519 }
46520
46521 - seq_printf(seq, "Device name : %s\n",
46522 - chtostr(tmp, result.device_name, 64));
46523 - seq_printf(seq, "Service name : %s\n",
46524 - chtostr(tmp, result.service_name, 64));
46525 - seq_printf(seq, "Physical name : %s\n",
46526 - chtostr(tmp, result.physical_location, 64));
46527 - seq_printf(seq, "Instance number : %s\n",
46528 - chtostr(tmp, result.instance_number, 4));
46529 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
46530 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
46531 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46532 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46533
46534 return 0;
46535 }
46536 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46537 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46538 {
46539 struct i2o_device *d = (struct i2o_device *)seq->private;
46540 - static u32 work32[12];
46541 - static u16 *work16 = (u16 *) work32;
46542 - static u8 *work8 = (u8 *) work32;
46543 + u32 work32[12];
46544 + u16 *work16 = (u16 *) work32;
46545 + u8 *work8 = (u8 *) work32;
46546 int token;
46547
46548 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46549 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46550 index 92752fb..a7494f6 100644
46551 --- a/drivers/message/i2o/iop.c
46552 +++ b/drivers/message/i2o/iop.c
46553 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46554
46555 spin_lock_irqsave(&c->context_list_lock, flags);
46556
46557 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46558 - atomic_inc(&c->context_list_counter);
46559 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46560 + atomic_inc_unchecked(&c->context_list_counter);
46561
46562 - entry->context = atomic_read(&c->context_list_counter);
46563 + entry->context = atomic_read_unchecked(&c->context_list_counter);
46564
46565 list_add(&entry->list, &c->context_list);
46566
46567 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46568
46569 #if BITS_PER_LONG == 64
46570 spin_lock_init(&c->context_list_lock);
46571 - atomic_set(&c->context_list_counter, 0);
46572 + atomic_set_unchecked(&c->context_list_counter, 0);
46573 INIT_LIST_HEAD(&c->context_list);
46574 #endif
46575
46576 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46577 index b2c7e3b..85aa4764 100644
46578 --- a/drivers/mfd/ab8500-debugfs.c
46579 +++ b/drivers/mfd/ab8500-debugfs.c
46580 @@ -100,7 +100,7 @@ static int irq_last;
46581 static u32 *irq_count;
46582 static int num_irqs;
46583
46584 -static struct device_attribute **dev_attr;
46585 +static device_attribute_no_const **dev_attr;
46586 static char **event_name;
46587
46588 static u8 avg_sample = SAMPLE_16;
46589 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46590 index c880c89..45a7c68 100644
46591 --- a/drivers/mfd/max8925-i2c.c
46592 +++ b/drivers/mfd/max8925-i2c.c
46593 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46594 const struct i2c_device_id *id)
46595 {
46596 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46597 - static struct max8925_chip *chip;
46598 + struct max8925_chip *chip;
46599 struct device_node *node = client->dev.of_node;
46600
46601 if (node && !pdata) {
46602 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46603 index 7612d89..70549c2 100644
46604 --- a/drivers/mfd/tps65910.c
46605 +++ b/drivers/mfd/tps65910.c
46606 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46607 struct tps65910_platform_data *pdata)
46608 {
46609 int ret = 0;
46610 - static struct regmap_irq_chip *tps6591x_irqs_chip;
46611 + struct regmap_irq_chip *tps6591x_irqs_chip;
46612
46613 if (!irq) {
46614 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46615 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46616 index 1b772ef..01e77d33 100644
46617 --- a/drivers/mfd/twl4030-irq.c
46618 +++ b/drivers/mfd/twl4030-irq.c
46619 @@ -34,6 +34,7 @@
46620 #include <linux/of.h>
46621 #include <linux/irqdomain.h>
46622 #include <linux/i2c/twl.h>
46623 +#include <asm/pgtable.h>
46624
46625 #include "twl-core.h"
46626
46627 @@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46628 * Install an irq handler for each of the SIH modules;
46629 * clone dummy irq_chip since PIH can't *do* anything
46630 */
46631 - twl4030_irq_chip = dummy_irq_chip;
46632 - twl4030_irq_chip.name = "twl4030";
46633 + pax_open_kernel();
46634 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46635 + *(const char **)&twl4030_irq_chip.name = "twl4030";
46636
46637 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46638 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46639 + pax_close_kernel();
46640
46641 for (i = irq_base; i < irq_end; i++) {
46642 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46643 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46644 index 464419b..64bae8d 100644
46645 --- a/drivers/misc/c2port/core.c
46646 +++ b/drivers/misc/c2port/core.c
46647 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46648 goto error_idr_alloc;
46649 c2dev->id = ret;
46650
46651 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46652 + pax_open_kernel();
46653 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46654 + pax_close_kernel();
46655
46656 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46657 "c2port%d", c2dev->id);
46658 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46659 index 3f2b625..945e179 100644
46660 --- a/drivers/misc/eeprom/sunxi_sid.c
46661 +++ b/drivers/misc/eeprom/sunxi_sid.c
46662 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46663
46664 platform_set_drvdata(pdev, sid_data);
46665
46666 - sid_bin_attr.size = sid_data->keysize;
46667 + pax_open_kernel();
46668 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46669 + pax_close_kernel();
46670 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46671 return -ENODEV;
46672
46673 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46674 index 36f5d52..32311c3 100644
46675 --- a/drivers/misc/kgdbts.c
46676 +++ b/drivers/misc/kgdbts.c
46677 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46678 char before[BREAK_INSTR_SIZE];
46679 char after[BREAK_INSTR_SIZE];
46680
46681 - probe_kernel_read(before, (char *)kgdbts_break_test,
46682 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46683 BREAK_INSTR_SIZE);
46684 init_simple_test();
46685 ts.tst = plant_and_detach_test;
46686 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46687 /* Activate test with initial breakpoint */
46688 if (!is_early)
46689 kgdb_breakpoint();
46690 - probe_kernel_read(after, (char *)kgdbts_break_test,
46691 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46692 BREAK_INSTR_SIZE);
46693 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46694 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46695 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46696 index 3ef4627..8d00486 100644
46697 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
46698 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46699 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46700 * the lid is closed. This leads to interrupts as soon as a little move
46701 * is done.
46702 */
46703 - atomic_inc(&lis3->count);
46704 + atomic_inc_unchecked(&lis3->count);
46705
46706 wake_up_interruptible(&lis3->misc_wait);
46707 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46708 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46709 if (lis3->pm_dev)
46710 pm_runtime_get_sync(lis3->pm_dev);
46711
46712 - atomic_set(&lis3->count, 0);
46713 + atomic_set_unchecked(&lis3->count, 0);
46714 return 0;
46715 }
46716
46717 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46718 add_wait_queue(&lis3->misc_wait, &wait);
46719 while (true) {
46720 set_current_state(TASK_INTERRUPTIBLE);
46721 - data = atomic_xchg(&lis3->count, 0);
46722 + data = atomic_xchg_unchecked(&lis3->count, 0);
46723 if (data)
46724 break;
46725
46726 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46727 struct lis3lv02d, miscdev);
46728
46729 poll_wait(file, &lis3->misc_wait, wait);
46730 - if (atomic_read(&lis3->count))
46731 + if (atomic_read_unchecked(&lis3->count))
46732 return POLLIN | POLLRDNORM;
46733 return 0;
46734 }
46735 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46736 index c439c82..1f20f57 100644
46737 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
46738 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46739 @@ -297,7 +297,7 @@ struct lis3lv02d {
46740 struct input_polled_dev *idev; /* input device */
46741 struct platform_device *pdev; /* platform device */
46742 struct regulator_bulk_data regulators[2];
46743 - atomic_t count; /* interrupt count after last read */
46744 + atomic_unchecked_t count; /* interrupt count after last read */
46745 union axis_conversion ac; /* hw -> logical axis */
46746 int mapped_btns[3];
46747
46748 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46749 index 2f30bad..c4c13d0 100644
46750 --- a/drivers/misc/sgi-gru/gruhandles.c
46751 +++ b/drivers/misc/sgi-gru/gruhandles.c
46752 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46753 unsigned long nsec;
46754
46755 nsec = CLKS2NSEC(clks);
46756 - atomic_long_inc(&mcs_op_statistics[op].count);
46757 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
46758 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46759 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46760 if (mcs_op_statistics[op].max < nsec)
46761 mcs_op_statistics[op].max = nsec;
46762 }
46763 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46764 index 4f76359..cdfcb2e 100644
46765 --- a/drivers/misc/sgi-gru/gruprocfs.c
46766 +++ b/drivers/misc/sgi-gru/gruprocfs.c
46767 @@ -32,9 +32,9 @@
46768
46769 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46770
46771 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46772 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46773 {
46774 - unsigned long val = atomic_long_read(v);
46775 + unsigned long val = atomic_long_read_unchecked(v);
46776
46777 seq_printf(s, "%16lu %s\n", val, id);
46778 }
46779 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46780
46781 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46782 for (op = 0; op < mcsop_last; op++) {
46783 - count = atomic_long_read(&mcs_op_statistics[op].count);
46784 - total = atomic_long_read(&mcs_op_statistics[op].total);
46785 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46786 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46787 max = mcs_op_statistics[op].max;
46788 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46789 count ? total / count : 0, max);
46790 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46791 index 5c3ce24..4915ccb 100644
46792 --- a/drivers/misc/sgi-gru/grutables.h
46793 +++ b/drivers/misc/sgi-gru/grutables.h
46794 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46795 * GRU statistics.
46796 */
46797 struct gru_stats_s {
46798 - atomic_long_t vdata_alloc;
46799 - atomic_long_t vdata_free;
46800 - atomic_long_t gts_alloc;
46801 - atomic_long_t gts_free;
46802 - atomic_long_t gms_alloc;
46803 - atomic_long_t gms_free;
46804 - atomic_long_t gts_double_allocate;
46805 - atomic_long_t assign_context;
46806 - atomic_long_t assign_context_failed;
46807 - atomic_long_t free_context;
46808 - atomic_long_t load_user_context;
46809 - atomic_long_t load_kernel_context;
46810 - atomic_long_t lock_kernel_context;
46811 - atomic_long_t unlock_kernel_context;
46812 - atomic_long_t steal_user_context;
46813 - atomic_long_t steal_kernel_context;
46814 - atomic_long_t steal_context_failed;
46815 - atomic_long_t nopfn;
46816 - atomic_long_t asid_new;
46817 - atomic_long_t asid_next;
46818 - atomic_long_t asid_wrap;
46819 - atomic_long_t asid_reuse;
46820 - atomic_long_t intr;
46821 - atomic_long_t intr_cbr;
46822 - atomic_long_t intr_tfh;
46823 - atomic_long_t intr_spurious;
46824 - atomic_long_t intr_mm_lock_failed;
46825 - atomic_long_t call_os;
46826 - atomic_long_t call_os_wait_queue;
46827 - atomic_long_t user_flush_tlb;
46828 - atomic_long_t user_unload_context;
46829 - atomic_long_t user_exception;
46830 - atomic_long_t set_context_option;
46831 - atomic_long_t check_context_retarget_intr;
46832 - atomic_long_t check_context_unload;
46833 - atomic_long_t tlb_dropin;
46834 - atomic_long_t tlb_preload_page;
46835 - atomic_long_t tlb_dropin_fail_no_asid;
46836 - atomic_long_t tlb_dropin_fail_upm;
46837 - atomic_long_t tlb_dropin_fail_invalid;
46838 - atomic_long_t tlb_dropin_fail_range_active;
46839 - atomic_long_t tlb_dropin_fail_idle;
46840 - atomic_long_t tlb_dropin_fail_fmm;
46841 - atomic_long_t tlb_dropin_fail_no_exception;
46842 - atomic_long_t tfh_stale_on_fault;
46843 - atomic_long_t mmu_invalidate_range;
46844 - atomic_long_t mmu_invalidate_page;
46845 - atomic_long_t flush_tlb;
46846 - atomic_long_t flush_tlb_gru;
46847 - atomic_long_t flush_tlb_gru_tgh;
46848 - atomic_long_t flush_tlb_gru_zero_asid;
46849 + atomic_long_unchecked_t vdata_alloc;
46850 + atomic_long_unchecked_t vdata_free;
46851 + atomic_long_unchecked_t gts_alloc;
46852 + atomic_long_unchecked_t gts_free;
46853 + atomic_long_unchecked_t gms_alloc;
46854 + atomic_long_unchecked_t gms_free;
46855 + atomic_long_unchecked_t gts_double_allocate;
46856 + atomic_long_unchecked_t assign_context;
46857 + atomic_long_unchecked_t assign_context_failed;
46858 + atomic_long_unchecked_t free_context;
46859 + atomic_long_unchecked_t load_user_context;
46860 + atomic_long_unchecked_t load_kernel_context;
46861 + atomic_long_unchecked_t lock_kernel_context;
46862 + atomic_long_unchecked_t unlock_kernel_context;
46863 + atomic_long_unchecked_t steal_user_context;
46864 + atomic_long_unchecked_t steal_kernel_context;
46865 + atomic_long_unchecked_t steal_context_failed;
46866 + atomic_long_unchecked_t nopfn;
46867 + atomic_long_unchecked_t asid_new;
46868 + atomic_long_unchecked_t asid_next;
46869 + atomic_long_unchecked_t asid_wrap;
46870 + atomic_long_unchecked_t asid_reuse;
46871 + atomic_long_unchecked_t intr;
46872 + atomic_long_unchecked_t intr_cbr;
46873 + atomic_long_unchecked_t intr_tfh;
46874 + atomic_long_unchecked_t intr_spurious;
46875 + atomic_long_unchecked_t intr_mm_lock_failed;
46876 + atomic_long_unchecked_t call_os;
46877 + atomic_long_unchecked_t call_os_wait_queue;
46878 + atomic_long_unchecked_t user_flush_tlb;
46879 + atomic_long_unchecked_t user_unload_context;
46880 + atomic_long_unchecked_t user_exception;
46881 + atomic_long_unchecked_t set_context_option;
46882 + atomic_long_unchecked_t check_context_retarget_intr;
46883 + atomic_long_unchecked_t check_context_unload;
46884 + atomic_long_unchecked_t tlb_dropin;
46885 + atomic_long_unchecked_t tlb_preload_page;
46886 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46887 + atomic_long_unchecked_t tlb_dropin_fail_upm;
46888 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
46889 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
46890 + atomic_long_unchecked_t tlb_dropin_fail_idle;
46891 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
46892 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46893 + atomic_long_unchecked_t tfh_stale_on_fault;
46894 + atomic_long_unchecked_t mmu_invalidate_range;
46895 + atomic_long_unchecked_t mmu_invalidate_page;
46896 + atomic_long_unchecked_t flush_tlb;
46897 + atomic_long_unchecked_t flush_tlb_gru;
46898 + atomic_long_unchecked_t flush_tlb_gru_tgh;
46899 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46900
46901 - atomic_long_t copy_gpa;
46902 - atomic_long_t read_gpa;
46903 + atomic_long_unchecked_t copy_gpa;
46904 + atomic_long_unchecked_t read_gpa;
46905
46906 - atomic_long_t mesq_receive;
46907 - atomic_long_t mesq_receive_none;
46908 - atomic_long_t mesq_send;
46909 - atomic_long_t mesq_send_failed;
46910 - atomic_long_t mesq_noop;
46911 - atomic_long_t mesq_send_unexpected_error;
46912 - atomic_long_t mesq_send_lb_overflow;
46913 - atomic_long_t mesq_send_qlimit_reached;
46914 - atomic_long_t mesq_send_amo_nacked;
46915 - atomic_long_t mesq_send_put_nacked;
46916 - atomic_long_t mesq_page_overflow;
46917 - atomic_long_t mesq_qf_locked;
46918 - atomic_long_t mesq_qf_noop_not_full;
46919 - atomic_long_t mesq_qf_switch_head_failed;
46920 - atomic_long_t mesq_qf_unexpected_error;
46921 - atomic_long_t mesq_noop_unexpected_error;
46922 - atomic_long_t mesq_noop_lb_overflow;
46923 - atomic_long_t mesq_noop_qlimit_reached;
46924 - atomic_long_t mesq_noop_amo_nacked;
46925 - atomic_long_t mesq_noop_put_nacked;
46926 - atomic_long_t mesq_noop_page_overflow;
46927 + atomic_long_unchecked_t mesq_receive;
46928 + atomic_long_unchecked_t mesq_receive_none;
46929 + atomic_long_unchecked_t mesq_send;
46930 + atomic_long_unchecked_t mesq_send_failed;
46931 + atomic_long_unchecked_t mesq_noop;
46932 + atomic_long_unchecked_t mesq_send_unexpected_error;
46933 + atomic_long_unchecked_t mesq_send_lb_overflow;
46934 + atomic_long_unchecked_t mesq_send_qlimit_reached;
46935 + atomic_long_unchecked_t mesq_send_amo_nacked;
46936 + atomic_long_unchecked_t mesq_send_put_nacked;
46937 + atomic_long_unchecked_t mesq_page_overflow;
46938 + atomic_long_unchecked_t mesq_qf_locked;
46939 + atomic_long_unchecked_t mesq_qf_noop_not_full;
46940 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
46941 + atomic_long_unchecked_t mesq_qf_unexpected_error;
46942 + atomic_long_unchecked_t mesq_noop_unexpected_error;
46943 + atomic_long_unchecked_t mesq_noop_lb_overflow;
46944 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
46945 + atomic_long_unchecked_t mesq_noop_amo_nacked;
46946 + atomic_long_unchecked_t mesq_noop_put_nacked;
46947 + atomic_long_unchecked_t mesq_noop_page_overflow;
46948
46949 };
46950
46951 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46952 tghop_invalidate, mcsop_last};
46953
46954 struct mcs_op_statistic {
46955 - atomic_long_t count;
46956 - atomic_long_t total;
46957 + atomic_long_unchecked_t count;
46958 + atomic_long_unchecked_t total;
46959 unsigned long max;
46960 };
46961
46962 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46963
46964 #define STAT(id) do { \
46965 if (gru_options & OPT_STATS) \
46966 - atomic_long_inc(&gru_stats.id); \
46967 + atomic_long_inc_unchecked(&gru_stats.id); \
46968 } while (0)
46969
46970 #ifdef CONFIG_SGI_GRU_DEBUG
46971 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46972 index c862cd4..0d176fe 100644
46973 --- a/drivers/misc/sgi-xp/xp.h
46974 +++ b/drivers/misc/sgi-xp/xp.h
46975 @@ -288,7 +288,7 @@ struct xpc_interface {
46976 xpc_notify_func, void *);
46977 void (*received) (short, int, void *);
46978 enum xp_retval (*partid_to_nasids) (short, void *);
46979 -};
46980 +} __no_const;
46981
46982 extern struct xpc_interface xpc_interface;
46983
46984 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46985 index 01be66d..e3a0c7e 100644
46986 --- a/drivers/misc/sgi-xp/xp_main.c
46987 +++ b/drivers/misc/sgi-xp/xp_main.c
46988 @@ -78,13 +78,13 @@ xpc_notloaded(void)
46989 }
46990
46991 struct xpc_interface xpc_interface = {
46992 - (void (*)(int))xpc_notloaded,
46993 - (void (*)(int))xpc_notloaded,
46994 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46995 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46996 + .connect = (void (*)(int))xpc_notloaded,
46997 + .disconnect = (void (*)(int))xpc_notloaded,
46998 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46999 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47000 void *))xpc_notloaded,
47001 - (void (*)(short, int, void *))xpc_notloaded,
47002 - (enum xp_retval(*)(short, void *))xpc_notloaded
47003 + .received = (void (*)(short, int, void *))xpc_notloaded,
47004 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47005 };
47006 EXPORT_SYMBOL_GPL(xpc_interface);
47007
47008 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47009 index b94d5f7..7f494c5 100644
47010 --- a/drivers/misc/sgi-xp/xpc.h
47011 +++ b/drivers/misc/sgi-xp/xpc.h
47012 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
47013 void (*received_payload) (struct xpc_channel *, void *);
47014 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47015 };
47016 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47017
47018 /* struct xpc_partition act_state values (for XPC HB) */
47019
47020 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47021 /* found in xpc_main.c */
47022 extern struct device *xpc_part;
47023 extern struct device *xpc_chan;
47024 -extern struct xpc_arch_operations xpc_arch_ops;
47025 +extern xpc_arch_operations_no_const xpc_arch_ops;
47026 extern int xpc_disengage_timelimit;
47027 extern int xpc_disengage_timedout;
47028 extern int xpc_activate_IRQ_rcvd;
47029 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47030 index 82dc574..8539ab2 100644
47031 --- a/drivers/misc/sgi-xp/xpc_main.c
47032 +++ b/drivers/misc/sgi-xp/xpc_main.c
47033 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47034 .notifier_call = xpc_system_die,
47035 };
47036
47037 -struct xpc_arch_operations xpc_arch_ops;
47038 +xpc_arch_operations_no_const xpc_arch_ops;
47039
47040 /*
47041 * Timer function to enforce the timelimit on the partition disengage.
47042 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47043
47044 if (((die_args->trapnr == X86_TRAP_MF) ||
47045 (die_args->trapnr == X86_TRAP_XF)) &&
47046 - !user_mode_vm(die_args->regs))
47047 + !user_mode(die_args->regs))
47048 xpc_die_deactivate();
47049
47050 break;
47051 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47052 index a11451f..9e1bbad 100644
47053 --- a/drivers/mmc/card/block.c
47054 +++ b/drivers/mmc/card/block.c
47055 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47056 if (idata->ic.postsleep_min_us)
47057 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47058
47059 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47060 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47061 err = -EFAULT;
47062 goto cmd_rel_host;
47063 }
47064 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47065 index 7911e05..d0f9dda 100644
47066 --- a/drivers/mmc/core/mmc_ops.c
47067 +++ b/drivers/mmc/core/mmc_ops.c
47068 @@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47069 void *data_buf;
47070 int is_on_stack;
47071
47072 - is_on_stack = object_is_on_stack(buf);
47073 + is_on_stack = object_starts_on_stack(buf);
47074 if (is_on_stack) {
47075 /*
47076 * dma onto stack is unsafe/nonportable, but callers to this
47077 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47078 index 01b99e8..5c325e3 100644
47079 --- a/drivers/mmc/host/dw_mmc.h
47080 +++ b/drivers/mmc/host/dw_mmc.h
47081 @@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47082 int (*parse_dt)(struct dw_mci *host);
47083 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47084 struct dw_mci_tuning_data *tuning_data);
47085 -};
47086 +} __do_const;
47087 #endif /* _DW_MMC_H_ */
47088 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47089 index 43af791..86f4c48 100644
47090 --- a/drivers/mmc/host/mmci.c
47091 +++ b/drivers/mmc/host/mmci.c
47092 @@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47093 mmc->caps |= MMC_CAP_CMD23;
47094
47095 if (variant->busy_detect) {
47096 - mmci_ops.card_busy = mmci_card_busy;
47097 + pax_open_kernel();
47098 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
47099 + pax_close_kernel();
47100 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47101 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47102 mmc->max_busy_timeout = 0;
47103 diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47104 index 9c2b9cb..cebb09a 100644
47105 --- a/drivers/mmc/host/omap_hsmmc.c
47106 +++ b/drivers/mmc/host/omap_hsmmc.c
47107 @@ -2113,7 +2113,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47108
47109 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47110 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47111 - omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47112 + pax_open_kernel();
47113 + *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47114 + pax_close_kernel();
47115 }
47116
47117 pm_runtime_enable(host->dev);
47118 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47119 index 587ee0e..b3bbcab 100644
47120 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
47121 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47122 @@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47123 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47124 }
47125
47126 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47127 - sdhci_esdhc_ops.platform_execute_tuning =
47128 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47129 + pax_open_kernel();
47130 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47131 esdhc_executing_tuning;
47132 + pax_close_kernel();
47133 + }
47134
47135 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47136 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47137 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47138 index 0ce6eb1..8dcce1b 100644
47139 --- a/drivers/mmc/host/sdhci-s3c.c
47140 +++ b/drivers/mmc/host/sdhci-s3c.c
47141 @@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47142 * we can use overriding functions instead of default.
47143 */
47144 if (sc->no_divider) {
47145 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47146 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47147 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47148 + pax_open_kernel();
47149 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47150 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47151 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47152 + pax_close_kernel();
47153 }
47154
47155 /* It supports additional host capabilities if needed */
47156 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47157 index 423666b..81ff5eb 100644
47158 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
47159 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47160 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47161 size_t totlen = 0, thislen;
47162 int ret = 0;
47163 size_t buflen = 0;
47164 - static char *buffer;
47165 + char *buffer;
47166
47167 if (!ECCBUF_SIZE) {
47168 /* We should fall back to a general writev implementation.
47169 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47170 index b3b7ca1..5dd4634 100644
47171 --- a/drivers/mtd/nand/denali.c
47172 +++ b/drivers/mtd/nand/denali.c
47173 @@ -24,6 +24,7 @@
47174 #include <linux/slab.h>
47175 #include <linux/mtd/mtd.h>
47176 #include <linux/module.h>
47177 +#include <linux/slab.h>
47178
47179 #include "denali.h"
47180
47181 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47182 index 959cb9b..8520fe5 100644
47183 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47184 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47185 @@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47186
47187 /* first try to map the upper buffer directly */
47188 if (virt_addr_valid(this->upper_buf) &&
47189 - !object_is_on_stack(this->upper_buf)) {
47190 + !object_starts_on_stack(this->upper_buf)) {
47191 sg_init_one(sgl, this->upper_buf, this->upper_len);
47192 ret = dma_map_sg(this->dev, sgl, 1, dr);
47193 if (ret == 0)
47194 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47195 index 51b9d6a..52af9a7 100644
47196 --- a/drivers/mtd/nftlmount.c
47197 +++ b/drivers/mtd/nftlmount.c
47198 @@ -24,6 +24,7 @@
47199 #include <asm/errno.h>
47200 #include <linux/delay.h>
47201 #include <linux/slab.h>
47202 +#include <linux/sched.h>
47203 #include <linux/mtd/mtd.h>
47204 #include <linux/mtd/nand.h>
47205 #include <linux/mtd/nftl.h>
47206 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47207 index c23184a..4115c41 100644
47208 --- a/drivers/mtd/sm_ftl.c
47209 +++ b/drivers/mtd/sm_ftl.c
47210 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47211 #define SM_CIS_VENDOR_OFFSET 0x59
47212 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47213 {
47214 - struct attribute_group *attr_group;
47215 + attribute_group_no_const *attr_group;
47216 struct attribute **attributes;
47217 struct sm_sysfs_attribute *vendor_attribute;
47218 char *vendor;
47219 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47220 index a5115fb..81b03f6 100644
47221 --- a/drivers/net/bonding/bond_main.c
47222 +++ b/drivers/net/bonding/bond_main.c
47223 @@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47224 bond_dev_queue_xmit(bond, skb, slave->dev);
47225 } else {
47226 dev_kfree_skb_any(skb);
47227 - atomic_long_inc(&dev->tx_dropped);
47228 + atomic_long_inc_unchecked(&dev->tx_dropped);
47229 }
47230
47231 return NETDEV_TX_OK;
47232 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47233 index 45f09a6..f154f8d 100644
47234 --- a/drivers/net/bonding/bond_netlink.c
47235 +++ b/drivers/net/bonding/bond_netlink.c
47236 @@ -585,7 +585,7 @@ nla_put_failure:
47237 return -EMSGSIZE;
47238 }
47239
47240 -struct rtnl_link_ops bond_link_ops __read_mostly = {
47241 +struct rtnl_link_ops bond_link_ops = {
47242 .kind = "bond",
47243 .priv_size = sizeof(struct bonding),
47244 .setup = bond_setup,
47245 diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47246 index 5e40a8b..126bfda 100644
47247 --- a/drivers/net/caif/caif_hsi.c
47248 +++ b/drivers/net/caif/caif_hsi.c
47249 @@ -1445,7 +1445,7 @@ err:
47250 return -ENODEV;
47251 }
47252
47253 -static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47254 +static struct rtnl_link_ops caif_hsi_link_ops = {
47255 .kind = "cfhsi",
47256 .priv_size = sizeof(struct cfhsi),
47257 .setup = cfhsi_setup,
47258 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47259 index 98d73aa..63ef9da 100644
47260 --- a/drivers/net/can/Kconfig
47261 +++ b/drivers/net/can/Kconfig
47262 @@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47263
47264 config CAN_FLEXCAN
47265 tristate "Support for Freescale FLEXCAN based chips"
47266 - depends on ARM || PPC
47267 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47268 ---help---
47269 Say Y here if you want to support for Freescale FlexCAN.
47270
47271 diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47272 index 4b008c9..2b1151f 100644
47273 --- a/drivers/net/can/dev.c
47274 +++ b/drivers/net/can/dev.c
47275 @@ -872,7 +872,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47276 return -EOPNOTSUPP;
47277 }
47278
47279 -static struct rtnl_link_ops can_link_ops __read_mostly = {
47280 +static struct rtnl_link_ops can_link_ops = {
47281 .kind = "can",
47282 .maxtype = IFLA_CAN_MAX,
47283 .policy = can_policy,
47284 diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47285 index 4e94057..32032ff 100644
47286 --- a/drivers/net/can/vcan.c
47287 +++ b/drivers/net/can/vcan.c
47288 @@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47289 dev->destructor = free_netdev;
47290 }
47291
47292 -static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47293 +static struct rtnl_link_ops vcan_link_ops = {
47294 .kind = "vcan",
47295 .setup = vcan_setup,
47296 };
47297 diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47298 index ff435fb..d408b1f 100644
47299 --- a/drivers/net/dummy.c
47300 +++ b/drivers/net/dummy.c
47301 @@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47302 return 0;
47303 }
47304
47305 -static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47306 +static struct rtnl_link_ops dummy_link_ops = {
47307 .kind = "dummy",
47308 .setup = dummy_setup,
47309 .validate = dummy_validate,
47310 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47311 index 1d162cc..b546a75 100644
47312 --- a/drivers/net/ethernet/8390/ax88796.c
47313 +++ b/drivers/net/ethernet/8390/ax88796.c
47314 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47315 if (ax->plat->reg_offsets)
47316 ei_local->reg_offset = ax->plat->reg_offsets;
47317 else {
47318 + resource_size_t _mem_size = mem_size;
47319 + do_div(_mem_size, 0x18);
47320 ei_local->reg_offset = ax->reg_offsets;
47321 for (ret = 0; ret < 0x18; ret++)
47322 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47323 + ax->reg_offsets[ret] = _mem_size * ret;
47324 }
47325
47326 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47327 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47328 index 4efc435..4ab9e14 100644
47329 --- a/drivers/net/ethernet/altera/altera_tse_main.c
47330 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
47331 @@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47332 return 0;
47333 }
47334
47335 -static struct net_device_ops altera_tse_netdev_ops = {
47336 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47337 .ndo_open = tse_open,
47338 .ndo_stop = tse_shutdown,
47339 .ndo_start_xmit = tse_start_xmit,
47340 @@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47341 ndev->netdev_ops = &altera_tse_netdev_ops;
47342 altera_tse_set_ethtool_ops(ndev);
47343
47344 + pax_open_kernel();
47345 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47346
47347 if (priv->hash_filter)
47348 altera_tse_netdev_ops.ndo_set_rx_mode =
47349 tse_set_rx_mode_hashfilter;
47350 + pax_close_kernel();
47351
47352 /* Scatter/gather IO is not supported,
47353 * so it is turned off
47354 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47355 index caade30..3e257d9 100644
47356 --- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47357 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47358 @@ -1072,14 +1072,14 @@ do { \
47359 * operations, everything works on mask values.
47360 */
47361 #define XMDIO_READ(_pdata, _mmd, _reg) \
47362 - ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47363 + ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47364 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47365
47366 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47367 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47368
47369 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47370 - ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47371 + ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47372 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47373
47374 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47375 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47376 index 8a50b01..39c1ad0 100644
47377 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47378 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47379 @@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47380
47381 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47382
47383 - pdata->hw_if.config_dcb_tc(pdata);
47384 + pdata->hw_if->config_dcb_tc(pdata);
47385
47386 return 0;
47387 }
47388 @@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47389
47390 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47391
47392 - pdata->hw_if.config_dcb_pfc(pdata);
47393 + pdata->hw_if->config_dcb_pfc(pdata);
47394
47395 return 0;
47396 }
47397 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47398 index 6fc5da0..61ac2cb 100644
47399 --- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47400 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47401 @@ -235,7 +235,7 @@ err_ring:
47402
47403 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47404 {
47405 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47406 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47407 struct xgbe_channel *channel;
47408 struct xgbe_ring *ring;
47409 struct xgbe_ring_data *rdata;
47410 @@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47411
47412 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47413 {
47414 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47415 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47416 struct xgbe_channel *channel;
47417 struct xgbe_ring *ring;
47418 struct xgbe_ring_desc *rdesc;
47419 @@ -505,7 +505,7 @@ err_out:
47420 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47421 {
47422 struct xgbe_prv_data *pdata = channel->pdata;
47423 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47424 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47425 struct xgbe_ring *ring = channel->rx_ring;
47426 struct xgbe_ring_data *rdata;
47427 struct sk_buff *skb = NULL;
47428 @@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47429 DBGPR("<--xgbe_realloc_skb\n");
47430 }
47431
47432 -void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47433 -{
47434 - DBGPR("-->xgbe_init_function_ptrs_desc\n");
47435 -
47436 - desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47437 - desc_if->free_ring_resources = xgbe_free_ring_resources;
47438 - desc_if->map_tx_skb = xgbe_map_tx_skb;
47439 - desc_if->realloc_skb = xgbe_realloc_skb;
47440 - desc_if->unmap_skb = xgbe_unmap_skb;
47441 - desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47442 - desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47443 -
47444 - DBGPR("<--xgbe_init_function_ptrs_desc\n");
47445 -}
47446 +const struct xgbe_desc_if default_xgbe_desc_if = {
47447 + .alloc_ring_resources = xgbe_alloc_ring_resources,
47448 + .free_ring_resources = xgbe_free_ring_resources,
47449 + .map_tx_skb = xgbe_map_tx_skb,
47450 + .realloc_skb = xgbe_realloc_skb,
47451 + .unmap_skb = xgbe_unmap_skb,
47452 + .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47453 + .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47454 +};
47455 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47456 index 9da3a03..022f15c 100644
47457 --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47458 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47459 @@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47460
47461 static int xgbe_init(struct xgbe_prv_data *pdata)
47462 {
47463 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47464 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47465 int ret;
47466
47467 DBGPR("-->xgbe_init\n");
47468 @@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47469 return 0;
47470 }
47471
47472 -void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47473 -{
47474 - DBGPR("-->xgbe_init_function_ptrs\n");
47475 -
47476 - hw_if->tx_complete = xgbe_tx_complete;
47477 -
47478 - hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47479 - hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47480 - hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47481 - hw_if->set_mac_address = xgbe_set_mac_address;
47482 -
47483 - hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47484 - hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47485 -
47486 - hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47487 - hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47488 - hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47489 - hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47490 - hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47491 -
47492 - hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47493 - hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47494 -
47495 - hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47496 - hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47497 - hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47498 -
47499 - hw_if->enable_tx = xgbe_enable_tx;
47500 - hw_if->disable_tx = xgbe_disable_tx;
47501 - hw_if->enable_rx = xgbe_enable_rx;
47502 - hw_if->disable_rx = xgbe_disable_rx;
47503 -
47504 - hw_if->powerup_tx = xgbe_powerup_tx;
47505 - hw_if->powerdown_tx = xgbe_powerdown_tx;
47506 - hw_if->powerup_rx = xgbe_powerup_rx;
47507 - hw_if->powerdown_rx = xgbe_powerdown_rx;
47508 -
47509 - hw_if->pre_xmit = xgbe_pre_xmit;
47510 - hw_if->dev_read = xgbe_dev_read;
47511 - hw_if->enable_int = xgbe_enable_int;
47512 - hw_if->disable_int = xgbe_disable_int;
47513 - hw_if->init = xgbe_init;
47514 - hw_if->exit = xgbe_exit;
47515 +const struct xgbe_hw_if default_xgbe_hw_if = {
47516 + .tx_complete = xgbe_tx_complete,
47517 +
47518 + .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47519 + .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47520 + .add_mac_addresses = xgbe_add_mac_addresses,
47521 + .set_mac_address = xgbe_set_mac_address,
47522 +
47523 + .enable_rx_csum = xgbe_enable_rx_csum,
47524 + .disable_rx_csum = xgbe_disable_rx_csum,
47525 +
47526 + .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47527 + .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47528 + .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47529 + .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47530 + .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47531 +
47532 + .read_mmd_regs = xgbe_read_mmd_regs,
47533 + .write_mmd_regs = xgbe_write_mmd_regs,
47534 +
47535 + .set_gmii_speed = xgbe_set_gmii_speed,
47536 + .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47537 + .set_xgmii_speed = xgbe_set_xgmii_speed,
47538 +
47539 + .enable_tx = xgbe_enable_tx,
47540 + .disable_tx = xgbe_disable_tx,
47541 + .enable_rx = xgbe_enable_rx,
47542 + .disable_rx = xgbe_disable_rx,
47543 +
47544 + .powerup_tx = xgbe_powerup_tx,
47545 + .powerdown_tx = xgbe_powerdown_tx,
47546 + .powerup_rx = xgbe_powerup_rx,
47547 + .powerdown_rx = xgbe_powerdown_rx,
47548 +
47549 + .pre_xmit = xgbe_pre_xmit,
47550 + .dev_read = xgbe_dev_read,
47551 + .enable_int = xgbe_enable_int,
47552 + .disable_int = xgbe_disable_int,
47553 + .init = xgbe_init,
47554 + .exit = xgbe_exit,
47555
47556 /* Descriptor related Sequences have to be initialized here */
47557 - hw_if->tx_desc_init = xgbe_tx_desc_init;
47558 - hw_if->rx_desc_init = xgbe_rx_desc_init;
47559 - hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47560 - hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47561 - hw_if->is_last_desc = xgbe_is_last_desc;
47562 - hw_if->is_context_desc = xgbe_is_context_desc;
47563 + .tx_desc_init = xgbe_tx_desc_init,
47564 + .rx_desc_init = xgbe_rx_desc_init,
47565 + .tx_desc_reset = xgbe_tx_desc_reset,
47566 + .rx_desc_reset = xgbe_rx_desc_reset,
47567 + .is_last_desc = xgbe_is_last_desc,
47568 + .is_context_desc = xgbe_is_context_desc,
47569
47570 /* For FLOW ctrl */
47571 - hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47572 - hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47573 + .config_tx_flow_control = xgbe_config_tx_flow_control,
47574 + .config_rx_flow_control = xgbe_config_rx_flow_control,
47575
47576 /* For RX coalescing */
47577 - hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47578 - hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47579 - hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47580 - hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47581 + .config_rx_coalesce = xgbe_config_rx_coalesce,
47582 + .config_tx_coalesce = xgbe_config_tx_coalesce,
47583 + .usec_to_riwt = xgbe_usec_to_riwt,
47584 + .riwt_to_usec = xgbe_riwt_to_usec,
47585
47586 /* For RX and TX threshold config */
47587 - hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47588 - hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47589 + .config_rx_threshold = xgbe_config_rx_threshold,
47590 + .config_tx_threshold = xgbe_config_tx_threshold,
47591
47592 /* For RX and TX Store and Forward Mode config */
47593 - hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47594 - hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47595 + .config_rsf_mode = xgbe_config_rsf_mode,
47596 + .config_tsf_mode = xgbe_config_tsf_mode,
47597
47598 /* For TX DMA Operating on Second Frame config */
47599 - hw_if->config_osp_mode = xgbe_config_osp_mode;
47600 + .config_osp_mode = xgbe_config_osp_mode,
47601
47602 /* For RX and TX PBL config */
47603 - hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47604 - hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47605 - hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47606 - hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47607 - hw_if->config_pblx8 = xgbe_config_pblx8;
47608 + .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47609 + .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47610 + .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47611 + .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47612 + .config_pblx8 = xgbe_config_pblx8,
47613
47614 /* For MMC statistics support */
47615 - hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47616 - hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47617 - hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47618 + .tx_mmc_int = xgbe_tx_mmc_int,
47619 + .rx_mmc_int = xgbe_rx_mmc_int,
47620 + .read_mmc_stats = xgbe_read_mmc_stats,
47621
47622 /* For PTP config */
47623 - hw_if->config_tstamp = xgbe_config_tstamp;
47624 - hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47625 - hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47626 - hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47627 - hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47628 + .config_tstamp = xgbe_config_tstamp,
47629 + .update_tstamp_addend = xgbe_update_tstamp_addend,
47630 + .set_tstamp_time = xgbe_set_tstamp_time,
47631 + .get_tstamp_time = xgbe_get_tstamp_time,
47632 + .get_tx_tstamp = xgbe_get_tx_tstamp,
47633
47634 /* For Data Center Bridging config */
47635 - hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47636 - hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47637 -
47638 - DBGPR("<--xgbe_init_function_ptrs\n");
47639 -}
47640 + .config_dcb_tc = xgbe_config_dcb_tc,
47641 + .config_dcb_pfc = xgbe_config_dcb_pfc,
47642 +};
47643 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47644 index 2349ea9..a83a677 100644
47645 --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47646 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47647 @@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47648
47649 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47650 {
47651 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47652 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47653 struct xgbe_channel *channel;
47654 enum xgbe_int int_id;
47655 unsigned int i;
47656 @@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47657
47658 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47659 {
47660 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47661 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47662 struct xgbe_channel *channel;
47663 enum xgbe_int int_id;
47664 unsigned int i;
47665 @@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47666 static irqreturn_t xgbe_isr(int irq, void *data)
47667 {
47668 struct xgbe_prv_data *pdata = data;
47669 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47670 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47671 struct xgbe_channel *channel;
47672 unsigned int dma_isr, dma_ch_isr;
47673 unsigned int mac_isr, mac_tssr;
47674 @@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47675
47676 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47677 {
47678 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47679 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47680
47681 DBGPR("-->xgbe_init_tx_coalesce\n");
47682
47683 @@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47684
47685 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47686 {
47687 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47688 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47689
47690 DBGPR("-->xgbe_init_rx_coalesce\n");
47691
47692 @@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47693
47694 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47695 {
47696 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47697 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47698 struct xgbe_channel *channel;
47699 struct xgbe_ring *ring;
47700 struct xgbe_ring_data *rdata;
47701 @@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47702
47703 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47704 {
47705 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47706 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47707 struct xgbe_channel *channel;
47708 struct xgbe_ring *ring;
47709 struct xgbe_ring_data *rdata;
47710 @@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47711 static void xgbe_adjust_link(struct net_device *netdev)
47712 {
47713 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47714 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47715 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47716 struct phy_device *phydev = pdata->phydev;
47717 int new_state = 0;
47718
47719 @@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47720 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47721 {
47722 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47723 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47724 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47725 unsigned long flags;
47726
47727 DBGPR("-->xgbe_powerdown\n");
47728 @@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47729 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47730 {
47731 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47732 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47733 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47734 unsigned long flags;
47735
47736 DBGPR("-->xgbe_powerup\n");
47737 @@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47738
47739 static int xgbe_start(struct xgbe_prv_data *pdata)
47740 {
47741 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47742 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47743 struct net_device *netdev = pdata->netdev;
47744
47745 DBGPR("-->xgbe_start\n");
47746 @@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47747
47748 static void xgbe_stop(struct xgbe_prv_data *pdata)
47749 {
47750 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47751 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47752 struct net_device *netdev = pdata->netdev;
47753
47754 DBGPR("-->xgbe_stop\n");
47755 @@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47756
47757 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47758 {
47759 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47760 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47761
47762 DBGPR("-->xgbe_restart_dev\n");
47763
47764 @@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47765 return -ERANGE;
47766 }
47767
47768 - pdata->hw_if.config_tstamp(pdata, mac_tscr);
47769 + pdata->hw_if->config_tstamp(pdata, mac_tscr);
47770
47771 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47772
47773 @@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47774 static int xgbe_open(struct net_device *netdev)
47775 {
47776 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47777 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47778 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47779 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47780 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47781 int ret;
47782
47783 DBGPR("-->xgbe_open\n");
47784 @@ -1170,8 +1170,8 @@ err_phy_init:
47785 static int xgbe_close(struct net_device *netdev)
47786 {
47787 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47788 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47789 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47790 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47791 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47792
47793 DBGPR("-->xgbe_close\n");
47794
47795 @@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47796 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47797 {
47798 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47799 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47800 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47801 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47802 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47803 struct xgbe_channel *channel;
47804 struct xgbe_ring *ring;
47805 struct xgbe_packet_data *packet;
47806 @@ -1275,7 +1275,7 @@ tx_netdev_return:
47807 static void xgbe_set_rx_mode(struct net_device *netdev)
47808 {
47809 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47810 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47811 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47812 unsigned int pr_mode, am_mode;
47813
47814 DBGPR("-->xgbe_set_rx_mode\n");
47815 @@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47816 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47817 {
47818 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47819 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47820 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47821 struct sockaddr *saddr = addr;
47822
47823 DBGPR("-->xgbe_set_mac_address\n");
47824 @@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47825
47826 DBGPR("-->%s\n", __func__);
47827
47828 - pdata->hw_if.read_mmc_stats(pdata);
47829 + pdata->hw_if->read_mmc_stats(pdata);
47830
47831 s->rx_packets = pstats->rxframecount_gb;
47832 s->rx_bytes = pstats->rxoctetcount_gb;
47833 @@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47834 u16 vid)
47835 {
47836 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47837 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47838 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47839
47840 DBGPR("-->%s\n", __func__);
47841
47842 @@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47843 u16 vid)
47844 {
47845 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47846 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47847 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47848
47849 DBGPR("-->%s\n", __func__);
47850
47851 @@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47852 netdev_features_t features)
47853 {
47854 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47855 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47856 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47857 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47858
47859 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47860 @@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47861 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47862 {
47863 struct xgbe_prv_data *pdata = channel->pdata;
47864 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47865 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47866 struct xgbe_ring *ring = channel->rx_ring;
47867 struct xgbe_ring_data *rdata;
47868
47869 @@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47870 static int xgbe_tx_poll(struct xgbe_channel *channel)
47871 {
47872 struct xgbe_prv_data *pdata = channel->pdata;
47873 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47874 - struct xgbe_desc_if *desc_if = &pdata->desc_if;
47875 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47876 + struct xgbe_desc_if *desc_if = pdata->desc_if;
47877 struct xgbe_ring *ring = channel->tx_ring;
47878 struct xgbe_ring_data *rdata;
47879 struct xgbe_ring_desc *rdesc;
47880 @@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47881 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47882 {
47883 struct xgbe_prv_data *pdata = channel->pdata;
47884 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47885 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47886 struct xgbe_ring *ring = channel->rx_ring;
47887 struct xgbe_ring_data *rdata;
47888 struct xgbe_packet_data *packet;
47889 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47890 index 49508ec..2617cca 100644
47891 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47892 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47893 @@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47894
47895 DBGPR("-->%s\n", __func__);
47896
47897 - pdata->hw_if.read_mmc_stats(pdata);
47898 + pdata->hw_if->read_mmc_stats(pdata);
47899 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47900 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47901 *data++ = *(u64 *)stat;
47902 @@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47903 struct ethtool_coalesce *ec)
47904 {
47905 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47906 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47907 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47908 unsigned int riwt;
47909
47910 DBGPR("-->xgbe_get_coalesce\n");
47911 @@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47912 struct ethtool_coalesce *ec)
47913 {
47914 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47915 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47916 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47917 unsigned int rx_frames, rx_riwt, rx_usecs;
47918 unsigned int tx_frames, tx_usecs;
47919
47920 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47921 index f5a8fa0..0bb58ff 100644
47922 --- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47923 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47924 @@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47925 DBGPR("<--xgbe_default_config\n");
47926 }
47927
47928 -static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47929 -{
47930 - xgbe_init_function_ptrs_dev(&pdata->hw_if);
47931 - xgbe_init_function_ptrs_desc(&pdata->desc_if);
47932 -}
47933 -
47934 static int xgbe_probe(struct platform_device *pdev)
47935 {
47936 struct xgbe_prv_data *pdata;
47937 @@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47938 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47939
47940 /* Set all the function pointers */
47941 - xgbe_init_all_fptrs(pdata);
47942 - hw_if = &pdata->hw_if;
47943 - desc_if = &pdata->desc_if;
47944 + hw_if = pdata->hw_if = &default_xgbe_hw_if;
47945 + desc_if = pdata->desc_if = &default_xgbe_desc_if;
47946
47947 /* Issue software reset to device */
47948 hw_if->exit(pdata);
47949 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47950 index 363b210..b241389 100644
47951 --- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47952 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47953 @@ -126,7 +126,7 @@
47954 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47955 {
47956 struct xgbe_prv_data *pdata = mii->priv;
47957 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47958 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47959 int mmd_data;
47960
47961 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47962 @@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47963 u16 mmd_val)
47964 {
47965 struct xgbe_prv_data *pdata = mii->priv;
47966 - struct xgbe_hw_if *hw_if = &pdata->hw_if;
47967 + struct xgbe_hw_if *hw_if = pdata->hw_if;
47968 int mmd_data = mmd_val;
47969
47970 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47971 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47972 index a1bf9d1c..84adcab 100644
47973 --- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47974 +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47975 @@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47976 tstamp_cc);
47977 u64 nsec;
47978
47979 - nsec = pdata->hw_if.get_tstamp_time(pdata);
47980 + nsec = pdata->hw_if->get_tstamp_time(pdata);
47981
47982 return nsec;
47983 }
47984 @@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47985
47986 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47987
47988 - pdata->hw_if.update_tstamp_addend(pdata, addend);
47989 + pdata->hw_if->update_tstamp_addend(pdata, addend);
47990
47991 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47992
47993 diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47994 index 789957d..d7d0245 100644
47995 --- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47996 +++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47997 @@ -583,8 +583,8 @@ struct xgbe_prv_data {
47998
47999 int irq_number;
48000
48001 - struct xgbe_hw_if hw_if;
48002 - struct xgbe_desc_if desc_if;
48003 + const struct xgbe_hw_if *hw_if;
48004 + const struct xgbe_desc_if *desc_if;
48005
48006 /* AXI DMA settings */
48007 unsigned int axdomain;
48008 @@ -697,6 +697,9 @@ struct xgbe_prv_data {
48009 #endif
48010 };
48011
48012 +extern const struct xgbe_hw_if default_xgbe_hw_if;
48013 +extern const struct xgbe_desc_if default_xgbe_desc_if;
48014 +
48015 /* Function prototypes*/
48016
48017 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48018 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48019 index adcacda..fa6e0ae 100644
48020 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48021 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48022 @@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48023 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48024 {
48025 /* RX_MODE controlling object */
48026 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48027 + bnx2x_init_rx_mode_obj(bp);
48028
48029 /* multicast configuration controlling object */
48030 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48031 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48032 index 7bc2924..2112002 100644
48033 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48034 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48035 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48036 return rc;
48037 }
48038
48039 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48040 - struct bnx2x_rx_mode_obj *o)
48041 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48042 {
48043 if (CHIP_IS_E1x(bp)) {
48044 - o->wait_comp = bnx2x_empty_rx_mode_wait;
48045 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48046 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48047 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48048 } else {
48049 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48050 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
48051 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48052 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48053 }
48054 }
48055
48056 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48057 index e97275f..52e28bc 100644
48058 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48059 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48060 @@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48061
48062 /********************* RX MODE ****************/
48063
48064 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48065 - struct bnx2x_rx_mode_obj *o);
48066 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48067
48068 /**
48069 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48070 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48071 index 31c9f82..e65e986 100644
48072 --- a/drivers/net/ethernet/broadcom/tg3.h
48073 +++ b/drivers/net/ethernet/broadcom/tg3.h
48074 @@ -150,6 +150,7 @@
48075 #define CHIPREV_ID_5750_A0 0x4000
48076 #define CHIPREV_ID_5750_A1 0x4001
48077 #define CHIPREV_ID_5750_A3 0x4003
48078 +#define CHIPREV_ID_5750_C1 0x4201
48079 #define CHIPREV_ID_5750_C2 0x4202
48080 #define CHIPREV_ID_5752_A0_HW 0x5000
48081 #define CHIPREV_ID_5752_A0 0x6000
48082 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48083 index 903466e..b285864 100644
48084 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48085 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48086 @@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48087 }
48088
48089 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48090 - bna_cb_ioceth_enable,
48091 - bna_cb_ioceth_disable,
48092 - bna_cb_ioceth_hbfail,
48093 - bna_cb_ioceth_reset
48094 + .enable_cbfn = bna_cb_ioceth_enable,
48095 + .disable_cbfn = bna_cb_ioceth_disable,
48096 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
48097 + .reset_cbfn = bna_cb_ioceth_reset
48098 };
48099
48100 static void bna_attr_init(struct bna_ioceth *ioceth)
48101 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48102 index 8cffcdf..aadf043 100644
48103 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48104 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48105 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48106 */
48107 struct l2t_skb_cb {
48108 arp_failure_handler_func arp_failure_handler;
48109 -};
48110 +} __no_const;
48111
48112 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48113
48114 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48115 index 279873c..11e1921 100644
48116 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48117 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48118 @@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48119
48120 int i;
48121 struct adapter *ap = netdev2adap(dev);
48122 - static const unsigned int *reg_ranges;
48123 + const unsigned int *reg_ranges;
48124 int arr_size = 0, buf_size = 0;
48125
48126 if (is_t4(ap->params.chip)) {
48127 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48128 index cf8b6ff..274271e 100644
48129 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
48130 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48131 @@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48132 for (i=0; i<ETH_ALEN; i++) {
48133 tmp.addr[i] = dev->dev_addr[i];
48134 }
48135 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48136 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48137 break;
48138
48139 case DE4X5_SET_HWADDR: /* Set the hardware address */
48140 @@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48141 spin_lock_irqsave(&lp->lock, flags);
48142 memcpy(&statbuf, &lp->pktStats, ioc->len);
48143 spin_unlock_irqrestore(&lp->lock, flags);
48144 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
48145 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48146 return -EFAULT;
48147 break;
48148 }
48149 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48150 index d2975fa..8aaec07 100644
48151 --- a/drivers/net/ethernet/emulex/benet/be_main.c
48152 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
48153 @@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48154
48155 if (wrapped)
48156 newacc += 65536;
48157 - ACCESS_ONCE(*acc) = newacc;
48158 + ACCESS_ONCE_RW(*acc) = newacc;
48159 }
48160
48161 static void populate_erx_stats(struct be_adapter *adapter,
48162 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48163 index c77fa4a..7fd42fc 100644
48164 --- a/drivers/net/ethernet/faraday/ftgmac100.c
48165 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
48166 @@ -30,6 +30,8 @@
48167 #include <linux/netdevice.h>
48168 #include <linux/phy.h>
48169 #include <linux/platform_device.h>
48170 +#include <linux/interrupt.h>
48171 +#include <linux/irqreturn.h>
48172 #include <net/ip.h>
48173
48174 #include "ftgmac100.h"
48175 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48176 index 4ff1adc..0ea6bf4 100644
48177 --- a/drivers/net/ethernet/faraday/ftmac100.c
48178 +++ b/drivers/net/ethernet/faraday/ftmac100.c
48179 @@ -31,6 +31,8 @@
48180 #include <linux/module.h>
48181 #include <linux/netdevice.h>
48182 #include <linux/platform_device.h>
48183 +#include <linux/interrupt.h>
48184 +#include <linux/irqreturn.h>
48185
48186 #include "ftmac100.h"
48187
48188 diff --git a/drivers/net/ethernet/freescale/gianfar_ethtool.c b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48189 index 76d7070..f6971182 100644
48190 --- a/drivers/net/ethernet/freescale/gianfar_ethtool.c
48191 +++ b/drivers/net/ethernet/freescale/gianfar_ethtool.c
48192 @@ -1581,7 +1581,7 @@ static int gfar_write_filer_table(struct gfar_private *priv,
48193 return -EBUSY;
48194
48195 /* Fill regular entries */
48196 - for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
48197 + for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].prop);
48198 i++)
48199 gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
48200 /* Fill the rest with fall-troughs */
48201 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48202 index 537b621..07f87ce 100644
48203 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48204 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48205 @@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48206 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48207
48208 /* Update the base adjustement value. */
48209 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
48210 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48211 smp_mb(); /* Force the above update. */
48212 }
48213
48214 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48215 index 5fd4b52..87aa34b 100644
48216 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48217 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48218 @@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48219 }
48220
48221 /* update the base incval used to calculate frequency adjustment */
48222 - ACCESS_ONCE(adapter->base_incval) = incval;
48223 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
48224 smp_mb();
48225
48226 /* need lock to prevent incorrect read while modifying cyclecounter */
48227 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48228 index 11ff28b..375d659 100644
48229 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48230 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48231 @@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48232 wmb();
48233
48234 /* we want to dirty this cache line once */
48235 - ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48236 - ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48237 + ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48238 + ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48239
48240 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48241
48242 diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48243 index de10dbb..8b54f29 100644
48244 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48245 +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
48246 @@ -233,7 +233,8 @@ do { \
48247 extern int mlx4_log_num_mgm_entry_size;
48248 extern int log_mtts_per_seg;
48249
48250 -#define MLX4_MAX_NUM_SLAVES (MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF)
48251 +#define MLX4_MAX_NUM_SLAVES (min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
48252 + MLX4_MFUNC_MAX))
48253 #define ALL_SLAVES 0xff
48254
48255 struct mlx4_bitmap {
48256 diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
48257 index f5e4b82..db0c7a9 100644
48258 --- a/drivers/net/ethernet/neterion/s2io.c
48259 +++ b/drivers/net/ethernet/neterion/s2io.c
48260 @@ -6987,7 +6987,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48261 if (sp->s2io_entries[i].in_use == MSIX_FLG) {
48262 if (sp->s2io_entries[i].type ==
48263 MSIX_RING_TYPE) {
48264 - sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
48265 + snprintf(sp->desc[i],
48266 + sizeof(sp->desc[i]),
48267 + "%s:MSI-X-%d-RX",
48268 dev->name, i);
48269 err = request_irq(sp->entries[i].vector,
48270 s2io_msix_ring_handle,
48271 @@ -6996,7 +6998,9 @@ static int s2io_add_isr(struct s2io_nic *sp)
48272 sp->s2io_entries[i].arg);
48273 } else if (sp->s2io_entries[i].type ==
48274 MSIX_ALARM_TYPE) {
48275 - sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
48276 + snprintf(sp->desc[i],
48277 + sizeof(sp->desc[i]),
48278 + "%s:MSI-X-%d-TX",
48279 dev->name, i);
48280 err = request_irq(sp->entries[i].vector,
48281 s2io_msix_fifo_handle,
48282 @@ -8154,7 +8158,8 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
48283 "%s: UDP Fragmentation Offload(UFO) enabled\n",
48284 dev->name);
48285 /* Initialize device name */
48286 - sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
48287 + snprintf(sp->name, sizeof(sp->name), "%s Neterion %s", dev->name,
48288 + sp->product_name);
48289
48290 if (vlan_tag_strip)
48291 sp->vlan_strip_flag = 1;
48292 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48293 index 2bbd01f..e8baa64 100644
48294 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48295 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48296 @@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48297 struct __vxge_hw_fifo *fifo;
48298 struct vxge_hw_fifo_config *config;
48299 u32 txdl_size, txdl_per_memblock;
48300 - struct vxge_hw_mempool_cbs fifo_mp_callback;
48301 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48302 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48303 + };
48304 +
48305 struct __vxge_hw_virtualpath *vpath;
48306
48307 if ((vp == NULL) || (attr == NULL)) {
48308 @@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48309 goto exit;
48310 }
48311
48312 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48313 -
48314 fifo->mempool =
48315 __vxge_hw_mempool_create(vpath->hldev,
48316 fifo->config->memblock_size,
48317 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48318 index 2bb48d5..d1a865d 100644
48319 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48320 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48321 @@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48322 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48323 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48324 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48325 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48326 + pax_open_kernel();
48327 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48328 + pax_close_kernel();
48329 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48330 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48331 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48332 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48333 index be7d7a6..a8983f8 100644
48334 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48335 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48336 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48337 case QLCNIC_NON_PRIV_FUNC:
48338 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48339 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48340 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48341 + pax_open_kernel();
48342 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48343 + pax_close_kernel();
48344 break;
48345 case QLCNIC_PRIV_FUNC:
48346 ahw->op_mode = QLCNIC_PRIV_FUNC;
48347 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48348 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48349 + pax_open_kernel();
48350 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48351 + pax_close_kernel();
48352 break;
48353 case QLCNIC_MGMT_FUNC:
48354 ahw->op_mode = QLCNIC_MGMT_FUNC;
48355 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48356 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48357 + pax_open_kernel();
48358 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48359 + pax_close_kernel();
48360 break;
48361 default:
48362 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48363 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48364 index c9f57fb..208bdc1 100644
48365 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48366 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48367 @@ -1285,7 +1285,7 @@ flash_temp:
48368 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48369 {
48370 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48371 - static const struct qlcnic_dump_operations *fw_dump_ops;
48372 + const struct qlcnic_dump_operations *fw_dump_ops;
48373 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48374 u32 entry_offset, dump, no_entries, buf_offset = 0;
48375 int i, k, ops_cnt, ops_index, dump_size = 0;
48376 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48377 index cf154f7..c948d1b 100644
48378 --- a/drivers/net/ethernet/realtek/r8169.c
48379 +++ b/drivers/net/ethernet/realtek/r8169.c
48380 @@ -788,22 +788,22 @@ struct rtl8169_private {
48381 struct mdio_ops {
48382 void (*write)(struct rtl8169_private *, int, int);
48383 int (*read)(struct rtl8169_private *, int);
48384 - } mdio_ops;
48385 + } __no_const mdio_ops;
48386
48387 struct pll_power_ops {
48388 void (*down)(struct rtl8169_private *);
48389 void (*up)(struct rtl8169_private *);
48390 - } pll_power_ops;
48391 + } __no_const pll_power_ops;
48392
48393 struct jumbo_ops {
48394 void (*enable)(struct rtl8169_private *);
48395 void (*disable)(struct rtl8169_private *);
48396 - } jumbo_ops;
48397 + } __no_const jumbo_ops;
48398
48399 struct csi_ops {
48400 void (*write)(struct rtl8169_private *, int, int);
48401 u32 (*read)(struct rtl8169_private *, int);
48402 - } csi_ops;
48403 + } __no_const csi_ops;
48404
48405 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48406 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48407 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48408 index 6b861e3..204ac86 100644
48409 --- a/drivers/net/ethernet/sfc/ptp.c
48410 +++ b/drivers/net/ethernet/sfc/ptp.c
48411 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48412 ptp->start.dma_addr);
48413
48414 /* Clear flag that signals MC ready */
48415 - ACCESS_ONCE(*start) = 0;
48416 + ACCESS_ONCE_RW(*start) = 0;
48417 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48418 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48419 EFX_BUG_ON_PARANOID(rc);
48420 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48421 index 08c483b..2c4a553 100644
48422 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48423 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48424 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48425
48426 writel(value, ioaddr + MMC_CNTRL);
48427
48428 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48429 - MMC_CNTRL, value);
48430 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48431 +// MMC_CNTRL, value);
48432 }
48433
48434 /* To mask all all interrupts.*/
48435 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48436 index 2f48f79..8ae1a1a 100644
48437 --- a/drivers/net/hyperv/hyperv_net.h
48438 +++ b/drivers/net/hyperv/hyperv_net.h
48439 @@ -171,7 +171,7 @@ struct rndis_device {
48440 enum rndis_device_state state;
48441 bool link_state;
48442 bool link_change;
48443 - atomic_t new_req_id;
48444 + atomic_unchecked_t new_req_id;
48445
48446 spinlock_t request_lock;
48447 struct list_head req_list;
48448 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48449 index 2b86f0b..ecc996f 100644
48450 --- a/drivers/net/hyperv/rndis_filter.c
48451 +++ b/drivers/net/hyperv/rndis_filter.c
48452 @@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48453 * template
48454 */
48455 set = &rndis_msg->msg.set_req;
48456 - set->req_id = atomic_inc_return(&dev->new_req_id);
48457 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48458
48459 /* Add to the request list */
48460 spin_lock_irqsave(&dev->request_lock, flags);
48461 @@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48462
48463 /* Setup the rndis set */
48464 halt = &request->request_msg.msg.halt_req;
48465 - halt->req_id = atomic_inc_return(&dev->new_req_id);
48466 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48467
48468 /* Ignore return since this msg is optional. */
48469 rndis_filter_send_request(dev, request);
48470 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48471 index 6cbc56a..5f7e6c8 100644
48472 --- a/drivers/net/ieee802154/fakehard.c
48473 +++ b/drivers/net/ieee802154/fakehard.c
48474 @@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48475 phy->transmit_power = 0xbf;
48476
48477 dev->netdev_ops = &fake_ops;
48478 - dev->ml_priv = &fake_mlme;
48479 + dev->ml_priv = (void *)&fake_mlme;
48480
48481 priv = netdev_priv(dev);
48482 priv->phy = phy;
48483 diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48484 index 34f846b..4a0d5b1 100644
48485 --- a/drivers/net/ifb.c
48486 +++ b/drivers/net/ifb.c
48487 @@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48488 return 0;
48489 }
48490
48491 -static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48492 +static struct rtnl_link_ops ifb_link_ops = {
48493 .kind = "ifb",
48494 .priv_size = sizeof(struct ifb_private),
48495 .setup = ifb_setup,
48496 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48497 index bfb0b6e..5c396ce 100644
48498 --- a/drivers/net/macvlan.c
48499 +++ b/drivers/net/macvlan.c
48500 @@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48501 free_nskb:
48502 kfree_skb(nskb);
48503 err:
48504 - atomic_long_inc(&skb->dev->rx_dropped);
48505 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48506 }
48507
48508 static void macvlan_flush_sources(struct macvlan_port *port,
48509 @@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48510 int macvlan_link_register(struct rtnl_link_ops *ops)
48511 {
48512 /* common fields */
48513 - ops->priv_size = sizeof(struct macvlan_dev);
48514 - ops->validate = macvlan_validate;
48515 - ops->maxtype = IFLA_MACVLAN_MAX;
48516 - ops->policy = macvlan_policy;
48517 - ops->changelink = macvlan_changelink;
48518 - ops->get_size = macvlan_get_size;
48519 - ops->fill_info = macvlan_fill_info;
48520 + pax_open_kernel();
48521 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48522 + *(void **)&ops->validate = macvlan_validate;
48523 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48524 + *(const void **)&ops->policy = macvlan_policy;
48525 + *(void **)&ops->changelink = macvlan_changelink;
48526 + *(void **)&ops->get_size = macvlan_get_size;
48527 + *(void **)&ops->fill_info = macvlan_fill_info;
48528 + pax_close_kernel();
48529
48530 return rtnl_link_register(ops);
48531 };
48532 @@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48533 return NOTIFY_DONE;
48534 }
48535
48536 -static struct notifier_block macvlan_notifier_block __read_mostly = {
48537 +static struct notifier_block macvlan_notifier_block = {
48538 .notifier_call = macvlan_device_event,
48539 };
48540
48541 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48542 index 880cc09..764aee1 100644
48543 --- a/drivers/net/macvtap.c
48544 +++ b/drivers/net/macvtap.c
48545 @@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48546 dev->tx_queue_len = TUN_READQ_SIZE;
48547 }
48548
48549 -static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48550 +static struct rtnl_link_ops macvtap_link_ops = {
48551 .kind = "macvtap",
48552 .setup = macvtap_setup,
48553 .newlink = macvtap_newlink,
48554 @@ -637,12 +637,15 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
48555 } /* else everything is zero */
48556 }
48557
48558 +/* Neighbour code has some assumptions on HH_DATA_MOD alignment */
48559 +#define MACVTAP_RESERVE HH_DATA_OFF(ETH_HLEN)
48560 +
48561 /* Get packet from user space buffer */
48562 static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
48563 const struct iovec *iv, unsigned long total_len,
48564 size_t count, int noblock)
48565 {
48566 - int good_linear = SKB_MAX_HEAD(NET_IP_ALIGN);
48567 + int good_linear = SKB_MAX_HEAD(MACVTAP_RESERVE);
48568 struct sk_buff *skb;
48569 struct macvlan_dev *vlan;
48570 unsigned long len = total_len;
48571 @@ -701,7 +704,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
48572 linear = vnet_hdr.hdr_len;
48573 }
48574
48575 - skb = macvtap_alloc_skb(&q->sk, NET_IP_ALIGN, copylen,
48576 + skb = macvtap_alloc_skb(&q->sk, MACVTAP_RESERVE, copylen,
48577 linear, noblock, &err);
48578 if (!skb)
48579 goto err;
48580 @@ -1020,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48581 }
48582
48583 ret = 0;
48584 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48585 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48586 put_user(q->flags, &ifr->ifr_flags))
48587 ret = -EFAULT;
48588 macvtap_put_vlan(vlan);
48589 @@ -1190,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48590 return NOTIFY_DONE;
48591 }
48592
48593 -static struct notifier_block macvtap_notifier_block __read_mostly = {
48594 +static struct notifier_block macvtap_notifier_block = {
48595 .notifier_call = macvtap_device_event,
48596 };
48597
48598 diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48599 index 34924df..a747360 100644
48600 --- a/drivers/net/nlmon.c
48601 +++ b/drivers/net/nlmon.c
48602 @@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48603 return 0;
48604 }
48605
48606 -static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48607 +static struct rtnl_link_ops nlmon_link_ops = {
48608 .kind = "nlmon",
48609 .priv_size = sizeof(struct nlmon),
48610 .setup = nlmon_setup,
48611 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48612 index 794a473..9fd437b 100644
48613 --- a/drivers/net/ppp/ppp_generic.c
48614 +++ b/drivers/net/ppp/ppp_generic.c
48615 @@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48616 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48617 struct ppp_stats stats;
48618 struct ppp_comp_stats cstats;
48619 - char *vers;
48620
48621 switch (cmd) {
48622 case SIOCGPPPSTATS:
48623 @@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48624 break;
48625
48626 case SIOCGPPPVER:
48627 - vers = PPP_VERSION;
48628 - if (copy_to_user(addr, vers, strlen(vers) + 1))
48629 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48630 break;
48631 err = 0;
48632 break;
48633 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48634 index 079f7ad..b2a2bfa7 100644
48635 --- a/drivers/net/slip/slhc.c
48636 +++ b/drivers/net/slip/slhc.c
48637 @@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48638 register struct tcphdr *thp;
48639 register struct iphdr *ip;
48640 register struct cstate *cs;
48641 - int len, hdrlen;
48642 + long len, hdrlen;
48643 unsigned char *cp = icp;
48644
48645 /* We've got a compressed packet; read the change byte */
48646 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48647 index 9c505c4..5d0c879 100644
48648 --- a/drivers/net/team/team.c
48649 +++ b/drivers/net/team/team.c
48650 @@ -2102,7 +2102,7 @@ static unsigned int team_get_num_rx_queues(void)
48651 return TEAM_DEFAULT_NUM_RX_QUEUES;
48652 }
48653
48654 -static struct rtnl_link_ops team_link_ops __read_mostly = {
48655 +static struct rtnl_link_ops team_link_ops = {
48656 .kind = DRV_NAME,
48657 .priv_size = sizeof(struct team),
48658 .setup = team_setup,
48659 @@ -2892,7 +2892,7 @@ static int team_device_event(struct notifier_block *unused,
48660 return NOTIFY_DONE;
48661 }
48662
48663 -static struct notifier_block team_notifier_block __read_mostly = {
48664 +static struct notifier_block team_notifier_block = {
48665 .notifier_call = team_device_event,
48666 };
48667
48668 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48669 index 9dd3746..74f191e 100644
48670 --- a/drivers/net/tun.c
48671 +++ b/drivers/net/tun.c
48672 @@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48673 return -EINVAL;
48674 }
48675
48676 -static struct rtnl_link_ops tun_link_ops __read_mostly = {
48677 +static struct rtnl_link_ops tun_link_ops = {
48678 .kind = DRV_NAME,
48679 .priv_size = sizeof(struct tun_struct),
48680 .setup = tun_setup,
48681 @@ -1868,7 +1868,7 @@ unlock:
48682 }
48683
48684 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48685 - unsigned long arg, int ifreq_len)
48686 + unsigned long arg, size_t ifreq_len)
48687 {
48688 struct tun_file *tfile = file->private_data;
48689 struct tun_struct *tun;
48690 @@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48691 unsigned int ifindex;
48692 int ret;
48693
48694 + if (ifreq_len > sizeof ifr)
48695 + return -EFAULT;
48696 +
48697 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48698 if (copy_from_user(&ifr, argp, ifreq_len))
48699 return -EFAULT;
48700 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48701 index babda7d..e40c90a 100644
48702 --- a/drivers/net/usb/hso.c
48703 +++ b/drivers/net/usb/hso.c
48704 @@ -71,7 +71,7 @@
48705 #include <asm/byteorder.h>
48706 #include <linux/serial_core.h>
48707 #include <linux/serial.h>
48708 -
48709 +#include <asm/local.h>
48710
48711 #define MOD_AUTHOR "Option Wireless"
48712 #define MOD_DESCRIPTION "USB High Speed Option driver"
48713 @@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48714 struct urb *urb;
48715
48716 urb = serial->rx_urb[0];
48717 - if (serial->port.count > 0) {
48718 + if (atomic_read(&serial->port.count) > 0) {
48719 count = put_rxbuf_data(urb, serial);
48720 if (count == -1)
48721 return;
48722 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48723 DUMP1(urb->transfer_buffer, urb->actual_length);
48724
48725 /* Anyone listening? */
48726 - if (serial->port.count == 0)
48727 + if (atomic_read(&serial->port.count) == 0)
48728 return;
48729
48730 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48731 @@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48732 tty_port_tty_set(&serial->port, tty);
48733
48734 /* check for port already opened, if not set the termios */
48735 - serial->port.count++;
48736 - if (serial->port.count == 1) {
48737 + if (atomic_inc_return(&serial->port.count) == 1) {
48738 serial->rx_state = RX_IDLE;
48739 /* Force default termio settings */
48740 _hso_serial_set_termios(tty, NULL);
48741 @@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48742 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48743 if (result) {
48744 hso_stop_serial_device(serial->parent);
48745 - serial->port.count--;
48746 + atomic_dec(&serial->port.count);
48747 kref_put(&serial->parent->ref, hso_serial_ref_free);
48748 }
48749 } else {
48750 @@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48751
48752 /* reset the rts and dtr */
48753 /* do the actual close */
48754 - serial->port.count--;
48755 + atomic_dec(&serial->port.count);
48756
48757 - if (serial->port.count <= 0) {
48758 - serial->port.count = 0;
48759 + if (atomic_read(&serial->port.count) <= 0) {
48760 + atomic_set(&serial->port.count, 0);
48761 tty_port_tty_set(&serial->port, NULL);
48762 if (!usb_gone)
48763 hso_stop_serial_device(serial->parent);
48764 @@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48765
48766 /* the actual setup */
48767 spin_lock_irqsave(&serial->serial_lock, flags);
48768 - if (serial->port.count)
48769 + if (atomic_read(&serial->port.count))
48770 _hso_serial_set_termios(tty, old);
48771 else
48772 tty->termios = *old;
48773 @@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48774 D1("Pending read interrupt on port %d\n", i);
48775 spin_lock(&serial->serial_lock);
48776 if (serial->rx_state == RX_IDLE &&
48777 - serial->port.count > 0) {
48778 + atomic_read(&serial->port.count) > 0) {
48779 /* Setup and send a ctrl req read on
48780 * port i */
48781 if (!serial->rx_urb_filled[0]) {
48782 @@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48783 /* Start all serial ports */
48784 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48785 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48786 - if (dev2ser(serial_table[i])->port.count) {
48787 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48788 result =
48789 hso_start_serial_device(serial_table[i], GFP_NOIO);
48790 hso_kick_transmit(dev2ser(serial_table[i]));
48791 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48792 index c6554c7..7e2ebd7 100644
48793 --- a/drivers/net/usb/r8152.c
48794 +++ b/drivers/net/usb/r8152.c
48795 @@ -577,7 +577,7 @@ struct r8152 {
48796 void (*unload)(struct r8152 *);
48797 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48798 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48799 - } rtl_ops;
48800 + } __no_const rtl_ops;
48801
48802 int intr_interval;
48803 u32 saved_wolopts;
48804 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48805 index a2515887..6d13233 100644
48806 --- a/drivers/net/usb/sierra_net.c
48807 +++ b/drivers/net/usb/sierra_net.c
48808 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48809 /* atomic counter partially included in MAC address to make sure 2 devices
48810 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48811 */
48812 -static atomic_t iface_counter = ATOMIC_INIT(0);
48813 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48814
48815 /*
48816 * SYNC Timer Delay definition used to set the expiry time
48817 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48818 dev->net->netdev_ops = &sierra_net_device_ops;
48819
48820 /* change MAC addr to include, ifacenum, and to be unique */
48821 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48822 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48823 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48824
48825 /* we will have to manufacture ethernet headers, prepare template */
48826 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48827 index b0bc8ea..3af931b5 100644
48828 --- a/drivers/net/virtio_net.c
48829 +++ b/drivers/net/virtio_net.c
48830 @@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48831 #define RECEIVE_AVG_WEIGHT 64
48832
48833 /* Minimum alignment for mergeable packet buffers. */
48834 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48835 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48836
48837 #define VIRTNET_DRIVER_VERSION "1.0.0"
48838
48839 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48840 index 42b2d6a5..2a2cb41 100644
48841 --- a/drivers/net/vxlan.c
48842 +++ b/drivers/net/vxlan.c
48843 @@ -2695,7 +2695,7 @@ nla_put_failure:
48844 return -EMSGSIZE;
48845 }
48846
48847 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48848 +static struct rtnl_link_ops vxlan_link_ops = {
48849 .kind = "vxlan",
48850 .maxtype = IFLA_VXLAN_MAX,
48851 .policy = vxlan_policy,
48852 @@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48853 return NOTIFY_DONE;
48854 }
48855
48856 -static struct notifier_block vxlan_notifier_block __read_mostly = {
48857 +static struct notifier_block vxlan_notifier_block = {
48858 .notifier_call = vxlan_lowerdev_event,
48859 };
48860
48861 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48862 index 5920c99..ff2e4a5 100644
48863 --- a/drivers/net/wan/lmc/lmc_media.c
48864 +++ b/drivers/net/wan/lmc/lmc_media.c
48865 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48866 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48867
48868 lmc_media_t lmc_ds3_media = {
48869 - lmc_ds3_init, /* special media init stuff */
48870 - lmc_ds3_default, /* reset to default state */
48871 - lmc_ds3_set_status, /* reset status to state provided */
48872 - lmc_dummy_set_1, /* set clock source */
48873 - lmc_dummy_set2_1, /* set line speed */
48874 - lmc_ds3_set_100ft, /* set cable length */
48875 - lmc_ds3_set_scram, /* set scrambler */
48876 - lmc_ds3_get_link_status, /* get link status */
48877 - lmc_dummy_set_1, /* set link status */
48878 - lmc_ds3_set_crc_length, /* set CRC length */
48879 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48880 - lmc_ds3_watchdog
48881 + .init = lmc_ds3_init, /* special media init stuff */
48882 + .defaults = lmc_ds3_default, /* reset to default state */
48883 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
48884 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
48885 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48886 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48887 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48888 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
48889 + .set_link_status = lmc_dummy_set_1, /* set link status */
48890 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48891 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48892 + .watchdog = lmc_ds3_watchdog
48893 };
48894
48895 lmc_media_t lmc_hssi_media = {
48896 - lmc_hssi_init, /* special media init stuff */
48897 - lmc_hssi_default, /* reset to default state */
48898 - lmc_hssi_set_status, /* reset status to state provided */
48899 - lmc_hssi_set_clock, /* set clock source */
48900 - lmc_dummy_set2_1, /* set line speed */
48901 - lmc_dummy_set_1, /* set cable length */
48902 - lmc_dummy_set_1, /* set scrambler */
48903 - lmc_hssi_get_link_status, /* get link status */
48904 - lmc_hssi_set_link_status, /* set link status */
48905 - lmc_hssi_set_crc_length, /* set CRC length */
48906 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48907 - lmc_hssi_watchdog
48908 + .init = lmc_hssi_init, /* special media init stuff */
48909 + .defaults = lmc_hssi_default, /* reset to default state */
48910 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
48911 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48912 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48913 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48914 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48915 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
48916 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
48917 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48918 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48919 + .watchdog = lmc_hssi_watchdog
48920 };
48921
48922 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48923 - lmc_ssi_default, /* reset to default state */
48924 - lmc_ssi_set_status, /* reset status to state provided */
48925 - lmc_ssi_set_clock, /* set clock source */
48926 - lmc_ssi_set_speed, /* set line speed */
48927 - lmc_dummy_set_1, /* set cable length */
48928 - lmc_dummy_set_1, /* set scrambler */
48929 - lmc_ssi_get_link_status, /* get link status */
48930 - lmc_ssi_set_link_status, /* set link status */
48931 - lmc_ssi_set_crc_length, /* set CRC length */
48932 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
48933 - lmc_ssi_watchdog
48934 +lmc_media_t lmc_ssi_media = {
48935 + .init = lmc_ssi_init, /* special media init stuff */
48936 + .defaults = lmc_ssi_default, /* reset to default state */
48937 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
48938 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48939 + .set_speed = lmc_ssi_set_speed, /* set line speed */
48940 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48941 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48942 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
48943 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
48944 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48945 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48946 + .watchdog = lmc_ssi_watchdog
48947 };
48948
48949 lmc_media_t lmc_t1_media = {
48950 - lmc_t1_init, /* special media init stuff */
48951 - lmc_t1_default, /* reset to default state */
48952 - lmc_t1_set_status, /* reset status to state provided */
48953 - lmc_t1_set_clock, /* set clock source */
48954 - lmc_dummy_set2_1, /* set line speed */
48955 - lmc_dummy_set_1, /* set cable length */
48956 - lmc_dummy_set_1, /* set scrambler */
48957 - lmc_t1_get_link_status, /* get link status */
48958 - lmc_dummy_set_1, /* set link status */
48959 - lmc_t1_set_crc_length, /* set CRC length */
48960 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48961 - lmc_t1_watchdog
48962 + .init = lmc_t1_init, /* special media init stuff */
48963 + .defaults = lmc_t1_default, /* reset to default state */
48964 + .set_status = lmc_t1_set_status, /* reset status to state provided */
48965 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
48966 + .set_speed = lmc_dummy_set2_1, /* set line speed */
48967 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
48968 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48969 + .get_link_status = lmc_t1_get_link_status, /* get link status */
48970 + .set_link_status = lmc_dummy_set_1, /* set link status */
48971 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48972 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48973 + .watchdog = lmc_t1_watchdog
48974 };
48975
48976 static void
48977 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48978 index feacc3b..5bac0de 100644
48979 --- a/drivers/net/wan/z85230.c
48980 +++ b/drivers/net/wan/z85230.c
48981 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48982
48983 struct z8530_irqhandler z8530_sync =
48984 {
48985 - z8530_rx,
48986 - z8530_tx,
48987 - z8530_status
48988 + .rx = z8530_rx,
48989 + .tx = z8530_tx,
48990 + .status = z8530_status
48991 };
48992
48993 EXPORT_SYMBOL(z8530_sync);
48994 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48995 }
48996
48997 static struct z8530_irqhandler z8530_dma_sync = {
48998 - z8530_dma_rx,
48999 - z8530_dma_tx,
49000 - z8530_dma_status
49001 + .rx = z8530_dma_rx,
49002 + .tx = z8530_dma_tx,
49003 + .status = z8530_dma_status
49004 };
49005
49006 static struct z8530_irqhandler z8530_txdma_sync = {
49007 - z8530_rx,
49008 - z8530_dma_tx,
49009 - z8530_dma_status
49010 + .rx = z8530_rx,
49011 + .tx = z8530_dma_tx,
49012 + .status = z8530_dma_status
49013 };
49014
49015 /**
49016 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49017
49018 struct z8530_irqhandler z8530_nop=
49019 {
49020 - z8530_rx_clear,
49021 - z8530_tx_clear,
49022 - z8530_status_clear
49023 + .rx = z8530_rx_clear,
49024 + .tx = z8530_tx_clear,
49025 + .status = z8530_status_clear
49026 };
49027
49028
49029 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49030 index 0b60295..b8bfa5b 100644
49031 --- a/drivers/net/wimax/i2400m/rx.c
49032 +++ b/drivers/net/wimax/i2400m/rx.c
49033 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49034 if (i2400m->rx_roq == NULL)
49035 goto error_roq_alloc;
49036
49037 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49038 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49039 GFP_KERNEL);
49040 if (rd == NULL) {
49041 result = -ENOMEM;
49042 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49043 index e71a2ce..2268d61 100644
49044 --- a/drivers/net/wireless/airo.c
49045 +++ b/drivers/net/wireless/airo.c
49046 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49047 struct airo_info *ai = dev->ml_priv;
49048 int ridcode;
49049 int enabled;
49050 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49051 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49052 unsigned char *iobuf;
49053
49054 /* Only super-user can write RIDs */
49055 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49056 index da92bfa..5a9001a 100644
49057 --- a/drivers/net/wireless/at76c50x-usb.c
49058 +++ b/drivers/net/wireless/at76c50x-usb.c
49059 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49060 }
49061
49062 /* Convert timeout from the DFU status to jiffies */
49063 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
49064 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49065 {
49066 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49067 | (s->poll_timeout[1] << 8)
49068 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49069 index 676bd4e..0b807a3 100644
49070 --- a/drivers/net/wireless/ath/ath10k/htc.c
49071 +++ b/drivers/net/wireless/ath/ath10k/htc.c
49072 @@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
49073 /* registered target arrival callback from the HIF layer */
49074 int ath10k_htc_init(struct ath10k *ar)
49075 {
49076 - struct ath10k_hif_cb htc_callbacks;
49077 + static struct ath10k_hif_cb htc_callbacks = {
49078 + .rx_completion = ath10k_htc_rx_completion_handler,
49079 + .tx_completion = ath10k_htc_tx_completion_handler,
49080 + };
49081 struct ath10k_htc_ep *ep = NULL;
49082 struct ath10k_htc *htc = &ar->htc;
49083
49084 @@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
49085 ath10k_htc_reset_endpoint_states(htc);
49086
49087 /* setup HIF layer callbacks */
49088 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49089 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49090 htc->ar = ar;
49091
49092 /* Get HIF default pipe for HTC message exchange */
49093 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49094 index 527179c..a890150 100644
49095 --- a/drivers/net/wireless/ath/ath10k/htc.h
49096 +++ b/drivers/net/wireless/ath/ath10k/htc.h
49097 @@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
49098
49099 struct ath10k_htc_ops {
49100 void (*target_send_suspend_complete)(struct ath10k *ar);
49101 -};
49102 +} __no_const;
49103
49104 struct ath10k_htc_ep_ops {
49105 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49106 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49107 void (*ep_tx_credits)(struct ath10k *);
49108 -};
49109 +} __no_const;
49110
49111 /* service connection information */
49112 struct ath10k_htc_svc_conn_req {
49113 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49114 index 2a93519..7052786 100644
49115 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49116 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49117 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49118 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49119 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49120
49121 - ACCESS_ONCE(ads->ds_link) = i->link;
49122 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49123 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
49124 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49125
49126 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49127 ctl6 = SM(i->keytype, AR_EncrType);
49128 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49129
49130 if ((i->is_first || i->is_last) &&
49131 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49132 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49133 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49134 | set11nTries(i->rates, 1)
49135 | set11nTries(i->rates, 2)
49136 | set11nTries(i->rates, 3)
49137 | (i->dur_update ? AR_DurUpdateEna : 0)
49138 | SM(0, AR_BurstDur);
49139
49140 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49141 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49142 | set11nRate(i->rates, 1)
49143 | set11nRate(i->rates, 2)
49144 | set11nRate(i->rates, 3);
49145 } else {
49146 - ACCESS_ONCE(ads->ds_ctl2) = 0;
49147 - ACCESS_ONCE(ads->ds_ctl3) = 0;
49148 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49149 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49150 }
49151
49152 if (!i->is_first) {
49153 - ACCESS_ONCE(ads->ds_ctl0) = 0;
49154 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49155 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49156 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49157 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49158 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49159 return;
49160 }
49161
49162 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49163 break;
49164 }
49165
49166 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49167 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49168 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49169 | SM(i->txpower, AR_XmitPower0)
49170 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49171 @@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49172 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49173 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49174
49175 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49176 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49177 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49178 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49179
49180 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49181 return;
49182
49183 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49184 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49185 | set11nPktDurRTSCTS(i->rates, 1);
49186
49187 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49188 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49189 | set11nPktDurRTSCTS(i->rates, 3);
49190
49191 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49192 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49193 | set11nRateFlags(i->rates, 1)
49194 | set11nRateFlags(i->rates, 2)
49195 | set11nRateFlags(i->rates, 3)
49196 | SM(i->rtscts_rate, AR_RTSCTSRate);
49197
49198 - ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49199 - ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49200 - ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49201 + ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49202 + ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49203 + ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49204 }
49205
49206 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49207 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49208 index 057b165..98ae88f 100644
49209 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49210 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49211 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49212 (i->qcu << AR_TxQcuNum_S) | desc_len;
49213
49214 checksum += val;
49215 - ACCESS_ONCE(ads->info) = val;
49216 + ACCESS_ONCE_RW(ads->info) = val;
49217
49218 checksum += i->link;
49219 - ACCESS_ONCE(ads->link) = i->link;
49220 + ACCESS_ONCE_RW(ads->link) = i->link;
49221
49222 checksum += i->buf_addr[0];
49223 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49224 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49225 checksum += i->buf_addr[1];
49226 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49227 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49228 checksum += i->buf_addr[2];
49229 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49230 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49231 checksum += i->buf_addr[3];
49232 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49233 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49234
49235 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49236 - ACCESS_ONCE(ads->ctl3) = val;
49237 + ACCESS_ONCE_RW(ads->ctl3) = val;
49238 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49239 - ACCESS_ONCE(ads->ctl5) = val;
49240 + ACCESS_ONCE_RW(ads->ctl5) = val;
49241 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49242 - ACCESS_ONCE(ads->ctl7) = val;
49243 + ACCESS_ONCE_RW(ads->ctl7) = val;
49244 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49245 - ACCESS_ONCE(ads->ctl9) = val;
49246 + ACCESS_ONCE_RW(ads->ctl9) = val;
49247
49248 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49249 - ACCESS_ONCE(ads->ctl10) = checksum;
49250 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
49251
49252 if (i->is_first || i->is_last) {
49253 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49254 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49255 | set11nTries(i->rates, 1)
49256 | set11nTries(i->rates, 2)
49257 | set11nTries(i->rates, 3)
49258 | (i->dur_update ? AR_DurUpdateEna : 0)
49259 | SM(0, AR_BurstDur);
49260
49261 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49262 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49263 | set11nRate(i->rates, 1)
49264 | set11nRate(i->rates, 2)
49265 | set11nRate(i->rates, 3);
49266 } else {
49267 - ACCESS_ONCE(ads->ctl13) = 0;
49268 - ACCESS_ONCE(ads->ctl14) = 0;
49269 + ACCESS_ONCE_RW(ads->ctl13) = 0;
49270 + ACCESS_ONCE_RW(ads->ctl14) = 0;
49271 }
49272
49273 ads->ctl20 = 0;
49274 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49275
49276 ctl17 = SM(i->keytype, AR_EncrType);
49277 if (!i->is_first) {
49278 - ACCESS_ONCE(ads->ctl11) = 0;
49279 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49280 - ACCESS_ONCE(ads->ctl15) = 0;
49281 - ACCESS_ONCE(ads->ctl16) = 0;
49282 - ACCESS_ONCE(ads->ctl17) = ctl17;
49283 - ACCESS_ONCE(ads->ctl18) = 0;
49284 - ACCESS_ONCE(ads->ctl19) = 0;
49285 + ACCESS_ONCE_RW(ads->ctl11) = 0;
49286 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49287 + ACCESS_ONCE_RW(ads->ctl15) = 0;
49288 + ACCESS_ONCE_RW(ads->ctl16) = 0;
49289 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49290 + ACCESS_ONCE_RW(ads->ctl18) = 0;
49291 + ACCESS_ONCE_RW(ads->ctl19) = 0;
49292 return;
49293 }
49294
49295 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49296 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49297 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49298 | SM(i->txpower, AR_XmitPower0)
49299 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49300 @@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49301 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49302 ctl12 |= SM(val, AR_PAPRDChainMask);
49303
49304 - ACCESS_ONCE(ads->ctl12) = ctl12;
49305 - ACCESS_ONCE(ads->ctl17) = ctl17;
49306 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49307 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49308
49309 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49310 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49311 | set11nPktDurRTSCTS(i->rates, 1);
49312
49313 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49314 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49315 | set11nPktDurRTSCTS(i->rates, 3);
49316
49317 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49318 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49319 | set11nRateFlags(i->rates, 1)
49320 | set11nRateFlags(i->rates, 2)
49321 | set11nRateFlags(i->rates, 3)
49322 | SM(i->rtscts_rate, AR_RTSCTSRate);
49323
49324 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49325 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49326
49327 - ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49328 - ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49329 - ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49330 + ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49331 + ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49332 + ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49333 }
49334
49335 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49336 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49337 index e8e8dd2..030f80e 100644
49338 --- a/drivers/net/wireless/ath/ath9k/hw.h
49339 +++ b/drivers/net/wireless/ath/ath9k/hw.h
49340 @@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49341
49342 /* ANI */
49343 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49344 -};
49345 +} __no_const;
49346
49347 /**
49348 * struct ath_spec_scan - parameters for Atheros spectral scan
49349 @@ -708,7 +708,7 @@ struct ath_hw_ops {
49350 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49351 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49352 #endif
49353 -};
49354 +} __no_const;
49355
49356 struct ath_nf_limits {
49357 s16 max;
49358 diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49359 index 4f18a6b..b07d92f 100644
49360 --- a/drivers/net/wireless/ath/ath9k/main.c
49361 +++ b/drivers/net/wireless/ath/ath9k/main.c
49362 @@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49363 if (!ath9k_is_chanctx_enabled())
49364 return;
49365
49366 - ath9k_ops.hw_scan = ath9k_hw_scan;
49367 - ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49368 - ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49369 - ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49370 - ath9k_ops.add_chanctx = ath9k_add_chanctx;
49371 - ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49372 - ath9k_ops.change_chanctx = ath9k_change_chanctx;
49373 - ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49374 - ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49375 - ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49376 + pax_open_kernel();
49377 + *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49378 + *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49379 + *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49380 + *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49381 + *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49382 + *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49383 + *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49384 + *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49385 + *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49386 + *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49387 + pax_close_kernel();
49388 }
49389
49390 #endif
49391 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49392 index 058a9f2..d5cb1ba 100644
49393 --- a/drivers/net/wireless/b43/phy_lp.c
49394 +++ b/drivers/net/wireless/b43/phy_lp.c
49395 @@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49396 {
49397 struct ssb_bus *bus = dev->dev->sdev->bus;
49398
49399 - static const struct b206x_channel *chandata = NULL;
49400 + const struct b206x_channel *chandata = NULL;
49401 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49402 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49403 u16 old_comm15, scale;
49404 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49405 index dc1d20c..f7a4f06 100644
49406 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
49407 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49408 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49409 */
49410 if (il3945_mod_params.disable_hw_scan) {
49411 D_INFO("Disabling hw_scan\n");
49412 - il3945_mac_ops.hw_scan = NULL;
49413 + pax_open_kernel();
49414 + *(void **)&il3945_mac_ops.hw_scan = NULL;
49415 + pax_close_kernel();
49416 }
49417
49418 D_INFO("*** LOAD DRIVER ***\n");
49419 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49420 index 0ffb6ff..c0b7f0e 100644
49421 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49422 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49423 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49424 {
49425 struct iwl_priv *priv = file->private_data;
49426 char buf[64];
49427 - int buf_size;
49428 + size_t buf_size;
49429 u32 offset, len;
49430
49431 memset(buf, 0, sizeof(buf));
49432 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49433 struct iwl_priv *priv = file->private_data;
49434
49435 char buf[8];
49436 - int buf_size;
49437 + size_t buf_size;
49438 u32 reset_flag;
49439
49440 memset(buf, 0, sizeof(buf));
49441 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49442 {
49443 struct iwl_priv *priv = file->private_data;
49444 char buf[8];
49445 - int buf_size;
49446 + size_t buf_size;
49447 int ht40;
49448
49449 memset(buf, 0, sizeof(buf));
49450 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49451 {
49452 struct iwl_priv *priv = file->private_data;
49453 char buf[8];
49454 - int buf_size;
49455 + size_t buf_size;
49456 int value;
49457
49458 memset(buf, 0, sizeof(buf));
49459 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49460 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49461 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49462
49463 -static const char *fmt_value = " %-30s %10u\n";
49464 -static const char *fmt_hex = " %-30s 0x%02X\n";
49465 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49466 -static const char *fmt_header =
49467 +static const char fmt_value[] = " %-30s %10u\n";
49468 +static const char fmt_hex[] = " %-30s 0x%02X\n";
49469 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49470 +static const char fmt_header[] =
49471 "%-32s current cumulative delta max\n";
49472
49473 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49474 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49475 {
49476 struct iwl_priv *priv = file->private_data;
49477 char buf[8];
49478 - int buf_size;
49479 + size_t buf_size;
49480 int clear;
49481
49482 memset(buf, 0, sizeof(buf));
49483 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49484 {
49485 struct iwl_priv *priv = file->private_data;
49486 char buf[8];
49487 - int buf_size;
49488 + size_t buf_size;
49489 int trace;
49490
49491 memset(buf, 0, sizeof(buf));
49492 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49493 {
49494 struct iwl_priv *priv = file->private_data;
49495 char buf[8];
49496 - int buf_size;
49497 + size_t buf_size;
49498 int missed;
49499
49500 memset(buf, 0, sizeof(buf));
49501 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49502
49503 struct iwl_priv *priv = file->private_data;
49504 char buf[8];
49505 - int buf_size;
49506 + size_t buf_size;
49507 int plcp;
49508
49509 memset(buf, 0, sizeof(buf));
49510 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49511
49512 struct iwl_priv *priv = file->private_data;
49513 char buf[8];
49514 - int buf_size;
49515 + size_t buf_size;
49516 int flush;
49517
49518 memset(buf, 0, sizeof(buf));
49519 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49520
49521 struct iwl_priv *priv = file->private_data;
49522 char buf[8];
49523 - int buf_size;
49524 + size_t buf_size;
49525 int rts;
49526
49527 if (!priv->cfg->ht_params)
49528 @@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49529 {
49530 struct iwl_priv *priv = file->private_data;
49531 char buf[8];
49532 - int buf_size;
49533 + size_t buf_size;
49534
49535 memset(buf, 0, sizeof(buf));
49536 buf_size = min(count, sizeof(buf) - 1);
49537 @@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49538 struct iwl_priv *priv = file->private_data;
49539 u32 event_log_flag;
49540 char buf[8];
49541 - int buf_size;
49542 + size_t buf_size;
49543
49544 /* check that the interface is up */
49545 if (!iwl_is_ready(priv))
49546 @@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49547 struct iwl_priv *priv = file->private_data;
49548 char buf[8];
49549 u32 calib_disabled;
49550 - int buf_size;
49551 + size_t buf_size;
49552
49553 memset(buf, 0, sizeof(buf));
49554 buf_size = min(count, sizeof(buf) - 1);
49555 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49556 index dd2f3f8..fb1ae88 100644
49557 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49558 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49559 @@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49560 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49561
49562 char buf[8];
49563 - int buf_size;
49564 + size_t buf_size;
49565 u32 reset_flag;
49566
49567 memset(buf, 0, sizeof(buf));
49568 @@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49569 {
49570 struct iwl_trans *trans = file->private_data;
49571 char buf[8];
49572 - int buf_size;
49573 + size_t buf_size;
49574 int csr;
49575
49576 memset(buf, 0, sizeof(buf));
49577 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49578 index c9ad4cf..49a2fa0 100644
49579 --- a/drivers/net/wireless/mac80211_hwsim.c
49580 +++ b/drivers/net/wireless/mac80211_hwsim.c
49581 @@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49582 if (channels < 1)
49583 return -EINVAL;
49584
49585 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49586 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49587 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49588 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49589 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49590 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49591 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49592 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49593 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49594 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49595 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49596 - mac80211_hwsim_assign_vif_chanctx;
49597 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49598 - mac80211_hwsim_unassign_vif_chanctx;
49599 + pax_open_kernel();
49600 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49601 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49602 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49603 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49604 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49605 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49606 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49607 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49608 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49609 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49610 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49611 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49612 + pax_close_kernel();
49613
49614 spin_lock_init(&hwsim_radio_lock);
49615 INIT_LIST_HEAD(&hwsim_radios);
49616 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49617 index 1a4facd..a2ecbbd 100644
49618 --- a/drivers/net/wireless/rndis_wlan.c
49619 +++ b/drivers/net/wireless/rndis_wlan.c
49620 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49621
49622 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49623
49624 - if (rts_threshold < 0 || rts_threshold > 2347)
49625 + if (rts_threshold > 2347)
49626 rts_threshold = 2347;
49627
49628 tmp = cpu_to_le32(rts_threshold);
49629 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49630 index d13f25c..2573994 100644
49631 --- a/drivers/net/wireless/rt2x00/rt2x00.h
49632 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
49633 @@ -375,7 +375,7 @@ struct rt2x00_intf {
49634 * for hardware which doesn't support hardware
49635 * sequence counting.
49636 */
49637 - atomic_t seqno;
49638 + atomic_unchecked_t seqno;
49639 };
49640
49641 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49642 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49643 index 66ff364..3ce34f7 100644
49644 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49645 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49646 @@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49647 * sequence counter given by mac80211.
49648 */
49649 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49650 - seqno = atomic_add_return(0x10, &intf->seqno);
49651 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49652 else
49653 - seqno = atomic_read(&intf->seqno);
49654 + seqno = atomic_read_unchecked(&intf->seqno);
49655
49656 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49657 hdr->seq_ctrl |= cpu_to_le16(seqno);
49658 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49659 index b661f896..ddf7d2b 100644
49660 --- a/drivers/net/wireless/ti/wl1251/sdio.c
49661 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
49662 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49663
49664 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49665
49666 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49667 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49668 + pax_open_kernel();
49669 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49670 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49671 + pax_close_kernel();
49672
49673 wl1251_info("using dedicated interrupt line");
49674 } else {
49675 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49676 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49677 + pax_open_kernel();
49678 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49679 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49680 + pax_close_kernel();
49681
49682 wl1251_info("using SDIO interrupt");
49683 }
49684 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49685 index 0bccf12..3d95068 100644
49686 --- a/drivers/net/wireless/ti/wl12xx/main.c
49687 +++ b/drivers/net/wireless/ti/wl12xx/main.c
49688 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49689 sizeof(wl->conf.mem));
49690
49691 /* read data preparation is only needed by wl127x */
49692 - wl->ops->prepare_read = wl127x_prepare_read;
49693 + pax_open_kernel();
49694 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49695 + pax_close_kernel();
49696
49697 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49698 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49699 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49700 sizeof(wl->conf.mem));
49701
49702 /* read data preparation is only needed by wl127x */
49703 - wl->ops->prepare_read = wl127x_prepare_read;
49704 + pax_open_kernel();
49705 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49706 + pax_close_kernel();
49707
49708 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49709 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49710 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49711 index 7af1936..128bb35 100644
49712 --- a/drivers/net/wireless/ti/wl18xx/main.c
49713 +++ b/drivers/net/wireless/ti/wl18xx/main.c
49714 @@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49715 }
49716
49717 if (!checksum_param) {
49718 - wl18xx_ops.set_rx_csum = NULL;
49719 - wl18xx_ops.init_vif = NULL;
49720 + pax_open_kernel();
49721 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
49722 + *(void **)&wl18xx_ops.init_vif = NULL;
49723 + pax_close_kernel();
49724 }
49725
49726 /* Enable 11a Band only if we have 5G antennas */
49727 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49728 index a912dc0..a8225ba 100644
49729 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
49730 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49731 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49732 {
49733 struct zd_usb *usb = urb->context;
49734 struct zd_usb_interrupt *intr = &usb->intr;
49735 - int len;
49736 + unsigned int len;
49737 u16 int_num;
49738
49739 ZD_ASSERT(in_interrupt());
49740 diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
49741 index d752d1c..23e3203 100644
49742 --- a/drivers/net/xen-netback/interface.c
49743 +++ b/drivers/net/xen-netback/interface.c
49744 @@ -578,6 +578,7 @@ int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
49745 goto err_rx_unbind;
49746 }
49747 queue->task = task;
49748 + get_task_struct(task);
49749
49750 task = kthread_create(xenvif_dealloc_kthread,
49751 (void *)queue, "%s-dealloc", queue->name);
49752 @@ -634,6 +635,7 @@ void xenvif_disconnect(struct xenvif *vif)
49753
49754 if (queue->task) {
49755 kthread_stop(queue->task);
49756 + put_task_struct(queue->task);
49757 queue->task = NULL;
49758 }
49759
49760 diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
49761 index c39aace..e18728d 100644
49762 --- a/drivers/net/xen-netback/netback.c
49763 +++ b/drivers/net/xen-netback/netback.c
49764 @@ -2111,8 +2111,7 @@ int xenvif_kthread_guest_rx(void *data)
49765 */
49766 if (unlikely(vif->disabled && queue->id == 0)) {
49767 xenvif_carrier_off(vif);
49768 - xenvif_rx_queue_purge(queue);
49769 - continue;
49770 + break;
49771 }
49772
49773 if (!skb_queue_empty(&queue->rx_queue))
49774 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49775 index 683671a..4519fc2 100644
49776 --- a/drivers/nfc/nfcwilink.c
49777 +++ b/drivers/nfc/nfcwilink.c
49778 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49779
49780 static int nfcwilink_probe(struct platform_device *pdev)
49781 {
49782 - static struct nfcwilink *drv;
49783 + struct nfcwilink *drv;
49784 int rc;
49785 __u32 protocols;
49786
49787 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49788 index d93b2b6..ae50401 100644
49789 --- a/drivers/oprofile/buffer_sync.c
49790 +++ b/drivers/oprofile/buffer_sync.c
49791 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49792 if (cookie == NO_COOKIE)
49793 offset = pc;
49794 if (cookie == INVALID_COOKIE) {
49795 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49796 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49797 offset = pc;
49798 }
49799 if (cookie != last_cookie) {
49800 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49801 /* add userspace sample */
49802
49803 if (!mm) {
49804 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
49805 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49806 return 0;
49807 }
49808
49809 cookie = lookup_dcookie(mm, s->eip, &offset);
49810
49811 if (cookie == INVALID_COOKIE) {
49812 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49813 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49814 return 0;
49815 }
49816
49817 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49818 /* ignore backtraces if failed to add a sample */
49819 if (state == sb_bt_start) {
49820 state = sb_bt_ignore;
49821 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49822 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49823 }
49824 }
49825 release_mm(mm);
49826 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49827 index c0cc4e7..44d4e54 100644
49828 --- a/drivers/oprofile/event_buffer.c
49829 +++ b/drivers/oprofile/event_buffer.c
49830 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49831 }
49832
49833 if (buffer_pos == buffer_size) {
49834 - atomic_inc(&oprofile_stats.event_lost_overflow);
49835 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49836 return;
49837 }
49838
49839 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49840 index ed2c3ec..deda85a 100644
49841 --- a/drivers/oprofile/oprof.c
49842 +++ b/drivers/oprofile/oprof.c
49843 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49844 if (oprofile_ops.switch_events())
49845 return;
49846
49847 - atomic_inc(&oprofile_stats.multiplex_counter);
49848 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49849 start_switch_worker();
49850 }
49851
49852 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49853 index ee2cfce..7f8f699 100644
49854 --- a/drivers/oprofile/oprofile_files.c
49855 +++ b/drivers/oprofile/oprofile_files.c
49856 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49857
49858 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49859
49860 -static ssize_t timeout_read(struct file *file, char __user *buf,
49861 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49862 size_t count, loff_t *offset)
49863 {
49864 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49865 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49866 index 59659ce..6c860a0 100644
49867 --- a/drivers/oprofile/oprofile_stats.c
49868 +++ b/drivers/oprofile/oprofile_stats.c
49869 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49870 cpu_buf->sample_invalid_eip = 0;
49871 }
49872
49873 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49874 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49875 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
49876 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49877 - atomic_set(&oprofile_stats.multiplex_counter, 0);
49878 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49879 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49880 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49881 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49882 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49883 }
49884
49885
49886 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49887 index 1fc622b..8c48fc3 100644
49888 --- a/drivers/oprofile/oprofile_stats.h
49889 +++ b/drivers/oprofile/oprofile_stats.h
49890 @@ -13,11 +13,11 @@
49891 #include <linux/atomic.h>
49892
49893 struct oprofile_stat_struct {
49894 - atomic_t sample_lost_no_mm;
49895 - atomic_t sample_lost_no_mapping;
49896 - atomic_t bt_lost_no_mapping;
49897 - atomic_t event_lost_overflow;
49898 - atomic_t multiplex_counter;
49899 + atomic_unchecked_t sample_lost_no_mm;
49900 + atomic_unchecked_t sample_lost_no_mapping;
49901 + atomic_unchecked_t bt_lost_no_mapping;
49902 + atomic_unchecked_t event_lost_overflow;
49903 + atomic_unchecked_t multiplex_counter;
49904 };
49905
49906 extern struct oprofile_stat_struct oprofile_stats;
49907 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49908 index 3f49345..c750d0b 100644
49909 --- a/drivers/oprofile/oprofilefs.c
49910 +++ b/drivers/oprofile/oprofilefs.c
49911 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49912
49913 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49914 {
49915 - atomic_t *val = file->private_data;
49916 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49917 + atomic_unchecked_t *val = file->private_data;
49918 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49919 }
49920
49921
49922 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49923
49924
49925 int oprofilefs_create_ro_atomic(struct dentry *root,
49926 - char const *name, atomic_t *val)
49927 + char const *name, atomic_unchecked_t *val)
49928 {
49929 return __oprofilefs_create_file(root, name,
49930 &atomic_ro_fops, 0444, val);
49931 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49932 index bdef916..88c7dee 100644
49933 --- a/drivers/oprofile/timer_int.c
49934 +++ b/drivers/oprofile/timer_int.c
49935 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49936 return NOTIFY_OK;
49937 }
49938
49939 -static struct notifier_block __refdata oprofile_cpu_notifier = {
49940 +static struct notifier_block oprofile_cpu_notifier = {
49941 .notifier_call = oprofile_cpu_notify,
49942 };
49943
49944 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49945 index 3b47080..6cd05dd 100644
49946 --- a/drivers/parport/procfs.c
49947 +++ b/drivers/parport/procfs.c
49948 @@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49949
49950 *ppos += len;
49951
49952 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49953 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49954 }
49955
49956 #ifdef CONFIG_PARPORT_1284
49957 @@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49958
49959 *ppos += len;
49960
49961 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49962 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49963 }
49964 #endif /* IEEE1284.3 support. */
49965
49966 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49967 index 6ca2399..68d866b 100644
49968 --- a/drivers/pci/hotplug/acpiphp_ibm.c
49969 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
49970 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49971 goto init_cleanup;
49972 }
49973
49974 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49975 + pax_open_kernel();
49976 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49977 + pax_close_kernel();
49978 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49979
49980 return retval;
49981 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49982 index 66b7bbe..26bee78 100644
49983 --- a/drivers/pci/hotplug/cpcihp_generic.c
49984 +++ b/drivers/pci/hotplug/cpcihp_generic.c
49985 @@ -73,7 +73,6 @@ static u16 port;
49986 static unsigned int enum_bit;
49987 static u8 enum_mask;
49988
49989 -static struct cpci_hp_controller_ops generic_hpc_ops;
49990 static struct cpci_hp_controller generic_hpc;
49991
49992 static int __init validate_parameters(void)
49993 @@ -139,6 +138,10 @@ static int query_enum(void)
49994 return ((value & enum_mask) == enum_mask);
49995 }
49996
49997 +static struct cpci_hp_controller_ops generic_hpc_ops = {
49998 + .query_enum = query_enum,
49999 +};
50000 +
50001 static int __init cpcihp_generic_init(void)
50002 {
50003 int status;
50004 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50005 pci_dev_put(dev);
50006
50007 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50008 - generic_hpc_ops.query_enum = query_enum;
50009 generic_hpc.ops = &generic_hpc_ops;
50010
50011 status = cpci_hp_register_controller(&generic_hpc);
50012 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50013 index 7ecf34e..effed62 100644
50014 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
50015 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50016 @@ -59,7 +59,6 @@
50017 /* local variables */
50018 static bool debug;
50019 static bool poll;
50020 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
50021 static struct cpci_hp_controller zt5550_hpc;
50022
50023 /* Primary cPCI bus bridge device */
50024 @@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
50025 return 0;
50026 }
50027
50028 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50029 + .query_enum = zt5550_hc_query_enum,
50030 +};
50031 +
50032 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50033 {
50034 int status;
50035 @@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50036 dbg("returned from zt5550_hc_config");
50037
50038 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50039 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50040 zt5550_hpc.ops = &zt5550_hpc_ops;
50041 if (!poll) {
50042 zt5550_hpc.irq = hc_dev->irq;
50043 zt5550_hpc.irq_flags = IRQF_SHARED;
50044 zt5550_hpc.dev_id = hc_dev;
50045
50046 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50047 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50048 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50049 + pax_open_kernel();
50050 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50051 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50052 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50053 + pax_open_kernel();
50054 } else {
50055 info("using ENUM# polling mode");
50056 }
50057 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50058 index 1e08ff8c..3cd145f 100644
50059 --- a/drivers/pci/hotplug/cpqphp_nvram.c
50060 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
50061 @@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
50062
50063 void compaq_nvram_init (void __iomem *rom_start)
50064 {
50065 +#ifndef CONFIG_PAX_KERNEXEC
50066 if (rom_start)
50067 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50068 +#endif
50069
50070 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50071
50072 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50073 index 56d8486..f26113f 100644
50074 --- a/drivers/pci/hotplug/pci_hotplug_core.c
50075 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
50076 @@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50077 return -EINVAL;
50078 }
50079
50080 - slot->ops->owner = owner;
50081 - slot->ops->mod_name = mod_name;
50082 + pax_open_kernel();
50083 + *(struct module **)&slot->ops->owner = owner;
50084 + *(const char **)&slot->ops->mod_name = mod_name;
50085 + pax_close_kernel();
50086
50087 mutex_lock(&pci_hp_mutex);
50088 /*
50089 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50090 index 07aa722..84514b4 100644
50091 --- a/drivers/pci/hotplug/pciehp_core.c
50092 +++ b/drivers/pci/hotplug/pciehp_core.c
50093 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50094 struct slot *slot = ctrl->slot;
50095 struct hotplug_slot *hotplug = NULL;
50096 struct hotplug_slot_info *info = NULL;
50097 - struct hotplug_slot_ops *ops = NULL;
50098 + hotplug_slot_ops_no_const *ops = NULL;
50099 char name[SLOT_NAME_SIZE];
50100 int retval = -ENOMEM;
50101
50102 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50103 index 084587d..4a8f9df 100644
50104 --- a/drivers/pci/msi.c
50105 +++ b/drivers/pci/msi.c
50106 @@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50107 {
50108 struct attribute **msi_attrs;
50109 struct attribute *msi_attr;
50110 - struct device_attribute *msi_dev_attr;
50111 - struct attribute_group *msi_irq_group;
50112 + device_attribute_no_const *msi_dev_attr;
50113 + attribute_group_no_const *msi_irq_group;
50114 const struct attribute_group **msi_irq_groups;
50115 struct msi_desc *entry;
50116 int ret = -ENOMEM;
50117 @@ -549,7 +549,7 @@ error_attrs:
50118 count = 0;
50119 msi_attr = msi_attrs[count];
50120 while (msi_attr) {
50121 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50122 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50123 kfree(msi_attr->name);
50124 kfree(msi_dev_attr);
50125 ++count;
50126 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50127 index 2c6643f..3a6d8e0 100644
50128 --- a/drivers/pci/pci-sysfs.c
50129 +++ b/drivers/pci/pci-sysfs.c
50130 @@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50131 {
50132 /* allocate attribute structure, piggyback attribute name */
50133 int name_len = write_combine ? 13 : 10;
50134 - struct bin_attribute *res_attr;
50135 + bin_attribute_no_const *res_attr;
50136 int retval;
50137
50138 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50139 @@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50140 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50141 {
50142 int retval;
50143 - struct bin_attribute *attr;
50144 + bin_attribute_no_const *attr;
50145
50146 /* If the device has VPD, try to expose it in sysfs. */
50147 if (dev->vpd) {
50148 @@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50149 {
50150 int retval;
50151 int rom_size = 0;
50152 - struct bin_attribute *attr;
50153 + bin_attribute_no_const *attr;
50154
50155 if (!sysfs_initialized)
50156 return -EACCES;
50157 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50158 index b5defca..e3664cc 100644
50159 --- a/drivers/pci/pci.h
50160 +++ b/drivers/pci/pci.h
50161 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
50162 struct pci_vpd {
50163 unsigned int len;
50164 const struct pci_vpd_ops *ops;
50165 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50166 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50167 };
50168
50169 int pci_vpd_pci22_init(struct pci_dev *dev);
50170 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50171 index e1e7026..d28dd33 100644
50172 --- a/drivers/pci/pcie/aspm.c
50173 +++ b/drivers/pci/pcie/aspm.c
50174 @@ -27,9 +27,9 @@
50175 #define MODULE_PARAM_PREFIX "pcie_aspm."
50176
50177 /* Note: those are not register definitions */
50178 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50179 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50180 -#define ASPM_STATE_L1 (4) /* L1 state */
50181 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50182 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50183 +#define ASPM_STATE_L1 (4U) /* L1 state */
50184 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50185 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50186
50187 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50188 index 3010ffc..5e2e133 100644
50189 --- a/drivers/pci/probe.c
50190 +++ b/drivers/pci/probe.c
50191 @@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50192 struct pci_bus_region region, inverted_region;
50193 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50194
50195 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50196 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50197
50198 /* No printks while decoding is disabled! */
50199 if (!dev->mmio_always_on) {
50200 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50201 index 3f155e7..0f4b1f0 100644
50202 --- a/drivers/pci/proc.c
50203 +++ b/drivers/pci/proc.c
50204 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50205 static int __init pci_proc_init(void)
50206 {
50207 struct pci_dev *dev = NULL;
50208 +
50209 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
50210 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50211 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50212 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50213 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50214 +#endif
50215 +#else
50216 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50217 +#endif
50218 proc_create("devices", 0, proc_bus_pci_dir,
50219 &proc_bus_pci_dev_operations);
50220 proc_initialized = 1;
50221 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50222 index d866db8..c827d1f 100644
50223 --- a/drivers/platform/chrome/chromeos_laptop.c
50224 +++ b/drivers/platform/chrome/chromeos_laptop.c
50225 @@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50226 .callback = chromeos_laptop_dmi_matched, \
50227 .driver_data = (void *)&board_
50228
50229 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50230 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50231 {
50232 .ident = "Samsung Series 5 550",
50233 .matches = {
50234 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50235 index c5af23b..3d62d5e 100644
50236 --- a/drivers/platform/x86/alienware-wmi.c
50237 +++ b/drivers/platform/x86/alienware-wmi.c
50238 @@ -150,7 +150,7 @@ struct wmax_led_args {
50239 } __packed;
50240
50241 static struct platform_device *platform_device;
50242 -static struct device_attribute *zone_dev_attrs;
50243 +static device_attribute_no_const *zone_dev_attrs;
50244 static struct attribute **zone_attrs;
50245 static struct platform_zone *zone_data;
50246
50247 @@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50248 }
50249 };
50250
50251 -static struct attribute_group zone_attribute_group = {
50252 +static attribute_group_no_const zone_attribute_group = {
50253 .name = "rgb_zones",
50254 };
50255
50256 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50257 index 21fc932..ee9394a 100644
50258 --- a/drivers/platform/x86/asus-wmi.c
50259 +++ b/drivers/platform/x86/asus-wmi.c
50260 @@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50261 int err;
50262 u32 retval = -1;
50263
50264 +#ifdef CONFIG_GRKERNSEC_KMEM
50265 + return -EPERM;
50266 +#endif
50267 +
50268 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50269
50270 if (err < 0)
50271 @@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50272 int err;
50273 u32 retval = -1;
50274
50275 +#ifdef CONFIG_GRKERNSEC_KMEM
50276 + return -EPERM;
50277 +#endif
50278 +
50279 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50280 &retval);
50281
50282 @@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50283 union acpi_object *obj;
50284 acpi_status status;
50285
50286 +#ifdef CONFIG_GRKERNSEC_KMEM
50287 + return -EPERM;
50288 +#endif
50289 +
50290 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50291 1, asus->debug.method_id,
50292 &input, &output);
50293 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50294 index 62f8030..c7f2a45 100644
50295 --- a/drivers/platform/x86/msi-laptop.c
50296 +++ b/drivers/platform/x86/msi-laptop.c
50297 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50298
50299 if (!quirks->ec_read_only) {
50300 /* allow userland write sysfs file */
50301 - dev_attr_bluetooth.store = store_bluetooth;
50302 - dev_attr_wlan.store = store_wlan;
50303 - dev_attr_threeg.store = store_threeg;
50304 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
50305 - dev_attr_wlan.attr.mode |= S_IWUSR;
50306 - dev_attr_threeg.attr.mode |= S_IWUSR;
50307 + pax_open_kernel();
50308 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50309 + *(void **)&dev_attr_wlan.store = store_wlan;
50310 + *(void **)&dev_attr_threeg.store = store_threeg;
50311 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50312 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50313 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50314 + pax_close_kernel();
50315 }
50316
50317 /* disable hardware control by fn key */
50318 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50319 index 70222f2..8c8ce66 100644
50320 --- a/drivers/platform/x86/msi-wmi.c
50321 +++ b/drivers/platform/x86/msi-wmi.c
50322 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50323 static void msi_wmi_notify(u32 value, void *context)
50324 {
50325 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50326 - static struct key_entry *key;
50327 + struct key_entry *key;
50328 union acpi_object *obj;
50329 acpi_status status;
50330
50331 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50332 index 26ad9ff..7c52909 100644
50333 --- a/drivers/platform/x86/sony-laptop.c
50334 +++ b/drivers/platform/x86/sony-laptop.c
50335 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50336 }
50337
50338 /* High speed charging function */
50339 -static struct device_attribute *hsc_handle;
50340 +static device_attribute_no_const *hsc_handle;
50341
50342 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50343 struct device_attribute *attr,
50344 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50345 }
50346
50347 /* low battery function */
50348 -static struct device_attribute *lowbatt_handle;
50349 +static device_attribute_no_const *lowbatt_handle;
50350
50351 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50352 struct device_attribute *attr,
50353 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50354 }
50355
50356 /* fan speed function */
50357 -static struct device_attribute *fan_handle, *hsf_handle;
50358 +static device_attribute_no_const *fan_handle, *hsf_handle;
50359
50360 static ssize_t sony_nc_hsfan_store(struct device *dev,
50361 struct device_attribute *attr,
50362 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50363 }
50364
50365 /* USB charge function */
50366 -static struct device_attribute *uc_handle;
50367 +static device_attribute_no_const *uc_handle;
50368
50369 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50370 struct device_attribute *attr,
50371 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50372 }
50373
50374 /* Panel ID function */
50375 -static struct device_attribute *panel_handle;
50376 +static device_attribute_no_const *panel_handle;
50377
50378 static ssize_t sony_nc_panelid_show(struct device *dev,
50379 struct device_attribute *attr, char *buffer)
50380 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50381 }
50382
50383 /* smart connect function */
50384 -static struct device_attribute *sc_handle;
50385 +static device_attribute_no_const *sc_handle;
50386
50387 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50388 struct device_attribute *attr,
50389 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50390 index cf0f893..5955997 100644
50391 --- a/drivers/platform/x86/thinkpad_acpi.c
50392 +++ b/drivers/platform/x86/thinkpad_acpi.c
50393 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50394 return 0;
50395 }
50396
50397 -void static hotkey_mask_warn_incomplete_mask(void)
50398 +static void hotkey_mask_warn_incomplete_mask(void)
50399 {
50400 /* log only what the user can fix... */
50401 const u32 wantedmask = hotkey_driver_mask &
50402 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50403 && !tp_features.bright_unkfw)
50404 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50405 }
50406 +}
50407
50408 #undef TPACPI_COMPARE_KEY
50409 #undef TPACPI_MAY_SEND_KEY
50410 -}
50411
50412 /*
50413 * Polling driver
50414 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50415 index 438d4c7..ca8a2fb 100644
50416 --- a/drivers/pnp/pnpbios/bioscalls.c
50417 +++ b/drivers/pnp/pnpbios/bioscalls.c
50418 @@ -59,7 +59,7 @@ do { \
50419 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50420 } while(0)
50421
50422 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50423 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50424 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50425
50426 /*
50427 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50428
50429 cpu = get_cpu();
50430 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50431 +
50432 + pax_open_kernel();
50433 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50434 + pax_close_kernel();
50435
50436 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50437 spin_lock_irqsave(&pnp_bios_lock, flags);
50438 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50439 :"memory");
50440 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50441
50442 + pax_open_kernel();
50443 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50444 + pax_close_kernel();
50445 +
50446 put_cpu();
50447
50448 /* If we get here and this is set then the PnP BIOS faulted on us. */
50449 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50450 return status;
50451 }
50452
50453 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
50454 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50455 {
50456 int i;
50457
50458 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50459 pnp_bios_callpoint.offset = header->fields.pm16offset;
50460 pnp_bios_callpoint.segment = PNP_CS16;
50461
50462 + pax_open_kernel();
50463 +
50464 for_each_possible_cpu(i) {
50465 struct desc_struct *gdt = get_cpu_gdt_table(i);
50466 if (!gdt)
50467 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50468 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50469 (unsigned long)__va(header->fields.pm16dseg));
50470 }
50471 +
50472 + pax_close_kernel();
50473 }
50474 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50475 index 0c52e2a..3421ab7 100644
50476 --- a/drivers/power/pda_power.c
50477 +++ b/drivers/power/pda_power.c
50478 @@ -37,7 +37,11 @@ static int polling;
50479
50480 #if IS_ENABLED(CONFIG_USB_PHY)
50481 static struct usb_phy *transceiver;
50482 -static struct notifier_block otg_nb;
50483 +static int otg_handle_notification(struct notifier_block *nb,
50484 + unsigned long event, void *unused);
50485 +static struct notifier_block otg_nb = {
50486 + .notifier_call = otg_handle_notification
50487 +};
50488 #endif
50489
50490 static struct regulator *ac_draw;
50491 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50492
50493 #if IS_ENABLED(CONFIG_USB_PHY)
50494 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50495 - otg_nb.notifier_call = otg_handle_notification;
50496 ret = usb_register_notifier(transceiver, &otg_nb);
50497 if (ret) {
50498 dev_err(dev, "failure to register otg notifier\n");
50499 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50500 index cc439fd..8fa30df 100644
50501 --- a/drivers/power/power_supply.h
50502 +++ b/drivers/power/power_supply.h
50503 @@ -16,12 +16,12 @@ struct power_supply;
50504
50505 #ifdef CONFIG_SYSFS
50506
50507 -extern void power_supply_init_attrs(struct device_type *dev_type);
50508 +extern void power_supply_init_attrs(void);
50509 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50510
50511 #else
50512
50513 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50514 +static inline void power_supply_init_attrs(void) {}
50515 #define power_supply_uevent NULL
50516
50517 #endif /* CONFIG_SYSFS */
50518 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50519 index 694e8cd..9f03483 100644
50520 --- a/drivers/power/power_supply_core.c
50521 +++ b/drivers/power/power_supply_core.c
50522 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50523 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50524 EXPORT_SYMBOL_GPL(power_supply_notifier);
50525
50526 -static struct device_type power_supply_dev_type;
50527 +extern const struct attribute_group *power_supply_attr_groups[];
50528 +static struct device_type power_supply_dev_type = {
50529 + .groups = power_supply_attr_groups,
50530 +};
50531
50532 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50533 struct power_supply *supply)
50534 @@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50535 return PTR_ERR(power_supply_class);
50536
50537 power_supply_class->dev_uevent = power_supply_uevent;
50538 - power_supply_init_attrs(&power_supply_dev_type);
50539 + power_supply_init_attrs();
50540
50541 return 0;
50542 }
50543 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50544 index 62653f5..d0bb485 100644
50545 --- a/drivers/power/power_supply_sysfs.c
50546 +++ b/drivers/power/power_supply_sysfs.c
50547 @@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50548 .is_visible = power_supply_attr_is_visible,
50549 };
50550
50551 -static const struct attribute_group *power_supply_attr_groups[] = {
50552 +const struct attribute_group *power_supply_attr_groups[] = {
50553 &power_supply_attr_group,
50554 NULL,
50555 };
50556
50557 -void power_supply_init_attrs(struct device_type *dev_type)
50558 +void power_supply_init_attrs(void)
50559 {
50560 int i;
50561
50562 - dev_type->groups = power_supply_attr_groups;
50563 -
50564 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50565 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50566 }
50567 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50568 index 84419af..268ede8 100644
50569 --- a/drivers/powercap/powercap_sys.c
50570 +++ b/drivers/powercap/powercap_sys.c
50571 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50572 struct device_attribute name_attr;
50573 };
50574
50575 +static ssize_t show_constraint_name(struct device *dev,
50576 + struct device_attribute *dev_attr,
50577 + char *buf);
50578 +
50579 static struct powercap_constraint_attr
50580 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50581 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50582 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50583 + .power_limit_attr = {
50584 + .attr = {
50585 + .name = NULL,
50586 + .mode = S_IWUSR | S_IRUGO
50587 + },
50588 + .show = show_constraint_power_limit_uw,
50589 + .store = store_constraint_power_limit_uw
50590 + },
50591 +
50592 + .time_window_attr = {
50593 + .attr = {
50594 + .name = NULL,
50595 + .mode = S_IWUSR | S_IRUGO
50596 + },
50597 + .show = show_constraint_time_window_us,
50598 + .store = store_constraint_time_window_us
50599 + },
50600 +
50601 + .max_power_attr = {
50602 + .attr = {
50603 + .name = NULL,
50604 + .mode = S_IRUGO
50605 + },
50606 + .show = show_constraint_max_power_uw,
50607 + .store = NULL
50608 + },
50609 +
50610 + .min_power_attr = {
50611 + .attr = {
50612 + .name = NULL,
50613 + .mode = S_IRUGO
50614 + },
50615 + .show = show_constraint_min_power_uw,
50616 + .store = NULL
50617 + },
50618 +
50619 + .max_time_window_attr = {
50620 + .attr = {
50621 + .name = NULL,
50622 + .mode = S_IRUGO
50623 + },
50624 + .show = show_constraint_max_time_window_us,
50625 + .store = NULL
50626 + },
50627 +
50628 + .min_time_window_attr = {
50629 + .attr = {
50630 + .name = NULL,
50631 + .mode = S_IRUGO
50632 + },
50633 + .show = show_constraint_min_time_window_us,
50634 + .store = NULL
50635 + },
50636 +
50637 + .name_attr = {
50638 + .attr = {
50639 + .name = NULL,
50640 + .mode = S_IRUGO
50641 + },
50642 + .show = show_constraint_name,
50643 + .store = NULL
50644 + }
50645 + }
50646 +};
50647
50648 /* A list of powercap control_types */
50649 static LIST_HEAD(powercap_cntrl_list);
50650 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50651 }
50652
50653 static int create_constraint_attribute(int id, const char *name,
50654 - int mode,
50655 - struct device_attribute *dev_attr,
50656 - ssize_t (*show)(struct device *,
50657 - struct device_attribute *, char *),
50658 - ssize_t (*store)(struct device *,
50659 - struct device_attribute *,
50660 - const char *, size_t)
50661 - )
50662 + struct device_attribute *dev_attr)
50663 {
50664 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50665
50666 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50667 - id, name);
50668 - if (!dev_attr->attr.name)
50669 + if (!name)
50670 return -ENOMEM;
50671 - dev_attr->attr.mode = mode;
50672 - dev_attr->show = show;
50673 - dev_attr->store = store;
50674 +
50675 + pax_open_kernel();
50676 + *(const char **)&dev_attr->attr.name = name;
50677 + pax_close_kernel();
50678
50679 return 0;
50680 }
50681 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50682
50683 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50684 ret = create_constraint_attribute(i, "power_limit_uw",
50685 - S_IWUSR | S_IRUGO,
50686 - &constraint_attrs[i].power_limit_attr,
50687 - show_constraint_power_limit_uw,
50688 - store_constraint_power_limit_uw);
50689 + &constraint_attrs[i].power_limit_attr);
50690 if (ret)
50691 goto err_alloc;
50692 ret = create_constraint_attribute(i, "time_window_us",
50693 - S_IWUSR | S_IRUGO,
50694 - &constraint_attrs[i].time_window_attr,
50695 - show_constraint_time_window_us,
50696 - store_constraint_time_window_us);
50697 + &constraint_attrs[i].time_window_attr);
50698 if (ret)
50699 goto err_alloc;
50700 - ret = create_constraint_attribute(i, "name", S_IRUGO,
50701 - &constraint_attrs[i].name_attr,
50702 - show_constraint_name,
50703 - NULL);
50704 + ret = create_constraint_attribute(i, "name",
50705 + &constraint_attrs[i].name_attr);
50706 if (ret)
50707 goto err_alloc;
50708 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50709 - &constraint_attrs[i].max_power_attr,
50710 - show_constraint_max_power_uw,
50711 - NULL);
50712 + ret = create_constraint_attribute(i, "max_power_uw",
50713 + &constraint_attrs[i].max_power_attr);
50714 if (ret)
50715 goto err_alloc;
50716 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50717 - &constraint_attrs[i].min_power_attr,
50718 - show_constraint_min_power_uw,
50719 - NULL);
50720 + ret = create_constraint_attribute(i, "min_power_uw",
50721 + &constraint_attrs[i].min_power_attr);
50722 if (ret)
50723 goto err_alloc;
50724 ret = create_constraint_attribute(i, "max_time_window_us",
50725 - S_IRUGO,
50726 - &constraint_attrs[i].max_time_window_attr,
50727 - show_constraint_max_time_window_us,
50728 - NULL);
50729 + &constraint_attrs[i].max_time_window_attr);
50730 if (ret)
50731 goto err_alloc;
50732 ret = create_constraint_attribute(i, "min_time_window_us",
50733 - S_IRUGO,
50734 - &constraint_attrs[i].min_time_window_attr,
50735 - show_constraint_min_time_window_us,
50736 - NULL);
50737 + &constraint_attrs[i].min_time_window_attr);
50738 if (ret)
50739 goto err_alloc;
50740
50741 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50742 power_zone->zone_dev_attrs[count++] =
50743 &dev_attr_max_energy_range_uj.attr;
50744 if (power_zone->ops->get_energy_uj) {
50745 + pax_open_kernel();
50746 if (power_zone->ops->reset_energy_uj)
50747 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50748 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50749 else
50750 - dev_attr_energy_uj.attr.mode = S_IRUGO;
50751 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50752 + pax_close_kernel();
50753 power_zone->zone_dev_attrs[count++] =
50754 &dev_attr_energy_uj.attr;
50755 }
50756 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50757 index 9c5d414..c7900ce 100644
50758 --- a/drivers/ptp/ptp_private.h
50759 +++ b/drivers/ptp/ptp_private.h
50760 @@ -51,7 +51,7 @@ struct ptp_clock {
50761 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50762 wait_queue_head_t tsev_wq;
50763 int defunct; /* tells readers to go away when clock is being removed */
50764 - struct device_attribute *pin_dev_attr;
50765 + device_attribute_no_const *pin_dev_attr;
50766 struct attribute **pin_attr;
50767 struct attribute_group pin_attr_group;
50768 };
50769 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50770 index 302e626..12579af 100644
50771 --- a/drivers/ptp/ptp_sysfs.c
50772 +++ b/drivers/ptp/ptp_sysfs.c
50773 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50774 goto no_pin_attr;
50775
50776 for (i = 0; i < n_pins; i++) {
50777 - struct device_attribute *da = &ptp->pin_dev_attr[i];
50778 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50779 sysfs_attr_init(&da->attr);
50780 da->attr.name = info->pin_config[i].name;
50781 da->attr.mode = 0644;
50782 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50783 index fc6fb54..b8c794ba 100644
50784 --- a/drivers/regulator/core.c
50785 +++ b/drivers/regulator/core.c
50786 @@ -3569,7 +3569,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50787 {
50788 const struct regulation_constraints *constraints = NULL;
50789 const struct regulator_init_data *init_data;
50790 - static atomic_t regulator_no = ATOMIC_INIT(0);
50791 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50792 struct regulator_dev *rdev;
50793 struct device *dev;
50794 int ret, i;
50795 @@ -3643,7 +3643,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50796 rdev->dev.class = &regulator_class;
50797 rdev->dev.parent = dev;
50798 dev_set_name(&rdev->dev, "regulator.%d",
50799 - atomic_inc_return(&regulator_no) - 1);
50800 + atomic_inc_return_unchecked(&regulator_no) - 1);
50801 ret = device_register(&rdev->dev);
50802 if (ret != 0) {
50803 put_device(&rdev->dev);
50804 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50805 index 7eee2ca..4024513 100644
50806 --- a/drivers/regulator/max8660.c
50807 +++ b/drivers/regulator/max8660.c
50808 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50809 max8660->shadow_regs[MAX8660_OVER1] = 5;
50810 } else {
50811 /* Otherwise devices can be toggled via software */
50812 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
50813 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
50814 + pax_open_kernel();
50815 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50816 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50817 + pax_close_kernel();
50818 }
50819
50820 /*
50821 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50822 index dbedf17..18ff6b7 100644
50823 --- a/drivers/regulator/max8973-regulator.c
50824 +++ b/drivers/regulator/max8973-regulator.c
50825 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50826 if (!pdata || !pdata->enable_ext_control) {
50827 max->desc.enable_reg = MAX8973_VOUT;
50828 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50829 - max->ops.enable = regulator_enable_regmap;
50830 - max->ops.disable = regulator_disable_regmap;
50831 - max->ops.is_enabled = regulator_is_enabled_regmap;
50832 + pax_open_kernel();
50833 + *(void **)&max->ops.enable = regulator_enable_regmap;
50834 + *(void **)&max->ops.disable = regulator_disable_regmap;
50835 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50836 + pax_close_kernel();
50837 }
50838
50839 if (pdata) {
50840 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50841 index 793b662..01c20fc 100644
50842 --- a/drivers/regulator/mc13892-regulator.c
50843 +++ b/drivers/regulator/mc13892-regulator.c
50844 @@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50845 mc13xxx_unlock(mc13892);
50846
50847 /* update mc13892_vcam ops */
50848 - memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50849 + pax_open_kernel();
50850 + memcpy((void *)&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50851 sizeof(struct regulator_ops));
50852 - mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50853 - mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50854 + *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50855 + *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50856 + pax_close_kernel();
50857 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50858
50859 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50860 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50861 index 5b2e761..c8c8a4a 100644
50862 --- a/drivers/rtc/rtc-cmos.c
50863 +++ b/drivers/rtc/rtc-cmos.c
50864 @@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50865 hpet_rtc_timer_init();
50866
50867 /* export at least the first block of NVRAM */
50868 - nvram.size = address_space - NVRAM_OFFSET;
50869 + pax_open_kernel();
50870 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50871 + pax_close_kernel();
50872 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50873 if (retval < 0) {
50874 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50875 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50876 index d049393..bb20be0 100644
50877 --- a/drivers/rtc/rtc-dev.c
50878 +++ b/drivers/rtc/rtc-dev.c
50879 @@ -16,6 +16,7 @@
50880 #include <linux/module.h>
50881 #include <linux/rtc.h>
50882 #include <linux/sched.h>
50883 +#include <linux/grsecurity.h>
50884 #include "rtc-core.h"
50885
50886 static dev_t rtc_devt;
50887 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50888 if (copy_from_user(&tm, uarg, sizeof(tm)))
50889 return -EFAULT;
50890
50891 + gr_log_timechange();
50892 +
50893 return rtc_set_time(rtc, &tm);
50894
50895 case RTC_PIE_ON:
50896 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50897 index bb43cf7..ee4d274 100644
50898 --- a/drivers/rtc/rtc-ds1307.c
50899 +++ b/drivers/rtc/rtc-ds1307.c
50900 @@ -107,7 +107,7 @@ struct ds1307 {
50901 u8 offset; /* register's offset */
50902 u8 regs[11];
50903 u16 nvram_offset;
50904 - struct bin_attribute *nvram;
50905 + bin_attribute_no_const *nvram;
50906 enum ds_type type;
50907 unsigned long flags;
50908 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50909 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50910 index 11880c1..b823aa4 100644
50911 --- a/drivers/rtc/rtc-m48t59.c
50912 +++ b/drivers/rtc/rtc-m48t59.c
50913 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50914 if (IS_ERR(m48t59->rtc))
50915 return PTR_ERR(m48t59->rtc);
50916
50917 - m48t59_nvram_attr.size = pdata->offset;
50918 + pax_open_kernel();
50919 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50920 + pax_close_kernel();
50921
50922 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50923 if (ret)
50924 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50925 index e693af6..2e525b6 100644
50926 --- a/drivers/scsi/bfa/bfa_fcpim.h
50927 +++ b/drivers/scsi/bfa/bfa_fcpim.h
50928 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
50929
50930 struct bfa_itn_s {
50931 bfa_isr_func_t isr;
50932 -};
50933 +} __no_const;
50934
50935 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50936 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50937 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50938 index 0f19455..ef7adb5 100644
50939 --- a/drivers/scsi/bfa/bfa_fcs.c
50940 +++ b/drivers/scsi/bfa/bfa_fcs.c
50941 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50942 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50943
50944 static struct bfa_fcs_mod_s fcs_modules[] = {
50945 - { bfa_fcs_port_attach, NULL, NULL },
50946 - { bfa_fcs_uf_attach, NULL, NULL },
50947 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50948 - bfa_fcs_fabric_modexit },
50949 + {
50950 + .attach = bfa_fcs_port_attach,
50951 + .modinit = NULL,
50952 + .modexit = NULL
50953 + },
50954 + {
50955 + .attach = bfa_fcs_uf_attach,
50956 + .modinit = NULL,
50957 + .modexit = NULL
50958 + },
50959 + {
50960 + .attach = bfa_fcs_fabric_attach,
50961 + .modinit = bfa_fcs_fabric_modinit,
50962 + .modexit = bfa_fcs_fabric_modexit
50963 + },
50964 };
50965
50966 /*
50967 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50968 index ff75ef8..2dfe00a 100644
50969 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
50970 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50971 @@ -89,15 +89,26 @@ static struct {
50972 void (*offline) (struct bfa_fcs_lport_s *port);
50973 } __port_action[] = {
50974 {
50975 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50976 - bfa_fcs_lport_unknown_offline}, {
50977 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50978 - bfa_fcs_lport_fab_offline}, {
50979 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50980 - bfa_fcs_lport_n2n_offline}, {
50981 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50982 - bfa_fcs_lport_loop_offline},
50983 - };
50984 + .init = bfa_fcs_lport_unknown_init,
50985 + .online = bfa_fcs_lport_unknown_online,
50986 + .offline = bfa_fcs_lport_unknown_offline
50987 + },
50988 + {
50989 + .init = bfa_fcs_lport_fab_init,
50990 + .online = bfa_fcs_lport_fab_online,
50991 + .offline = bfa_fcs_lport_fab_offline
50992 + },
50993 + {
50994 + .init = bfa_fcs_lport_n2n_init,
50995 + .online = bfa_fcs_lport_n2n_online,
50996 + .offline = bfa_fcs_lport_n2n_offline
50997 + },
50998 + {
50999 + .init = bfa_fcs_lport_loop_init,
51000 + .online = bfa_fcs_lport_loop_online,
51001 + .offline = bfa_fcs_lport_loop_offline
51002 + },
51003 +};
51004
51005 /*
51006 * fcs_port_sm FCS logical port state machine
51007 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51008 index a38aafa0..fe8f03b 100644
51009 --- a/drivers/scsi/bfa/bfa_ioc.h
51010 +++ b/drivers/scsi/bfa/bfa_ioc.h
51011 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51012 bfa_ioc_disable_cbfn_t disable_cbfn;
51013 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51014 bfa_ioc_reset_cbfn_t reset_cbfn;
51015 -};
51016 +} __no_const;
51017
51018 /*
51019 * IOC event notification mechanism.
51020 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51021 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51022 enum bfi_ioc_state fwstate);
51023 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51024 -};
51025 +} __no_const;
51026
51027 /*
51028 * Queue element to wait for room in request queue. FIFO order is
51029 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51030 index a14c784..6de6790 100644
51031 --- a/drivers/scsi/bfa/bfa_modules.h
51032 +++ b/drivers/scsi/bfa/bfa_modules.h
51033 @@ -78,12 +78,12 @@ enum {
51034 \
51035 extern struct bfa_module_s hal_mod_ ## __mod; \
51036 struct bfa_module_s hal_mod_ ## __mod = { \
51037 - bfa_ ## __mod ## _meminfo, \
51038 - bfa_ ## __mod ## _attach, \
51039 - bfa_ ## __mod ## _detach, \
51040 - bfa_ ## __mod ## _start, \
51041 - bfa_ ## __mod ## _stop, \
51042 - bfa_ ## __mod ## _iocdisable, \
51043 + .meminfo = bfa_ ## __mod ## _meminfo, \
51044 + .attach = bfa_ ## __mod ## _attach, \
51045 + .detach = bfa_ ## __mod ## _detach, \
51046 + .start = bfa_ ## __mod ## _start, \
51047 + .stop = bfa_ ## __mod ## _stop, \
51048 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
51049 }
51050
51051 #define BFA_CACHELINE_SZ (256)
51052 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51053 index 045c4e1..13de803 100644
51054 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
51055 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51056 @@ -33,8 +33,8 @@
51057 */
51058 #include "libfcoe.h"
51059
51060 -static atomic_t ctlr_num;
51061 -static atomic_t fcf_num;
51062 +static atomic_unchecked_t ctlr_num;
51063 +static atomic_unchecked_t fcf_num;
51064
51065 /*
51066 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51067 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51068 if (!ctlr)
51069 goto out;
51070
51071 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51072 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51073 ctlr->f = f;
51074 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51075 INIT_LIST_HEAD(&ctlr->fcfs);
51076 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51077 fcf->dev.parent = &ctlr->dev;
51078 fcf->dev.bus = &fcoe_bus_type;
51079 fcf->dev.type = &fcoe_fcf_device_type;
51080 - fcf->id = atomic_inc_return(&fcf_num) - 1;
51081 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51082 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51083
51084 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51085 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51086 {
51087 int error;
51088
51089 - atomic_set(&ctlr_num, 0);
51090 - atomic_set(&fcf_num, 0);
51091 + atomic_set_unchecked(&ctlr_num, 0);
51092 + atomic_set_unchecked(&fcf_num, 0);
51093
51094 error = bus_register(&fcoe_bus_type);
51095 if (error)
51096 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51097 index 6de80e3..a11e0ac 100644
51098 --- a/drivers/scsi/hosts.c
51099 +++ b/drivers/scsi/hosts.c
51100 @@ -42,7 +42,7 @@
51101 #include "scsi_logging.h"
51102
51103
51104 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51105 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51106
51107
51108 static void scsi_host_cls_release(struct device *dev)
51109 @@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51110 * subtract one because we increment first then return, but we need to
51111 * know what the next host number was before increment
51112 */
51113 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51114 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51115 shost->dma_channel = 0xff;
51116
51117 /* These three are default values which can be overridden */
51118 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51119 index cef5d49..01e280e 100644
51120 --- a/drivers/scsi/hpsa.c
51121 +++ b/drivers/scsi/hpsa.c
51122 @@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51123 unsigned long flags;
51124
51125 if (h->transMethod & CFGTBL_Trans_io_accel1)
51126 - return h->access.command_completed(h, q);
51127 + return h->access->command_completed(h, q);
51128
51129 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51130 - return h->access.command_completed(h, q);
51131 + return h->access->command_completed(h, q);
51132
51133 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51134 a = rq->head[rq->current_entry];
51135 @@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51136 while (!list_empty(&h->reqQ)) {
51137 c = list_entry(h->reqQ.next, struct CommandList, list);
51138 /* can't do anything if fifo is full */
51139 - if ((h->access.fifo_full(h))) {
51140 + if ((h->access->fifo_full(h))) {
51141 h->fifo_recently_full = 1;
51142 dev_warn(&h->pdev->dev, "fifo full\n");
51143 break;
51144 @@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51145
51146 /* Tell the controller execute command */
51147 spin_unlock_irqrestore(&h->lock, *flags);
51148 - h->access.submit_command(h, c);
51149 + h->access->submit_command(h, c);
51150 spin_lock_irqsave(&h->lock, *flags);
51151 }
51152 }
51153 @@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51154
51155 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51156 {
51157 - return h->access.command_completed(h, q);
51158 + return h->access->command_completed(h, q);
51159 }
51160
51161 static inline bool interrupt_pending(struct ctlr_info *h)
51162 {
51163 - return h->access.intr_pending(h);
51164 + return h->access->intr_pending(h);
51165 }
51166
51167 static inline long interrupt_not_for_us(struct ctlr_info *h)
51168 {
51169 - return (h->access.intr_pending(h) == 0) ||
51170 + return (h->access->intr_pending(h) == 0) ||
51171 (h->interrupts_enabled == 0);
51172 }
51173
51174 @@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51175 if (prod_index < 0)
51176 return -ENODEV;
51177 h->product_name = products[prod_index].product_name;
51178 - h->access = *(products[prod_index].access);
51179 + h->access = products[prod_index].access;
51180
51181 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51182 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51183 @@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51184 unsigned long flags;
51185 u32 lockup_detected;
51186
51187 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51188 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51189 spin_lock_irqsave(&h->lock, flags);
51190 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51191 if (!lockup_detected) {
51192 @@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51193 }
51194
51195 /* make sure the board interrupts are off */
51196 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51197 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51198
51199 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51200 goto clean2;
51201 @@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51202 * fake ones to scoop up any residual completions.
51203 */
51204 spin_lock_irqsave(&h->lock, flags);
51205 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51206 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51207 spin_unlock_irqrestore(&h->lock, flags);
51208 free_irqs(h);
51209 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51210 @@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51211 dev_info(&h->pdev->dev, "Board READY.\n");
51212 dev_info(&h->pdev->dev,
51213 "Waiting for stale completions to drain.\n");
51214 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51215 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51216 msleep(10000);
51217 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51218 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51219
51220 rc = controller_reset_failed(h->cfgtable);
51221 if (rc)
51222 @@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51223 h->drv_req_rescan = 0;
51224
51225 /* Turn the interrupts on so we can service requests */
51226 - h->access.set_intr_mask(h, HPSA_INTR_ON);
51227 + h->access->set_intr_mask(h, HPSA_INTR_ON);
51228
51229 hpsa_hba_inquiry(h);
51230 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51231 @@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51232 * To write all data in the battery backed cache to disks
51233 */
51234 hpsa_flush_cache(h);
51235 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
51236 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
51237 hpsa_free_irqs_and_disable_msix(h);
51238 }
51239
51240 @@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51241 CFGTBL_Trans_enable_directed_msix |
51242 (trans_support & (CFGTBL_Trans_io_accel1 |
51243 CFGTBL_Trans_io_accel2));
51244 - struct access_method access = SA5_performant_access;
51245 + struct access_method *access = &SA5_performant_access;
51246
51247 /* This is a bit complicated. There are 8 registers on
51248 * the controller which we write to to tell it 8 different
51249 @@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51250 * perform the superfluous readl() after each command submission.
51251 */
51252 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51253 - access = SA5_performant_access_no_read;
51254 + access = &SA5_performant_access_no_read;
51255
51256 /* Controller spec: zero out this buffer. */
51257 for (i = 0; i < h->nreply_queues; i++)
51258 @@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51259 * enable outbound interrupt coalescing in accelerator mode;
51260 */
51261 if (trans_support & CFGTBL_Trans_io_accel1) {
51262 - access = SA5_ioaccel_mode1_access;
51263 + access = &SA5_ioaccel_mode1_access;
51264 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51265 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51266 } else {
51267 if (trans_support & CFGTBL_Trans_io_accel2) {
51268 - access = SA5_ioaccel_mode2_access;
51269 + access = &SA5_ioaccel_mode2_access;
51270 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51271 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51272 }
51273 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51274 index 24472ce..8782caf 100644
51275 --- a/drivers/scsi/hpsa.h
51276 +++ b/drivers/scsi/hpsa.h
51277 @@ -127,7 +127,7 @@ struct ctlr_info {
51278 unsigned int msix_vector;
51279 unsigned int msi_vector;
51280 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51281 - struct access_method access;
51282 + struct access_method *access;
51283 char hba_mode_enabled;
51284
51285 /* queue and queue Info */
51286 @@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51287 }
51288
51289 static struct access_method SA5_access = {
51290 - SA5_submit_command,
51291 - SA5_intr_mask,
51292 - SA5_fifo_full,
51293 - SA5_intr_pending,
51294 - SA5_completed,
51295 + .submit_command = SA5_submit_command,
51296 + .set_intr_mask = SA5_intr_mask,
51297 + .fifo_full = SA5_fifo_full,
51298 + .intr_pending = SA5_intr_pending,
51299 + .command_completed = SA5_completed,
51300 };
51301
51302 static struct access_method SA5_ioaccel_mode1_access = {
51303 - SA5_submit_command,
51304 - SA5_performant_intr_mask,
51305 - SA5_fifo_full,
51306 - SA5_ioaccel_mode1_intr_pending,
51307 - SA5_ioaccel_mode1_completed,
51308 + .submit_command = SA5_submit_command,
51309 + .set_intr_mask = SA5_performant_intr_mask,
51310 + .fifo_full = SA5_fifo_full,
51311 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
51312 + .command_completed = SA5_ioaccel_mode1_completed,
51313 };
51314
51315 static struct access_method SA5_ioaccel_mode2_access = {
51316 - SA5_submit_command_ioaccel2,
51317 - SA5_performant_intr_mask,
51318 - SA5_fifo_full,
51319 - SA5_performant_intr_pending,
51320 - SA5_performant_completed,
51321 + .submit_command = SA5_submit_command_ioaccel2,
51322 + .set_intr_mask = SA5_performant_intr_mask,
51323 + .fifo_full = SA5_fifo_full,
51324 + .intr_pending = SA5_performant_intr_pending,
51325 + .command_completed = SA5_performant_completed,
51326 };
51327
51328 static struct access_method SA5_performant_access = {
51329 - SA5_submit_command,
51330 - SA5_performant_intr_mask,
51331 - SA5_fifo_full,
51332 - SA5_performant_intr_pending,
51333 - SA5_performant_completed,
51334 + .submit_command = SA5_submit_command,
51335 + .set_intr_mask = SA5_performant_intr_mask,
51336 + .fifo_full = SA5_fifo_full,
51337 + .intr_pending = SA5_performant_intr_pending,
51338 + .command_completed = SA5_performant_completed,
51339 };
51340
51341 static struct access_method SA5_performant_access_no_read = {
51342 - SA5_submit_command_no_read,
51343 - SA5_performant_intr_mask,
51344 - SA5_fifo_full,
51345 - SA5_performant_intr_pending,
51346 - SA5_performant_completed,
51347 + .submit_command = SA5_submit_command_no_read,
51348 + .set_intr_mask = SA5_performant_intr_mask,
51349 + .fifo_full = SA5_fifo_full,
51350 + .intr_pending = SA5_performant_intr_pending,
51351 + .command_completed = SA5_performant_completed,
51352 };
51353
51354 struct board_type {
51355 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51356 index 1b3a094..068e683 100644
51357 --- a/drivers/scsi/libfc/fc_exch.c
51358 +++ b/drivers/scsi/libfc/fc_exch.c
51359 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
51360 u16 pool_max_index;
51361
51362 struct {
51363 - atomic_t no_free_exch;
51364 - atomic_t no_free_exch_xid;
51365 - atomic_t xid_not_found;
51366 - atomic_t xid_busy;
51367 - atomic_t seq_not_found;
51368 - atomic_t non_bls_resp;
51369 + atomic_unchecked_t no_free_exch;
51370 + atomic_unchecked_t no_free_exch_xid;
51371 + atomic_unchecked_t xid_not_found;
51372 + atomic_unchecked_t xid_busy;
51373 + atomic_unchecked_t seq_not_found;
51374 + atomic_unchecked_t non_bls_resp;
51375 } stats;
51376 };
51377
51378 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51379 /* allocate memory for exchange */
51380 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51381 if (!ep) {
51382 - atomic_inc(&mp->stats.no_free_exch);
51383 + atomic_inc_unchecked(&mp->stats.no_free_exch);
51384 goto out;
51385 }
51386 memset(ep, 0, sizeof(*ep));
51387 @@ -874,7 +874,7 @@ out:
51388 return ep;
51389 err:
51390 spin_unlock_bh(&pool->lock);
51391 - atomic_inc(&mp->stats.no_free_exch_xid);
51392 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51393 mempool_free(ep, mp->ep_pool);
51394 return NULL;
51395 }
51396 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51397 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51398 ep = fc_exch_find(mp, xid);
51399 if (!ep) {
51400 - atomic_inc(&mp->stats.xid_not_found);
51401 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51402 reject = FC_RJT_OX_ID;
51403 goto out;
51404 }
51405 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51406 ep = fc_exch_find(mp, xid);
51407 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51408 if (ep) {
51409 - atomic_inc(&mp->stats.xid_busy);
51410 + atomic_inc_unchecked(&mp->stats.xid_busy);
51411 reject = FC_RJT_RX_ID;
51412 goto rel;
51413 }
51414 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51415 }
51416 xid = ep->xid; /* get our XID */
51417 } else if (!ep) {
51418 - atomic_inc(&mp->stats.xid_not_found);
51419 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51420 reject = FC_RJT_RX_ID; /* XID not found */
51421 goto out;
51422 }
51423 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51424 } else {
51425 sp = &ep->seq;
51426 if (sp->id != fh->fh_seq_id) {
51427 - atomic_inc(&mp->stats.seq_not_found);
51428 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51429 if (f_ctl & FC_FC_END_SEQ) {
51430 /*
51431 * Update sequence_id based on incoming last
51432 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51433
51434 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51435 if (!ep) {
51436 - atomic_inc(&mp->stats.xid_not_found);
51437 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51438 goto out;
51439 }
51440 if (ep->esb_stat & ESB_ST_COMPLETE) {
51441 - atomic_inc(&mp->stats.xid_not_found);
51442 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51443 goto rel;
51444 }
51445 if (ep->rxid == FC_XID_UNKNOWN)
51446 ep->rxid = ntohs(fh->fh_rx_id);
51447 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51448 - atomic_inc(&mp->stats.xid_not_found);
51449 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51450 goto rel;
51451 }
51452 if (ep->did != ntoh24(fh->fh_s_id) &&
51453 ep->did != FC_FID_FLOGI) {
51454 - atomic_inc(&mp->stats.xid_not_found);
51455 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51456 goto rel;
51457 }
51458 sof = fr_sof(fp);
51459 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51460 sp->ssb_stat |= SSB_ST_RESP;
51461 sp->id = fh->fh_seq_id;
51462 } else if (sp->id != fh->fh_seq_id) {
51463 - atomic_inc(&mp->stats.seq_not_found);
51464 + atomic_inc_unchecked(&mp->stats.seq_not_found);
51465 goto rel;
51466 }
51467
51468 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51469 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51470
51471 if (!sp)
51472 - atomic_inc(&mp->stats.xid_not_found);
51473 + atomic_inc_unchecked(&mp->stats.xid_not_found);
51474 else
51475 - atomic_inc(&mp->stats.non_bls_resp);
51476 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
51477
51478 fc_frame_free(fp);
51479 }
51480 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51481
51482 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51483 mp = ema->mp;
51484 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51485 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51486 st->fc_no_free_exch_xid +=
51487 - atomic_read(&mp->stats.no_free_exch_xid);
51488 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51489 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51490 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51491 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51492 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51493 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51494 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51495 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51496 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51497 }
51498 }
51499 EXPORT_SYMBOL(fc_exch_update_stats);
51500 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51501 index 766098a..1c6c971 100644
51502 --- a/drivers/scsi/libsas/sas_ata.c
51503 +++ b/drivers/scsi/libsas/sas_ata.c
51504 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51505 .postreset = ata_std_postreset,
51506 .error_handler = ata_std_error_handler,
51507 .post_internal_cmd = sas_ata_post_internal,
51508 - .qc_defer = ata_std_qc_defer,
51509 + .qc_defer = ata_std_qc_defer,
51510 .qc_prep = ata_noop_qc_prep,
51511 .qc_issue = sas_ata_qc_issue,
51512 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51513 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51514 index 434e903..5a4a79b 100644
51515 --- a/drivers/scsi/lpfc/lpfc.h
51516 +++ b/drivers/scsi/lpfc/lpfc.h
51517 @@ -430,7 +430,7 @@ struct lpfc_vport {
51518 struct dentry *debug_nodelist;
51519 struct dentry *vport_debugfs_root;
51520 struct lpfc_debugfs_trc *disc_trc;
51521 - atomic_t disc_trc_cnt;
51522 + atomic_unchecked_t disc_trc_cnt;
51523 #endif
51524 uint8_t stat_data_enabled;
51525 uint8_t stat_data_blocked;
51526 @@ -880,8 +880,8 @@ struct lpfc_hba {
51527 struct timer_list fabric_block_timer;
51528 unsigned long bit_flags;
51529 #define FABRIC_COMANDS_BLOCKED 0
51530 - atomic_t num_rsrc_err;
51531 - atomic_t num_cmd_success;
51532 + atomic_unchecked_t num_rsrc_err;
51533 + atomic_unchecked_t num_cmd_success;
51534 unsigned long last_rsrc_error_time;
51535 unsigned long last_ramp_down_time;
51536 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51537 @@ -916,7 +916,7 @@ struct lpfc_hba {
51538
51539 struct dentry *debug_slow_ring_trc;
51540 struct lpfc_debugfs_trc *slow_ring_trc;
51541 - atomic_t slow_ring_trc_cnt;
51542 + atomic_unchecked_t slow_ring_trc_cnt;
51543 /* iDiag debugfs sub-directory */
51544 struct dentry *idiag_root;
51545 struct dentry *idiag_pci_cfg;
51546 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51547 index 786a2af..562c6a2 100644
51548 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
51549 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51550 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51551
51552 #include <linux/debugfs.h>
51553
51554 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51555 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51556 static unsigned long lpfc_debugfs_start_time = 0L;
51557
51558 /* iDiag */
51559 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51560 lpfc_debugfs_enable = 0;
51561
51562 len = 0;
51563 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51564 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51565 (lpfc_debugfs_max_disc_trc - 1);
51566 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51567 dtp = vport->disc_trc + i;
51568 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51569 lpfc_debugfs_enable = 0;
51570
51571 len = 0;
51572 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51573 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51574 (lpfc_debugfs_max_slow_ring_trc - 1);
51575 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51576 dtp = phba->slow_ring_trc + i;
51577 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51578 !vport || !vport->disc_trc)
51579 return;
51580
51581 - index = atomic_inc_return(&vport->disc_trc_cnt) &
51582 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51583 (lpfc_debugfs_max_disc_trc - 1);
51584 dtp = vport->disc_trc + index;
51585 dtp->fmt = fmt;
51586 dtp->data1 = data1;
51587 dtp->data2 = data2;
51588 dtp->data3 = data3;
51589 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51590 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51591 dtp->jif = jiffies;
51592 #endif
51593 return;
51594 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51595 !phba || !phba->slow_ring_trc)
51596 return;
51597
51598 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51599 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51600 (lpfc_debugfs_max_slow_ring_trc - 1);
51601 dtp = phba->slow_ring_trc + index;
51602 dtp->fmt = fmt;
51603 dtp->data1 = data1;
51604 dtp->data2 = data2;
51605 dtp->data3 = data3;
51606 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51607 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51608 dtp->jif = jiffies;
51609 #endif
51610 return;
51611 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51612 "slow_ring buffer\n");
51613 goto debug_failed;
51614 }
51615 - atomic_set(&phba->slow_ring_trc_cnt, 0);
51616 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51617 memset(phba->slow_ring_trc, 0,
51618 (sizeof(struct lpfc_debugfs_trc) *
51619 lpfc_debugfs_max_slow_ring_trc));
51620 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51621 "buffer\n");
51622 goto debug_failed;
51623 }
51624 - atomic_set(&vport->disc_trc_cnt, 0);
51625 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51626
51627 snprintf(name, sizeof(name), "discovery_trace");
51628 vport->debug_disc_trc =
51629 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51630 index 0b2c53a..aec2b45 100644
51631 --- a/drivers/scsi/lpfc/lpfc_init.c
51632 +++ b/drivers/scsi/lpfc/lpfc_init.c
51633 @@ -11290,8 +11290,10 @@ lpfc_init(void)
51634 "misc_register returned with status %d", error);
51635
51636 if (lpfc_enable_npiv) {
51637 - lpfc_transport_functions.vport_create = lpfc_vport_create;
51638 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51639 + pax_open_kernel();
51640 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51641 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51642 + pax_close_kernel();
51643 }
51644 lpfc_transport_template =
51645 fc_attach_transport(&lpfc_transport_functions);
51646 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51647 index b99399f..d29dc75 100644
51648 --- a/drivers/scsi/lpfc/lpfc_scsi.c
51649 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
51650 @@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51651 unsigned long expires;
51652
51653 spin_lock_irqsave(&phba->hbalock, flags);
51654 - atomic_inc(&phba->num_rsrc_err);
51655 + atomic_inc_unchecked(&phba->num_rsrc_err);
51656 phba->last_rsrc_error_time = jiffies;
51657
51658 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51659 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51660 unsigned long num_rsrc_err, num_cmd_success;
51661 int i;
51662
51663 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51664 - num_cmd_success = atomic_read(&phba->num_cmd_success);
51665 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51666 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51667
51668 /*
51669 * The error and success command counters are global per
51670 @@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51671 }
51672 }
51673 lpfc_destroy_vport_work_array(phba, vports);
51674 - atomic_set(&phba->num_rsrc_err, 0);
51675 - atomic_set(&phba->num_cmd_success, 0);
51676 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
51677 + atomic_set_unchecked(&phba->num_cmd_success, 0);
51678 }
51679
51680 /**
51681 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51682 index c80ed04..e674f01 100644
51683 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51684 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51685 @@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51686 {
51687 struct scsi_device *sdev = to_scsi_device(dev);
51688 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51689 - static struct _raid_device *raid_device;
51690 + struct _raid_device *raid_device;
51691 unsigned long flags;
51692 Mpi2RaidVolPage0_t vol_pg0;
51693 Mpi2ConfigReply_t mpi_reply;
51694 @@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51695 {
51696 struct scsi_device *sdev = to_scsi_device(dev);
51697 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51698 - static struct _raid_device *raid_device;
51699 + struct _raid_device *raid_device;
51700 unsigned long flags;
51701 Mpi2RaidVolPage0_t vol_pg0;
51702 Mpi2ConfigReply_t mpi_reply;
51703 @@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51704 Mpi2EventDataIrOperationStatus_t *event_data =
51705 (Mpi2EventDataIrOperationStatus_t *)
51706 fw_event->event_data;
51707 - static struct _raid_device *raid_device;
51708 + struct _raid_device *raid_device;
51709 unsigned long flags;
51710 u16 handle;
51711
51712 @@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51713 u64 sas_address;
51714 struct _sas_device *sas_device;
51715 struct _sas_node *expander_device;
51716 - static struct _raid_device *raid_device;
51717 + struct _raid_device *raid_device;
51718 u8 retry_count;
51719 unsigned long flags;
51720
51721 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51722 index bcb64eb..f08cf71 100644
51723 --- a/drivers/scsi/pmcraid.c
51724 +++ b/drivers/scsi/pmcraid.c
51725 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51726 res->scsi_dev = scsi_dev;
51727 scsi_dev->hostdata = res;
51728 res->change_detected = 0;
51729 - atomic_set(&res->read_failures, 0);
51730 - atomic_set(&res->write_failures, 0);
51731 + atomic_set_unchecked(&res->read_failures, 0);
51732 + atomic_set_unchecked(&res->write_failures, 0);
51733 rc = 0;
51734 }
51735 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51736 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51737
51738 /* If this was a SCSI read/write command keep count of errors */
51739 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51740 - atomic_inc(&res->read_failures);
51741 + atomic_inc_unchecked(&res->read_failures);
51742 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51743 - atomic_inc(&res->write_failures);
51744 + atomic_inc_unchecked(&res->write_failures);
51745
51746 if (!RES_IS_GSCSI(res->cfg_entry) &&
51747 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51748 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51749 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51750 * hrrq_id assigned here in queuecommand
51751 */
51752 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51753 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51754 pinstance->num_hrrq;
51755 cmd->cmd_done = pmcraid_io_done;
51756
51757 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51758 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51759 * hrrq_id assigned here in queuecommand
51760 */
51761 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51762 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51763 pinstance->num_hrrq;
51764
51765 if (request_size) {
51766 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51767
51768 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51769 /* add resources only after host is added into system */
51770 - if (!atomic_read(&pinstance->expose_resources))
51771 + if (!atomic_read_unchecked(&pinstance->expose_resources))
51772 return;
51773
51774 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51775 @@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51776 init_waitqueue_head(&pinstance->reset_wait_q);
51777
51778 atomic_set(&pinstance->outstanding_cmds, 0);
51779 - atomic_set(&pinstance->last_message_id, 0);
51780 - atomic_set(&pinstance->expose_resources, 0);
51781 + atomic_set_unchecked(&pinstance->last_message_id, 0);
51782 + atomic_set_unchecked(&pinstance->expose_resources, 0);
51783
51784 INIT_LIST_HEAD(&pinstance->free_res_q);
51785 INIT_LIST_HEAD(&pinstance->used_res_q);
51786 @@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51787 /* Schedule worker thread to handle CCN and take care of adding and
51788 * removing devices to OS
51789 */
51790 - atomic_set(&pinstance->expose_resources, 1);
51791 + atomic_set_unchecked(&pinstance->expose_resources, 1);
51792 schedule_work(&pinstance->worker_q);
51793 return rc;
51794
51795 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51796 index e1d150f..6c6df44 100644
51797 --- a/drivers/scsi/pmcraid.h
51798 +++ b/drivers/scsi/pmcraid.h
51799 @@ -748,7 +748,7 @@ struct pmcraid_instance {
51800 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51801
51802 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51803 - atomic_t last_message_id;
51804 + atomic_unchecked_t last_message_id;
51805
51806 /* configuration table */
51807 struct pmcraid_config_table *cfg_table;
51808 @@ -777,7 +777,7 @@ struct pmcraid_instance {
51809 atomic_t outstanding_cmds;
51810
51811 /* should add/delete resources to mid-layer now ?*/
51812 - atomic_t expose_resources;
51813 + atomic_unchecked_t expose_resources;
51814
51815
51816
51817 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51818 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51819 };
51820 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51821 - atomic_t read_failures; /* count of failed READ commands */
51822 - atomic_t write_failures; /* count of failed WRITE commands */
51823 + atomic_unchecked_t read_failures; /* count of failed READ commands */
51824 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51825
51826 /* To indicate add/delete/modify during CCN */
51827 u8 change_detected;
51828 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51829 index 82b92c4..3178171 100644
51830 --- a/drivers/scsi/qla2xxx/qla_attr.c
51831 +++ b/drivers/scsi/qla2xxx/qla_attr.c
51832 @@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51833 return 0;
51834 }
51835
51836 -struct fc_function_template qla2xxx_transport_functions = {
51837 +fc_function_template_no_const qla2xxx_transport_functions = {
51838
51839 .show_host_node_name = 1,
51840 .show_host_port_name = 1,
51841 @@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51842 .bsg_timeout = qla24xx_bsg_timeout,
51843 };
51844
51845 -struct fc_function_template qla2xxx_transport_vport_functions = {
51846 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
51847
51848 .show_host_node_name = 1,
51849 .show_host_port_name = 1,
51850 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51851 index b1865a7..a7723d3 100644
51852 --- a/drivers/scsi/qla2xxx/qla_gbl.h
51853 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
51854 @@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51855 struct device_attribute;
51856 extern struct device_attribute *qla2x00_host_attrs[];
51857 struct fc_function_template;
51858 -extern struct fc_function_template qla2xxx_transport_functions;
51859 -extern struct fc_function_template qla2xxx_transport_vport_functions;
51860 +extern fc_function_template_no_const qla2xxx_transport_functions;
51861 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51862 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51863 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51864 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51865 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51866 index db3dbd9..2492392 100644
51867 --- a/drivers/scsi/qla2xxx/qla_os.c
51868 +++ b/drivers/scsi/qla2xxx/qla_os.c
51869 @@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51870 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51871 /* Ok, a 64bit DMA mask is applicable. */
51872 ha->flags.enable_64bit_addressing = 1;
51873 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51874 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51875 + pax_open_kernel();
51876 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51877 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51878 + pax_close_kernel();
51879 return;
51880 }
51881 }
51882 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51883 index 8f6d0fb..1b21097 100644
51884 --- a/drivers/scsi/qla4xxx/ql4_def.h
51885 +++ b/drivers/scsi/qla4xxx/ql4_def.h
51886 @@ -305,7 +305,7 @@ struct ddb_entry {
51887 * (4000 only) */
51888 atomic_t relogin_timer; /* Max Time to wait for
51889 * relogin to complete */
51890 - atomic_t relogin_retry_count; /* Num of times relogin has been
51891 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51892 * retried */
51893 uint32_t default_time2wait; /* Default Min time between
51894 * relogins (+aens) */
51895 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51896 index 199fcf7..3c3a918 100644
51897 --- a/drivers/scsi/qla4xxx/ql4_os.c
51898 +++ b/drivers/scsi/qla4xxx/ql4_os.c
51899 @@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51900 */
51901 if (!iscsi_is_session_online(cls_sess)) {
51902 /* Reset retry relogin timer */
51903 - atomic_inc(&ddb_entry->relogin_retry_count);
51904 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51905 DEBUG2(ql4_printk(KERN_INFO, ha,
51906 "%s: index[%d] relogin timed out-retrying"
51907 " relogin (%d), retry (%d)\n", __func__,
51908 ddb_entry->fw_ddb_index,
51909 - atomic_read(&ddb_entry->relogin_retry_count),
51910 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51911 ddb_entry->default_time2wait + 4));
51912 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51913 atomic_set(&ddb_entry->retry_relogin_timer,
51914 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51915
51916 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51917 atomic_set(&ddb_entry->relogin_timer, 0);
51918 - atomic_set(&ddb_entry->relogin_retry_count, 0);
51919 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51920 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51921 ddb_entry->default_relogin_timeout =
51922 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51923 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51924 index 79c77b4..ef6ec0b 100644
51925 --- a/drivers/scsi/scsi.c
51926 +++ b/drivers/scsi/scsi.c
51927 @@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51928 struct Scsi_Host *host = cmd->device->host;
51929 int rtn = 0;
51930
51931 - atomic_inc(&cmd->device->iorequest_cnt);
51932 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51933
51934 /* check if the device is still usable */
51935 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51936 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51937 index 17fb051..937fbbd 100644
51938 --- a/drivers/scsi/scsi_lib.c
51939 +++ b/drivers/scsi/scsi_lib.c
51940 @@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51941 shost = sdev->host;
51942 scsi_init_cmd_errh(cmd);
51943 cmd->result = DID_NO_CONNECT << 16;
51944 - atomic_inc(&cmd->device->iorequest_cnt);
51945 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51946
51947 /*
51948 * SCSI request completion path will do scsi_device_unbusy(),
51949 @@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51950
51951 INIT_LIST_HEAD(&cmd->eh_entry);
51952
51953 - atomic_inc(&cmd->device->iodone_cnt);
51954 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
51955 if (cmd->result)
51956 - atomic_inc(&cmd->device->ioerr_cnt);
51957 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51958
51959 disposition = scsi_decide_disposition(cmd);
51960 if (disposition != SUCCESS &&
51961 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51962 index f4cb7b3..dfa79c4 100644
51963 --- a/drivers/scsi/scsi_sysfs.c
51964 +++ b/drivers/scsi/scsi_sysfs.c
51965 @@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51966 char *buf) \
51967 { \
51968 struct scsi_device *sdev = to_scsi_device(dev); \
51969 - unsigned long long count = atomic_read(&sdev->field); \
51970 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
51971 return snprintf(buf, 20, "0x%llx\n", count); \
51972 } \
51973 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51974 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51975 index 5d6f348..18778a6b 100644
51976 --- a/drivers/scsi/scsi_transport_fc.c
51977 +++ b/drivers/scsi/scsi_transport_fc.c
51978 @@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51979 * Netlink Infrastructure
51980 */
51981
51982 -static atomic_t fc_event_seq;
51983 +static atomic_unchecked_t fc_event_seq;
51984
51985 /**
51986 * fc_get_event_number - Obtain the next sequential FC event number
51987 @@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51988 u32
51989 fc_get_event_number(void)
51990 {
51991 - return atomic_add_return(1, &fc_event_seq);
51992 + return atomic_add_return_unchecked(1, &fc_event_seq);
51993 }
51994 EXPORT_SYMBOL(fc_get_event_number);
51995
51996 @@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51997 {
51998 int error;
51999
52000 - atomic_set(&fc_event_seq, 0);
52001 + atomic_set_unchecked(&fc_event_seq, 0);
52002
52003 error = transport_class_register(&fc_host_class);
52004 if (error)
52005 @@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52006 char *cp;
52007
52008 *val = simple_strtoul(buf, &cp, 0);
52009 - if ((*cp && (*cp != '\n')) || (*val < 0))
52010 + if (*cp && (*cp != '\n'))
52011 return -EINVAL;
52012 /*
52013 * Check for overflow; dev_loss_tmo is u32
52014 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52015 index 67d43e3..8cee73c 100644
52016 --- a/drivers/scsi/scsi_transport_iscsi.c
52017 +++ b/drivers/scsi/scsi_transport_iscsi.c
52018 @@ -79,7 +79,7 @@ struct iscsi_internal {
52019 struct transport_container session_cont;
52020 };
52021
52022 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52023 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52024 static struct workqueue_struct *iscsi_eh_timer_workq;
52025
52026 static DEFINE_IDA(iscsi_sess_ida);
52027 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52028 int err;
52029
52030 ihost = shost->shost_data;
52031 - session->sid = atomic_add_return(1, &iscsi_session_nr);
52032 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52033
52034 if (target_id == ISCSI_MAX_TARGET) {
52035 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52036 @@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52037 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52038 ISCSI_TRANSPORT_VERSION);
52039
52040 - atomic_set(&iscsi_session_nr, 0);
52041 + atomic_set_unchecked(&iscsi_session_nr, 0);
52042
52043 err = class_register(&iscsi_transport_class);
52044 if (err)
52045 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52046 index ae45bd9..c32a586 100644
52047 --- a/drivers/scsi/scsi_transport_srp.c
52048 +++ b/drivers/scsi/scsi_transport_srp.c
52049 @@ -35,7 +35,7 @@
52050 #include "scsi_priv.h"
52051
52052 struct srp_host_attrs {
52053 - atomic_t next_port_id;
52054 + atomic_unchecked_t next_port_id;
52055 };
52056 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52057
52058 @@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52059 struct Scsi_Host *shost = dev_to_shost(dev);
52060 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52061
52062 - atomic_set(&srp_host->next_port_id, 0);
52063 + atomic_set_unchecked(&srp_host->next_port_id, 0);
52064 return 0;
52065 }
52066
52067 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52068 rport_fast_io_fail_timedout);
52069 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52070
52071 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52072 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52073 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52074
52075 transport_setup_device(&rport->dev);
52076 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52077 index dd8c8d6..4cdf6a1 100644
52078 --- a/drivers/scsi/sd.c
52079 +++ b/drivers/scsi/sd.c
52080 @@ -3024,7 +3024,7 @@ static int sd_probe(struct device *dev)
52081 sdkp->disk = gd;
52082 sdkp->index = index;
52083 atomic_set(&sdkp->openers, 0);
52084 - atomic_set(&sdkp->device->ioerr_cnt, 0);
52085 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52086
52087 if (!sdp->request_queue->rq_timeout) {
52088 if (sdp->type != TYPE_MOD)
52089 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52090 index 843594c..b1dc3b2 100644
52091 --- a/drivers/scsi/sg.c
52092 +++ b/drivers/scsi/sg.c
52093 @@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52094 sdp->disk->disk_name,
52095 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52096 NULL,
52097 - (char *)arg);
52098 + (char __user *)arg);
52099 case BLKTRACESTART:
52100 return blk_trace_startstop(sdp->device->request_queue, 1);
52101 case BLKTRACESTOP:
52102 diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52103 index 11a5043..e36f04c 100644
52104 --- a/drivers/soc/tegra/fuse/fuse-tegra.c
52105 +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52106 @@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52107 return i;
52108 }
52109
52110 -static struct bin_attribute fuse_bin_attr = {
52111 +static bin_attribute_no_const fuse_bin_attr = {
52112 .attr = { .name = "fuse", .mode = S_IRUGO, },
52113 .read = fuse_read,
52114 };
52115 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52116 index 50f20f2..6bd81e0 100644
52117 --- a/drivers/spi/spi.c
52118 +++ b/drivers/spi/spi.c
52119 @@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
52120 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52121
52122 /* portable code must never pass more than 32 bytes */
52123 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52124 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52125
52126 static u8 *buf;
52127
52128 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52129 index b41429f..2de5373 100644
52130 --- a/drivers/staging/android/timed_output.c
52131 +++ b/drivers/staging/android/timed_output.c
52132 @@ -25,7 +25,7 @@
52133 #include "timed_output.h"
52134
52135 static struct class *timed_output_class;
52136 -static atomic_t device_count;
52137 +static atomic_unchecked_t device_count;
52138
52139 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52140 char *buf)
52141 @@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52142 timed_output_class = class_create(THIS_MODULE, "timed_output");
52143 if (IS_ERR(timed_output_class))
52144 return PTR_ERR(timed_output_class);
52145 - atomic_set(&device_count, 0);
52146 + atomic_set_unchecked(&device_count, 0);
52147 timed_output_class->dev_groups = timed_output_groups;
52148 }
52149
52150 @@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52151 if (ret < 0)
52152 return ret;
52153
52154 - tdev->index = atomic_inc_return(&device_count);
52155 + tdev->index = atomic_inc_return_unchecked(&device_count);
52156 tdev->dev = device_create(timed_output_class, NULL,
52157 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52158 if (IS_ERR(tdev->dev))
52159 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52160 index 001348c..cfaac8a 100644
52161 --- a/drivers/staging/gdm724x/gdm_tty.c
52162 +++ b/drivers/staging/gdm724x/gdm_tty.c
52163 @@ -44,7 +44,7 @@
52164 #define gdm_tty_send_control(n, r, v, d, l) (\
52165 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52166
52167 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52168 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52169
52170 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52171 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52172 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52173 index 9cb222e..8766f26 100644
52174 --- a/drivers/staging/imx-drm/imx-drm-core.c
52175 +++ b/drivers/staging/imx-drm/imx-drm-core.c
52176 @@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52177 if (imxdrm->pipes >= MAX_CRTC)
52178 return -EINVAL;
52179
52180 - if (imxdrm->drm->open_count)
52181 + if (local_read(&imxdrm->drm->open_count))
52182 return -EBUSY;
52183
52184 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52185 diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52186 index 503b2d7..c904931 100644
52187 --- a/drivers/staging/line6/driver.c
52188 +++ b/drivers/staging/line6/driver.c
52189 @@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52190 {
52191 struct usb_device *usbdev = line6->usbdev;
52192 int ret;
52193 - unsigned char len;
52194 + unsigned char *plen;
52195
52196 /* query the serial number: */
52197 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52198 @@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52199 return ret;
52200 }
52201
52202 + plen = kmalloc(1, GFP_KERNEL);
52203 + if (plen == NULL)
52204 + return -ENOMEM;
52205 +
52206 /* Wait for data length. We'll get 0xff until length arrives. */
52207 do {
52208 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52209 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52210 USB_DIR_IN,
52211 - 0x0012, 0x0000, &len, 1,
52212 + 0x0012, 0x0000, plen, 1,
52213 LINE6_TIMEOUT * HZ);
52214 if (ret < 0) {
52215 dev_err(line6->ifcdev,
52216 "receive length failed (error %d)\n", ret);
52217 + kfree(plen);
52218 return ret;
52219 }
52220 - } while (len == 0xff);
52221 + } while (*plen == 0xff);
52222
52223 - if (len != datalen) {
52224 + if (*plen != datalen) {
52225 /* should be equal or something went wrong */
52226 dev_err(line6->ifcdev,
52227 "length mismatch (expected %d, got %d)\n",
52228 - (int)datalen, (int)len);
52229 + (int)datalen, (int)*plen);
52230 + kfree(plen);
52231 return -EINVAL;
52232 }
52233 + kfree(plen);
52234
52235 /* receive the result: */
52236 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52237 @@ -520,7 +527,7 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52238 {
52239 struct usb_device *usbdev = line6->usbdev;
52240 int ret;
52241 - unsigned char status;
52242 + unsigned char *status;
52243
52244 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52245 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
52246 @@ -533,26 +540,34 @@ int line6_write_data(struct usb_line6 *line6, int address, void *data,
52247 return ret;
52248 }
52249
52250 + status = kmalloc(1, GFP_KERNEL);
52251 + if (status == NULL)
52252 + return -ENOMEM;
52253 +
52254 do {
52255 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0),
52256 0x67,
52257 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52258 USB_DIR_IN,
52259 0x0012, 0x0000,
52260 - &status, 1, LINE6_TIMEOUT * HZ);
52261 + status, 1, LINE6_TIMEOUT * HZ);
52262
52263 if (ret < 0) {
52264 dev_err(line6->ifcdev,
52265 "receiving status failed (error %d)\n", ret);
52266 + kfree(status);
52267 return ret;
52268 }
52269 - } while (status == 0xff);
52270 + } while (*status == 0xff);
52271
52272 - if (status != 0) {
52273 + if (*status != 0) {
52274 dev_err(line6->ifcdev, "write failed (error %d)\n", ret);
52275 + kfree(status);
52276 return -EINVAL;
52277 }
52278
52279 + kfree(status);
52280 +
52281 return 0;
52282 }
52283
52284 diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
52285 index 6943715..0a93632 100644
52286 --- a/drivers/staging/line6/toneport.c
52287 +++ b/drivers/staging/line6/toneport.c
52288 @@ -11,6 +11,7 @@
52289 */
52290
52291 #include <linux/wait.h>
52292 +#include <linux/slab.h>
52293 #include <sound/control.h>
52294
52295 #include "audio.h"
52296 @@ -307,14 +308,20 @@ static void toneport_destruct(struct usb_interface *interface)
52297 */
52298 static void toneport_setup(struct usb_line6_toneport *toneport)
52299 {
52300 - int ticks;
52301 + int *ticks;
52302 struct usb_line6 *line6 = &toneport->line6;
52303 struct usb_device *usbdev = line6->usbdev;
52304 u16 idProduct = le16_to_cpu(usbdev->descriptor.idProduct);
52305
52306 + ticks = kmalloc(sizeof(int), GFP_KERNEL);
52307 + if (ticks == NULL)
52308 + return;
52309 +
52310 /* sync time on device with host: */
52311 - ticks = (int)get_seconds();
52312 - line6_write_data(line6, 0x80c6, &ticks, 4);
52313 + *ticks = (int)get_seconds();
52314 + line6_write_data(line6, 0x80c6, ticks, sizeof(int));
52315 +
52316 + kfree(ticks);
52317
52318 /* enable device: */
52319 toneport_send_cmd(usbdev, 0x0301, 0x0000);
52320 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52321 index a94f336..6a1924d 100644
52322 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52323 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52324 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52325 return 0;
52326 }
52327
52328 -sfw_test_client_ops_t brw_test_client;
52329 -void brw_init_test_client(void)
52330 -{
52331 - brw_test_client.tso_init = brw_client_init;
52332 - brw_test_client.tso_fini = brw_client_fini;
52333 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52334 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
52335 +sfw_test_client_ops_t brw_test_client = {
52336 + .tso_init = brw_client_init,
52337 + .tso_fini = brw_client_fini,
52338 + .tso_prep_rpc = brw_client_prep_rpc,
52339 + .tso_done_rpc = brw_client_done_rpc,
52340 };
52341
52342 srpc_service_t brw_test_service;
52343 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52344 index df04ab7..1deb1ac 100644
52345 --- a/drivers/staging/lustre/lnet/selftest/framework.c
52346 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
52347 @@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52348
52349 extern sfw_test_client_ops_t ping_test_client;
52350 extern srpc_service_t ping_test_service;
52351 -extern void ping_init_test_client(void);
52352 extern void ping_init_test_service(void);
52353
52354 extern sfw_test_client_ops_t brw_test_client;
52355 extern srpc_service_t brw_test_service;
52356 -extern void brw_init_test_client(void);
52357 extern void brw_init_test_service(void);
52358
52359
52360 @@ -1681,12 +1679,10 @@ sfw_startup (void)
52361 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52362 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52363
52364 - brw_init_test_client();
52365 brw_init_test_service();
52366 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52367 LASSERT (rc == 0);
52368
52369 - ping_init_test_client();
52370 ping_init_test_service();
52371 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52372 LASSERT (rc == 0);
52373 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52374 index 750cac4..e4d751f 100644
52375 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52376 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52377 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52378 return 0;
52379 }
52380
52381 -sfw_test_client_ops_t ping_test_client;
52382 -void ping_init_test_client(void)
52383 -{
52384 - ping_test_client.tso_init = ping_client_init;
52385 - ping_test_client.tso_fini = ping_client_fini;
52386 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52387 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
52388 -}
52389 +sfw_test_client_ops_t ping_test_client = {
52390 + .tso_init = ping_client_init,
52391 + .tso_fini = ping_client_fini,
52392 + .tso_prep_rpc = ping_client_prep_rpc,
52393 + .tso_done_rpc = ping_client_done_rpc,
52394 +};
52395
52396 srpc_service_t ping_test_service;
52397 void ping_init_test_service(void)
52398 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52399 index 14ac46f..eca2c16 100644
52400 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52401 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52402 @@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52403 ldlm_completion_callback lcs_completion;
52404 ldlm_blocking_callback lcs_blocking;
52405 ldlm_glimpse_callback lcs_glimpse;
52406 -};
52407 +} __no_const;
52408
52409 /* ldlm_lockd.c */
52410 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52411 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52412 index 2a88b80..62e7e5f 100644
52413 --- a/drivers/staging/lustre/lustre/include/obd.h
52414 +++ b/drivers/staging/lustre/lustre/include/obd.h
52415 @@ -1362,7 +1362,7 @@ struct md_ops {
52416 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52417 * wrapper function in include/linux/obd_class.h.
52418 */
52419 -};
52420 +} __no_const;
52421
52422 struct lsm_operations {
52423 void (*lsm_free)(struct lov_stripe_md *);
52424 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52425 index b798daa..b28ca8f 100644
52426 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52427 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52428 @@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52429 int added = (mode == LCK_NL);
52430 int overlaps = 0;
52431 int splitted = 0;
52432 - const struct ldlm_callback_suite null_cbs = { NULL };
52433 + const struct ldlm_callback_suite null_cbs = { };
52434
52435 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52436 *flags, new->l_policy_data.l_flock.owner,
52437 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52438 index bbe2c68..c6b4275 100644
52439 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52440 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52441 @@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52442 void __user *buffer, size_t *lenp, loff_t *ppos)
52443 {
52444 int rc, max_delay_cs;
52445 - struct ctl_table dummy = *table;
52446 + ctl_table_no_const dummy = *table;
52447 long d;
52448
52449 dummy.data = &max_delay_cs;
52450 @@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52451 void __user *buffer, size_t *lenp, loff_t *ppos)
52452 {
52453 int rc, min_delay_cs;
52454 - struct ctl_table dummy = *table;
52455 + ctl_table_no_const dummy = *table;
52456 long d;
52457
52458 dummy.data = &min_delay_cs;
52459 @@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52460 void __user *buffer, size_t *lenp, loff_t *ppos)
52461 {
52462 int rc, backoff;
52463 - struct ctl_table dummy = *table;
52464 + ctl_table_no_const dummy = *table;
52465
52466 dummy.data = &backoff;
52467 dummy.proc_handler = &proc_dointvec;
52468 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52469 index 2c4fc74..b04ca79 100644
52470 --- a/drivers/staging/lustre/lustre/libcfs/module.c
52471 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
52472 @@ -315,11 +315,11 @@ out:
52473
52474
52475 struct cfs_psdev_ops libcfs_psdev_ops = {
52476 - libcfs_psdev_open,
52477 - libcfs_psdev_release,
52478 - NULL,
52479 - NULL,
52480 - libcfs_ioctl
52481 + .p_open = libcfs_psdev_open,
52482 + .p_close = libcfs_psdev_release,
52483 + .p_read = NULL,
52484 + .p_write = NULL,
52485 + .p_ioctl = libcfs_ioctl
52486 };
52487
52488 extern int insert_proc(void);
52489 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52490 index b0bb709..0117c96 100644
52491 --- a/drivers/staging/lustre/lustre/llite/dir.c
52492 +++ b/drivers/staging/lustre/lustre/llite/dir.c
52493 @@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52494 int mode;
52495 int err;
52496
52497 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52498 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52499 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52500 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52501 lump);
52502 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52503 index b2b6c3c..302e4e4 100644
52504 --- a/drivers/staging/octeon/ethernet-rx.c
52505 +++ b/drivers/staging/octeon/ethernet-rx.c
52506 @@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52507 /* Increment RX stats for virtual ports */
52508 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52509 #ifdef CONFIG_64BIT
52510 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52511 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52512 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52513 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52514 #else
52515 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52516 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52517 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52518 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52519 #endif
52520 }
52521 netif_receive_skb(skb);
52522 @@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52523 dev->name);
52524 */
52525 #ifdef CONFIG_64BIT
52526 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52527 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52528 #else
52529 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52530 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52531 #endif
52532 dev_kfree_skb_irq(skb);
52533 }
52534 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52535 index 8f9e3fb..d283fb9 100644
52536 --- a/drivers/staging/octeon/ethernet.c
52537 +++ b/drivers/staging/octeon/ethernet.c
52538 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52539 * since the RX tasklet also increments it.
52540 */
52541 #ifdef CONFIG_64BIT
52542 - atomic64_add(rx_status.dropped_packets,
52543 - (atomic64_t *)&priv->stats.rx_dropped);
52544 + atomic64_add_unchecked(rx_status.dropped_packets,
52545 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52546 #else
52547 - atomic_add(rx_status.dropped_packets,
52548 - (atomic_t *)&priv->stats.rx_dropped);
52549 + atomic_add_unchecked(rx_status.dropped_packets,
52550 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
52551 #endif
52552 }
52553
52554 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52555 index 9191993..30e9817 100644
52556 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
52557 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52558 @@ -225,7 +225,7 @@ struct hal_ops {
52559
52560 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52561 void (*hal_reset_security_engine)(struct adapter *adapter);
52562 -};
52563 +} __no_const;
52564
52565 enum rt_eeprom_type {
52566 EEPROM_93C46,
52567 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52568 index 070cc03..6806e37 100644
52569 --- a/drivers/staging/rtl8712/rtl871x_io.h
52570 +++ b/drivers/staging/rtl8712/rtl871x_io.h
52571 @@ -108,7 +108,7 @@ struct _io_ops {
52572 u8 *pmem);
52573 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52574 u8 *pmem);
52575 -};
52576 +} __no_const;
52577
52578 struct io_req {
52579 struct list_head list;
52580 diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52581 index 2bf2e2f..84421c9 100644
52582 --- a/drivers/staging/unisys/visorchipset/visorchipset.h
52583 +++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52584 @@ -228,7 +228,7 @@ typedef struct {
52585 void (*device_resume)(ulong busNo, ulong devNo);
52586 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52587 ulong *maxSize);
52588 -} VISORCHIPSET_BUSDEV_NOTIFIERS;
52589 +} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52590
52591 /* These functions live inside visorchipset, and will be called to indicate
52592 * responses to specific events (by code outside of visorchipset).
52593 @@ -243,7 +243,7 @@ typedef struct {
52594 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52595 void (*device_pause)(ulong busNo, ulong devNo, int response);
52596 void (*device_resume)(ulong busNo, ulong devNo, int response);
52597 -} VISORCHIPSET_BUSDEV_RESPONDERS;
52598 +} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52599
52600 /** Register functions (in the bus driver) to get called by visorchipset
52601 * whenever a bus or device appears for which this service partition is
52602 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52603 index ae0dade..803d53a 100644
52604 --- a/drivers/staging/vt6655/hostap.c
52605 +++ b/drivers/staging/vt6655/hostap.c
52606 @@ -65,14 +65,13 @@
52607 *
52608 */
52609
52610 +static net_device_ops_no_const apdev_netdev_ops;
52611 +
52612 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52613 {
52614 struct vnt_private *apdev_priv;
52615 struct net_device *dev = pDevice->dev;
52616 int ret;
52617 - const struct net_device_ops apdev_netdev_ops = {
52618 - .ndo_start_xmit = pDevice->tx_80211,
52619 - };
52620
52621 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52622
52623 @@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52624 *apdev_priv = *pDevice;
52625 eth_hw_addr_inherit(pDevice->apdev, dev);
52626
52627 + /* only half broken now */
52628 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52629 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52630
52631 pDevice->apdev->type = ARPHRD_IEEE80211;
52632 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52633 index e7e9372..161f530 100644
52634 --- a/drivers/target/sbp/sbp_target.c
52635 +++ b/drivers/target/sbp/sbp_target.c
52636 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52637
52638 #define SESSION_MAINTENANCE_INTERVAL HZ
52639
52640 -static atomic_t login_id = ATOMIC_INIT(0);
52641 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52642
52643 static void session_maintenance_work(struct work_struct *);
52644 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52645 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
52646 login->lun = se_lun;
52647 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52648 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52649 - login->login_id = atomic_inc_return(&login_id);
52650 + login->login_id = atomic_inc_return_unchecked(&login_id);
52651
52652 login->tgt_agt = sbp_target_agent_register(login);
52653 if (IS_ERR(login->tgt_agt)) {
52654 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52655 index 24fa5d1..fae56f1 100644
52656 --- a/drivers/target/target_core_device.c
52657 +++ b/drivers/target/target_core_device.c
52658 @@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52659 spin_lock_init(&dev->se_tmr_lock);
52660 spin_lock_init(&dev->qf_cmd_lock);
52661 sema_init(&dev->caw_sem, 1);
52662 - atomic_set(&dev->dev_ordered_id, 0);
52663 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
52664 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52665 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52666 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52667 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52668 index be877bf..7be9cd4 100644
52669 --- a/drivers/target/target_core_transport.c
52670 +++ b/drivers/target/target_core_transport.c
52671 @@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52672 * Used to determine when ORDERED commands should go from
52673 * Dormant to Active status.
52674 */
52675 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52676 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52677 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52678 cmd->se_ordered_id, cmd->sam_task_attr,
52679 dev->transport->name);
52680 diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52681 index edc1cce..769e4cb 100644
52682 --- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52683 +++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52684 @@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52685 platform_set_drvdata(pdev, priv);
52686
52687 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52688 - int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52689 - int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52690 + pax_open_kernel();
52691 + *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52692 + *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52693 + pax_close_kernel();
52694 }
52695 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52696 priv, &int3400_thermal_ops,
52697 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52698 index 62143ba..ae21165 100644
52699 --- a/drivers/thermal/of-thermal.c
52700 +++ b/drivers/thermal/of-thermal.c
52701 @@ -30,6 +30,7 @@
52702 #include <linux/err.h>
52703 #include <linux/export.h>
52704 #include <linux/string.h>
52705 +#include <linux/mm.h>
52706
52707 #include "thermal_core.h"
52708
52709 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52710 tz->get_trend = get_trend;
52711 tz->sensor_data = data;
52712
52713 - tzd->ops->get_temp = of_thermal_get_temp;
52714 - tzd->ops->get_trend = of_thermal_get_trend;
52715 + pax_open_kernel();
52716 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52717 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52718 + pax_close_kernel();
52719 mutex_unlock(&tzd->lock);
52720
52721 return tzd;
52722 @@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52723 return;
52724
52725 mutex_lock(&tzd->lock);
52726 - tzd->ops->get_temp = NULL;
52727 - tzd->ops->get_trend = NULL;
52728 + pax_open_kernel();
52729 + *(void **)&tzd->ops->get_temp = NULL;
52730 + *(void **)&tzd->ops->get_trend = NULL;
52731 + pax_close_kernel();
52732
52733 tz->get_temp = NULL;
52734 tz->get_trend = NULL;
52735 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52736 index fd66f57..48e6376 100644
52737 --- a/drivers/tty/cyclades.c
52738 +++ b/drivers/tty/cyclades.c
52739 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52740 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52741 info->port.count);
52742 #endif
52743 - info->port.count++;
52744 + atomic_inc(&info->port.count);
52745 #ifdef CY_DEBUG_COUNT
52746 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52747 - current->pid, info->port.count);
52748 + current->pid, atomic_read(&info->port.count));
52749 #endif
52750
52751 /*
52752 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52753 for (j = 0; j < cy_card[i].nports; j++) {
52754 info = &cy_card[i].ports[j];
52755
52756 - if (info->port.count) {
52757 + if (atomic_read(&info->port.count)) {
52758 /* XXX is the ldisc num worth this? */
52759 struct tty_struct *tty;
52760 struct tty_ldisc *ld;
52761 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52762 index 4fcec1d..5a036f7 100644
52763 --- a/drivers/tty/hvc/hvc_console.c
52764 +++ b/drivers/tty/hvc/hvc_console.c
52765 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52766
52767 spin_lock_irqsave(&hp->port.lock, flags);
52768 /* Check and then increment for fast path open. */
52769 - if (hp->port.count++ > 0) {
52770 + if (atomic_inc_return(&hp->port.count) > 1) {
52771 spin_unlock_irqrestore(&hp->port.lock, flags);
52772 hvc_kick();
52773 return 0;
52774 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52775
52776 spin_lock_irqsave(&hp->port.lock, flags);
52777
52778 - if (--hp->port.count == 0) {
52779 + if (atomic_dec_return(&hp->port.count) == 0) {
52780 spin_unlock_irqrestore(&hp->port.lock, flags);
52781 /* We are done with the tty pointer now. */
52782 tty_port_tty_set(&hp->port, NULL);
52783 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52784 */
52785 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52786 } else {
52787 - if (hp->port.count < 0)
52788 + if (atomic_read(&hp->port.count) < 0)
52789 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52790 - hp->vtermno, hp->port.count);
52791 + hp->vtermno, atomic_read(&hp->port.count));
52792 spin_unlock_irqrestore(&hp->port.lock, flags);
52793 }
52794 }
52795 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52796 * open->hangup case this can be called after the final close so prevent
52797 * that from happening for now.
52798 */
52799 - if (hp->port.count <= 0) {
52800 + if (atomic_read(&hp->port.count) <= 0) {
52801 spin_unlock_irqrestore(&hp->port.lock, flags);
52802 return;
52803 }
52804
52805 - hp->port.count = 0;
52806 + atomic_set(&hp->port.count, 0);
52807 spin_unlock_irqrestore(&hp->port.lock, flags);
52808 tty_port_tty_set(&hp->port, NULL);
52809
52810 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52811 return -EPIPE;
52812
52813 /* FIXME what's this (unprotected) check for? */
52814 - if (hp->port.count <= 0)
52815 + if (atomic_read(&hp->port.count) <= 0)
52816 return -EIO;
52817
52818 spin_lock_irqsave(&hp->lock, flags);
52819 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52820 index 81e939e..95ead10 100644
52821 --- a/drivers/tty/hvc/hvcs.c
52822 +++ b/drivers/tty/hvc/hvcs.c
52823 @@ -83,6 +83,7 @@
52824 #include <asm/hvcserver.h>
52825 #include <asm/uaccess.h>
52826 #include <asm/vio.h>
52827 +#include <asm/local.h>
52828
52829 /*
52830 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52831 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52832
52833 spin_lock_irqsave(&hvcsd->lock, flags);
52834
52835 - if (hvcsd->port.count > 0) {
52836 + if (atomic_read(&hvcsd->port.count) > 0) {
52837 spin_unlock_irqrestore(&hvcsd->lock, flags);
52838 printk(KERN_INFO "HVCS: vterm state unchanged. "
52839 "The hvcs device node is still in use.\n");
52840 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52841 }
52842 }
52843
52844 - hvcsd->port.count = 0;
52845 + atomic_set(&hvcsd->port.count, 0);
52846 hvcsd->port.tty = tty;
52847 tty->driver_data = hvcsd;
52848
52849 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52850 unsigned long flags;
52851
52852 spin_lock_irqsave(&hvcsd->lock, flags);
52853 - hvcsd->port.count++;
52854 + atomic_inc(&hvcsd->port.count);
52855 hvcsd->todo_mask |= HVCS_SCHED_READ;
52856 spin_unlock_irqrestore(&hvcsd->lock, flags);
52857
52858 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52859 hvcsd = tty->driver_data;
52860
52861 spin_lock_irqsave(&hvcsd->lock, flags);
52862 - if (--hvcsd->port.count == 0) {
52863 + if (atomic_dec_and_test(&hvcsd->port.count)) {
52864
52865 vio_disable_interrupts(hvcsd->vdev);
52866
52867 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52868
52869 free_irq(irq, hvcsd);
52870 return;
52871 - } else if (hvcsd->port.count < 0) {
52872 + } else if (atomic_read(&hvcsd->port.count) < 0) {
52873 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52874 " is missmanaged.\n",
52875 - hvcsd->vdev->unit_address, hvcsd->port.count);
52876 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52877 }
52878
52879 spin_unlock_irqrestore(&hvcsd->lock, flags);
52880 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52881
52882 spin_lock_irqsave(&hvcsd->lock, flags);
52883 /* Preserve this so that we know how many kref refs to put */
52884 - temp_open_count = hvcsd->port.count;
52885 + temp_open_count = atomic_read(&hvcsd->port.count);
52886
52887 /*
52888 * Don't kref put inside the spinlock because the destruction
52889 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52890 tty->driver_data = NULL;
52891 hvcsd->port.tty = NULL;
52892
52893 - hvcsd->port.count = 0;
52894 + atomic_set(&hvcsd->port.count, 0);
52895
52896 /* This will drop any buffered data on the floor which is OK in a hangup
52897 * scenario. */
52898 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52899 * the middle of a write operation? This is a crummy place to do this
52900 * but we want to keep it all in the spinlock.
52901 */
52902 - if (hvcsd->port.count <= 0) {
52903 + if (atomic_read(&hvcsd->port.count) <= 0) {
52904 spin_unlock_irqrestore(&hvcsd->lock, flags);
52905 return -ENODEV;
52906 }
52907 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52908 {
52909 struct hvcs_struct *hvcsd = tty->driver_data;
52910
52911 - if (!hvcsd || hvcsd->port.count <= 0)
52912 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52913 return 0;
52914
52915 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52916 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52917 index 4190199..06d5bfa 100644
52918 --- a/drivers/tty/hvc/hvsi.c
52919 +++ b/drivers/tty/hvc/hvsi.c
52920 @@ -85,7 +85,7 @@ struct hvsi_struct {
52921 int n_outbuf;
52922 uint32_t vtermno;
52923 uint32_t virq;
52924 - atomic_t seqno; /* HVSI packet sequence number */
52925 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
52926 uint16_t mctrl;
52927 uint8_t state; /* HVSI protocol state */
52928 uint8_t flags;
52929 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52930
52931 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52932 packet.hdr.len = sizeof(struct hvsi_query_response);
52933 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52934 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52935 packet.verb = VSV_SEND_VERSION_NUMBER;
52936 packet.u.version = HVSI_VERSION;
52937 packet.query_seqno = query_seqno+1;
52938 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52939
52940 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52941 packet.hdr.len = sizeof(struct hvsi_query);
52942 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52943 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52944 packet.verb = verb;
52945
52946 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52947 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52948 int wrote;
52949
52950 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52951 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52952 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52953 packet.hdr.len = sizeof(struct hvsi_control);
52954 packet.verb = VSV_SET_MODEM_CTL;
52955 packet.mask = HVSI_TSDTR;
52956 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52957 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52958
52959 packet.hdr.type = VS_DATA_PACKET_HEADER;
52960 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52961 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52962 packet.hdr.len = count + sizeof(struct hvsi_header);
52963 memcpy(&packet.data, buf, count);
52964
52965 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52966 struct hvsi_control packet __ALIGNED__;
52967
52968 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52969 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52970 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52971 packet.hdr.len = 6;
52972 packet.verb = VSV_CLOSE_PROTOCOL;
52973
52974 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52975
52976 tty_port_tty_set(&hp->port, tty);
52977 spin_lock_irqsave(&hp->lock, flags);
52978 - hp->port.count++;
52979 + atomic_inc(&hp->port.count);
52980 atomic_set(&hp->seqno, 0);
52981 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52982 spin_unlock_irqrestore(&hp->lock, flags);
52983 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52984
52985 spin_lock_irqsave(&hp->lock, flags);
52986
52987 - if (--hp->port.count == 0) {
52988 + if (atomic_dec_return(&hp->port.count) == 0) {
52989 tty_port_tty_set(&hp->port, NULL);
52990 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52991
52992 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52993
52994 spin_lock_irqsave(&hp->lock, flags);
52995 }
52996 - } else if (hp->port.count < 0)
52997 + } else if (atomic_read(&hp->port.count) < 0)
52998 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52999 - hp - hvsi_ports, hp->port.count);
53000 + hp - hvsi_ports, atomic_read(&hp->port.count));
53001
53002 spin_unlock_irqrestore(&hp->lock, flags);
53003 }
53004 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53005 tty_port_tty_set(&hp->port, NULL);
53006
53007 spin_lock_irqsave(&hp->lock, flags);
53008 - hp->port.count = 0;
53009 + atomic_set(&hp->port.count, 0);
53010 hp->n_outbuf = 0;
53011 spin_unlock_irqrestore(&hp->lock, flags);
53012 }
53013 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53014 index 7ae6c29..05c6dba 100644
53015 --- a/drivers/tty/hvc/hvsi_lib.c
53016 +++ b/drivers/tty/hvc/hvsi_lib.c
53017 @@ -8,7 +8,7 @@
53018
53019 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53020 {
53021 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53022 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53023
53024 /* Assumes that always succeeds, works in practice */
53025 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53026 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53027
53028 /* Reset state */
53029 pv->established = 0;
53030 - atomic_set(&pv->seqno, 0);
53031 + atomic_set_unchecked(&pv->seqno, 0);
53032
53033 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53034
53035 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53036 index 345cebb..d5a1e9e 100644
53037 --- a/drivers/tty/ipwireless/tty.c
53038 +++ b/drivers/tty/ipwireless/tty.c
53039 @@ -28,6 +28,7 @@
53040 #include <linux/tty_driver.h>
53041 #include <linux/tty_flip.h>
53042 #include <linux/uaccess.h>
53043 +#include <asm/local.h>
53044
53045 #include "tty.h"
53046 #include "network.h"
53047 @@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53048 return -ENODEV;
53049
53050 mutex_lock(&tty->ipw_tty_mutex);
53051 - if (tty->port.count == 0)
53052 + if (atomic_read(&tty->port.count) == 0)
53053 tty->tx_bytes_queued = 0;
53054
53055 - tty->port.count++;
53056 + atomic_inc(&tty->port.count);
53057
53058 tty->port.tty = linux_tty;
53059 linux_tty->driver_data = tty;
53060 @@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53061
53062 static void do_ipw_close(struct ipw_tty *tty)
53063 {
53064 - tty->port.count--;
53065 -
53066 - if (tty->port.count == 0) {
53067 + if (atomic_dec_return(&tty->port.count) == 0) {
53068 struct tty_struct *linux_tty = tty->port.tty;
53069
53070 if (linux_tty != NULL) {
53071 @@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53072 return;
53073
53074 mutex_lock(&tty->ipw_tty_mutex);
53075 - if (tty->port.count == 0) {
53076 + if (atomic_read(&tty->port.count) == 0) {
53077 mutex_unlock(&tty->ipw_tty_mutex);
53078 return;
53079 }
53080 @@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53081
53082 mutex_lock(&tty->ipw_tty_mutex);
53083
53084 - if (!tty->port.count) {
53085 + if (!atomic_read(&tty->port.count)) {
53086 mutex_unlock(&tty->ipw_tty_mutex);
53087 return;
53088 }
53089 @@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53090 return -ENODEV;
53091
53092 mutex_lock(&tty->ipw_tty_mutex);
53093 - if (!tty->port.count) {
53094 + if (!atomic_read(&tty->port.count)) {
53095 mutex_unlock(&tty->ipw_tty_mutex);
53096 return -EINVAL;
53097 }
53098 @@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53099 if (!tty)
53100 return -ENODEV;
53101
53102 - if (!tty->port.count)
53103 + if (!atomic_read(&tty->port.count))
53104 return -EINVAL;
53105
53106 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53107 @@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53108 if (!tty)
53109 return 0;
53110
53111 - if (!tty->port.count)
53112 + if (!atomic_read(&tty->port.count))
53113 return 0;
53114
53115 return tty->tx_bytes_queued;
53116 @@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53117 if (!tty)
53118 return -ENODEV;
53119
53120 - if (!tty->port.count)
53121 + if (!atomic_read(&tty->port.count))
53122 return -EINVAL;
53123
53124 return get_control_lines(tty);
53125 @@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53126 if (!tty)
53127 return -ENODEV;
53128
53129 - if (!tty->port.count)
53130 + if (!atomic_read(&tty->port.count))
53131 return -EINVAL;
53132
53133 return set_control_lines(tty, set, clear);
53134 @@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53135 if (!tty)
53136 return -ENODEV;
53137
53138 - if (!tty->port.count)
53139 + if (!atomic_read(&tty->port.count))
53140 return -EINVAL;
53141
53142 /* FIXME: Exactly how is the tty object locked here .. */
53143 @@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53144 * are gone */
53145 mutex_lock(&ttyj->ipw_tty_mutex);
53146 }
53147 - while (ttyj->port.count)
53148 + while (atomic_read(&ttyj->port.count))
53149 do_ipw_close(ttyj);
53150 ipwireless_disassociate_network_ttys(network,
53151 ttyj->channel_idx);
53152 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53153 index 14c54e0..1efd4f2 100644
53154 --- a/drivers/tty/moxa.c
53155 +++ b/drivers/tty/moxa.c
53156 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53157 }
53158
53159 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53160 - ch->port.count++;
53161 + atomic_inc(&ch->port.count);
53162 tty->driver_data = ch;
53163 tty_port_tty_set(&ch->port, tty);
53164 mutex_lock(&ch->port.mutex);
53165 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53166 index c434376..114ce13 100644
53167 --- a/drivers/tty/n_gsm.c
53168 +++ b/drivers/tty/n_gsm.c
53169 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53170 spin_lock_init(&dlci->lock);
53171 mutex_init(&dlci->mutex);
53172 dlci->fifo = &dlci->_fifo;
53173 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53174 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53175 kfree(dlci);
53176 return NULL;
53177 }
53178 @@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53179 struct gsm_dlci *dlci = tty->driver_data;
53180 struct tty_port *port = &dlci->port;
53181
53182 - port->count++;
53183 + atomic_inc(&port->count);
53184 tty_port_tty_set(port, tty);
53185
53186 dlci->modem_rx = 0;
53187 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53188 index 47ca0f3..3c0b803 100644
53189 --- a/drivers/tty/n_tty.c
53190 +++ b/drivers/tty/n_tty.c
53191 @@ -115,7 +115,7 @@ struct n_tty_data {
53192 int minimum_to_wake;
53193
53194 /* consumer-published */
53195 - size_t read_tail;
53196 + size_t read_tail __intentional_overflow(-1);
53197 size_t line_start;
53198
53199 /* protected by output lock */
53200 @@ -2523,6 +2523,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53201 {
53202 *ops = tty_ldisc_N_TTY;
53203 ops->owner = NULL;
53204 - ops->refcount = ops->flags = 0;
53205 + atomic_set(&ops->refcount, 0);
53206 + ops->flags = 0;
53207 }
53208 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53209 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53210 index 082304d..d8360ec 100644
53211 --- a/drivers/tty/pty.c
53212 +++ b/drivers/tty/pty.c
53213 @@ -833,8 +833,10 @@ static void __init unix98_pty_init(void)
53214 panic("Couldn't register Unix98 pts driver");
53215
53216 /* Now create the /dev/ptmx special device */
53217 + pax_open_kernel();
53218 tty_default_fops(&ptmx_fops);
53219 - ptmx_fops.open = ptmx_open;
53220 + *(void **)&ptmx_fops.open = ptmx_open;
53221 + pax_close_kernel();
53222
53223 cdev_init(&ptmx_cdev, &ptmx_fops);
53224 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53225 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53226 index 383c4c7..d408e21 100644
53227 --- a/drivers/tty/rocket.c
53228 +++ b/drivers/tty/rocket.c
53229 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53230 tty->driver_data = info;
53231 tty_port_tty_set(port, tty);
53232
53233 - if (port->count++ == 0) {
53234 + if (atomic_inc_return(&port->count) == 1) {
53235 atomic_inc(&rp_num_ports_open);
53236
53237 #ifdef ROCKET_DEBUG_OPEN
53238 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53239 #endif
53240 }
53241 #ifdef ROCKET_DEBUG_OPEN
53242 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53243 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53244 #endif
53245
53246 /*
53247 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53248 spin_unlock_irqrestore(&info->port.lock, flags);
53249 return;
53250 }
53251 - if (info->port.count)
53252 + if (atomic_read(&info->port.count))
53253 atomic_dec(&rp_num_ports_open);
53254 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53255 spin_unlock_irqrestore(&info->port.lock, flags);
53256 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53257 index aa28209..e08fb85 100644
53258 --- a/drivers/tty/serial/ioc4_serial.c
53259 +++ b/drivers/tty/serial/ioc4_serial.c
53260 @@ -437,7 +437,7 @@ struct ioc4_soft {
53261 } is_intr_info[MAX_IOC4_INTR_ENTS];
53262
53263 /* Number of entries active in the above array */
53264 - atomic_t is_num_intrs;
53265 + atomic_unchecked_t is_num_intrs;
53266 } is_intr_type[IOC4_NUM_INTR_TYPES];
53267
53268 /* is_ir_lock must be held while
53269 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53270 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53271 || (type == IOC4_OTHER_INTR_TYPE)));
53272
53273 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53274 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53275 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53276
53277 /* Save off the lower level interrupt handler */
53278 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53279
53280 soft = arg;
53281 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53282 - num_intrs = (int)atomic_read(
53283 + num_intrs = (int)atomic_read_unchecked(
53284 &soft->is_intr_type[intr_type].is_num_intrs);
53285
53286 this_mir = this_ir = pending_intrs(soft, intr_type);
53287 diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53288 index 129dc5b..1da5bb8 100644
53289 --- a/drivers/tty/serial/kgdb_nmi.c
53290 +++ b/drivers/tty/serial/kgdb_nmi.c
53291 @@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53292 * I/O utilities that messages sent to the console will automatically
53293 * be displayed on the dbg_io.
53294 */
53295 - dbg_io_ops->is_console = true;
53296 + pax_open_kernel();
53297 + *(int *)&dbg_io_ops->is_console = true;
53298 + pax_close_kernel();
53299
53300 return 0;
53301 }
53302 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53303 index a260cde..6b2b5ce 100644
53304 --- a/drivers/tty/serial/kgdboc.c
53305 +++ b/drivers/tty/serial/kgdboc.c
53306 @@ -24,8 +24,9 @@
53307 #define MAX_CONFIG_LEN 40
53308
53309 static struct kgdb_io kgdboc_io_ops;
53310 +static struct kgdb_io kgdboc_io_ops_console;
53311
53312 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53313 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53314 static int configured = -1;
53315
53316 static char config[MAX_CONFIG_LEN];
53317 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53318 kgdboc_unregister_kbd();
53319 if (configured == 1)
53320 kgdb_unregister_io_module(&kgdboc_io_ops);
53321 + else if (configured == 2)
53322 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
53323 }
53324
53325 static int configure_kgdboc(void)
53326 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53327 int err;
53328 char *cptr = config;
53329 struct console *cons;
53330 + int is_console = 0;
53331
53332 err = kgdboc_option_setup(config);
53333 if (err || !strlen(config) || isspace(config[0]))
53334 goto noconfig;
53335
53336 err = -ENODEV;
53337 - kgdboc_io_ops.is_console = 0;
53338 kgdb_tty_driver = NULL;
53339
53340 kgdboc_use_kms = 0;
53341 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53342 int idx;
53343 if (cons->device && cons->device(cons, &idx) == p &&
53344 idx == tty_line) {
53345 - kgdboc_io_ops.is_console = 1;
53346 + is_console = 1;
53347 break;
53348 }
53349 cons = cons->next;
53350 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53351 kgdb_tty_line = tty_line;
53352
53353 do_register:
53354 - err = kgdb_register_io_module(&kgdboc_io_ops);
53355 + if (is_console) {
53356 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
53357 + configured = 2;
53358 + } else {
53359 + err = kgdb_register_io_module(&kgdboc_io_ops);
53360 + configured = 1;
53361 + }
53362 if (err)
53363 goto noconfig;
53364
53365 @@ -205,8 +214,6 @@ do_register:
53366 if (err)
53367 goto nmi_con_failed;
53368
53369 - configured = 1;
53370 -
53371 return 0;
53372
53373 nmi_con_failed:
53374 @@ -223,7 +230,7 @@ noconfig:
53375 static int __init init_kgdboc(void)
53376 {
53377 /* Already configured? */
53378 - if (configured == 1)
53379 + if (configured >= 1)
53380 return 0;
53381
53382 return configure_kgdboc();
53383 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53384 if (config[len - 1] == '\n')
53385 config[len - 1] = '\0';
53386
53387 - if (configured == 1)
53388 + if (configured >= 1)
53389 cleanup_kgdboc();
53390
53391 /* Go and configure with the new params. */
53392 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53393 .post_exception = kgdboc_post_exp_handler,
53394 };
53395
53396 +static struct kgdb_io kgdboc_io_ops_console = {
53397 + .name = "kgdboc",
53398 + .read_char = kgdboc_get_char,
53399 + .write_char = kgdboc_put_char,
53400 + .pre_exception = kgdboc_pre_exp_handler,
53401 + .post_exception = kgdboc_post_exp_handler,
53402 + .is_console = 1
53403 +};
53404 +
53405 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53406 /* This is only available if kgdboc is a built in for early debugging */
53407 static int __init kgdboc_early_init(char *opt)
53408 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53409 index 4b6c783..9a19db3 100644
53410 --- a/drivers/tty/serial/msm_serial.c
53411 +++ b/drivers/tty/serial/msm_serial.c
53412 @@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53413 .cons = MSM_CONSOLE,
53414 };
53415
53416 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53417 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53418
53419 static const struct of_device_id msm_uartdm_table[] = {
53420 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53421 @@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53422 int irq;
53423
53424 if (pdev->id == -1)
53425 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53426 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53427
53428 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53429 return -ENXIO;
53430 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53431 index 587d63b..48423a6 100644
53432 --- a/drivers/tty/serial/samsung.c
53433 +++ b/drivers/tty/serial/samsung.c
53434 @@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53435 }
53436 }
53437
53438 +static int s3c64xx_serial_startup(struct uart_port *port);
53439 static int s3c24xx_serial_startup(struct uart_port *port)
53440 {
53441 struct s3c24xx_uart_port *ourport = to_ourport(port);
53442 int ret;
53443
53444 + /* Startup sequence is different for s3c64xx and higher SoC's */
53445 + if (s3c24xx_serial_has_interrupt_mask(port))
53446 + return s3c64xx_serial_startup(port);
53447 +
53448 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53449 port, (unsigned long long)port->mapbase, port->membase);
53450
53451 @@ -1159,10 +1164,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53452 /* setup info for port */
53453 port->dev = &platdev->dev;
53454
53455 - /* Startup sequence is different for s3c64xx and higher SoC's */
53456 - if (s3c24xx_serial_has_interrupt_mask(port))
53457 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53458 -
53459 port->uartclk = 1;
53460
53461 if (cfg->uart_flags & UPF_CONS_FLOW) {
53462 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53463 index a28dee9..168ba47 100644
53464 --- a/drivers/tty/serial/serial_core.c
53465 +++ b/drivers/tty/serial/serial_core.c
53466 @@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53467
53468 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53469
53470 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53471 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53472 return;
53473
53474 /*
53475 @@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53476 uart_flush_buffer(tty);
53477 uart_shutdown(tty, state);
53478 spin_lock_irqsave(&port->lock, flags);
53479 - port->count = 0;
53480 + atomic_set(&port->count, 0);
53481 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53482 spin_unlock_irqrestore(&port->lock, flags);
53483 tty_port_tty_set(port, NULL);
53484 @@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53485 goto end;
53486 }
53487
53488 - port->count++;
53489 + atomic_inc(&port->count);
53490 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53491 retval = -ENXIO;
53492 goto err_dec_count;
53493 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53494 end:
53495 return retval;
53496 err_dec_count:
53497 - port->count--;
53498 + atomic_dec(&port->count);
53499 mutex_unlock(&port->mutex);
53500 goto end;
53501 }
53502 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53503 index b799170..87dafd5 100644
53504 --- a/drivers/tty/synclink.c
53505 +++ b/drivers/tty/synclink.c
53506 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53507
53508 if (debug_level >= DEBUG_LEVEL_INFO)
53509 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53510 - __FILE__,__LINE__, info->device_name, info->port.count);
53511 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53512
53513 if (tty_port_close_start(&info->port, tty, filp) == 0)
53514 goto cleanup;
53515 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53516 cleanup:
53517 if (debug_level >= DEBUG_LEVEL_INFO)
53518 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53519 - tty->driver->name, info->port.count);
53520 + tty->driver->name, atomic_read(&info->port.count));
53521
53522 } /* end of mgsl_close() */
53523
53524 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53525
53526 mgsl_flush_buffer(tty);
53527 shutdown(info);
53528 -
53529 - info->port.count = 0;
53530 +
53531 + atomic_set(&info->port.count, 0);
53532 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53533 info->port.tty = NULL;
53534
53535 @@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53536
53537 if (debug_level >= DEBUG_LEVEL_INFO)
53538 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53539 - __FILE__,__LINE__, tty->driver->name, port->count );
53540 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53541
53542 spin_lock_irqsave(&info->irq_spinlock, flags);
53543 - port->count--;
53544 + atomic_dec(&port->count);
53545 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53546 port->blocked_open++;
53547
53548 @@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53549
53550 if (debug_level >= DEBUG_LEVEL_INFO)
53551 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53552 - __FILE__,__LINE__, tty->driver->name, port->count );
53553 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53554
53555 tty_unlock(tty);
53556 schedule();
53557 @@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53558
53559 /* FIXME: Racy on hangup during close wait */
53560 if (!tty_hung_up_p(filp))
53561 - port->count++;
53562 + atomic_inc(&port->count);
53563 port->blocked_open--;
53564
53565 if (debug_level >= DEBUG_LEVEL_INFO)
53566 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53567 - __FILE__,__LINE__, tty->driver->name, port->count );
53568 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53569
53570 if (!retval)
53571 port->flags |= ASYNC_NORMAL_ACTIVE;
53572 @@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53573
53574 if (debug_level >= DEBUG_LEVEL_INFO)
53575 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53576 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53577 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53578
53579 /* If port is closing, signal caller to try again */
53580 if (info->port.flags & ASYNC_CLOSING){
53581 @@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53582 spin_unlock_irqrestore(&info->netlock, flags);
53583 goto cleanup;
53584 }
53585 - info->port.count++;
53586 + atomic_inc(&info->port.count);
53587 spin_unlock_irqrestore(&info->netlock, flags);
53588
53589 - if (info->port.count == 1) {
53590 + if (atomic_read(&info->port.count) == 1) {
53591 /* 1st open on this device, init hardware */
53592 retval = startup(info);
53593 if (retval < 0)
53594 @@ -3442,8 +3442,8 @@ cleanup:
53595 if (retval) {
53596 if (tty->count == 1)
53597 info->port.tty = NULL; /* tty layer will release tty struct */
53598 - if(info->port.count)
53599 - info->port.count--;
53600 + if (atomic_read(&info->port.count))
53601 + atomic_dec(&info->port.count);
53602 }
53603
53604 return retval;
53605 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53606 unsigned short new_crctype;
53607
53608 /* return error if TTY interface open */
53609 - if (info->port.count)
53610 + if (atomic_read(&info->port.count))
53611 return -EBUSY;
53612
53613 switch (encoding)
53614 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53615
53616 /* arbitrate between network and tty opens */
53617 spin_lock_irqsave(&info->netlock, flags);
53618 - if (info->port.count != 0 || info->netcount != 0) {
53619 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53620 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53621 spin_unlock_irqrestore(&info->netlock, flags);
53622 return -EBUSY;
53623 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53624 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53625
53626 /* return error if TTY interface open */
53627 - if (info->port.count)
53628 + if (atomic_read(&info->port.count))
53629 return -EBUSY;
53630
53631 if (cmd != SIOCWANDEV)
53632 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53633 index 0e8c39b..e0cb171 100644
53634 --- a/drivers/tty/synclink_gt.c
53635 +++ b/drivers/tty/synclink_gt.c
53636 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53637 tty->driver_data = info;
53638 info->port.tty = tty;
53639
53640 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53641 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53642
53643 /* If port is closing, signal caller to try again */
53644 if (info->port.flags & ASYNC_CLOSING){
53645 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53646 mutex_unlock(&info->port.mutex);
53647 goto cleanup;
53648 }
53649 - info->port.count++;
53650 + atomic_inc(&info->port.count);
53651 spin_unlock_irqrestore(&info->netlock, flags);
53652
53653 - if (info->port.count == 1) {
53654 + if (atomic_read(&info->port.count) == 1) {
53655 /* 1st open on this device, init hardware */
53656 retval = startup(info);
53657 if (retval < 0) {
53658 @@ -715,8 +715,8 @@ cleanup:
53659 if (retval) {
53660 if (tty->count == 1)
53661 info->port.tty = NULL; /* tty layer will release tty struct */
53662 - if(info->port.count)
53663 - info->port.count--;
53664 + if(atomic_read(&info->port.count))
53665 + atomic_dec(&info->port.count);
53666 }
53667
53668 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53669 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53670
53671 if (sanity_check(info, tty->name, "close"))
53672 return;
53673 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53674 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53675
53676 if (tty_port_close_start(&info->port, tty, filp) == 0)
53677 goto cleanup;
53678 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53679 tty_port_close_end(&info->port, tty);
53680 info->port.tty = NULL;
53681 cleanup:
53682 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53683 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53684 }
53685
53686 static void hangup(struct tty_struct *tty)
53687 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53688 shutdown(info);
53689
53690 spin_lock_irqsave(&info->port.lock, flags);
53691 - info->port.count = 0;
53692 + atomic_set(&info->port.count, 0);
53693 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53694 info->port.tty = NULL;
53695 spin_unlock_irqrestore(&info->port.lock, flags);
53696 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53697 unsigned short new_crctype;
53698
53699 /* return error if TTY interface open */
53700 - if (info->port.count)
53701 + if (atomic_read(&info->port.count))
53702 return -EBUSY;
53703
53704 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53705 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53706
53707 /* arbitrate between network and tty opens */
53708 spin_lock_irqsave(&info->netlock, flags);
53709 - if (info->port.count != 0 || info->netcount != 0) {
53710 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53711 DBGINFO(("%s hdlc_open busy\n", dev->name));
53712 spin_unlock_irqrestore(&info->netlock, flags);
53713 return -EBUSY;
53714 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53715 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53716
53717 /* return error if TTY interface open */
53718 - if (info->port.count)
53719 + if (atomic_read(&info->port.count))
53720 return -EBUSY;
53721
53722 if (cmd != SIOCWANDEV)
53723 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53724 if (port == NULL)
53725 continue;
53726 spin_lock(&port->lock);
53727 - if ((port->port.count || port->netcount) &&
53728 + if ((atomic_read(&port->port.count) || port->netcount) &&
53729 port->pending_bh && !port->bh_running &&
53730 !port->bh_requested) {
53731 DBGISR(("%s bh queued\n", port->device_name));
53732 @@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53733 add_wait_queue(&port->open_wait, &wait);
53734
53735 spin_lock_irqsave(&info->lock, flags);
53736 - port->count--;
53737 + atomic_dec(&port->count);
53738 spin_unlock_irqrestore(&info->lock, flags);
53739 port->blocked_open++;
53740
53741 @@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53742 remove_wait_queue(&port->open_wait, &wait);
53743
53744 if (!tty_hung_up_p(filp))
53745 - port->count++;
53746 + atomic_inc(&port->count);
53747 port->blocked_open--;
53748
53749 if (!retval)
53750 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53751 index c3f9091..abe4601 100644
53752 --- a/drivers/tty/synclinkmp.c
53753 +++ b/drivers/tty/synclinkmp.c
53754 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53755
53756 if (debug_level >= DEBUG_LEVEL_INFO)
53757 printk("%s(%d):%s open(), old ref count = %d\n",
53758 - __FILE__,__LINE__,tty->driver->name, info->port.count);
53759 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53760
53761 /* If port is closing, signal caller to try again */
53762 if (info->port.flags & ASYNC_CLOSING){
53763 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53764 spin_unlock_irqrestore(&info->netlock, flags);
53765 goto cleanup;
53766 }
53767 - info->port.count++;
53768 + atomic_inc(&info->port.count);
53769 spin_unlock_irqrestore(&info->netlock, flags);
53770
53771 - if (info->port.count == 1) {
53772 + if (atomic_read(&info->port.count) == 1) {
53773 /* 1st open on this device, init hardware */
53774 retval = startup(info);
53775 if (retval < 0)
53776 @@ -796,8 +796,8 @@ cleanup:
53777 if (retval) {
53778 if (tty->count == 1)
53779 info->port.tty = NULL; /* tty layer will release tty struct */
53780 - if(info->port.count)
53781 - info->port.count--;
53782 + if(atomic_read(&info->port.count))
53783 + atomic_dec(&info->port.count);
53784 }
53785
53786 return retval;
53787 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53788
53789 if (debug_level >= DEBUG_LEVEL_INFO)
53790 printk("%s(%d):%s close() entry, count=%d\n",
53791 - __FILE__,__LINE__, info->device_name, info->port.count);
53792 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53793
53794 if (tty_port_close_start(&info->port, tty, filp) == 0)
53795 goto cleanup;
53796 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53797 cleanup:
53798 if (debug_level >= DEBUG_LEVEL_INFO)
53799 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53800 - tty->driver->name, info->port.count);
53801 + tty->driver->name, atomic_read(&info->port.count));
53802 }
53803
53804 /* Called by tty_hangup() when a hangup is signaled.
53805 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53806 shutdown(info);
53807
53808 spin_lock_irqsave(&info->port.lock, flags);
53809 - info->port.count = 0;
53810 + atomic_set(&info->port.count, 0);
53811 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53812 info->port.tty = NULL;
53813 spin_unlock_irqrestore(&info->port.lock, flags);
53814 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53815 unsigned short new_crctype;
53816
53817 /* return error if TTY interface open */
53818 - if (info->port.count)
53819 + if (atomic_read(&info->port.count))
53820 return -EBUSY;
53821
53822 switch (encoding)
53823 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53824
53825 /* arbitrate between network and tty opens */
53826 spin_lock_irqsave(&info->netlock, flags);
53827 - if (info->port.count != 0 || info->netcount != 0) {
53828 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53829 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53830 spin_unlock_irqrestore(&info->netlock, flags);
53831 return -EBUSY;
53832 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53833 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53834
53835 /* return error if TTY interface open */
53836 - if (info->port.count)
53837 + if (atomic_read(&info->port.count))
53838 return -EBUSY;
53839
53840 if (cmd != SIOCWANDEV)
53841 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53842 * do not request bottom half processing if the
53843 * device is not open in a normal mode.
53844 */
53845 - if ( port && (port->port.count || port->netcount) &&
53846 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53847 port->pending_bh && !port->bh_running &&
53848 !port->bh_requested ) {
53849 if ( debug_level >= DEBUG_LEVEL_ISR )
53850 @@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53851
53852 if (debug_level >= DEBUG_LEVEL_INFO)
53853 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53854 - __FILE__,__LINE__, tty->driver->name, port->count );
53855 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53856
53857 spin_lock_irqsave(&info->lock, flags);
53858 - port->count--;
53859 + atomic_dec(&port->count);
53860 spin_unlock_irqrestore(&info->lock, flags);
53861 port->blocked_open++;
53862
53863 @@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53864
53865 if (debug_level >= DEBUG_LEVEL_INFO)
53866 printk("%s(%d):%s block_til_ready() count=%d\n",
53867 - __FILE__,__LINE__, tty->driver->name, port->count );
53868 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53869
53870 tty_unlock(tty);
53871 schedule();
53872 @@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53873 set_current_state(TASK_RUNNING);
53874 remove_wait_queue(&port->open_wait, &wait);
53875 if (!tty_hung_up_p(filp))
53876 - port->count++;
53877 + atomic_inc(&port->count);
53878 port->blocked_open--;
53879
53880 if (debug_level >= DEBUG_LEVEL_INFO)
53881 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53882 - __FILE__,__LINE__, tty->driver->name, port->count );
53883 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53884
53885 if (!retval)
53886 port->flags |= ASYNC_NORMAL_ACTIVE;
53887 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53888 index 42bad18..447d7a2 100644
53889 --- a/drivers/tty/sysrq.c
53890 +++ b/drivers/tty/sysrq.c
53891 @@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53892 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53893 size_t count, loff_t *ppos)
53894 {
53895 - if (count) {
53896 + if (count && capable(CAP_SYS_ADMIN)) {
53897 char c;
53898
53899 if (get_user(c, buf))
53900 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53901 index 0508a1d..b610592 100644
53902 --- a/drivers/tty/tty_io.c
53903 +++ b/drivers/tty/tty_io.c
53904 @@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53905
53906 void tty_default_fops(struct file_operations *fops)
53907 {
53908 - *fops = tty_fops;
53909 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53910 }
53911
53912 /*
53913 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53914 index 2d822aa..a566234 100644
53915 --- a/drivers/tty/tty_ldisc.c
53916 +++ b/drivers/tty/tty_ldisc.c
53917 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53918 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53919 tty_ldiscs[disc] = new_ldisc;
53920 new_ldisc->num = disc;
53921 - new_ldisc->refcount = 0;
53922 + atomic_set(&new_ldisc->refcount, 0);
53923 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53924
53925 return ret;
53926 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53927 return -EINVAL;
53928
53929 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53930 - if (tty_ldiscs[disc]->refcount)
53931 + if (atomic_read(&tty_ldiscs[disc]->refcount))
53932 ret = -EBUSY;
53933 else
53934 tty_ldiscs[disc] = NULL;
53935 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53936 if (ldops) {
53937 ret = ERR_PTR(-EAGAIN);
53938 if (try_module_get(ldops->owner)) {
53939 - ldops->refcount++;
53940 + atomic_inc(&ldops->refcount);
53941 ret = ldops;
53942 }
53943 }
53944 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53945 unsigned long flags;
53946
53947 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53948 - ldops->refcount--;
53949 + atomic_dec(&ldops->refcount);
53950 module_put(ldops->owner);
53951 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53952 }
53953 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53954 index 1b93357..ea9f82c 100644
53955 --- a/drivers/tty/tty_port.c
53956 +++ b/drivers/tty/tty_port.c
53957 @@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53958 unsigned long flags;
53959
53960 spin_lock_irqsave(&port->lock, flags);
53961 - port->count = 0;
53962 + atomic_set(&port->count, 0);
53963 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53964 tty = port->tty;
53965 if (tty)
53966 @@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53967
53968 /* The port lock protects the port counts */
53969 spin_lock_irqsave(&port->lock, flags);
53970 - port->count--;
53971 + atomic_dec(&port->count);
53972 port->blocked_open++;
53973 spin_unlock_irqrestore(&port->lock, flags);
53974
53975 @@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53976 we must not mess that up further */
53977 spin_lock_irqsave(&port->lock, flags);
53978 if (!tty_hung_up_p(filp))
53979 - port->count++;
53980 + atomic_inc(&port->count);
53981 port->blocked_open--;
53982 if (retval == 0)
53983 port->flags |= ASYNC_NORMAL_ACTIVE;
53984 @@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53985 return 0;
53986 }
53987
53988 - if (tty->count == 1 && port->count != 1) {
53989 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
53990 printk(KERN_WARNING
53991 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53992 - port->count);
53993 - port->count = 1;
53994 + atomic_read(&port->count));
53995 + atomic_set(&port->count, 1);
53996 }
53997 - if (--port->count < 0) {
53998 + if (atomic_dec_return(&port->count) < 0) {
53999 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54000 - port->count);
54001 - port->count = 0;
54002 + atomic_read(&port->count));
54003 + atomic_set(&port->count, 0);
54004 }
54005
54006 - if (port->count) {
54007 + if (atomic_read(&port->count)) {
54008 spin_unlock_irqrestore(&port->lock, flags);
54009 return 0;
54010 }
54011 @@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54012 struct file *filp)
54013 {
54014 spin_lock_irq(&port->lock);
54015 - ++port->count;
54016 + atomic_inc(&port->count);
54017 spin_unlock_irq(&port->lock);
54018 tty_port_tty_set(port, tty);
54019
54020 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54021 index c039cfe..0b463b0 100644
54022 --- a/drivers/tty/vt/keyboard.c
54023 +++ b/drivers/tty/vt/keyboard.c
54024 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54025 kbd->kbdmode == VC_OFF) &&
54026 value != KVAL(K_SAK))
54027 return; /* SAK is allowed even in raw mode */
54028 +
54029 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54030 + {
54031 + void *func = fn_handler[value];
54032 + if (func == fn_show_state || func == fn_show_ptregs ||
54033 + func == fn_show_mem)
54034 + return;
54035 + }
54036 +#endif
54037 +
54038 fn_handler[value](vc);
54039 }
54040
54041 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54042 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54043 return -EFAULT;
54044
54045 - if (!capable(CAP_SYS_TTY_CONFIG))
54046 - perm = 0;
54047 -
54048 switch (cmd) {
54049 case KDGKBENT:
54050 /* Ensure another thread doesn't free it under us */
54051 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54052 spin_unlock_irqrestore(&kbd_event_lock, flags);
54053 return put_user(val, &user_kbe->kb_value);
54054 case KDSKBENT:
54055 + if (!capable(CAP_SYS_TTY_CONFIG))
54056 + perm = 0;
54057 +
54058 if (!perm)
54059 return -EPERM;
54060 if (!i && v == K_NOSUCHMAP) {
54061 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54062 int i, j, k;
54063 int ret;
54064
54065 - if (!capable(CAP_SYS_TTY_CONFIG))
54066 - perm = 0;
54067 -
54068 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54069 if (!kbs) {
54070 ret = -ENOMEM;
54071 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54072 kfree(kbs);
54073 return ((p && *p) ? -EOVERFLOW : 0);
54074 case KDSKBSENT:
54075 + if (!capable(CAP_SYS_TTY_CONFIG))
54076 + perm = 0;
54077 +
54078 if (!perm) {
54079 ret = -EPERM;
54080 goto reterr;
54081 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54082 index 60fa627..7214965 100644
54083 --- a/drivers/uio/uio.c
54084 +++ b/drivers/uio/uio.c
54085 @@ -25,6 +25,7 @@
54086 #include <linux/kobject.h>
54087 #include <linux/cdev.h>
54088 #include <linux/uio_driver.h>
54089 +#include <asm/local.h>
54090
54091 #define UIO_MAX_DEVICES (1U << MINORBITS)
54092
54093 @@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
54094 struct device_attribute *attr, char *buf)
54095 {
54096 struct uio_device *idev = dev_get_drvdata(dev);
54097 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54098 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54099 }
54100 static DEVICE_ATTR_RO(event);
54101
54102 @@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
54103 {
54104 struct uio_device *idev = info->uio_dev;
54105
54106 - atomic_inc(&idev->event);
54107 + atomic_inc_unchecked(&idev->event);
54108 wake_up_interruptible(&idev->wait);
54109 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54110 }
54111 @@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54112 }
54113
54114 listener->dev = idev;
54115 - listener->event_count = atomic_read(&idev->event);
54116 + listener->event_count = atomic_read_unchecked(&idev->event);
54117 filep->private_data = listener;
54118
54119 if (idev->info->open) {
54120 @@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54121 return -EIO;
54122
54123 poll_wait(filep, &idev->wait, wait);
54124 - if (listener->event_count != atomic_read(&idev->event))
54125 + if (listener->event_count != atomic_read_unchecked(&idev->event))
54126 return POLLIN | POLLRDNORM;
54127 return 0;
54128 }
54129 @@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54130 do {
54131 set_current_state(TASK_INTERRUPTIBLE);
54132
54133 - event_count = atomic_read(&idev->event);
54134 + event_count = atomic_read_unchecked(&idev->event);
54135 if (event_count != listener->event_count) {
54136 if (copy_to_user(buf, &event_count, count))
54137 retval = -EFAULT;
54138 @@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54139 static int uio_find_mem_index(struct vm_area_struct *vma)
54140 {
54141 struct uio_device *idev = vma->vm_private_data;
54142 + unsigned long size;
54143
54144 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54145 - if (idev->info->mem[vma->vm_pgoff].size == 0)
54146 + size = idev->info->mem[vma->vm_pgoff].size;
54147 + if (size == 0)
54148 + return -1;
54149 + if (vma->vm_end - vma->vm_start > size)
54150 return -1;
54151 return (int)vma->vm_pgoff;
54152 }
54153 @@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
54154 idev->owner = owner;
54155 idev->info = info;
54156 init_waitqueue_head(&idev->wait);
54157 - atomic_set(&idev->event, 0);
54158 + atomic_set_unchecked(&idev->event, 0);
54159
54160 ret = uio_get_minor(idev);
54161 if (ret)
54162 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54163 index 813d4d3..a71934f 100644
54164 --- a/drivers/usb/atm/cxacru.c
54165 +++ b/drivers/usb/atm/cxacru.c
54166 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54167 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54168 if (ret < 2)
54169 return -EINVAL;
54170 - if (index < 0 || index > 0x7f)
54171 + if (index > 0x7f)
54172 return -EINVAL;
54173 pos += tmp;
54174
54175 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54176 index dada014..1d0d517 100644
54177 --- a/drivers/usb/atm/usbatm.c
54178 +++ b/drivers/usb/atm/usbatm.c
54179 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54180 if (printk_ratelimit())
54181 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54182 __func__, vpi, vci);
54183 - atomic_inc(&vcc->stats->rx_err);
54184 + atomic_inc_unchecked(&vcc->stats->rx_err);
54185 return;
54186 }
54187
54188 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54189 if (length > ATM_MAX_AAL5_PDU) {
54190 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54191 __func__, length, vcc);
54192 - atomic_inc(&vcc->stats->rx_err);
54193 + atomic_inc_unchecked(&vcc->stats->rx_err);
54194 goto out;
54195 }
54196
54197 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54198 if (sarb->len < pdu_length) {
54199 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54200 __func__, pdu_length, sarb->len, vcc);
54201 - atomic_inc(&vcc->stats->rx_err);
54202 + atomic_inc_unchecked(&vcc->stats->rx_err);
54203 goto out;
54204 }
54205
54206 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54207 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54208 __func__, vcc);
54209 - atomic_inc(&vcc->stats->rx_err);
54210 + atomic_inc_unchecked(&vcc->stats->rx_err);
54211 goto out;
54212 }
54213
54214 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54215 if (printk_ratelimit())
54216 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54217 __func__, length);
54218 - atomic_inc(&vcc->stats->rx_drop);
54219 + atomic_inc_unchecked(&vcc->stats->rx_drop);
54220 goto out;
54221 }
54222
54223 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54224
54225 vcc->push(vcc, skb);
54226
54227 - atomic_inc(&vcc->stats->rx);
54228 + atomic_inc_unchecked(&vcc->stats->rx);
54229 out:
54230 skb_trim(sarb, 0);
54231 }
54232 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54233 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54234
54235 usbatm_pop(vcc, skb);
54236 - atomic_inc(&vcc->stats->tx);
54237 + atomic_inc_unchecked(&vcc->stats->tx);
54238
54239 skb = skb_dequeue(&instance->sndqueue);
54240 }
54241 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54242 if (!left--)
54243 return sprintf(page,
54244 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54245 - atomic_read(&atm_dev->stats.aal5.tx),
54246 - atomic_read(&atm_dev->stats.aal5.tx_err),
54247 - atomic_read(&atm_dev->stats.aal5.rx),
54248 - atomic_read(&atm_dev->stats.aal5.rx_err),
54249 - atomic_read(&atm_dev->stats.aal5.rx_drop));
54250 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54251 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54252 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54253 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54254 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54255
54256 if (!left--) {
54257 if (instance->disconnected)
54258 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54259 index 2a3bbdf..91d72cf 100644
54260 --- a/drivers/usb/core/devices.c
54261 +++ b/drivers/usb/core/devices.c
54262 @@ -126,7 +126,7 @@ static const char format_endpt[] =
54263 * time it gets called.
54264 */
54265 static struct device_connect_event {
54266 - atomic_t count;
54267 + atomic_unchecked_t count;
54268 wait_queue_head_t wait;
54269 } device_event = {
54270 .count = ATOMIC_INIT(1),
54271 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54272
54273 void usbfs_conn_disc_event(void)
54274 {
54275 - atomic_add(2, &device_event.count);
54276 + atomic_add_unchecked(2, &device_event.count);
54277 wake_up(&device_event.wait);
54278 }
54279
54280 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54281
54282 poll_wait(file, &device_event.wait, wait);
54283
54284 - event_count = atomic_read(&device_event.count);
54285 + event_count = atomic_read_unchecked(&device_event.count);
54286 if (file->f_version != event_count) {
54287 file->f_version = event_count;
54288 return POLLIN | POLLRDNORM;
54289 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54290 index 0b59731..46ee7d1 100644
54291 --- a/drivers/usb/core/devio.c
54292 +++ b/drivers/usb/core/devio.c
54293 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54294 struct usb_dev_state *ps = file->private_data;
54295 struct usb_device *dev = ps->dev;
54296 ssize_t ret = 0;
54297 - unsigned len;
54298 + size_t len;
54299 loff_t pos;
54300 int i;
54301
54302 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54303 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54304 struct usb_config_descriptor *config =
54305 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54306 - unsigned int length = le16_to_cpu(config->wTotalLength);
54307 + size_t length = le16_to_cpu(config->wTotalLength);
54308
54309 if (*ppos < pos + length) {
54310
54311 /* The descriptor may claim to be longer than it
54312 * really is. Here is the actual allocated length. */
54313 - unsigned alloclen =
54314 + size_t alloclen =
54315 le16_to_cpu(dev->config[i].desc.wTotalLength);
54316
54317 - len = length - (*ppos - pos);
54318 + len = length + pos - *ppos;
54319 if (len > nbytes)
54320 len = nbytes;
54321
54322 /* Simply don't write (skip over) unallocated parts */
54323 if (alloclen > (*ppos - pos)) {
54324 - alloclen -= (*ppos - pos);
54325 + alloclen = alloclen + pos - *ppos;
54326 if (copy_to_user(buf,
54327 dev->rawdescriptors[i] + (*ppos - pos),
54328 min(len, alloclen))) {
54329 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54330 index 0009fc8..483f7e5 100644
54331 --- a/drivers/usb/core/hcd.c
54332 +++ b/drivers/usb/core/hcd.c
54333 @@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54334 */
54335 usb_get_urb(urb);
54336 atomic_inc(&urb->use_count);
54337 - atomic_inc(&urb->dev->urbnum);
54338 + atomic_inc_unchecked(&urb->dev->urbnum);
54339 usbmon_urb_submit(&hcd->self, urb);
54340
54341 /* NOTE requirements on root-hub callers (usbfs and the hub
54342 @@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54343 urb->hcpriv = NULL;
54344 INIT_LIST_HEAD(&urb->urb_list);
54345 atomic_dec(&urb->use_count);
54346 - atomic_dec(&urb->dev->urbnum);
54347 + atomic_dec_unchecked(&urb->dev->urbnum);
54348 if (atomic_read(&urb->reject))
54349 wake_up(&usb_kill_urb_queue);
54350 usb_put_urb(urb);
54351 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54352 index 2246954..d75b0b1 100644
54353 --- a/drivers/usb/core/hub.c
54354 +++ b/drivers/usb/core/hub.c
54355 @@ -26,6 +26,7 @@
54356 #include <linux/mutex.h>
54357 #include <linux/random.h>
54358 #include <linux/pm_qos.h>
54359 +#include <linux/grsecurity.h>
54360
54361 #include <asm/uaccess.h>
54362 #include <asm/byteorder.h>
54363 @@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54364 goto done;
54365 return;
54366 }
54367 +
54368 + if (gr_handle_new_usb())
54369 + goto done;
54370 +
54371 if (hub_is_superspeed(hub->hdev))
54372 unit_load = 150;
54373 else
54374 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54375 index f368d20..0c30ac5 100644
54376 --- a/drivers/usb/core/message.c
54377 +++ b/drivers/usb/core/message.c
54378 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54379 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54380 * error number.
54381 */
54382 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54383 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54384 __u8 requesttype, __u16 value, __u16 index, void *data,
54385 __u16 size, int timeout)
54386 {
54387 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54388 * If successful, 0. Otherwise a negative error number. The number of actual
54389 * bytes transferred will be stored in the @actual_length parameter.
54390 */
54391 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54392 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54393 void *data, int len, int *actual_length, int timeout)
54394 {
54395 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54396 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54397 * bytes transferred will be stored in the @actual_length parameter.
54398 *
54399 */
54400 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54401 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54402 void *data, int len, int *actual_length, int timeout)
54403 {
54404 struct urb *urb;
54405 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54406 index 1236c60..d47a51c 100644
54407 --- a/drivers/usb/core/sysfs.c
54408 +++ b/drivers/usb/core/sysfs.c
54409 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54410 struct usb_device *udev;
54411
54412 udev = to_usb_device(dev);
54413 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54414 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54415 }
54416 static DEVICE_ATTR_RO(urbnum);
54417
54418 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54419 index 29ee936..55e3f99 100644
54420 --- a/drivers/usb/core/usb.c
54421 +++ b/drivers/usb/core/usb.c
54422 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54423 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54424 dev->state = USB_STATE_ATTACHED;
54425 dev->lpm_disable_count = 1;
54426 - atomic_set(&dev->urbnum, 0);
54427 + atomic_set_unchecked(&dev->urbnum, 0);
54428
54429 INIT_LIST_HEAD(&dev->ep0.urb_list);
54430 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54431 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54432 index 8cfc319..4868255 100644
54433 --- a/drivers/usb/early/ehci-dbgp.c
54434 +++ b/drivers/usb/early/ehci-dbgp.c
54435 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54436
54437 #ifdef CONFIG_KGDB
54438 static struct kgdb_io kgdbdbgp_io_ops;
54439 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54440 +static struct kgdb_io kgdbdbgp_io_ops_console;
54441 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54442 #else
54443 #define dbgp_kgdb_mode (0)
54444 #endif
54445 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54446 .write_char = kgdbdbgp_write_char,
54447 };
54448
54449 +static struct kgdb_io kgdbdbgp_io_ops_console = {
54450 + .name = "kgdbdbgp",
54451 + .read_char = kgdbdbgp_read_char,
54452 + .write_char = kgdbdbgp_write_char,
54453 + .is_console = 1
54454 +};
54455 +
54456 static int kgdbdbgp_wait_time;
54457
54458 static int __init kgdbdbgp_parse_config(char *str)
54459 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54460 ptr++;
54461 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54462 }
54463 - kgdb_register_io_module(&kgdbdbgp_io_ops);
54464 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54465 + if (early_dbgp_console.index != -1)
54466 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54467 + else
54468 + kgdb_register_io_module(&kgdbdbgp_io_ops);
54469
54470 return 0;
54471 }
54472 diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54473 index f7b2032..fbb340c 100644
54474 --- a/drivers/usb/gadget/function/f_uac1.c
54475 +++ b/drivers/usb/gadget/function/f_uac1.c
54476 @@ -14,6 +14,7 @@
54477 #include <linux/module.h>
54478 #include <linux/device.h>
54479 #include <linux/atomic.h>
54480 +#include <linux/module.h>
54481
54482 #include "u_uac1.h"
54483
54484 diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54485 index 491082a..dfd7d17 100644
54486 --- a/drivers/usb/gadget/function/u_serial.c
54487 +++ b/drivers/usb/gadget/function/u_serial.c
54488 @@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54489 spin_lock_irq(&port->port_lock);
54490
54491 /* already open? Great. */
54492 - if (port->port.count) {
54493 + if (atomic_read(&port->port.count)) {
54494 status = 0;
54495 - port->port.count++;
54496 + atomic_inc(&port->port.count);
54497
54498 /* currently opening/closing? wait ... */
54499 } else if (port->openclose) {
54500 @@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54501 tty->driver_data = port;
54502 port->port.tty = tty;
54503
54504 - port->port.count = 1;
54505 + atomic_set(&port->port.count, 1);
54506 port->openclose = false;
54507
54508 /* if connected, start the I/O stream */
54509 @@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54510
54511 spin_lock_irq(&port->port_lock);
54512
54513 - if (port->port.count != 1) {
54514 - if (port->port.count == 0)
54515 + if (atomic_read(&port->port.count) != 1) {
54516 + if (atomic_read(&port->port.count) == 0)
54517 WARN_ON(1);
54518 else
54519 - --port->port.count;
54520 + atomic_dec(&port->port.count);
54521 goto exit;
54522 }
54523
54524 @@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54525 * and sleep if necessary
54526 */
54527 port->openclose = true;
54528 - port->port.count = 0;
54529 + atomic_set(&port->port.count, 0);
54530
54531 gser = port->port_usb;
54532 if (gser && gser->disconnect)
54533 @@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54534 int cond;
54535
54536 spin_lock_irq(&port->port_lock);
54537 - cond = (port->port.count == 0) && !port->openclose;
54538 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54539 spin_unlock_irq(&port->port_lock);
54540 return cond;
54541 }
54542 @@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54543 /* if it's already open, start I/O ... and notify the serial
54544 * protocol about open/close status (connect/disconnect).
54545 */
54546 - if (port->port.count) {
54547 + if (atomic_read(&port->port.count)) {
54548 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54549 gs_start_io(port);
54550 if (gser->connect)
54551 @@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54552
54553 port->port_usb = NULL;
54554 gser->ioport = NULL;
54555 - if (port->port.count > 0 || port->openclose) {
54556 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
54557 wake_up_interruptible(&port->drain_wait);
54558 if (port->port.tty)
54559 tty_hangup(port->port.tty);
54560 @@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54561
54562 /* finally, free any unused/unusable I/O buffers */
54563 spin_lock_irqsave(&port->port_lock, flags);
54564 - if (port->port.count == 0 && !port->openclose)
54565 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
54566 gs_buf_free(&port->port_write_buf);
54567 gs_free_requests(gser->out, &port->read_pool, NULL);
54568 gs_free_requests(gser->out, &port->read_queue, NULL);
54569 diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54570 index a44a07f..ecea924 100644
54571 --- a/drivers/usb/gadget/function/u_uac1.c
54572 +++ b/drivers/usb/gadget/function/u_uac1.c
54573 @@ -17,6 +17,7 @@
54574 #include <linux/ctype.h>
54575 #include <linux/random.h>
54576 #include <linux/syscalls.h>
54577 +#include <linux/module.h>
54578
54579 #include "u_uac1.h"
54580
54581 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54582 index 5728829..fefc6bf 100644
54583 --- a/drivers/usb/host/ehci-hub.c
54584 +++ b/drivers/usb/host/ehci-hub.c
54585 @@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54586 urb->transfer_flags = URB_DIR_IN;
54587 usb_get_urb(urb);
54588 atomic_inc(&urb->use_count);
54589 - atomic_inc(&urb->dev->urbnum);
54590 + atomic_inc_unchecked(&urb->dev->urbnum);
54591 urb->setup_dma = dma_map_single(
54592 hcd->self.controller,
54593 urb->setup_packet,
54594 @@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54595 urb->status = -EINPROGRESS;
54596 usb_get_urb(urb);
54597 atomic_inc(&urb->use_count);
54598 - atomic_inc(&urb->dev->urbnum);
54599 + atomic_inc_unchecked(&urb->dev->urbnum);
54600 retval = submit_single_step_set_feature(hcd, urb, 0);
54601 if (!retval && !wait_for_completion_timeout(&done,
54602 msecs_to_jiffies(2000))) {
54603 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54604 index 1db0626..4948782 100644
54605 --- a/drivers/usb/host/hwa-hc.c
54606 +++ b/drivers/usb/host/hwa-hc.c
54607 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54608 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54609 struct wahc *wa = &hwahc->wa;
54610 struct device *dev = &wa->usb_iface->dev;
54611 - u8 mas_le[UWB_NUM_MAS/8];
54612 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54613 +
54614 + if (mas_le == NULL)
54615 + return -ENOMEM;
54616
54617 /* Set the stream index */
54618 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54619 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54620 WUSB_REQ_SET_WUSB_MAS,
54621 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54622 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54623 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
54624 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54625 if (result < 0)
54626 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54627 out:
54628 + kfree(mas_le);
54629 +
54630 return result;
54631 }
54632
54633 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54634 index b3d245e..99549ed 100644
54635 --- a/drivers/usb/misc/appledisplay.c
54636 +++ b/drivers/usb/misc/appledisplay.c
54637 @@ -84,7 +84,7 @@ struct appledisplay {
54638 struct mutex sysfslock; /* concurrent read and write */
54639 };
54640
54641 -static atomic_t count_displays = ATOMIC_INIT(0);
54642 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54643 static struct workqueue_struct *wq;
54644
54645 static void appledisplay_complete(struct urb *urb)
54646 @@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54647
54648 /* Register backlight device */
54649 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54650 - atomic_inc_return(&count_displays) - 1);
54651 + atomic_inc_return_unchecked(&count_displays) - 1);
54652 memset(&props, 0, sizeof(struct backlight_properties));
54653 props.type = BACKLIGHT_RAW;
54654 props.max_brightness = 0xff;
54655 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54656 index 29fa1c3..a57b08e 100644
54657 --- a/drivers/usb/serial/console.c
54658 +++ b/drivers/usb/serial/console.c
54659 @@ -125,7 +125,7 @@ static int usb_console_setup(struct console *co, char *options)
54660
54661 info->port = port;
54662
54663 - ++port->port.count;
54664 + atomic_inc(&port->port.count);
54665 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54666 if (serial->type->set_termios) {
54667 /*
54668 @@ -173,7 +173,7 @@ static int usb_console_setup(struct console *co, char *options)
54669 }
54670 /* Now that any required fake tty operations are completed restore
54671 * the tty port count */
54672 - --port->port.count;
54673 + atomic_dec(&port->port.count);
54674 /* The console is special in terms of closing the device so
54675 * indicate this port is now acting as a system console. */
54676 port->port.console = 1;
54677 @@ -186,7 +186,7 @@ static int usb_console_setup(struct console *co, char *options)
54678 put_tty:
54679 tty_kref_put(tty);
54680 reset_open_count:
54681 - port->port.count = 0;
54682 + atomic_set(&port->port.count, 0);
54683 usb_autopm_put_interface(serial->interface);
54684 error_get_interface:
54685 usb_serial_put(serial);
54686 @@ -197,7 +197,7 @@ static int usb_console_setup(struct console *co, char *options)
54687 static void usb_console_write(struct console *co,
54688 const char *buf, unsigned count)
54689 {
54690 - static struct usbcons_info *info = &usbcons_info;
54691 + struct usbcons_info *info = &usbcons_info;
54692 struct usb_serial_port *port = info->port;
54693 struct usb_serial *serial;
54694 int retval = -ENODEV;
54695 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54696 index 307e339..6aa97cb 100644
54697 --- a/drivers/usb/storage/usb.h
54698 +++ b/drivers/usb/storage/usb.h
54699 @@ -63,7 +63,7 @@ struct us_unusual_dev {
54700 __u8 useProtocol;
54701 __u8 useTransport;
54702 int (*initFunction)(struct us_data *);
54703 -};
54704 +} __do_const;
54705
54706
54707 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54708 diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54709 index a863a98..d272795 100644
54710 --- a/drivers/usb/usbip/vhci.h
54711 +++ b/drivers/usb/usbip/vhci.h
54712 @@ -83,7 +83,7 @@ struct vhci_hcd {
54713 unsigned resuming:1;
54714 unsigned long re_timeout;
54715
54716 - atomic_t seqnum;
54717 + atomic_unchecked_t seqnum;
54718
54719 /*
54720 * NOTE:
54721 diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54722 index c02374b..32d47a9 100644
54723 --- a/drivers/usb/usbip/vhci_hcd.c
54724 +++ b/drivers/usb/usbip/vhci_hcd.c
54725 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54726
54727 spin_lock(&vdev->priv_lock);
54728
54729 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54730 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54731 if (priv->seqnum == 0xffff)
54732 dev_info(&urb->dev->dev, "seqnum max\n");
54733
54734 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54735 return -ENOMEM;
54736 }
54737
54738 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54739 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54740 if (unlink->seqnum == 0xffff)
54741 pr_info("seqnum max\n");
54742
54743 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54744 vdev->rhport = rhport;
54745 }
54746
54747 - atomic_set(&vhci->seqnum, 0);
54748 + atomic_set_unchecked(&vhci->seqnum, 0);
54749 spin_lock_init(&vhci->lock);
54750
54751 hcd->power_budget = 0; /* no limit */
54752 diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54753 index 00e4a54..d676f85 100644
54754 --- a/drivers/usb/usbip/vhci_rx.c
54755 +++ b/drivers/usb/usbip/vhci_rx.c
54756 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54757 if (!urb) {
54758 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54759 pr_info("max seqnum %d\n",
54760 - atomic_read(&the_controller->seqnum));
54761 + atomic_read_unchecked(&the_controller->seqnum));
54762 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54763 return;
54764 }
54765 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54766 index edc7267..9f65ce2 100644
54767 --- a/drivers/usb/wusbcore/wa-hc.h
54768 +++ b/drivers/usb/wusbcore/wa-hc.h
54769 @@ -240,7 +240,7 @@ struct wahc {
54770 spinlock_t xfer_list_lock;
54771 struct work_struct xfer_enqueue_work;
54772 struct work_struct xfer_error_work;
54773 - atomic_t xfer_id_count;
54774 + atomic_unchecked_t xfer_id_count;
54775
54776 kernel_ulong_t quirks;
54777 };
54778 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54779 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54780 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54781 wa->dto_in_use = 0;
54782 - atomic_set(&wa->xfer_id_count, 1);
54783 + atomic_set_unchecked(&wa->xfer_id_count, 1);
54784 /* init the buf in URBs */
54785 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54786 usb_init_urb(&(wa->buf_in_urbs[index]));
54787 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54788 index 69af4fd..da390d7 100644
54789 --- a/drivers/usb/wusbcore/wa-xfer.c
54790 +++ b/drivers/usb/wusbcore/wa-xfer.c
54791 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54792 */
54793 static void wa_xfer_id_init(struct wa_xfer *xfer)
54794 {
54795 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54796 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54797 }
54798
54799 /* Return the xfer's ID. */
54800 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54801 index f018d8d..ccab63f 100644
54802 --- a/drivers/vfio/vfio.c
54803 +++ b/drivers/vfio/vfio.c
54804 @@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54805 return 0;
54806
54807 /* TODO Prevent device auto probing */
54808 - WARN("Device %s added to live group %d!\n", dev_name(dev),
54809 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54810 iommu_group_id(group->iommu_group));
54811
54812 return 0;
54813 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54814 index 5174eba..451e6bc 100644
54815 --- a/drivers/vhost/vringh.c
54816 +++ b/drivers/vhost/vringh.c
54817 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54818 /* Userspace access helpers: in this case, addresses are really userspace. */
54819 static inline int getu16_user(u16 *val, const u16 *p)
54820 {
54821 - return get_user(*val, (__force u16 __user *)p);
54822 + return get_user(*val, (u16 __force_user *)p);
54823 }
54824
54825 static inline int putu16_user(u16 *p, u16 val)
54826 {
54827 - return put_user(val, (__force u16 __user *)p);
54828 + return put_user(val, (u16 __force_user *)p);
54829 }
54830
54831 static inline int copydesc_user(void *dst, const void *src, size_t len)
54832 {
54833 - return copy_from_user(dst, (__force void __user *)src, len) ?
54834 + return copy_from_user(dst, (void __force_user *)src, len) ?
54835 -EFAULT : 0;
54836 }
54837
54838 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54839 const struct vring_used_elem *src,
54840 unsigned int num)
54841 {
54842 - return copy_to_user((__force void __user *)dst, src,
54843 + return copy_to_user((void __force_user *)dst, src,
54844 sizeof(*dst) * num) ? -EFAULT : 0;
54845 }
54846
54847 static inline int xfer_from_user(void *src, void *dst, size_t len)
54848 {
54849 - return copy_from_user(dst, (__force void __user *)src, len) ?
54850 + return copy_from_user(dst, (void __force_user *)src, len) ?
54851 -EFAULT : 0;
54852 }
54853
54854 static inline int xfer_to_user(void *dst, void *src, size_t len)
54855 {
54856 - return copy_to_user((__force void __user *)dst, src, len) ?
54857 + return copy_to_user((void __force_user *)dst, src, len) ?
54858 -EFAULT : 0;
54859 }
54860
54861 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54862 vrh->last_used_idx = 0;
54863 vrh->vring.num = num;
54864 /* vring expects kernel addresses, but only used via accessors. */
54865 - vrh->vring.desc = (__force struct vring_desc *)desc;
54866 - vrh->vring.avail = (__force struct vring_avail *)avail;
54867 - vrh->vring.used = (__force struct vring_used *)used;
54868 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54869 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54870 + vrh->vring.used = (__force_kernel struct vring_used *)used;
54871 return 0;
54872 }
54873 EXPORT_SYMBOL(vringh_init_user);
54874 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54875
54876 static inline int putu16_kern(u16 *p, u16 val)
54877 {
54878 - ACCESS_ONCE(*p) = val;
54879 + ACCESS_ONCE_RW(*p) = val;
54880 return 0;
54881 }
54882
54883 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54884 index 84a110a..96312c3 100644
54885 --- a/drivers/video/backlight/kb3886_bl.c
54886 +++ b/drivers/video/backlight/kb3886_bl.c
54887 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54888 static unsigned long kb3886bl_flags;
54889 #define KB3886BL_SUSPENDED 0x01
54890
54891 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54892 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54893 {
54894 .ident = "Sahara Touch-iT",
54895 .matches = {
54896 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54897 index 1b0b233..6f34c2c 100644
54898 --- a/drivers/video/fbdev/arcfb.c
54899 +++ b/drivers/video/fbdev/arcfb.c
54900 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54901 return -ENOSPC;
54902
54903 err = 0;
54904 - if ((count + p) > fbmemlength) {
54905 + if (count > (fbmemlength - p)) {
54906 count = fbmemlength - p;
54907 err = -ENOSPC;
54908 }
54909 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54910 index aedf2fb..47c9aca 100644
54911 --- a/drivers/video/fbdev/aty/aty128fb.c
54912 +++ b/drivers/video/fbdev/aty/aty128fb.c
54913 @@ -149,7 +149,7 @@ enum {
54914 };
54915
54916 /* Must match above enum */
54917 -static char * const r128_family[] = {
54918 +static const char * const r128_family[] = {
54919 "AGP",
54920 "PCI",
54921 "PRO AGP",
54922 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54923 index 37ec09b..98f8862 100644
54924 --- a/drivers/video/fbdev/aty/atyfb_base.c
54925 +++ b/drivers/video/fbdev/aty/atyfb_base.c
54926 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54927 par->accel_flags = var->accel_flags; /* hack */
54928
54929 if (var->accel_flags) {
54930 - info->fbops->fb_sync = atyfb_sync;
54931 + pax_open_kernel();
54932 + *(void **)&info->fbops->fb_sync = atyfb_sync;
54933 + pax_close_kernel();
54934 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54935 } else {
54936 - info->fbops->fb_sync = NULL;
54937 + pax_open_kernel();
54938 + *(void **)&info->fbops->fb_sync = NULL;
54939 + pax_close_kernel();
54940 info->flags |= FBINFO_HWACCEL_DISABLED;
54941 }
54942
54943 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54944 index 2fa0317..4983f2a 100644
54945 --- a/drivers/video/fbdev/aty/mach64_cursor.c
54946 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
54947 @@ -8,6 +8,7 @@
54948 #include "../core/fb_draw.h"
54949
54950 #include <asm/io.h>
54951 +#include <asm/pgtable.h>
54952
54953 #ifdef __sparc__
54954 #include <asm/fbio.h>
54955 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54956 info->sprite.buf_align = 16; /* and 64 lines tall. */
54957 info->sprite.flags = FB_PIXMAP_IO;
54958
54959 - info->fbops->fb_cursor = atyfb_cursor;
54960 + pax_open_kernel();
54961 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54962 + pax_close_kernel();
54963
54964 return 0;
54965 }
54966 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54967 index d6cab1f..112f680 100644
54968 --- a/drivers/video/fbdev/core/fb_defio.c
54969 +++ b/drivers/video/fbdev/core/fb_defio.c
54970 @@ -207,7 +207,9 @@ void fb_deferred_io_init(struct fb_info *info)
54971
54972 BUG_ON(!fbdefio);
54973 mutex_init(&fbdefio->lock);
54974 - info->fbops->fb_mmap = fb_deferred_io_mmap;
54975 + pax_open_kernel();
54976 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54977 + pax_close_kernel();
54978 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54979 INIT_LIST_HEAD(&fbdefio->pagelist);
54980 if (fbdefio->delay == 0) /* set a default of 1 s */
54981 @@ -238,7 +240,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54982 page->mapping = NULL;
54983 }
54984
54985 - info->fbops->fb_mmap = NULL;
54986 + *(void **)&info->fbops->fb_mmap = NULL;
54987 mutex_destroy(&fbdefio->lock);
54988 }
54989 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54990 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54991 index 0705d88..d9429bf 100644
54992 --- a/drivers/video/fbdev/core/fbmem.c
54993 +++ b/drivers/video/fbdev/core/fbmem.c
54994 @@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54995 __u32 data;
54996 int err;
54997
54998 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54999 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55000
55001 data = (__u32) (unsigned long) fix->smem_start;
55002 err |= put_user(data, &fix32->smem_start);
55003 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55004 index 4254336..282567e 100644
55005 --- a/drivers/video/fbdev/hyperv_fb.c
55006 +++ b/drivers/video/fbdev/hyperv_fb.c
55007 @@ -240,7 +240,7 @@ static uint screen_fb_size;
55008 static inline int synthvid_send(struct hv_device *hdev,
55009 struct synthvid_msg *msg)
55010 {
55011 - static atomic64_t request_id = ATOMIC64_INIT(0);
55012 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55013 int ret;
55014
55015 msg->pipe_hdr.type = PIPE_MSG_DATA;
55016 @@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55017
55018 ret = vmbus_sendpacket(hdev->channel, msg,
55019 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55020 - atomic64_inc_return(&request_id),
55021 + atomic64_inc_return_unchecked(&request_id),
55022 VM_PKT_DATA_INBAND, 0);
55023
55024 if (ret)
55025 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55026 index 7672d2e..b56437f 100644
55027 --- a/drivers/video/fbdev/i810/i810_accel.c
55028 +++ b/drivers/video/fbdev/i810/i810_accel.c
55029 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55030 }
55031 }
55032 printk("ringbuffer lockup!!!\n");
55033 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55034 i810_report_error(mmio);
55035 par->dev_flags |= LOCKUP;
55036 info->pixmap.scan_align = 1;
55037 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55038 index a01147f..5d896f8 100644
55039 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55040 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55041 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55042
55043 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55044 struct matrox_switch matrox_mystique = {
55045 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55046 + .preinit = MGA1064_preinit,
55047 + .reset = MGA1064_reset,
55048 + .init = MGA1064_init,
55049 + .restore = MGA1064_restore,
55050 };
55051 EXPORT_SYMBOL(matrox_mystique);
55052 #endif
55053
55054 #ifdef CONFIG_FB_MATROX_G
55055 struct matrox_switch matrox_G100 = {
55056 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55057 + .preinit = MGAG100_preinit,
55058 + .reset = MGAG100_reset,
55059 + .init = MGAG100_init,
55060 + .restore = MGAG100_restore,
55061 };
55062 EXPORT_SYMBOL(matrox_G100);
55063 #endif
55064 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55065 index 195ad7c..09743fc 100644
55066 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55067 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55068 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55069 }
55070
55071 struct matrox_switch matrox_millennium = {
55072 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55073 + .preinit = Ti3026_preinit,
55074 + .reset = Ti3026_reset,
55075 + .init = Ti3026_init,
55076 + .restore = Ti3026_restore
55077 };
55078 EXPORT_SYMBOL(matrox_millennium);
55079 #endif
55080 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55081 index fe92eed..106e085 100644
55082 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55083 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55084 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55085 struct mb862xxfb_par *par = info->par;
55086
55087 if (info->var.bits_per_pixel == 32) {
55088 - info->fbops->fb_fillrect = cfb_fillrect;
55089 - info->fbops->fb_copyarea = cfb_copyarea;
55090 - info->fbops->fb_imageblit = cfb_imageblit;
55091 + pax_open_kernel();
55092 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55093 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55094 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55095 + pax_close_kernel();
55096 } else {
55097 outreg(disp, GC_L0EM, 3);
55098 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55099 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55100 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55101 + pax_open_kernel();
55102 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55103 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55104 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55105 + pax_close_kernel();
55106 }
55107 outreg(draw, GDC_REG_DRAW_BASE, 0);
55108 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55109 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55110 index def0412..fed6529 100644
55111 --- a/drivers/video/fbdev/nvidia/nvidia.c
55112 +++ b/drivers/video/fbdev/nvidia/nvidia.c
55113 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55114 info->fix.line_length = (info->var.xres_virtual *
55115 info->var.bits_per_pixel) >> 3;
55116 if (info->var.accel_flags) {
55117 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55118 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55119 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55120 - info->fbops->fb_sync = nvidiafb_sync;
55121 + pax_open_kernel();
55122 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55123 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55124 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55125 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55126 + pax_close_kernel();
55127 info->pixmap.scan_align = 4;
55128 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55129 info->flags |= FBINFO_READS_FAST;
55130 NVResetGraphics(info);
55131 } else {
55132 - info->fbops->fb_imageblit = cfb_imageblit;
55133 - info->fbops->fb_fillrect = cfb_fillrect;
55134 - info->fbops->fb_copyarea = cfb_copyarea;
55135 - info->fbops->fb_sync = NULL;
55136 + pax_open_kernel();
55137 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55138 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55139 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55140 + *(void **)&info->fbops->fb_sync = NULL;
55141 + pax_close_kernel();
55142 info->pixmap.scan_align = 1;
55143 info->flags |= FBINFO_HWACCEL_DISABLED;
55144 info->flags &= ~FBINFO_READS_FAST;
55145 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55146 info->pixmap.size = 8 * 1024;
55147 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55148
55149 - if (!hwcur)
55150 - info->fbops->fb_cursor = NULL;
55151 + if (!hwcur) {
55152 + pax_open_kernel();
55153 + *(void **)&info->fbops->fb_cursor = NULL;
55154 + pax_close_kernel();
55155 + }
55156
55157 info->var.accel_flags = (!noaccel);
55158
55159 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55160 index 2412a0d..294215b 100644
55161 --- a/drivers/video/fbdev/omap2/dss/display.c
55162 +++ b/drivers/video/fbdev/omap2/dss/display.c
55163 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55164 if (dssdev->name == NULL)
55165 dssdev->name = dssdev->alias;
55166
55167 + pax_open_kernel();
55168 if (drv && drv->get_resolution == NULL)
55169 - drv->get_resolution = omapdss_default_get_resolution;
55170 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55171 if (drv && drv->get_recommended_bpp == NULL)
55172 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55173 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55174 if (drv && drv->get_timings == NULL)
55175 - drv->get_timings = omapdss_default_get_timings;
55176 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55177 + pax_close_kernel();
55178
55179 mutex_lock(&panel_list_mutex);
55180 list_add_tail(&dssdev->panel_list, &panel_list);
55181 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55182 index 83433cb..71e9b98 100644
55183 --- a/drivers/video/fbdev/s1d13xxxfb.c
55184 +++ b/drivers/video/fbdev/s1d13xxxfb.c
55185 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55186
55187 switch(prod_id) {
55188 case S1D13506_PROD_ID: /* activate acceleration */
55189 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55190 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55191 + pax_open_kernel();
55192 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55193 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55194 + pax_close_kernel();
55195 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55196 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55197 break;
55198 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55199 index 2bcc84a..29dd1ea 100644
55200 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55201 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55202 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55203 }
55204
55205 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55206 - lcdc_sys_write_index,
55207 - lcdc_sys_write_data,
55208 - lcdc_sys_read_data,
55209 + .write_index = lcdc_sys_write_index,
55210 + .write_data = lcdc_sys_write_data,
55211 + .read_data = lcdc_sys_read_data,
55212 };
55213
55214 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55215 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55216 index d513ed6..90b0de9 100644
55217 --- a/drivers/video/fbdev/smscufx.c
55218 +++ b/drivers/video/fbdev/smscufx.c
55219 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55220 fb_deferred_io_cleanup(info);
55221 kfree(info->fbdefio);
55222 info->fbdefio = NULL;
55223 - info->fbops->fb_mmap = ufx_ops_mmap;
55224 + pax_open_kernel();
55225 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55226 + pax_close_kernel();
55227 }
55228
55229 pr_debug("released /dev/fb%d user=%d count=%d",
55230 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55231 index 046d51d..be564da 100644
55232 --- a/drivers/video/fbdev/udlfb.c
55233 +++ b/drivers/video/fbdev/udlfb.c
55234 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55235 dlfb_urb_completion(urb);
55236
55237 error:
55238 - atomic_add(bytes_sent, &dev->bytes_sent);
55239 - atomic_add(bytes_identical, &dev->bytes_identical);
55240 - atomic_add(width*height*2, &dev->bytes_rendered);
55241 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55242 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55243 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55244 end_cycles = get_cycles();
55245 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55246 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55247 >> 10)), /* Kcycles */
55248 &dev->cpu_kcycles_used);
55249
55250 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55251 dlfb_urb_completion(urb);
55252
55253 error:
55254 - atomic_add(bytes_sent, &dev->bytes_sent);
55255 - atomic_add(bytes_identical, &dev->bytes_identical);
55256 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55257 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55258 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55259 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55260 end_cycles = get_cycles();
55261 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55262 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55263 >> 10)), /* Kcycles */
55264 &dev->cpu_kcycles_used);
55265 }
55266 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55267 fb_deferred_io_cleanup(info);
55268 kfree(info->fbdefio);
55269 info->fbdefio = NULL;
55270 - info->fbops->fb_mmap = dlfb_ops_mmap;
55271 + pax_open_kernel();
55272 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55273 + pax_close_kernel();
55274 }
55275
55276 pr_warn("released /dev/fb%d user=%d count=%d\n",
55277 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55278 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55279 struct dlfb_data *dev = fb_info->par;
55280 return snprintf(buf, PAGE_SIZE, "%u\n",
55281 - atomic_read(&dev->bytes_rendered));
55282 + atomic_read_unchecked(&dev->bytes_rendered));
55283 }
55284
55285 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55286 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55287 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55288 struct dlfb_data *dev = fb_info->par;
55289 return snprintf(buf, PAGE_SIZE, "%u\n",
55290 - atomic_read(&dev->bytes_identical));
55291 + atomic_read_unchecked(&dev->bytes_identical));
55292 }
55293
55294 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55295 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55296 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55297 struct dlfb_data *dev = fb_info->par;
55298 return snprintf(buf, PAGE_SIZE, "%u\n",
55299 - atomic_read(&dev->bytes_sent));
55300 + atomic_read_unchecked(&dev->bytes_sent));
55301 }
55302
55303 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55304 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55305 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55306 struct dlfb_data *dev = fb_info->par;
55307 return snprintf(buf, PAGE_SIZE, "%u\n",
55308 - atomic_read(&dev->cpu_kcycles_used));
55309 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55310 }
55311
55312 static ssize_t edid_show(
55313 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55314 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55315 struct dlfb_data *dev = fb_info->par;
55316
55317 - atomic_set(&dev->bytes_rendered, 0);
55318 - atomic_set(&dev->bytes_identical, 0);
55319 - atomic_set(&dev->bytes_sent, 0);
55320 - atomic_set(&dev->cpu_kcycles_used, 0);
55321 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55322 + atomic_set_unchecked(&dev->bytes_identical, 0);
55323 + atomic_set_unchecked(&dev->bytes_sent, 0);
55324 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55325
55326 return count;
55327 }
55328 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55329 index 509d452..7c9d2de 100644
55330 --- a/drivers/video/fbdev/uvesafb.c
55331 +++ b/drivers/video/fbdev/uvesafb.c
55332 @@ -19,6 +19,7 @@
55333 #include <linux/io.h>
55334 #include <linux/mutex.h>
55335 #include <linux/slab.h>
55336 +#include <linux/moduleloader.h>
55337 #include <video/edid.h>
55338 #include <video/uvesafb.h>
55339 #ifdef CONFIG_X86
55340 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55341 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55342 par->pmi_setpal = par->ypan = 0;
55343 } else {
55344 +
55345 +#ifdef CONFIG_PAX_KERNEXEC
55346 +#ifdef CONFIG_MODULES
55347 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55348 +#endif
55349 + if (!par->pmi_code) {
55350 + par->pmi_setpal = par->ypan = 0;
55351 + return 0;
55352 + }
55353 +#endif
55354 +
55355 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55356 + task->t.regs.edi);
55357 +
55358 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55359 + pax_open_kernel();
55360 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55361 + pax_close_kernel();
55362 +
55363 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55364 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55365 +#else
55366 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55367 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55368 +#endif
55369 +
55370 printk(KERN_INFO "uvesafb: protected mode interface info at "
55371 "%04x:%04x\n",
55372 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55373 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55374 par->ypan = ypan;
55375
55376 if (par->pmi_setpal || par->ypan) {
55377 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55378 if (__supported_pte_mask & _PAGE_NX) {
55379 par->pmi_setpal = par->ypan = 0;
55380 printk(KERN_WARNING "uvesafb: NX protection is active, "
55381 "better not use the PMI.\n");
55382 - } else {
55383 + } else
55384 +#endif
55385 uvesafb_vbe_getpmi(task, par);
55386 - }
55387 }
55388 #else
55389 /* The protected mode interface is not available on non-x86. */
55390 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55391 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55392
55393 /* Disable blanking if the user requested so. */
55394 - if (!blank)
55395 - info->fbops->fb_blank = NULL;
55396 + if (!blank) {
55397 + pax_open_kernel();
55398 + *(void **)&info->fbops->fb_blank = NULL;
55399 + pax_close_kernel();
55400 + }
55401
55402 /*
55403 * Find out how much IO memory is required for the mode with
55404 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55405 info->flags = FBINFO_FLAG_DEFAULT |
55406 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55407
55408 - if (!par->ypan)
55409 - info->fbops->fb_pan_display = NULL;
55410 + if (!par->ypan) {
55411 + pax_open_kernel();
55412 + *(void **)&info->fbops->fb_pan_display = NULL;
55413 + pax_close_kernel();
55414 + }
55415 }
55416
55417 static void uvesafb_init_mtrr(struct fb_info *info)
55418 @@ -1787,6 +1817,11 @@ out_mode:
55419 out:
55420 kfree(par->vbe_modes);
55421
55422 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55423 + if (par->pmi_code)
55424 + module_free_exec(NULL, par->pmi_code);
55425 +#endif
55426 +
55427 framebuffer_release(info);
55428 return err;
55429 }
55430 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55431 kfree(par->vbe_state_orig);
55432 kfree(par->vbe_state_saved);
55433
55434 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55435 + if (par->pmi_code)
55436 + module_free_exec(NULL, par->pmi_code);
55437 +#endif
55438 +
55439 framebuffer_release(info);
55440 }
55441 return 0;
55442 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55443 index 6170e7f..dd63031 100644
55444 --- a/drivers/video/fbdev/vesafb.c
55445 +++ b/drivers/video/fbdev/vesafb.c
55446 @@ -9,6 +9,7 @@
55447 */
55448
55449 #include <linux/module.h>
55450 +#include <linux/moduleloader.h>
55451 #include <linux/kernel.h>
55452 #include <linux/errno.h>
55453 #include <linux/string.h>
55454 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55455 static int vram_total; /* Set total amount of memory */
55456 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55457 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55458 -static void (*pmi_start)(void) __read_mostly;
55459 -static void (*pmi_pal) (void) __read_mostly;
55460 +static void (*pmi_start)(void) __read_only;
55461 +static void (*pmi_pal) (void) __read_only;
55462 static int depth __read_mostly;
55463 static int vga_compat __read_mostly;
55464 /* --------------------------------------------------------------------- */
55465 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55466 unsigned int size_remap;
55467 unsigned int size_total;
55468 char *option = NULL;
55469 + void *pmi_code = NULL;
55470
55471 /* ignore error return of fb_get_options */
55472 fb_get_options("vesafb", &option);
55473 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55474 size_remap = size_total;
55475 vesafb_fix.smem_len = size_remap;
55476
55477 -#ifndef __i386__
55478 - screen_info.vesapm_seg = 0;
55479 -#endif
55480 -
55481 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55482 printk(KERN_WARNING
55483 "vesafb: cannot reserve video memory at 0x%lx\n",
55484 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55485 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55486 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55487
55488 +#ifdef __i386__
55489 +
55490 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55491 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55492 + if (!pmi_code)
55493 +#elif !defined(CONFIG_PAX_KERNEXEC)
55494 + if (0)
55495 +#endif
55496 +
55497 +#endif
55498 + screen_info.vesapm_seg = 0;
55499 +
55500 if (screen_info.vesapm_seg) {
55501 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55502 - screen_info.vesapm_seg,screen_info.vesapm_off);
55503 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55504 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55505 }
55506
55507 if (screen_info.vesapm_seg < 0xc000)
55508 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55509
55510 if (ypan || pmi_setpal) {
55511 unsigned short *pmi_base;
55512 +
55513 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55514 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55515 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55516 +
55517 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55518 + pax_open_kernel();
55519 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55520 +#else
55521 + pmi_code = pmi_base;
55522 +#endif
55523 +
55524 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55525 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55526 +
55527 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55528 + pmi_start = ktva_ktla(pmi_start);
55529 + pmi_pal = ktva_ktla(pmi_pal);
55530 + pax_close_kernel();
55531 +#endif
55532 +
55533 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55534 if (pmi_base[3]) {
55535 printk(KERN_INFO "vesafb: pmi: ports = ");
55536 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55537 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55538 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55539
55540 - if (!ypan)
55541 - info->fbops->fb_pan_display = NULL;
55542 + if (!ypan) {
55543 + pax_open_kernel();
55544 + *(void **)&info->fbops->fb_pan_display = NULL;
55545 + pax_close_kernel();
55546 + }
55547
55548 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55549 err = -ENOMEM;
55550 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55551 fb_info(info, "%s frame buffer device\n", info->fix.id);
55552 return 0;
55553 err:
55554 +
55555 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55556 + module_free_exec(NULL, pmi_code);
55557 +#endif
55558 +
55559 if (info->screen_base)
55560 iounmap(info->screen_base);
55561 framebuffer_release(info);
55562 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55563 index 88714ae..16c2e11 100644
55564 --- a/drivers/video/fbdev/via/via_clock.h
55565 +++ b/drivers/video/fbdev/via/via_clock.h
55566 @@ -56,7 +56,7 @@ struct via_clock {
55567
55568 void (*set_engine_pll_state)(u8 state);
55569 void (*set_engine_pll)(struct via_pll_config config);
55570 -};
55571 +} __no_const;
55572
55573
55574 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55575 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55576 index 3c14e43..2630570 100644
55577 --- a/drivers/video/logo/logo_linux_clut224.ppm
55578 +++ b/drivers/video/logo/logo_linux_clut224.ppm
55579 @@ -2,1603 +2,1123 @@ P3
55580 # Standard 224-color Linux logo
55581 80 80
55582 255
55583 - 0 0 0 0 0 0 0 0 0 0 0 0
55584 - 0 0 0 0 0 0 0 0 0 0 0 0
55585 - 0 0 0 0 0 0 0 0 0 0 0 0
55586 - 0 0 0 0 0 0 0 0 0 0 0 0
55587 - 0 0 0 0 0 0 0 0 0 0 0 0
55588 - 0 0 0 0 0 0 0 0 0 0 0 0
55589 - 0 0 0 0 0 0 0 0 0 0 0 0
55590 - 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 - 6 6 6 6 6 6 10 10 10 10 10 10
55593 - 10 10 10 6 6 6 6 6 6 6 6 6
55594 - 0 0 0 0 0 0 0 0 0 0 0 0
55595 - 0 0 0 0 0 0 0 0 0 0 0 0
55596 - 0 0 0 0 0 0 0 0 0 0 0 0
55597 - 0 0 0 0 0 0 0 0 0 0 0 0
55598 - 0 0 0 0 0 0 0 0 0 0 0 0
55599 - 0 0 0 0 0 0 0 0 0 0 0 0
55600 - 0 0 0 0 0 0 0 0 0 0 0 0
55601 - 0 0 0 0 0 0 0 0 0 0 0 0
55602 - 0 0 0 0 0 0 0 0 0 0 0 0
55603 - 0 0 0 0 0 0 0 0 0 0 0 0
55604 - 0 0 0 0 0 0 0 0 0 0 0 0
55605 - 0 0 0 0 0 0 0 0 0 0 0 0
55606 - 0 0 0 0 0 0 0 0 0 0 0 0
55607 - 0 0 0 0 0 0 0 0 0 0 0 0
55608 - 0 0 0 0 0 0 0 0 0 0 0 0
55609 - 0 0 0 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 6 6 6 10 10 10 14 14 14
55612 - 22 22 22 26 26 26 30 30 30 34 34 34
55613 - 30 30 30 30 30 30 26 26 26 18 18 18
55614 - 14 14 14 10 10 10 6 6 6 0 0 0
55615 - 0 0 0 0 0 0 0 0 0 0 0 0
55616 - 0 0 0 0 0 0 0 0 0 0 0 0
55617 - 0 0 0 0 0 0 0 0 0 0 0 0
55618 - 0 0 0 0 0 0 0 0 0 0 0 0
55619 - 0 0 0 0 0 0 0 0 0 0 0 0
55620 - 0 0 0 0 0 0 0 0 0 0 0 0
55621 - 0 0 0 0 0 0 0 0 0 0 0 0
55622 - 0 0 0 0 0 0 0 0 0 0 0 0
55623 - 0 0 0 0 0 0 0 0 0 0 0 0
55624 - 0 0 0 0 0 1 0 0 1 0 0 0
55625 - 0 0 0 0 0 0 0 0 0 0 0 0
55626 - 0 0 0 0 0 0 0 0 0 0 0 0
55627 - 0 0 0 0 0 0 0 0 0 0 0 0
55628 - 0 0 0 0 0 0 0 0 0 0 0 0
55629 - 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 - 6 6 6 14 14 14 26 26 26 42 42 42
55632 - 54 54 54 66 66 66 78 78 78 78 78 78
55633 - 78 78 78 74 74 74 66 66 66 54 54 54
55634 - 42 42 42 26 26 26 18 18 18 10 10 10
55635 - 6 6 6 0 0 0 0 0 0 0 0 0
55636 - 0 0 0 0 0 0 0 0 0 0 0 0
55637 - 0 0 0 0 0 0 0 0 0 0 0 0
55638 - 0 0 0 0 0 0 0 0 0 0 0 0
55639 - 0 0 0 0 0 0 0 0 0 0 0 0
55640 - 0 0 0 0 0 0 0 0 0 0 0 0
55641 - 0 0 0 0 0 0 0 0 0 0 0 0
55642 - 0 0 0 0 0 0 0 0 0 0 0 0
55643 - 0 0 0 0 0 0 0 0 0 0 0 0
55644 - 0 0 1 0 0 0 0 0 0 0 0 0
55645 - 0 0 0 0 0 0 0 0 0 0 0 0
55646 - 0 0 0 0 0 0 0 0 0 0 0 0
55647 - 0 0 0 0 0 0 0 0 0 0 0 0
55648 - 0 0 0 0 0 0 0 0 0 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 10 10 10
55651 - 22 22 22 42 42 42 66 66 66 86 86 86
55652 - 66 66 66 38 38 38 38 38 38 22 22 22
55653 - 26 26 26 34 34 34 54 54 54 66 66 66
55654 - 86 86 86 70 70 70 46 46 46 26 26 26
55655 - 14 14 14 6 6 6 0 0 0 0 0 0
55656 - 0 0 0 0 0 0 0 0 0 0 0 0
55657 - 0 0 0 0 0 0 0 0 0 0 0 0
55658 - 0 0 0 0 0 0 0 0 0 0 0 0
55659 - 0 0 0 0 0 0 0 0 0 0 0 0
55660 - 0 0 0 0 0 0 0 0 0 0 0 0
55661 - 0 0 0 0 0 0 0 0 0 0 0 0
55662 - 0 0 0 0 0 0 0 0 0 0 0 0
55663 - 0 0 0 0 0 0 0 0 0 0 0 0
55664 - 0 0 1 0 0 1 0 0 1 0 0 0
55665 - 0 0 0 0 0 0 0 0 0 0 0 0
55666 - 0 0 0 0 0 0 0 0 0 0 0 0
55667 - 0 0 0 0 0 0 0 0 0 0 0 0
55668 - 0 0 0 0 0 0 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 10 10 10 26 26 26
55671 - 50 50 50 82 82 82 58 58 58 6 6 6
55672 - 2 2 6 2 2 6 2 2 6 2 2 6
55673 - 2 2 6 2 2 6 2 2 6 2 2 6
55674 - 6 6 6 54 54 54 86 86 86 66 66 66
55675 - 38 38 38 18 18 18 6 6 6 0 0 0
55676 - 0 0 0 0 0 0 0 0 0 0 0 0
55677 - 0 0 0 0 0 0 0 0 0 0 0 0
55678 - 0 0 0 0 0 0 0 0 0 0 0 0
55679 - 0 0 0 0 0 0 0 0 0 0 0 0
55680 - 0 0 0 0 0 0 0 0 0 0 0 0
55681 - 0 0 0 0 0 0 0 0 0 0 0 0
55682 - 0 0 0 0 0 0 0 0 0 0 0 0
55683 - 0 0 0 0 0 0 0 0 0 0 0 0
55684 - 0 0 0 0 0 0 0 0 0 0 0 0
55685 - 0 0 0 0 0 0 0 0 0 0 0 0
55686 - 0 0 0 0 0 0 0 0 0 0 0 0
55687 - 0 0 0 0 0 0 0 0 0 0 0 0
55688 - 0 0 0 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 6 6 6 22 22 22 50 50 50
55691 - 78 78 78 34 34 34 2 2 6 2 2 6
55692 - 2 2 6 2 2 6 2 2 6 2 2 6
55693 - 2 2 6 2 2 6 2 2 6 2 2 6
55694 - 2 2 6 2 2 6 6 6 6 70 70 70
55695 - 78 78 78 46 46 46 22 22 22 6 6 6
55696 - 0 0 0 0 0 0 0 0 0 0 0 0
55697 - 0 0 0 0 0 0 0 0 0 0 0 0
55698 - 0 0 0 0 0 0 0 0 0 0 0 0
55699 - 0 0 0 0 0 0 0 0 0 0 0 0
55700 - 0 0 0 0 0 0 0 0 0 0 0 0
55701 - 0 0 0 0 0 0 0 0 0 0 0 0
55702 - 0 0 0 0 0 0 0 0 0 0 0 0
55703 - 0 0 0 0 0 0 0 0 0 0 0 0
55704 - 0 0 1 0 0 1 0 0 1 0 0 0
55705 - 0 0 0 0 0 0 0 0 0 0 0 0
55706 - 0 0 0 0 0 0 0 0 0 0 0 0
55707 - 0 0 0 0 0 0 0 0 0 0 0 0
55708 - 0 0 0 0 0 0 0 0 0 0 0 0
55709 - 0 0 0 0 0 0 0 0 0 0 0 0
55710 - 6 6 6 18 18 18 42 42 42 82 82 82
55711 - 26 26 26 2 2 6 2 2 6 2 2 6
55712 - 2 2 6 2 2 6 2 2 6 2 2 6
55713 - 2 2 6 2 2 6 2 2 6 14 14 14
55714 - 46 46 46 34 34 34 6 6 6 2 2 6
55715 - 42 42 42 78 78 78 42 42 42 18 18 18
55716 - 6 6 6 0 0 0 0 0 0 0 0 0
55717 - 0 0 0 0 0 0 0 0 0 0 0 0
55718 - 0 0 0 0 0 0 0 0 0 0 0 0
55719 - 0 0 0 0 0 0 0 0 0 0 0 0
55720 - 0 0 0 0 0 0 0 0 0 0 0 0
55721 - 0 0 0 0 0 0 0 0 0 0 0 0
55722 - 0 0 0 0 0 0 0 0 0 0 0 0
55723 - 0 0 0 0 0 0 0 0 0 0 0 0
55724 - 0 0 1 0 0 0 0 0 1 0 0 0
55725 - 0 0 0 0 0 0 0 0 0 0 0 0
55726 - 0 0 0 0 0 0 0 0 0 0 0 0
55727 - 0 0 0 0 0 0 0 0 0 0 0 0
55728 - 0 0 0 0 0 0 0 0 0 0 0 0
55729 - 0 0 0 0 0 0 0 0 0 0 0 0
55730 - 10 10 10 30 30 30 66 66 66 58 58 58
55731 - 2 2 6 2 2 6 2 2 6 2 2 6
55732 - 2 2 6 2 2 6 2 2 6 2 2 6
55733 - 2 2 6 2 2 6 2 2 6 26 26 26
55734 - 86 86 86 101 101 101 46 46 46 10 10 10
55735 - 2 2 6 58 58 58 70 70 70 34 34 34
55736 - 10 10 10 0 0 0 0 0 0 0 0 0
55737 - 0 0 0 0 0 0 0 0 0 0 0 0
55738 - 0 0 0 0 0 0 0 0 0 0 0 0
55739 - 0 0 0 0 0 0 0 0 0 0 0 0
55740 - 0 0 0 0 0 0 0 0 0 0 0 0
55741 - 0 0 0 0 0 0 0 0 0 0 0 0
55742 - 0 0 0 0 0 0 0 0 0 0 0 0
55743 - 0 0 0 0 0 0 0 0 0 0 0 0
55744 - 0 0 1 0 0 1 0 0 1 0 0 0
55745 - 0 0 0 0 0 0 0 0 0 0 0 0
55746 - 0 0 0 0 0 0 0 0 0 0 0 0
55747 - 0 0 0 0 0 0 0 0 0 0 0 0
55748 - 0 0 0 0 0 0 0 0 0 0 0 0
55749 - 0 0 0 0 0 0 0 0 0 0 0 0
55750 - 14 14 14 42 42 42 86 86 86 10 10 10
55751 - 2 2 6 2 2 6 2 2 6 2 2 6
55752 - 2 2 6 2 2 6 2 2 6 2 2 6
55753 - 2 2 6 2 2 6 2 2 6 30 30 30
55754 - 94 94 94 94 94 94 58 58 58 26 26 26
55755 - 2 2 6 6 6 6 78 78 78 54 54 54
55756 - 22 22 22 6 6 6 0 0 0 0 0 0
55757 - 0 0 0 0 0 0 0 0 0 0 0 0
55758 - 0 0 0 0 0 0 0 0 0 0 0 0
55759 - 0 0 0 0 0 0 0 0 0 0 0 0
55760 - 0 0 0 0 0 0 0 0 0 0 0 0
55761 - 0 0 0 0 0 0 0 0 0 0 0 0
55762 - 0 0 0 0 0 0 0 0 0 0 0 0
55763 - 0 0 0 0 0 0 0 0 0 0 0 0
55764 - 0 0 0 0 0 0 0 0 0 0 0 0
55765 - 0 0 0 0 0 0 0 0 0 0 0 0
55766 - 0 0 0 0 0 0 0 0 0 0 0 0
55767 - 0 0 0 0 0 0 0 0 0 0 0 0
55768 - 0 0 0 0 0 0 0 0 0 0 0 0
55769 - 0 0 0 0 0 0 0 0 0 6 6 6
55770 - 22 22 22 62 62 62 62 62 62 2 2 6
55771 - 2 2 6 2 2 6 2 2 6 2 2 6
55772 - 2 2 6 2 2 6 2 2 6 2 2 6
55773 - 2 2 6 2 2 6 2 2 6 26 26 26
55774 - 54 54 54 38 38 38 18 18 18 10 10 10
55775 - 2 2 6 2 2 6 34 34 34 82 82 82
55776 - 38 38 38 14 14 14 0 0 0 0 0 0
55777 - 0 0 0 0 0 0 0 0 0 0 0 0
55778 - 0 0 0 0 0 0 0 0 0 0 0 0
55779 - 0 0 0 0 0 0 0 0 0 0 0 0
55780 - 0 0 0 0 0 0 0 0 0 0 0 0
55781 - 0 0 0 0 0 0 0 0 0 0 0 0
55782 - 0 0 0 0 0 0 0 0 0 0 0 0
55783 - 0 0 0 0 0 0 0 0 0 0 0 0
55784 - 0 0 0 0 0 1 0 0 1 0 0 0
55785 - 0 0 0 0 0 0 0 0 0 0 0 0
55786 - 0 0 0 0 0 0 0 0 0 0 0 0
55787 - 0 0 0 0 0 0 0 0 0 0 0 0
55788 - 0 0 0 0 0 0 0 0 0 0 0 0
55789 - 0 0 0 0 0 0 0 0 0 6 6 6
55790 - 30 30 30 78 78 78 30 30 30 2 2 6
55791 - 2 2 6 2 2 6 2 2 6 2 2 6
55792 - 2 2 6 2 2 6 2 2 6 2 2 6
55793 - 2 2 6 2 2 6 2 2 6 10 10 10
55794 - 10 10 10 2 2 6 2 2 6 2 2 6
55795 - 2 2 6 2 2 6 2 2 6 78 78 78
55796 - 50 50 50 18 18 18 6 6 6 0 0 0
55797 - 0 0 0 0 0 0 0 0 0 0 0 0
55798 - 0 0 0 0 0 0 0 0 0 0 0 0
55799 - 0 0 0 0 0 0 0 0 0 0 0 0
55800 - 0 0 0 0 0 0 0 0 0 0 0 0
55801 - 0 0 0 0 0 0 0 0 0 0 0 0
55802 - 0 0 0 0 0 0 0 0 0 0 0 0
55803 - 0 0 0 0 0 0 0 0 0 0 0 0
55804 - 0 0 1 0 0 0 0 0 0 0 0 0
55805 - 0 0 0 0 0 0 0 0 0 0 0 0
55806 - 0 0 0 0 0 0 0 0 0 0 0 0
55807 - 0 0 0 0 0 0 0 0 0 0 0 0
55808 - 0 0 0 0 0 0 0 0 0 0 0 0
55809 - 0 0 0 0 0 0 0 0 0 10 10 10
55810 - 38 38 38 86 86 86 14 14 14 2 2 6
55811 - 2 2 6 2 2 6 2 2 6 2 2 6
55812 - 2 2 6 2 2 6 2 2 6 2 2 6
55813 - 2 2 6 2 2 6 2 2 6 2 2 6
55814 - 2 2 6 2 2 6 2 2 6 2 2 6
55815 - 2 2 6 2 2 6 2 2 6 54 54 54
55816 - 66 66 66 26 26 26 6 6 6 0 0 0
55817 - 0 0 0 0 0 0 0 0 0 0 0 0
55818 - 0 0 0 0 0 0 0 0 0 0 0 0
55819 - 0 0 0 0 0 0 0 0 0 0 0 0
55820 - 0 0 0 0 0 0 0 0 0 0 0 0
55821 - 0 0 0 0 0 0 0 0 0 0 0 0
55822 - 0 0 0 0 0 0 0 0 0 0 0 0
55823 - 0 0 0 0 0 0 0 0 0 0 0 0
55824 - 0 0 0 0 0 1 0 0 1 0 0 0
55825 - 0 0 0 0 0 0 0 0 0 0 0 0
55826 - 0 0 0 0 0 0 0 0 0 0 0 0
55827 - 0 0 0 0 0 0 0 0 0 0 0 0
55828 - 0 0 0 0 0 0 0 0 0 0 0 0
55829 - 0 0 0 0 0 0 0 0 0 14 14 14
55830 - 42 42 42 82 82 82 2 2 6 2 2 6
55831 - 2 2 6 6 6 6 10 10 10 2 2 6
55832 - 2 2 6 2 2 6 2 2 6 2 2 6
55833 - 2 2 6 2 2 6 2 2 6 6 6 6
55834 - 14 14 14 10 10 10 2 2 6 2 2 6
55835 - 2 2 6 2 2 6 2 2 6 18 18 18
55836 - 82 82 82 34 34 34 10 10 10 0 0 0
55837 - 0 0 0 0 0 0 0 0 0 0 0 0
55838 - 0 0 0 0 0 0 0 0 0 0 0 0
55839 - 0 0 0 0 0 0 0 0 0 0 0 0
55840 - 0 0 0 0 0 0 0 0 0 0 0 0
55841 - 0 0 0 0 0 0 0 0 0 0 0 0
55842 - 0 0 0 0 0 0 0 0 0 0 0 0
55843 - 0 0 0 0 0 0 0 0 0 0 0 0
55844 - 0 0 1 0 0 0 0 0 0 0 0 0
55845 - 0 0 0 0 0 0 0 0 0 0 0 0
55846 - 0 0 0 0 0 0 0 0 0 0 0 0
55847 - 0 0 0 0 0 0 0 0 0 0 0 0
55848 - 0 0 0 0 0 0 0 0 0 0 0 0
55849 - 0 0 0 0 0 0 0 0 0 14 14 14
55850 - 46 46 46 86 86 86 2 2 6 2 2 6
55851 - 6 6 6 6 6 6 22 22 22 34 34 34
55852 - 6 6 6 2 2 6 2 2 6 2 2 6
55853 - 2 2 6 2 2 6 18 18 18 34 34 34
55854 - 10 10 10 50 50 50 22 22 22 2 2 6
55855 - 2 2 6 2 2 6 2 2 6 10 10 10
55856 - 86 86 86 42 42 42 14 14 14 0 0 0
55857 - 0 0 0 0 0 0 0 0 0 0 0 0
55858 - 0 0 0 0 0 0 0 0 0 0 0 0
55859 - 0 0 0 0 0 0 0 0 0 0 0 0
55860 - 0 0 0 0 0 0 0 0 0 0 0 0
55861 - 0 0 0 0 0 0 0 0 0 0 0 0
55862 - 0 0 0 0 0 0 0 0 0 0 0 0
55863 - 0 0 0 0 0 0 0 0 0 0 0 0
55864 - 0 0 1 0 0 1 0 0 1 0 0 0
55865 - 0 0 0 0 0 0 0 0 0 0 0 0
55866 - 0 0 0 0 0 0 0 0 0 0 0 0
55867 - 0 0 0 0 0 0 0 0 0 0 0 0
55868 - 0 0 0 0 0 0 0 0 0 0 0 0
55869 - 0 0 0 0 0 0 0 0 0 14 14 14
55870 - 46 46 46 86 86 86 2 2 6 2 2 6
55871 - 38 38 38 116 116 116 94 94 94 22 22 22
55872 - 22 22 22 2 2 6 2 2 6 2 2 6
55873 - 14 14 14 86 86 86 138 138 138 162 162 162
55874 -154 154 154 38 38 38 26 26 26 6 6 6
55875 - 2 2 6 2 2 6 2 2 6 2 2 6
55876 - 86 86 86 46 46 46 14 14 14 0 0 0
55877 - 0 0 0 0 0 0 0 0 0 0 0 0
55878 - 0 0 0 0 0 0 0 0 0 0 0 0
55879 - 0 0 0 0 0 0 0 0 0 0 0 0
55880 - 0 0 0 0 0 0 0 0 0 0 0 0
55881 - 0 0 0 0 0 0 0 0 0 0 0 0
55882 - 0 0 0 0 0 0 0 0 0 0 0 0
55883 - 0 0 0 0 0 0 0 0 0 0 0 0
55884 - 0 0 0 0 0 0 0 0 0 0 0 0
55885 - 0 0 0 0 0 0 0 0 0 0 0 0
55886 - 0 0 0 0 0 0 0 0 0 0 0 0
55887 - 0 0 0 0 0 0 0 0 0 0 0 0
55888 - 0 0 0 0 0 0 0 0 0 0 0 0
55889 - 0 0 0 0 0 0 0 0 0 14 14 14
55890 - 46 46 46 86 86 86 2 2 6 14 14 14
55891 -134 134 134 198 198 198 195 195 195 116 116 116
55892 - 10 10 10 2 2 6 2 2 6 6 6 6
55893 -101 98 89 187 187 187 210 210 210 218 218 218
55894 -214 214 214 134 134 134 14 14 14 6 6 6
55895 - 2 2 6 2 2 6 2 2 6 2 2 6
55896 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
55902 - 0 0 0 0 0 0 0 0 0 0 0 0
55903 - 0 0 0 0 0 0 0 0 1 0 0 0
55904 - 0 0 1 0 0 1 0 0 1 0 0 0
55905 - 0 0 0 0 0 0 0 0 0 0 0 0
55906 - 0 0 0 0 0 0 0 0 0 0 0 0
55907 - 0 0 0 0 0 0 0 0 0 0 0 0
55908 - 0 0 0 0 0 0 0 0 0 0 0 0
55909 - 0 0 0 0 0 0 0 0 0 14 14 14
55910 - 46 46 46 86 86 86 2 2 6 54 54 54
55911 -218 218 218 195 195 195 226 226 226 246 246 246
55912 - 58 58 58 2 2 6 2 2 6 30 30 30
55913 -210 210 210 253 253 253 174 174 174 123 123 123
55914 -221 221 221 234 234 234 74 74 74 2 2 6
55915 - 2 2 6 2 2 6 2 2 6 2 2 6
55916 - 70 70 70 58 58 58 22 22 22 6 6 6
55917 - 0 0 0 0 0 0 0 0 0 0 0 0
55918 - 0 0 0 0 0 0 0 0 0 0 0 0
55919 - 0 0 0 0 0 0 0 0 0 0 0 0
55920 - 0 0 0 0 0 0 0 0 0 0 0 0
55921 - 0 0 0 0 0 0 0 0 0 0 0 0
55922 - 0 0 0 0 0 0 0 0 0 0 0 0
55923 - 0 0 0 0 0 0 0 0 0 0 0 0
55924 - 0 0 0 0 0 0 0 0 0 0 0 0
55925 - 0 0 0 0 0 0 0 0 0 0 0 0
55926 - 0 0 0 0 0 0 0 0 0 0 0 0
55927 - 0 0 0 0 0 0 0 0 0 0 0 0
55928 - 0 0 0 0 0 0 0 0 0 0 0 0
55929 - 0 0 0 0 0 0 0 0 0 14 14 14
55930 - 46 46 46 82 82 82 2 2 6 106 106 106
55931 -170 170 170 26 26 26 86 86 86 226 226 226
55932 -123 123 123 10 10 10 14 14 14 46 46 46
55933 -231 231 231 190 190 190 6 6 6 70 70 70
55934 - 90 90 90 238 238 238 158 158 158 2 2 6
55935 - 2 2 6 2 2 6 2 2 6 2 2 6
55936 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
55942 - 0 0 0 0 0 0 0 0 0 0 0 0
55943 - 0 0 0 0 0 0 0 0 1 0 0 0
55944 - 0 0 1 0 0 1 0 0 1 0 0 0
55945 - 0 0 0 0 0 0 0 0 0 0 0 0
55946 - 0 0 0 0 0 0 0 0 0 0 0 0
55947 - 0 0 0 0 0 0 0 0 0 0 0 0
55948 - 0 0 0 0 0 0 0 0 0 0 0 0
55949 - 0 0 0 0 0 0 0 0 0 14 14 14
55950 - 42 42 42 86 86 86 6 6 6 116 116 116
55951 -106 106 106 6 6 6 70 70 70 149 149 149
55952 -128 128 128 18 18 18 38 38 38 54 54 54
55953 -221 221 221 106 106 106 2 2 6 14 14 14
55954 - 46 46 46 190 190 190 198 198 198 2 2 6
55955 - 2 2 6 2 2 6 2 2 6 2 2 6
55956 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
55962 - 0 0 0 0 0 0 0 0 0 0 0 0
55963 - 0 0 0 0 0 0 0 0 1 0 0 0
55964 - 0 0 1 0 0 0 0 0 1 0 0 0
55965 - 0 0 0 0 0 0 0 0 0 0 0 0
55966 - 0 0 0 0 0 0 0 0 0 0 0 0
55967 - 0 0 0 0 0 0 0 0 0 0 0 0
55968 - 0 0 0 0 0 0 0 0 0 0 0 0
55969 - 0 0 0 0 0 0 0 0 0 14 14 14
55970 - 42 42 42 94 94 94 14 14 14 101 101 101
55971 -128 128 128 2 2 6 18 18 18 116 116 116
55972 -118 98 46 121 92 8 121 92 8 98 78 10
55973 -162 162 162 106 106 106 2 2 6 2 2 6
55974 - 2 2 6 195 195 195 195 195 195 6 6 6
55975 - 2 2 6 2 2 6 2 2 6 2 2 6
55976 - 74 74 74 62 62 62 22 22 22 6 6 6
55977 - 0 0 0 0 0 0 0 0 0 0 0 0
55978 - 0 0 0 0 0 0 0 0 0 0 0 0
55979 - 0 0 0 0 0 0 0 0 0 0 0 0
55980 - 0 0 0 0 0 0 0 0 0 0 0 0
55981 - 0 0 0 0 0 0 0 0 0 0 0 0
55982 - 0 0 0 0 0 0 0 0 0 0 0 0
55983 - 0 0 0 0 0 0 0 0 1 0 0 1
55984 - 0 0 1 0 0 0 0 0 1 0 0 0
55985 - 0 0 0 0 0 0 0 0 0 0 0 0
55986 - 0 0 0 0 0 0 0 0 0 0 0 0
55987 - 0 0 0 0 0 0 0 0 0 0 0 0
55988 - 0 0 0 0 0 0 0 0 0 0 0 0
55989 - 0 0 0 0 0 0 0 0 0 10 10 10
55990 - 38 38 38 90 90 90 14 14 14 58 58 58
55991 -210 210 210 26 26 26 54 38 6 154 114 10
55992 -226 170 11 236 186 11 225 175 15 184 144 12
55993 -215 174 15 175 146 61 37 26 9 2 2 6
55994 - 70 70 70 246 246 246 138 138 138 2 2 6
55995 - 2 2 6 2 2 6 2 2 6 2 2 6
55996 - 70 70 70 66 66 66 26 26 26 6 6 6
55997 - 0 0 0 0 0 0 0 0 0 0 0 0
55998 - 0 0 0 0 0 0 0 0 0 0 0 0
55999 - 0 0 0 0 0 0 0 0 0 0 0 0
56000 - 0 0 0 0 0 0 0 0 0 0 0 0
56001 - 0 0 0 0 0 0 0 0 0 0 0 0
56002 - 0 0 0 0 0 0 0 0 0 0 0 0
56003 - 0 0 0 0 0 0 0 0 0 0 0 0
56004 - 0 0 0 0 0 0 0 0 0 0 0 0
56005 - 0 0 0 0 0 0 0 0 0 0 0 0
56006 - 0 0 0 0 0 0 0 0 0 0 0 0
56007 - 0 0 0 0 0 0 0 0 0 0 0 0
56008 - 0 0 0 0 0 0 0 0 0 0 0 0
56009 - 0 0 0 0 0 0 0 0 0 10 10 10
56010 - 38 38 38 86 86 86 14 14 14 10 10 10
56011 -195 195 195 188 164 115 192 133 9 225 175 15
56012 -239 182 13 234 190 10 232 195 16 232 200 30
56013 -245 207 45 241 208 19 232 195 16 184 144 12
56014 -218 194 134 211 206 186 42 42 42 2 2 6
56015 - 2 2 6 2 2 6 2 2 6 2 2 6
56016 - 50 50 50 74 74 74 30 30 30 6 6 6
56017 - 0 0 0 0 0 0 0 0 0 0 0 0
56018 - 0 0 0 0 0 0 0 0 0 0 0 0
56019 - 0 0 0 0 0 0 0 0 0 0 0 0
56020 - 0 0 0 0 0 0 0 0 0 0 0 0
56021 - 0 0 0 0 0 0 0 0 0 0 0 0
56022 - 0 0 0 0 0 0 0 0 0 0 0 0
56023 - 0 0 0 0 0 0 0 0 0 0 0 0
56024 - 0 0 0 0 0 0 0 0 0 0 0 0
56025 - 0 0 0 0 0 0 0 0 0 0 0 0
56026 - 0 0 0 0 0 0 0 0 0 0 0 0
56027 - 0 0 0 0 0 0 0 0 0 0 0 0
56028 - 0 0 0 0 0 0 0 0 0 0 0 0
56029 - 0 0 0 0 0 0 0 0 0 10 10 10
56030 - 34 34 34 86 86 86 14 14 14 2 2 6
56031 -121 87 25 192 133 9 219 162 10 239 182 13
56032 -236 186 11 232 195 16 241 208 19 244 214 54
56033 -246 218 60 246 218 38 246 215 20 241 208 19
56034 -241 208 19 226 184 13 121 87 25 2 2 6
56035 - 2 2 6 2 2 6 2 2 6 2 2 6
56036 - 50 50 50 82 82 82 34 34 34 10 10 10
56037 - 0 0 0 0 0 0 0 0 0 0 0 0
56038 - 0 0 0 0 0 0 0 0 0 0 0 0
56039 - 0 0 0 0 0 0 0 0 0 0 0 0
56040 - 0 0 0 0 0 0 0 0 0 0 0 0
56041 - 0 0 0 0 0 0 0 0 0 0 0 0
56042 - 0 0 0 0 0 0 0 0 0 0 0 0
56043 - 0 0 0 0 0 0 0 0 0 0 0 0
56044 - 0 0 0 0 0 0 0 0 0 0 0 0
56045 - 0 0 0 0 0 0 0 0 0 0 0 0
56046 - 0 0 0 0 0 0 0 0 0 0 0 0
56047 - 0 0 0 0 0 0 0 0 0 0 0 0
56048 - 0 0 0 0 0 0 0 0 0 0 0 0
56049 - 0 0 0 0 0 0 0 0 0 10 10 10
56050 - 34 34 34 82 82 82 30 30 30 61 42 6
56051 -180 123 7 206 145 10 230 174 11 239 182 13
56052 -234 190 10 238 202 15 241 208 19 246 218 74
56053 -246 218 38 246 215 20 246 215 20 246 215 20
56054 -226 184 13 215 174 15 184 144 12 6 6 6
56055 - 2 2 6 2 2 6 2 2 6 2 2 6
56056 - 26 26 26 94 94 94 42 42 42 14 14 14
56057 - 0 0 0 0 0 0 0 0 0 0 0 0
56058 - 0 0 0 0 0 0 0 0 0 0 0 0
56059 - 0 0 0 0 0 0 0 0 0 0 0 0
56060 - 0 0 0 0 0 0 0 0 0 0 0 0
56061 - 0 0 0 0 0 0 0 0 0 0 0 0
56062 - 0 0 0 0 0 0 0 0 0 0 0 0
56063 - 0 0 0 0 0 0 0 0 0 0 0 0
56064 - 0 0 0 0 0 0 0 0 0 0 0 0
56065 - 0 0 0 0 0 0 0 0 0 0 0 0
56066 - 0 0 0 0 0 0 0 0 0 0 0 0
56067 - 0 0 0 0 0 0 0 0 0 0 0 0
56068 - 0 0 0 0 0 0 0 0 0 0 0 0
56069 - 0 0 0 0 0 0 0 0 0 10 10 10
56070 - 30 30 30 78 78 78 50 50 50 104 69 6
56071 -192 133 9 216 158 10 236 178 12 236 186 11
56072 -232 195 16 241 208 19 244 214 54 245 215 43
56073 -246 215 20 246 215 20 241 208 19 198 155 10
56074 -200 144 11 216 158 10 156 118 10 2 2 6
56075 - 2 2 6 2 2 6 2 2 6 2 2 6
56076 - 6 6 6 90 90 90 54 54 54 18 18 18
56077 - 6 6 6 0 0 0 0 0 0 0 0 0
56078 - 0 0 0 0 0 0 0 0 0 0 0 0
56079 - 0 0 0 0 0 0 0 0 0 0 0 0
56080 - 0 0 0 0 0 0 0 0 0 0 0 0
56081 - 0 0 0 0 0 0 0 0 0 0 0 0
56082 - 0 0 0 0 0 0 0 0 0 0 0 0
56083 - 0 0 0 0 0 0 0 0 0 0 0 0
56084 - 0 0 0 0 0 0 0 0 0 0 0 0
56085 - 0 0 0 0 0 0 0 0 0 0 0 0
56086 - 0 0 0 0 0 0 0 0 0 0 0 0
56087 - 0 0 0 0 0 0 0 0 0 0 0 0
56088 - 0 0 0 0 0 0 0 0 0 0 0 0
56089 - 0 0 0 0 0 0 0 0 0 10 10 10
56090 - 30 30 30 78 78 78 46 46 46 22 22 22
56091 -137 92 6 210 162 10 239 182 13 238 190 10
56092 -238 202 15 241 208 19 246 215 20 246 215 20
56093 -241 208 19 203 166 17 185 133 11 210 150 10
56094 -216 158 10 210 150 10 102 78 10 2 2 6
56095 - 6 6 6 54 54 54 14 14 14 2 2 6
56096 - 2 2 6 62 62 62 74 74 74 30 30 30
56097 - 10 10 10 0 0 0 0 0 0 0 0 0
56098 - 0 0 0 0 0 0 0 0 0 0 0 0
56099 - 0 0 0 0 0 0 0 0 0 0 0 0
56100 - 0 0 0 0 0 0 0 0 0 0 0 0
56101 - 0 0 0 0 0 0 0 0 0 0 0 0
56102 - 0 0 0 0 0 0 0 0 0 0 0 0
56103 - 0 0 0 0 0 0 0 0 0 0 0 0
56104 - 0 0 0 0 0 0 0 0 0 0 0 0
56105 - 0 0 0 0 0 0 0 0 0 0 0 0
56106 - 0 0 0 0 0 0 0 0 0 0 0 0
56107 - 0 0 0 0 0 0 0 0 0 0 0 0
56108 - 0 0 0 0 0 0 0 0 0 0 0 0
56109 - 0 0 0 0 0 0 0 0 0 10 10 10
56110 - 34 34 34 78 78 78 50 50 50 6 6 6
56111 - 94 70 30 139 102 15 190 146 13 226 184 13
56112 -232 200 30 232 195 16 215 174 15 190 146 13
56113 -168 122 10 192 133 9 210 150 10 213 154 11
56114 -202 150 34 182 157 106 101 98 89 2 2 6
56115 - 2 2 6 78 78 78 116 116 116 58 58 58
56116 - 2 2 6 22 22 22 90 90 90 46 46 46
56117 - 18 18 18 6 6 6 0 0 0 0 0 0
56118 - 0 0 0 0 0 0 0 0 0 0 0 0
56119 - 0 0 0 0 0 0 0 0 0 0 0 0
56120 - 0 0 0 0 0 0 0 0 0 0 0 0
56121 - 0 0 0 0 0 0 0 0 0 0 0 0
56122 - 0 0 0 0 0 0 0 0 0 0 0 0
56123 - 0 0 0 0 0 0 0 0 0 0 0 0
56124 - 0 0 0 0 0 0 0 0 0 0 0 0
56125 - 0 0 0 0 0 0 0 0 0 0 0 0
56126 - 0 0 0 0 0 0 0 0 0 0 0 0
56127 - 0 0 0 0 0 0 0 0 0 0 0 0
56128 - 0 0 0 0 0 0 0 0 0 0 0 0
56129 - 0 0 0 0 0 0 0 0 0 10 10 10
56130 - 38 38 38 86 86 86 50 50 50 6 6 6
56131 -128 128 128 174 154 114 156 107 11 168 122 10
56132 -198 155 10 184 144 12 197 138 11 200 144 11
56133 -206 145 10 206 145 10 197 138 11 188 164 115
56134 -195 195 195 198 198 198 174 174 174 14 14 14
56135 - 2 2 6 22 22 22 116 116 116 116 116 116
56136 - 22 22 22 2 2 6 74 74 74 70 70 70
56137 - 30 30 30 10 10 10 0 0 0 0 0 0
56138 - 0 0 0 0 0 0 0 0 0 0 0 0
56139 - 0 0 0 0 0 0 0 0 0 0 0 0
56140 - 0 0 0 0 0 0 0 0 0 0 0 0
56141 - 0 0 0 0 0 0 0 0 0 0 0 0
56142 - 0 0 0 0 0 0 0 0 0 0 0 0
56143 - 0 0 0 0 0 0 0 0 0 0 0 0
56144 - 0 0 0 0 0 0 0 0 0 0 0 0
56145 - 0 0 0 0 0 0 0 0 0 0 0 0
56146 - 0 0 0 0 0 0 0 0 0 0 0 0
56147 - 0 0 0 0 0 0 0 0 0 0 0 0
56148 - 0 0 0 0 0 0 0 0 0 0 0 0
56149 - 0 0 0 0 0 0 6 6 6 18 18 18
56150 - 50 50 50 101 101 101 26 26 26 10 10 10
56151 -138 138 138 190 190 190 174 154 114 156 107 11
56152 -197 138 11 200 144 11 197 138 11 192 133 9
56153 -180 123 7 190 142 34 190 178 144 187 187 187
56154 -202 202 202 221 221 221 214 214 214 66 66 66
56155 - 2 2 6 2 2 6 50 50 50 62 62 62
56156 - 6 6 6 2 2 6 10 10 10 90 90 90
56157 - 50 50 50 18 18 18 6 6 6 0 0 0
56158 - 0 0 0 0 0 0 0 0 0 0 0 0
56159 - 0 0 0 0 0 0 0 0 0 0 0 0
56160 - 0 0 0 0 0 0 0 0 0 0 0 0
56161 - 0 0 0 0 0 0 0 0 0 0 0 0
56162 - 0 0 0 0 0 0 0 0 0 0 0 0
56163 - 0 0 0 0 0 0 0 0 0 0 0 0
56164 - 0 0 0 0 0 0 0 0 0 0 0 0
56165 - 0 0 0 0 0 0 0 0 0 0 0 0
56166 - 0 0 0 0 0 0 0 0 0 0 0 0
56167 - 0 0 0 0 0 0 0 0 0 0 0 0
56168 - 0 0 0 0 0 0 0 0 0 0 0 0
56169 - 0 0 0 0 0 0 10 10 10 34 34 34
56170 - 74 74 74 74 74 74 2 2 6 6 6 6
56171 -144 144 144 198 198 198 190 190 190 178 166 146
56172 -154 121 60 156 107 11 156 107 11 168 124 44
56173 -174 154 114 187 187 187 190 190 190 210 210 210
56174 -246 246 246 253 253 253 253 253 253 182 182 182
56175 - 6 6 6 2 2 6 2 2 6 2 2 6
56176 - 2 2 6 2 2 6 2 2 6 62 62 62
56177 - 74 74 74 34 34 34 14 14 14 0 0 0
56178 - 0 0 0 0 0 0 0 0 0 0 0 0
56179 - 0 0 0 0 0 0 0 0 0 0 0 0
56180 - 0 0 0 0 0 0 0 0 0 0 0 0
56181 - 0 0 0 0 0 0 0 0 0 0 0 0
56182 - 0 0 0 0 0 0 0 0 0 0 0 0
56183 - 0 0 0 0 0 0 0 0 0 0 0 0
56184 - 0 0 0 0 0 0 0 0 0 0 0 0
56185 - 0 0 0 0 0 0 0 0 0 0 0 0
56186 - 0 0 0 0 0 0 0 0 0 0 0 0
56187 - 0 0 0 0 0 0 0 0 0 0 0 0
56188 - 0 0 0 0 0 0 0 0 0 0 0 0
56189 - 0 0 0 10 10 10 22 22 22 54 54 54
56190 - 94 94 94 18 18 18 2 2 6 46 46 46
56191 -234 234 234 221 221 221 190 190 190 190 190 190
56192 -190 190 190 187 187 187 187 187 187 190 190 190
56193 -190 190 190 195 195 195 214 214 214 242 242 242
56194 -253 253 253 253 253 253 253 253 253 253 253 253
56195 - 82 82 82 2 2 6 2 2 6 2 2 6
56196 - 2 2 6 2 2 6 2 2 6 14 14 14
56197 - 86 86 86 54 54 54 22 22 22 6 6 6
56198 - 0 0 0 0 0 0 0 0 0 0 0 0
56199 - 0 0 0 0 0 0 0 0 0 0 0 0
56200 - 0 0 0 0 0 0 0 0 0 0 0 0
56201 - 0 0 0 0 0 0 0 0 0 0 0 0
56202 - 0 0 0 0 0 0 0 0 0 0 0 0
56203 - 0 0 0 0 0 0 0 0 0 0 0 0
56204 - 0 0 0 0 0 0 0 0 0 0 0 0
56205 - 0 0 0 0 0 0 0 0 0 0 0 0
56206 - 0 0 0 0 0 0 0 0 0 0 0 0
56207 - 0 0 0 0 0 0 0 0 0 0 0 0
56208 - 0 0 0 0 0 0 0 0 0 0 0 0
56209 - 6 6 6 18 18 18 46 46 46 90 90 90
56210 - 46 46 46 18 18 18 6 6 6 182 182 182
56211 -253 253 253 246 246 246 206 206 206 190 190 190
56212 -190 190 190 190 190 190 190 190 190 190 190 190
56213 -206 206 206 231 231 231 250 250 250 253 253 253
56214 -253 253 253 253 253 253 253 253 253 253 253 253
56215 -202 202 202 14 14 14 2 2 6 2 2 6
56216 - 2 2 6 2 2 6 2 2 6 2 2 6
56217 - 42 42 42 86 86 86 42 42 42 18 18 18
56218 - 6 6 6 0 0 0 0 0 0 0 0 0
56219 - 0 0 0 0 0 0 0 0 0 0 0 0
56220 - 0 0 0 0 0 0 0 0 0 0 0 0
56221 - 0 0 0 0 0 0 0 0 0 0 0 0
56222 - 0 0 0 0 0 0 0 0 0 0 0 0
56223 - 0 0 0 0 0 0 0 0 0 0 0 0
56224 - 0 0 0 0 0 0 0 0 0 0 0 0
56225 - 0 0 0 0 0 0 0 0 0 0 0 0
56226 - 0 0 0 0 0 0 0 0 0 0 0 0
56227 - 0 0 0 0 0 0 0 0 0 0 0 0
56228 - 0 0 0 0 0 0 0 0 0 6 6 6
56229 - 14 14 14 38 38 38 74 74 74 66 66 66
56230 - 2 2 6 6 6 6 90 90 90 250 250 250
56231 -253 253 253 253 253 253 238 238 238 198 198 198
56232 -190 190 190 190 190 190 195 195 195 221 221 221
56233 -246 246 246 253 253 253 253 253 253 253 253 253
56234 -253 253 253 253 253 253 253 253 253 253 253 253
56235 -253 253 253 82 82 82 2 2 6 2 2 6
56236 - 2 2 6 2 2 6 2 2 6 2 2 6
56237 - 2 2 6 78 78 78 70 70 70 34 34 34
56238 - 14 14 14 6 6 6 0 0 0 0 0 0
56239 - 0 0 0 0 0 0 0 0 0 0 0 0
56240 - 0 0 0 0 0 0 0 0 0 0 0 0
56241 - 0 0 0 0 0 0 0 0 0 0 0 0
56242 - 0 0 0 0 0 0 0 0 0 0 0 0
56243 - 0 0 0 0 0 0 0 0 0 0 0 0
56244 - 0 0 0 0 0 0 0 0 0 0 0 0
56245 - 0 0 0 0 0 0 0 0 0 0 0 0
56246 - 0 0 0 0 0 0 0 0 0 0 0 0
56247 - 0 0 0 0 0 0 0 0 0 0 0 0
56248 - 0 0 0 0 0 0 0 0 0 14 14 14
56249 - 34 34 34 66 66 66 78 78 78 6 6 6
56250 - 2 2 6 18 18 18 218 218 218 253 253 253
56251 -253 253 253 253 253 253 253 253 253 246 246 246
56252 -226 226 226 231 231 231 246 246 246 253 253 253
56253 -253 253 253 253 253 253 253 253 253 253 253 253
56254 -253 253 253 253 253 253 253 253 253 253 253 253
56255 -253 253 253 178 178 178 2 2 6 2 2 6
56256 - 2 2 6 2 2 6 2 2 6 2 2 6
56257 - 2 2 6 18 18 18 90 90 90 62 62 62
56258 - 30 30 30 10 10 10 0 0 0 0 0 0
56259 - 0 0 0 0 0 0 0 0 0 0 0 0
56260 - 0 0 0 0 0 0 0 0 0 0 0 0
56261 - 0 0 0 0 0 0 0 0 0 0 0 0
56262 - 0 0 0 0 0 0 0 0 0 0 0 0
56263 - 0 0 0 0 0 0 0 0 0 0 0 0
56264 - 0 0 0 0 0 0 0 0 0 0 0 0
56265 - 0 0 0 0 0 0 0 0 0 0 0 0
56266 - 0 0 0 0 0 0 0 0 0 0 0 0
56267 - 0 0 0 0 0 0 0 0 0 0 0 0
56268 - 0 0 0 0 0 0 10 10 10 26 26 26
56269 - 58 58 58 90 90 90 18 18 18 2 2 6
56270 - 2 2 6 110 110 110 253 253 253 253 253 253
56271 -253 253 253 253 253 253 253 253 253 253 253 253
56272 -250 250 250 253 253 253 253 253 253 253 253 253
56273 -253 253 253 253 253 253 253 253 253 253 253 253
56274 -253 253 253 253 253 253 253 253 253 253 253 253
56275 -253 253 253 231 231 231 18 18 18 2 2 6
56276 - 2 2 6 2 2 6 2 2 6 2 2 6
56277 - 2 2 6 2 2 6 18 18 18 94 94 94
56278 - 54 54 54 26 26 26 10 10 10 0 0 0
56279 - 0 0 0 0 0 0 0 0 0 0 0 0
56280 - 0 0 0 0 0 0 0 0 0 0 0 0
56281 - 0 0 0 0 0 0 0 0 0 0 0 0
56282 - 0 0 0 0 0 0 0 0 0 0 0 0
56283 - 0 0 0 0 0 0 0 0 0 0 0 0
56284 - 0 0 0 0 0 0 0 0 0 0 0 0
56285 - 0 0 0 0 0 0 0 0 0 0 0 0
56286 - 0 0 0 0 0 0 0 0 0 0 0 0
56287 - 0 0 0 0 0 0 0 0 0 0 0 0
56288 - 0 0 0 6 6 6 22 22 22 50 50 50
56289 - 90 90 90 26 26 26 2 2 6 2 2 6
56290 - 14 14 14 195 195 195 250 250 250 253 253 253
56291 -253 253 253 253 253 253 253 253 253 253 253 253
56292 -253 253 253 253 253 253 253 253 253 253 253 253
56293 -253 253 253 253 253 253 253 253 253 253 253 253
56294 -253 253 253 253 253 253 253 253 253 253 253 253
56295 -250 250 250 242 242 242 54 54 54 2 2 6
56296 - 2 2 6 2 2 6 2 2 6 2 2 6
56297 - 2 2 6 2 2 6 2 2 6 38 38 38
56298 - 86 86 86 50 50 50 22 22 22 6 6 6
56299 - 0 0 0 0 0 0 0 0 0 0 0 0
56300 - 0 0 0 0 0 0 0 0 0 0 0 0
56301 - 0 0 0 0 0 0 0 0 0 0 0 0
56302 - 0 0 0 0 0 0 0 0 0 0 0 0
56303 - 0 0 0 0 0 0 0 0 0 0 0 0
56304 - 0 0 0 0 0 0 0 0 0 0 0 0
56305 - 0 0 0 0 0 0 0 0 0 0 0 0
56306 - 0 0 0 0 0 0 0 0 0 0 0 0
56307 - 0 0 0 0 0 0 0 0 0 0 0 0
56308 - 6 6 6 14 14 14 38 38 38 82 82 82
56309 - 34 34 34 2 2 6 2 2 6 2 2 6
56310 - 42 42 42 195 195 195 246 246 246 253 253 253
56311 -253 253 253 253 253 253 253 253 253 250 250 250
56312 -242 242 242 242 242 242 250 250 250 253 253 253
56313 -253 253 253 253 253 253 253 253 253 253 253 253
56314 -253 253 253 250 250 250 246 246 246 238 238 238
56315 -226 226 226 231 231 231 101 101 101 6 6 6
56316 - 2 2 6 2 2 6 2 2 6 2 2 6
56317 - 2 2 6 2 2 6 2 2 6 2 2 6
56318 - 38 38 38 82 82 82 42 42 42 14 14 14
56319 - 6 6 6 0 0 0 0 0 0 0 0 0
56320 - 0 0 0 0 0 0 0 0 0 0 0 0
56321 - 0 0 0 0 0 0 0 0 0 0 0 0
56322 - 0 0 0 0 0 0 0 0 0 0 0 0
56323 - 0 0 0 0 0 0 0 0 0 0 0 0
56324 - 0 0 0 0 0 0 0 0 0 0 0 0
56325 - 0 0 0 0 0 0 0 0 0 0 0 0
56326 - 0 0 0 0 0 0 0 0 0 0 0 0
56327 - 0 0 0 0 0 0 0 0 0 0 0 0
56328 - 10 10 10 26 26 26 62 62 62 66 66 66
56329 - 2 2 6 2 2 6 2 2 6 6 6 6
56330 - 70 70 70 170 170 170 206 206 206 234 234 234
56331 -246 246 246 250 250 250 250 250 250 238 238 238
56332 -226 226 226 231 231 231 238 238 238 250 250 250
56333 -250 250 250 250 250 250 246 246 246 231 231 231
56334 -214 214 214 206 206 206 202 202 202 202 202 202
56335 -198 198 198 202 202 202 182 182 182 18 18 18
56336 - 2 2 6 2 2 6 2 2 6 2 2 6
56337 - 2 2 6 2 2 6 2 2 6 2 2 6
56338 - 2 2 6 62 62 62 66 66 66 30 30 30
56339 - 10 10 10 0 0 0 0 0 0 0 0 0
56340 - 0 0 0 0 0 0 0 0 0 0 0 0
56341 - 0 0 0 0 0 0 0 0 0 0 0 0
56342 - 0 0 0 0 0 0 0 0 0 0 0 0
56343 - 0 0 0 0 0 0 0 0 0 0 0 0
56344 - 0 0 0 0 0 0 0 0 0 0 0 0
56345 - 0 0 0 0 0 0 0 0 0 0 0 0
56346 - 0 0 0 0 0 0 0 0 0 0 0 0
56347 - 0 0 0 0 0 0 0 0 0 0 0 0
56348 - 14 14 14 42 42 42 82 82 82 18 18 18
56349 - 2 2 6 2 2 6 2 2 6 10 10 10
56350 - 94 94 94 182 182 182 218 218 218 242 242 242
56351 -250 250 250 253 253 253 253 253 253 250 250 250
56352 -234 234 234 253 253 253 253 253 253 253 253 253
56353 -253 253 253 253 253 253 253 253 253 246 246 246
56354 -238 238 238 226 226 226 210 210 210 202 202 202
56355 -195 195 195 195 195 195 210 210 210 158 158 158
56356 - 6 6 6 14 14 14 50 50 50 14 14 14
56357 - 2 2 6 2 2 6 2 2 6 2 2 6
56358 - 2 2 6 6 6 6 86 86 86 46 46 46
56359 - 18 18 18 6 6 6 0 0 0 0 0 0
56360 - 0 0 0 0 0 0 0 0 0 0 0 0
56361 - 0 0 0 0 0 0 0 0 0 0 0 0
56362 - 0 0 0 0 0 0 0 0 0 0 0 0
56363 - 0 0 0 0 0 0 0 0 0 0 0 0
56364 - 0 0 0 0 0 0 0 0 0 0 0 0
56365 - 0 0 0 0 0 0 0 0 0 0 0 0
56366 - 0 0 0 0 0 0 0 0 0 0 0 0
56367 - 0 0 0 0 0 0 0 0 0 6 6 6
56368 - 22 22 22 54 54 54 70 70 70 2 2 6
56369 - 2 2 6 10 10 10 2 2 6 22 22 22
56370 -166 166 166 231 231 231 250 250 250 253 253 253
56371 -253 253 253 253 253 253 253 253 253 250 250 250
56372 -242 242 242 253 253 253 253 253 253 253 253 253
56373 -253 253 253 253 253 253 253 253 253 253 253 253
56374 -253 253 253 253 253 253 253 253 253 246 246 246
56375 -231 231 231 206 206 206 198 198 198 226 226 226
56376 - 94 94 94 2 2 6 6 6 6 38 38 38
56377 - 30 30 30 2 2 6 2 2 6 2 2 6
56378 - 2 2 6 2 2 6 62 62 62 66 66 66
56379 - 26 26 26 10 10 10 0 0 0 0 0 0
56380 - 0 0 0 0 0 0 0 0 0 0 0 0
56381 - 0 0 0 0 0 0 0 0 0 0 0 0
56382 - 0 0 0 0 0 0 0 0 0 0 0 0
56383 - 0 0 0 0 0 0 0 0 0 0 0 0
56384 - 0 0 0 0 0 0 0 0 0 0 0 0
56385 - 0 0 0 0 0 0 0 0 0 0 0 0
56386 - 0 0 0 0 0 0 0 0 0 0 0 0
56387 - 0 0 0 0 0 0 0 0 0 10 10 10
56388 - 30 30 30 74 74 74 50 50 50 2 2 6
56389 - 26 26 26 26 26 26 2 2 6 106 106 106
56390 -238 238 238 253 253 253 253 253 253 253 253 253
56391 -253 253 253 253 253 253 253 253 253 253 253 253
56392 -253 253 253 253 253 253 253 253 253 253 253 253
56393 -253 253 253 253 253 253 253 253 253 253 253 253
56394 -253 253 253 253 253 253 253 253 253 253 253 253
56395 -253 253 253 246 246 246 218 218 218 202 202 202
56396 -210 210 210 14 14 14 2 2 6 2 2 6
56397 - 30 30 30 22 22 22 2 2 6 2 2 6
56398 - 2 2 6 2 2 6 18 18 18 86 86 86
56399 - 42 42 42 14 14 14 0 0 0 0 0 0
56400 - 0 0 0 0 0 0 0 0 0 0 0 0
56401 - 0 0 0 0 0 0 0 0 0 0 0 0
56402 - 0 0 0 0 0 0 0 0 0 0 0 0
56403 - 0 0 0 0 0 0 0 0 0 0 0 0
56404 - 0 0 0 0 0 0 0 0 0 0 0 0
56405 - 0 0 0 0 0 0 0 0 0 0 0 0
56406 - 0 0 0 0 0 0 0 0 0 0 0 0
56407 - 0 0 0 0 0 0 0 0 0 14 14 14
56408 - 42 42 42 90 90 90 22 22 22 2 2 6
56409 - 42 42 42 2 2 6 18 18 18 218 218 218
56410 -253 253 253 253 253 253 253 253 253 253 253 253
56411 -253 253 253 253 253 253 253 253 253 253 253 253
56412 -253 253 253 253 253 253 253 253 253 253 253 253
56413 -253 253 253 253 253 253 253 253 253 253 253 253
56414 -253 253 253 253 253 253 253 253 253 253 253 253
56415 -253 253 253 253 253 253 250 250 250 221 221 221
56416 -218 218 218 101 101 101 2 2 6 14 14 14
56417 - 18 18 18 38 38 38 10 10 10 2 2 6
56418 - 2 2 6 2 2 6 2 2 6 78 78 78
56419 - 58 58 58 22 22 22 6 6 6 0 0 0
56420 - 0 0 0 0 0 0 0 0 0 0 0 0
56421 - 0 0 0 0 0 0 0 0 0 0 0 0
56422 - 0 0 0 0 0 0 0 0 0 0 0 0
56423 - 0 0 0 0 0 0 0 0 0 0 0 0
56424 - 0 0 0 0 0 0 0 0 0 0 0 0
56425 - 0 0 0 0 0 0 0 0 0 0 0 0
56426 - 0 0 0 0 0 0 0 0 0 0 0 0
56427 - 0 0 0 0 0 0 6 6 6 18 18 18
56428 - 54 54 54 82 82 82 2 2 6 26 26 26
56429 - 22 22 22 2 2 6 123 123 123 253 253 253
56430 -253 253 253 253 253 253 253 253 253 253 253 253
56431 -253 253 253 253 253 253 253 253 253 253 253 253
56432 -253 253 253 253 253 253 253 253 253 253 253 253
56433 -253 253 253 253 253 253 253 253 253 253 253 253
56434 -253 253 253 253 253 253 253 253 253 253 253 253
56435 -253 253 253 253 253 253 253 253 253 250 250 250
56436 -238 238 238 198 198 198 6 6 6 38 38 38
56437 - 58 58 58 26 26 26 38 38 38 2 2 6
56438 - 2 2 6 2 2 6 2 2 6 46 46 46
56439 - 78 78 78 30 30 30 10 10 10 0 0 0
56440 - 0 0 0 0 0 0 0 0 0 0 0 0
56441 - 0 0 0 0 0 0 0 0 0 0 0 0
56442 - 0 0 0 0 0 0 0 0 0 0 0 0
56443 - 0 0 0 0 0 0 0 0 0 0 0 0
56444 - 0 0 0 0 0 0 0 0 0 0 0 0
56445 - 0 0 0 0 0 0 0 0 0 0 0 0
56446 - 0 0 0 0 0 0 0 0 0 0 0 0
56447 - 0 0 0 0 0 0 10 10 10 30 30 30
56448 - 74 74 74 58 58 58 2 2 6 42 42 42
56449 - 2 2 6 22 22 22 231 231 231 253 253 253
56450 -253 253 253 253 253 253 253 253 253 253 253 253
56451 -253 253 253 253 253 253 253 253 253 250 250 250
56452 -253 253 253 253 253 253 253 253 253 253 253 253
56453 -253 253 253 253 253 253 253 253 253 253 253 253
56454 -253 253 253 253 253 253 253 253 253 253 253 253
56455 -253 253 253 253 253 253 253 253 253 253 253 253
56456 -253 253 253 246 246 246 46 46 46 38 38 38
56457 - 42 42 42 14 14 14 38 38 38 14 14 14
56458 - 2 2 6 2 2 6 2 2 6 6 6 6
56459 - 86 86 86 46 46 46 14 14 14 0 0 0
56460 - 0 0 0 0 0 0 0 0 0 0 0 0
56461 - 0 0 0 0 0 0 0 0 0 0 0 0
56462 - 0 0 0 0 0 0 0 0 0 0 0 0
56463 - 0 0 0 0 0 0 0 0 0 0 0 0
56464 - 0 0 0 0 0 0 0 0 0 0 0 0
56465 - 0 0 0 0 0 0 0 0 0 0 0 0
56466 - 0 0 0 0 0 0 0 0 0 0 0 0
56467 - 0 0 0 6 6 6 14 14 14 42 42 42
56468 - 90 90 90 18 18 18 18 18 18 26 26 26
56469 - 2 2 6 116 116 116 253 253 253 253 253 253
56470 -253 253 253 253 253 253 253 253 253 253 253 253
56471 -253 253 253 253 253 253 250 250 250 238 238 238
56472 -253 253 253 253 253 253 253 253 253 253 253 253
56473 -253 253 253 253 253 253 253 253 253 253 253 253
56474 -253 253 253 253 253 253 253 253 253 253 253 253
56475 -253 253 253 253 253 253 253 253 253 253 253 253
56476 -253 253 253 253 253 253 94 94 94 6 6 6
56477 - 2 2 6 2 2 6 10 10 10 34 34 34
56478 - 2 2 6 2 2 6 2 2 6 2 2 6
56479 - 74 74 74 58 58 58 22 22 22 6 6 6
56480 - 0 0 0 0 0 0 0 0 0 0 0 0
56481 - 0 0 0 0 0 0 0 0 0 0 0 0
56482 - 0 0 0 0 0 0 0 0 0 0 0 0
56483 - 0 0 0 0 0 0 0 0 0 0 0 0
56484 - 0 0 0 0 0 0 0 0 0 0 0 0
56485 - 0 0 0 0 0 0 0 0 0 0 0 0
56486 - 0 0 0 0 0 0 0 0 0 0 0 0
56487 - 0 0 0 10 10 10 26 26 26 66 66 66
56488 - 82 82 82 2 2 6 38 38 38 6 6 6
56489 - 14 14 14 210 210 210 253 253 253 253 253 253
56490 -253 253 253 253 253 253 253 253 253 253 253 253
56491 -253 253 253 253 253 253 246 246 246 242 242 242
56492 -253 253 253 253 253 253 253 253 253 253 253 253
56493 -253 253 253 253 253 253 253 253 253 253 253 253
56494 -253 253 253 253 253 253 253 253 253 253 253 253
56495 -253 253 253 253 253 253 253 253 253 253 253 253
56496 -253 253 253 253 253 253 144 144 144 2 2 6
56497 - 2 2 6 2 2 6 2 2 6 46 46 46
56498 - 2 2 6 2 2 6 2 2 6 2 2 6
56499 - 42 42 42 74 74 74 30 30 30 10 10 10
56500 - 0 0 0 0 0 0 0 0 0 0 0 0
56501 - 0 0 0 0 0 0 0 0 0 0 0 0
56502 - 0 0 0 0 0 0 0 0 0 0 0 0
56503 - 0 0 0 0 0 0 0 0 0 0 0 0
56504 - 0 0 0 0 0 0 0 0 0 0 0 0
56505 - 0 0 0 0 0 0 0 0 0 0 0 0
56506 - 0 0 0 0 0 0 0 0 0 0 0 0
56507 - 6 6 6 14 14 14 42 42 42 90 90 90
56508 - 26 26 26 6 6 6 42 42 42 2 2 6
56509 - 74 74 74 250 250 250 253 253 253 253 253 253
56510 -253 253 253 253 253 253 253 253 253 253 253 253
56511 -253 253 253 253 253 253 242 242 242 242 242 242
56512 -253 253 253 253 253 253 253 253 253 253 253 253
56513 -253 253 253 253 253 253 253 253 253 253 253 253
56514 -253 253 253 253 253 253 253 253 253 253 253 253
56515 -253 253 253 253 253 253 253 253 253 253 253 253
56516 -253 253 253 253 253 253 182 182 182 2 2 6
56517 - 2 2 6 2 2 6 2 2 6 46 46 46
56518 - 2 2 6 2 2 6 2 2 6 2 2 6
56519 - 10 10 10 86 86 86 38 38 38 10 10 10
56520 - 0 0 0 0 0 0 0 0 0 0 0 0
56521 - 0 0 0 0 0 0 0 0 0 0 0 0
56522 - 0 0 0 0 0 0 0 0 0 0 0 0
56523 - 0 0 0 0 0 0 0 0 0 0 0 0
56524 - 0 0 0 0 0 0 0 0 0 0 0 0
56525 - 0 0 0 0 0 0 0 0 0 0 0 0
56526 - 0 0 0 0 0 0 0 0 0 0 0 0
56527 - 10 10 10 26 26 26 66 66 66 82 82 82
56528 - 2 2 6 22 22 22 18 18 18 2 2 6
56529 -149 149 149 253 253 253 253 253 253 253 253 253
56530 -253 253 253 253 253 253 253 253 253 253 253 253
56531 -253 253 253 253 253 253 234 234 234 242 242 242
56532 -253 253 253 253 253 253 253 253 253 253 253 253
56533 -253 253 253 253 253 253 253 253 253 253 253 253
56534 -253 253 253 253 253 253 253 253 253 253 253 253
56535 -253 253 253 253 253 253 253 253 253 253 253 253
56536 -253 253 253 253 253 253 206 206 206 2 2 6
56537 - 2 2 6 2 2 6 2 2 6 38 38 38
56538 - 2 2 6 2 2 6 2 2 6 2 2 6
56539 - 6 6 6 86 86 86 46 46 46 14 14 14
56540 - 0 0 0 0 0 0 0 0 0 0 0 0
56541 - 0 0 0 0 0 0 0 0 0 0 0 0
56542 - 0 0 0 0 0 0 0 0 0 0 0 0
56543 - 0 0 0 0 0 0 0 0 0 0 0 0
56544 - 0 0 0 0 0 0 0 0 0 0 0 0
56545 - 0 0 0 0 0 0 0 0 0 0 0 0
56546 - 0 0 0 0 0 0 0 0 0 6 6 6
56547 - 18 18 18 46 46 46 86 86 86 18 18 18
56548 - 2 2 6 34 34 34 10 10 10 6 6 6
56549 -210 210 210 253 253 253 253 253 253 253 253 253
56550 -253 253 253 253 253 253 253 253 253 253 253 253
56551 -253 253 253 253 253 253 234 234 234 242 242 242
56552 -253 253 253 253 253 253 253 253 253 253 253 253
56553 -253 253 253 253 253 253 253 253 253 253 253 253
56554 -253 253 253 253 253 253 253 253 253 253 253 253
56555 -253 253 253 253 253 253 253 253 253 253 253 253
56556 -253 253 253 253 253 253 221 221 221 6 6 6
56557 - 2 2 6 2 2 6 6 6 6 30 30 30
56558 - 2 2 6 2 2 6 2 2 6 2 2 6
56559 - 2 2 6 82 82 82 54 54 54 18 18 18
56560 - 6 6 6 0 0 0 0 0 0 0 0 0
56561 - 0 0 0 0 0 0 0 0 0 0 0 0
56562 - 0 0 0 0 0 0 0 0 0 0 0 0
56563 - 0 0 0 0 0 0 0 0 0 0 0 0
56564 - 0 0 0 0 0 0 0 0 0 0 0 0
56565 - 0 0 0 0 0 0 0 0 0 0 0 0
56566 - 0 0 0 0 0 0 0 0 0 10 10 10
56567 - 26 26 26 66 66 66 62 62 62 2 2 6
56568 - 2 2 6 38 38 38 10 10 10 26 26 26
56569 -238 238 238 253 253 253 253 253 253 253 253 253
56570 -253 253 253 253 253 253 253 253 253 253 253 253
56571 -253 253 253 253 253 253 231 231 231 238 238 238
56572 -253 253 253 253 253 253 253 253 253 253 253 253
56573 -253 253 253 253 253 253 253 253 253 253 253 253
56574 -253 253 253 253 253 253 253 253 253 253 253 253
56575 -253 253 253 253 253 253 253 253 253 253 253 253
56576 -253 253 253 253 253 253 231 231 231 6 6 6
56577 - 2 2 6 2 2 6 10 10 10 30 30 30
56578 - 2 2 6 2 2 6 2 2 6 2 2 6
56579 - 2 2 6 66 66 66 58 58 58 22 22 22
56580 - 6 6 6 0 0 0 0 0 0 0 0 0
56581 - 0 0 0 0 0 0 0 0 0 0 0 0
56582 - 0 0 0 0 0 0 0 0 0 0 0 0
56583 - 0 0 0 0 0 0 0 0 0 0 0 0
56584 - 0 0 0 0 0 0 0 0 0 0 0 0
56585 - 0 0 0 0 0 0 0 0 0 0 0 0
56586 - 0 0 0 0 0 0 0 0 0 10 10 10
56587 - 38 38 38 78 78 78 6 6 6 2 2 6
56588 - 2 2 6 46 46 46 14 14 14 42 42 42
56589 -246 246 246 253 253 253 253 253 253 253 253 253
56590 -253 253 253 253 253 253 253 253 253 253 253 253
56591 -253 253 253 253 253 253 231 231 231 242 242 242
56592 -253 253 253 253 253 253 253 253 253 253 253 253
56593 -253 253 253 253 253 253 253 253 253 253 253 253
56594 -253 253 253 253 253 253 253 253 253 253 253 253
56595 -253 253 253 253 253 253 253 253 253 253 253 253
56596 -253 253 253 253 253 253 234 234 234 10 10 10
56597 - 2 2 6 2 2 6 22 22 22 14 14 14
56598 - 2 2 6 2 2 6 2 2 6 2 2 6
56599 - 2 2 6 66 66 66 62 62 62 22 22 22
56600 - 6 6 6 0 0 0 0 0 0 0 0 0
56601 - 0 0 0 0 0 0 0 0 0 0 0 0
56602 - 0 0 0 0 0 0 0 0 0 0 0 0
56603 - 0 0 0 0 0 0 0 0 0 0 0 0
56604 - 0 0 0 0 0 0 0 0 0 0 0 0
56605 - 0 0 0 0 0 0 0 0 0 0 0 0
56606 - 0 0 0 0 0 0 6 6 6 18 18 18
56607 - 50 50 50 74 74 74 2 2 6 2 2 6
56608 - 14 14 14 70 70 70 34 34 34 62 62 62
56609 -250 250 250 253 253 253 253 253 253 253 253 253
56610 -253 253 253 253 253 253 253 253 253 253 253 253
56611 -253 253 253 253 253 253 231 231 231 246 246 246
56612 -253 253 253 253 253 253 253 253 253 253 253 253
56613 -253 253 253 253 253 253 253 253 253 253 253 253
56614 -253 253 253 253 253 253 253 253 253 253 253 253
56615 -253 253 253 253 253 253 253 253 253 253 253 253
56616 -253 253 253 253 253 253 234 234 234 14 14 14
56617 - 2 2 6 2 2 6 30 30 30 2 2 6
56618 - 2 2 6 2 2 6 2 2 6 2 2 6
56619 - 2 2 6 66 66 66 62 62 62 22 22 22
56620 - 6 6 6 0 0 0 0 0 0 0 0 0
56621 - 0 0 0 0 0 0 0 0 0 0 0 0
56622 - 0 0 0 0 0 0 0 0 0 0 0 0
56623 - 0 0 0 0 0 0 0 0 0 0 0 0
56624 - 0 0 0 0 0 0 0 0 0 0 0 0
56625 - 0 0 0 0 0 0 0 0 0 0 0 0
56626 - 0 0 0 0 0 0 6 6 6 18 18 18
56627 - 54 54 54 62 62 62 2 2 6 2 2 6
56628 - 2 2 6 30 30 30 46 46 46 70 70 70
56629 -250 250 250 253 253 253 253 253 253 253 253 253
56630 -253 253 253 253 253 253 253 253 253 253 253 253
56631 -253 253 253 253 253 253 231 231 231 246 246 246
56632 -253 253 253 253 253 253 253 253 253 253 253 253
56633 -253 253 253 253 253 253 253 253 253 253 253 253
56634 -253 253 253 253 253 253 253 253 253 253 253 253
56635 -253 253 253 253 253 253 253 253 253 253 253 253
56636 -253 253 253 253 253 253 226 226 226 10 10 10
56637 - 2 2 6 6 6 6 30 30 30 2 2 6
56638 - 2 2 6 2 2 6 2 2 6 2 2 6
56639 - 2 2 6 66 66 66 58 58 58 22 22 22
56640 - 6 6 6 0 0 0 0 0 0 0 0 0
56641 - 0 0 0 0 0 0 0 0 0 0 0 0
56642 - 0 0 0 0 0 0 0 0 0 0 0 0
56643 - 0 0 0 0 0 0 0 0 0 0 0 0
56644 - 0 0 0 0 0 0 0 0 0 0 0 0
56645 - 0 0 0 0 0 0 0 0 0 0 0 0
56646 - 0 0 0 0 0 0 6 6 6 22 22 22
56647 - 58 58 58 62 62 62 2 2 6 2 2 6
56648 - 2 2 6 2 2 6 30 30 30 78 78 78
56649 -250 250 250 253 253 253 253 253 253 253 253 253
56650 -253 253 253 253 253 253 253 253 253 253 253 253
56651 -253 253 253 253 253 253 231 231 231 246 246 246
56652 -253 253 253 253 253 253 253 253 253 253 253 253
56653 -253 253 253 253 253 253 253 253 253 253 253 253
56654 -253 253 253 253 253 253 253 253 253 253 253 253
56655 -253 253 253 253 253 253 253 253 253 253 253 253
56656 -253 253 253 253 253 253 206 206 206 2 2 6
56657 - 22 22 22 34 34 34 18 14 6 22 22 22
56658 - 26 26 26 18 18 18 6 6 6 2 2 6
56659 - 2 2 6 82 82 82 54 54 54 18 18 18
56660 - 6 6 6 0 0 0 0 0 0 0 0 0
56661 - 0 0 0 0 0 0 0 0 0 0 0 0
56662 - 0 0 0 0 0 0 0 0 0 0 0 0
56663 - 0 0 0 0 0 0 0 0 0 0 0 0
56664 - 0 0 0 0 0 0 0 0 0 0 0 0
56665 - 0 0 0 0 0 0 0 0 0 0 0 0
56666 - 0 0 0 0 0 0 6 6 6 26 26 26
56667 - 62 62 62 106 106 106 74 54 14 185 133 11
56668 -210 162 10 121 92 8 6 6 6 62 62 62
56669 -238 238 238 253 253 253 253 253 253 253 253 253
56670 -253 253 253 253 253 253 253 253 253 253 253 253
56671 -253 253 253 253 253 253 231 231 231 246 246 246
56672 -253 253 253 253 253 253 253 253 253 253 253 253
56673 -253 253 253 253 253 253 253 253 253 253 253 253
56674 -253 253 253 253 253 253 253 253 253 253 253 253
56675 -253 253 253 253 253 253 253 253 253 253 253 253
56676 -253 253 253 253 253 253 158 158 158 18 18 18
56677 - 14 14 14 2 2 6 2 2 6 2 2 6
56678 - 6 6 6 18 18 18 66 66 66 38 38 38
56679 - 6 6 6 94 94 94 50 50 50 18 18 18
56680 - 6 6 6 0 0 0 0 0 0 0 0 0
56681 - 0 0 0 0 0 0 0 0 0 0 0 0
56682 - 0 0 0 0 0 0 0 0 0 0 0 0
56683 - 0 0 0 0 0 0 0 0 0 0 0 0
56684 - 0 0 0 0 0 0 0 0 0 0 0 0
56685 - 0 0 0 0 0 0 0 0 0 6 6 6
56686 - 10 10 10 10 10 10 18 18 18 38 38 38
56687 - 78 78 78 142 134 106 216 158 10 242 186 14
56688 -246 190 14 246 190 14 156 118 10 10 10 10
56689 - 90 90 90 238 238 238 253 253 253 253 253 253
56690 -253 253 253 253 253 253 253 253 253 253 253 253
56691 -253 253 253 253 253 253 231 231 231 250 250 250
56692 -253 253 253 253 253 253 253 253 253 253 253 253
56693 -253 253 253 253 253 253 253 253 253 253 253 253
56694 -253 253 253 253 253 253 253 253 253 253 253 253
56695 -253 253 253 253 253 253 253 253 253 246 230 190
56696 -238 204 91 238 204 91 181 142 44 37 26 9
56697 - 2 2 6 2 2 6 2 2 6 2 2 6
56698 - 2 2 6 2 2 6 38 38 38 46 46 46
56699 - 26 26 26 106 106 106 54 54 54 18 18 18
56700 - 6 6 6 0 0 0 0 0 0 0 0 0
56701 - 0 0 0 0 0 0 0 0 0 0 0 0
56702 - 0 0 0 0 0 0 0 0 0 0 0 0
56703 - 0 0 0 0 0 0 0 0 0 0 0 0
56704 - 0 0 0 0 0 0 0 0 0 0 0 0
56705 - 0 0 0 6 6 6 14 14 14 22 22 22
56706 - 30 30 30 38 38 38 50 50 50 70 70 70
56707 -106 106 106 190 142 34 226 170 11 242 186 14
56708 -246 190 14 246 190 14 246 190 14 154 114 10
56709 - 6 6 6 74 74 74 226 226 226 253 253 253
56710 -253 253 253 253 253 253 253 253 253 253 253 253
56711 -253 253 253 253 253 253 231 231 231 250 250 250
56712 -253 253 253 253 253 253 253 253 253 253 253 253
56713 -253 253 253 253 253 253 253 253 253 253 253 253
56714 -253 253 253 253 253 253 253 253 253 253 253 253
56715 -253 253 253 253 253 253 253 253 253 228 184 62
56716 -241 196 14 241 208 19 232 195 16 38 30 10
56717 - 2 2 6 2 2 6 2 2 6 2 2 6
56718 - 2 2 6 6 6 6 30 30 30 26 26 26
56719 -203 166 17 154 142 90 66 66 66 26 26 26
56720 - 6 6 6 0 0 0 0 0 0 0 0 0
56721 - 0 0 0 0 0 0 0 0 0 0 0 0
56722 - 0 0 0 0 0 0 0 0 0 0 0 0
56723 - 0 0 0 0 0 0 0 0 0 0 0 0
56724 - 0 0 0 0 0 0 0 0 0 0 0 0
56725 - 6 6 6 18 18 18 38 38 38 58 58 58
56726 - 78 78 78 86 86 86 101 101 101 123 123 123
56727 -175 146 61 210 150 10 234 174 13 246 186 14
56728 -246 190 14 246 190 14 246 190 14 238 190 10
56729 -102 78 10 2 2 6 46 46 46 198 198 198
56730 -253 253 253 253 253 253 253 253 253 253 253 253
56731 -253 253 253 253 253 253 234 234 234 242 242 242
56732 -253 253 253 253 253 253 253 253 253 253 253 253
56733 -253 253 253 253 253 253 253 253 253 253 253 253
56734 -253 253 253 253 253 253 253 253 253 253 253 253
56735 -253 253 253 253 253 253 253 253 253 224 178 62
56736 -242 186 14 241 196 14 210 166 10 22 18 6
56737 - 2 2 6 2 2 6 2 2 6 2 2 6
56738 - 2 2 6 2 2 6 6 6 6 121 92 8
56739 -238 202 15 232 195 16 82 82 82 34 34 34
56740 - 10 10 10 0 0 0 0 0 0 0 0 0
56741 - 0 0 0 0 0 0 0 0 0 0 0 0
56742 - 0 0 0 0 0 0 0 0 0 0 0 0
56743 - 0 0 0 0 0 0 0 0 0 0 0 0
56744 - 0 0 0 0 0 0 0 0 0 0 0 0
56745 - 14 14 14 38 38 38 70 70 70 154 122 46
56746 -190 142 34 200 144 11 197 138 11 197 138 11
56747 -213 154 11 226 170 11 242 186 14 246 190 14
56748 -246 190 14 246 190 14 246 190 14 246 190 14
56749 -225 175 15 46 32 6 2 2 6 22 22 22
56750 -158 158 158 250 250 250 253 253 253 253 253 253
56751 -253 253 253 253 253 253 253 253 253 253 253 253
56752 -253 253 253 253 253 253 253 253 253 253 253 253
56753 -253 253 253 253 253 253 253 253 253 253 253 253
56754 -253 253 253 253 253 253 253 253 253 253 253 253
56755 -253 253 253 250 250 250 242 242 242 224 178 62
56756 -239 182 13 236 186 11 213 154 11 46 32 6
56757 - 2 2 6 2 2 6 2 2 6 2 2 6
56758 - 2 2 6 2 2 6 61 42 6 225 175 15
56759 -238 190 10 236 186 11 112 100 78 42 42 42
56760 - 14 14 14 0 0 0 0 0 0 0 0 0
56761 - 0 0 0 0 0 0 0 0 0 0 0 0
56762 - 0 0 0 0 0 0 0 0 0 0 0 0
56763 - 0 0 0 0 0 0 0 0 0 0 0 0
56764 - 0 0 0 0 0 0 0 0 0 6 6 6
56765 - 22 22 22 54 54 54 154 122 46 213 154 11
56766 -226 170 11 230 174 11 226 170 11 226 170 11
56767 -236 178 12 242 186 14 246 190 14 246 190 14
56768 -246 190 14 246 190 14 246 190 14 246 190 14
56769 -241 196 14 184 144 12 10 10 10 2 2 6
56770 - 6 6 6 116 116 116 242 242 242 253 253 253
56771 -253 253 253 253 253 253 253 253 253 253 253 253
56772 -253 253 253 253 253 253 253 253 253 253 253 253
56773 -253 253 253 253 253 253 253 253 253 253 253 253
56774 -253 253 253 253 253 253 253 253 253 253 253 253
56775 -253 253 253 231 231 231 198 198 198 214 170 54
56776 -236 178 12 236 178 12 210 150 10 137 92 6
56777 - 18 14 6 2 2 6 2 2 6 2 2 6
56778 - 6 6 6 70 47 6 200 144 11 236 178 12
56779 -239 182 13 239 182 13 124 112 88 58 58 58
56780 - 22 22 22 6 6 6 0 0 0 0 0 0
56781 - 0 0 0 0 0 0 0 0 0 0 0 0
56782 - 0 0 0 0 0 0 0 0 0 0 0 0
56783 - 0 0 0 0 0 0 0 0 0 0 0 0
56784 - 0 0 0 0 0 0 0 0 0 10 10 10
56785 - 30 30 30 70 70 70 180 133 36 226 170 11
56786 -239 182 13 242 186 14 242 186 14 246 186 14
56787 -246 190 14 246 190 14 246 190 14 246 190 14
56788 -246 190 14 246 190 14 246 190 14 246 190 14
56789 -246 190 14 232 195 16 98 70 6 2 2 6
56790 - 2 2 6 2 2 6 66 66 66 221 221 221
56791 -253 253 253 253 253 253 253 253 253 253 253 253
56792 -253 253 253 253 253 253 253 253 253 253 253 253
56793 -253 253 253 253 253 253 253 253 253 253 253 253
56794 -253 253 253 253 253 253 253 253 253 253 253 253
56795 -253 253 253 206 206 206 198 198 198 214 166 58
56796 -230 174 11 230 174 11 216 158 10 192 133 9
56797 -163 110 8 116 81 8 102 78 10 116 81 8
56798 -167 114 7 197 138 11 226 170 11 239 182 13
56799 -242 186 14 242 186 14 162 146 94 78 78 78
56800 - 34 34 34 14 14 14 6 6 6 0 0 0
56801 - 0 0 0 0 0 0 0 0 0 0 0 0
56802 - 0 0 0 0 0 0 0 0 0 0 0 0
56803 - 0 0 0 0 0 0 0 0 0 0 0 0
56804 - 0 0 0 0 0 0 0 0 0 6 6 6
56805 - 30 30 30 78 78 78 190 142 34 226 170 11
56806 -239 182 13 246 190 14 246 190 14 246 190 14
56807 -246 190 14 246 190 14 246 190 14 246 190 14
56808 -246 190 14 246 190 14 246 190 14 246 190 14
56809 -246 190 14 241 196 14 203 166 17 22 18 6
56810 - 2 2 6 2 2 6 2 2 6 38 38 38
56811 -218 218 218 253 253 253 253 253 253 253 253 253
56812 -253 253 253 253 253 253 253 253 253 253 253 253
56813 -253 253 253 253 253 253 253 253 253 253 253 253
56814 -253 253 253 253 253 253 253 253 253 253 253 253
56815 -250 250 250 206 206 206 198 198 198 202 162 69
56816 -226 170 11 236 178 12 224 166 10 210 150 10
56817 -200 144 11 197 138 11 192 133 9 197 138 11
56818 -210 150 10 226 170 11 242 186 14 246 190 14
56819 -246 190 14 246 186 14 225 175 15 124 112 88
56820 - 62 62 62 30 30 30 14 14 14 6 6 6
56821 - 0 0 0 0 0 0 0 0 0 0 0 0
56822 - 0 0 0 0 0 0 0 0 0 0 0 0
56823 - 0 0 0 0 0 0 0 0 0 0 0 0
56824 - 0 0 0 0 0 0 0 0 0 10 10 10
56825 - 30 30 30 78 78 78 174 135 50 224 166 10
56826 -239 182 13 246 190 14 246 190 14 246 190 14
56827 -246 190 14 246 190 14 246 190 14 246 190 14
56828 -246 190 14 246 190 14 246 190 14 246 190 14
56829 -246 190 14 246 190 14 241 196 14 139 102 15
56830 - 2 2 6 2 2 6 2 2 6 2 2 6
56831 - 78 78 78 250 250 250 253 253 253 253 253 253
56832 -253 253 253 253 253 253 253 253 253 253 253 253
56833 -253 253 253 253 253 253 253 253 253 253 253 253
56834 -253 253 253 253 253 253 253 253 253 253 253 253
56835 -250 250 250 214 214 214 198 198 198 190 150 46
56836 -219 162 10 236 178 12 234 174 13 224 166 10
56837 -216 158 10 213 154 11 213 154 11 216 158 10
56838 -226 170 11 239 182 13 246 190 14 246 190 14
56839 -246 190 14 246 190 14 242 186 14 206 162 42
56840 -101 101 101 58 58 58 30 30 30 14 14 14
56841 - 6 6 6 0 0 0 0 0 0 0 0 0
56842 - 0 0 0 0 0 0 0 0 0 0 0 0
56843 - 0 0 0 0 0 0 0 0 0 0 0 0
56844 - 0 0 0 0 0 0 0 0 0 10 10 10
56845 - 30 30 30 74 74 74 174 135 50 216 158 10
56846 -236 178 12 246 190 14 246 190 14 246 190 14
56847 -246 190 14 246 190 14 246 190 14 246 190 14
56848 -246 190 14 246 190 14 246 190 14 246 190 14
56849 -246 190 14 246 190 14 241 196 14 226 184 13
56850 - 61 42 6 2 2 6 2 2 6 2 2 6
56851 - 22 22 22 238 238 238 253 253 253 253 253 253
56852 -253 253 253 253 253 253 253 253 253 253 253 253
56853 -253 253 253 253 253 253 253 253 253 253 253 253
56854 -253 253 253 253 253 253 253 253 253 253 253 253
56855 -253 253 253 226 226 226 187 187 187 180 133 36
56856 -216 158 10 236 178 12 239 182 13 236 178 12
56857 -230 174 11 226 170 11 226 170 11 230 174 11
56858 -236 178 12 242 186 14 246 190 14 246 190 14
56859 -246 190 14 246 190 14 246 186 14 239 182 13
56860 -206 162 42 106 106 106 66 66 66 34 34 34
56861 - 14 14 14 6 6 6 0 0 0 0 0 0
56862 - 0 0 0 0 0 0 0 0 0 0 0 0
56863 - 0 0 0 0 0 0 0 0 0 0 0 0
56864 - 0 0 0 0 0 0 0 0 0 6 6 6
56865 - 26 26 26 70 70 70 163 133 67 213 154 11
56866 -236 178 12 246 190 14 246 190 14 246 190 14
56867 -246 190 14 246 190 14 246 190 14 246 190 14
56868 -246 190 14 246 190 14 246 190 14 246 190 14
56869 -246 190 14 246 190 14 246 190 14 241 196 14
56870 -190 146 13 18 14 6 2 2 6 2 2 6
56871 - 46 46 46 246 246 246 253 253 253 253 253 253
56872 -253 253 253 253 253 253 253 253 253 253 253 253
56873 -253 253 253 253 253 253 253 253 253 253 253 253
56874 -253 253 253 253 253 253 253 253 253 253 253 253
56875 -253 253 253 221 221 221 86 86 86 156 107 11
56876 -216 158 10 236 178 12 242 186 14 246 186 14
56877 -242 186 14 239 182 13 239 182 13 242 186 14
56878 -242 186 14 246 186 14 246 190 14 246 190 14
56879 -246 190 14 246 190 14 246 190 14 246 190 14
56880 -242 186 14 225 175 15 142 122 72 66 66 66
56881 - 30 30 30 10 10 10 0 0 0 0 0 0
56882 - 0 0 0 0 0 0 0 0 0 0 0 0
56883 - 0 0 0 0 0 0 0 0 0 0 0 0
56884 - 0 0 0 0 0 0 0 0 0 6 6 6
56885 - 26 26 26 70 70 70 163 133 67 210 150 10
56886 -236 178 12 246 190 14 246 190 14 246 190 14
56887 -246 190 14 246 190 14 246 190 14 246 190 14
56888 -246 190 14 246 190 14 246 190 14 246 190 14
56889 -246 190 14 246 190 14 246 190 14 246 190 14
56890 -232 195 16 121 92 8 34 34 34 106 106 106
56891 -221 221 221 253 253 253 253 253 253 253 253 253
56892 -253 253 253 253 253 253 253 253 253 253 253 253
56893 -253 253 253 253 253 253 253 253 253 253 253 253
56894 -253 253 253 253 253 253 253 253 253 253 253 253
56895 -242 242 242 82 82 82 18 14 6 163 110 8
56896 -216 158 10 236 178 12 242 186 14 246 190 14
56897 -246 190 14 246 190 14 246 190 14 246 190 14
56898 -246 190 14 246 190 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 242 186 14 163 133 67
56901 - 46 46 46 18 18 18 6 6 6 0 0 0
56902 - 0 0 0 0 0 0 0 0 0 0 0 0
56903 - 0 0 0 0 0 0 0 0 0 0 0 0
56904 - 0 0 0 0 0 0 0 0 0 10 10 10
56905 - 30 30 30 78 78 78 163 133 67 210 150 10
56906 -236 178 12 246 186 14 246 190 14 246 190 14
56907 -246 190 14 246 190 14 246 190 14 246 190 14
56908 -246 190 14 246 190 14 246 190 14 246 190 14
56909 -246 190 14 246 190 14 246 190 14 246 190 14
56910 -241 196 14 215 174 15 190 178 144 253 253 253
56911 -253 253 253 253 253 253 253 253 253 253 253 253
56912 -253 253 253 253 253 253 253 253 253 253 253 253
56913 -253 253 253 253 253 253 253 253 253 253 253 253
56914 -253 253 253 253 253 253 253 253 253 218 218 218
56915 - 58 58 58 2 2 6 22 18 6 167 114 7
56916 -216 158 10 236 178 12 246 186 14 246 190 14
56917 -246 190 14 246 190 14 246 190 14 246 190 14
56918 -246 190 14 246 190 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 186 14 242 186 14 190 150 46
56921 - 54 54 54 22 22 22 6 6 6 0 0 0
56922 - 0 0 0 0 0 0 0 0 0 0 0 0
56923 - 0 0 0 0 0 0 0 0 0 0 0 0
56924 - 0 0 0 0 0 0 0 0 0 14 14 14
56925 - 38 38 38 86 86 86 180 133 36 213 154 11
56926 -236 178 12 246 186 14 246 190 14 246 190 14
56927 -246 190 14 246 190 14 246 190 14 246 190 14
56928 -246 190 14 246 190 14 246 190 14 246 190 14
56929 -246 190 14 246 190 14 246 190 14 246 190 14
56930 -246 190 14 232 195 16 190 146 13 214 214 214
56931 -253 253 253 253 253 253 253 253 253 253 253 253
56932 -253 253 253 253 253 253 253 253 253 253 253 253
56933 -253 253 253 253 253 253 253 253 253 253 253 253
56934 -253 253 253 250 250 250 170 170 170 26 26 26
56935 - 2 2 6 2 2 6 37 26 9 163 110 8
56936 -219 162 10 239 182 13 246 186 14 246 190 14
56937 -246 190 14 246 190 14 246 190 14 246 190 14
56938 -246 190 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 186 14 236 178 12 224 166 10 142 122 72
56941 - 46 46 46 18 18 18 6 6 6 0 0 0
56942 - 0 0 0 0 0 0 0 0 0 0 0 0
56943 - 0 0 0 0 0 0 0 0 0 0 0 0
56944 - 0 0 0 0 0 0 6 6 6 18 18 18
56945 - 50 50 50 109 106 95 192 133 9 224 166 10
56946 -242 186 14 246 190 14 246 190 14 246 190 14
56947 -246 190 14 246 190 14 246 190 14 246 190 14
56948 -246 190 14 246 190 14 246 190 14 246 190 14
56949 -246 190 14 246 190 14 246 190 14 246 190 14
56950 -242 186 14 226 184 13 210 162 10 142 110 46
56951 -226 226 226 253 253 253 253 253 253 253 253 253
56952 -253 253 253 253 253 253 253 253 253 253 253 253
56953 -253 253 253 253 253 253 253 253 253 253 253 253
56954 -198 198 198 66 66 66 2 2 6 2 2 6
56955 - 2 2 6 2 2 6 50 34 6 156 107 11
56956 -219 162 10 239 182 13 246 186 14 246 190 14
56957 -246 190 14 246 190 14 246 190 14 246 190 14
56958 -246 190 14 246 190 14 246 190 14 246 190 14
56959 -246 190 14 246 190 14 246 190 14 242 186 14
56960 -234 174 13 213 154 11 154 122 46 66 66 66
56961 - 30 30 30 10 10 10 0 0 0 0 0 0
56962 - 0 0 0 0 0 0 0 0 0 0 0 0
56963 - 0 0 0 0 0 0 0 0 0 0 0 0
56964 - 0 0 0 0 0 0 6 6 6 22 22 22
56965 - 58 58 58 154 121 60 206 145 10 234 174 13
56966 -242 186 14 246 186 14 246 190 14 246 190 14
56967 -246 190 14 246 190 14 246 190 14 246 190 14
56968 -246 190 14 246 190 14 246 190 14 246 190 14
56969 -246 190 14 246 190 14 246 190 14 246 190 14
56970 -246 186 14 236 178 12 210 162 10 163 110 8
56971 - 61 42 6 138 138 138 218 218 218 250 250 250
56972 -253 253 253 253 253 253 253 253 253 250 250 250
56973 -242 242 242 210 210 210 144 144 144 66 66 66
56974 - 6 6 6 2 2 6 2 2 6 2 2 6
56975 - 2 2 6 2 2 6 61 42 6 163 110 8
56976 -216 158 10 236 178 12 246 190 14 246 190 14
56977 -246 190 14 246 190 14 246 190 14 246 190 14
56978 -246 190 14 246 190 14 246 190 14 246 190 14
56979 -246 190 14 239 182 13 230 174 11 216 158 10
56980 -190 142 34 124 112 88 70 70 70 38 38 38
56981 - 18 18 18 6 6 6 0 0 0 0 0 0
56982 - 0 0 0 0 0 0 0 0 0 0 0 0
56983 - 0 0 0 0 0 0 0 0 0 0 0 0
56984 - 0 0 0 0 0 0 6 6 6 22 22 22
56985 - 62 62 62 168 124 44 206 145 10 224 166 10
56986 -236 178 12 239 182 13 242 186 14 242 186 14
56987 -246 186 14 246 190 14 246 190 14 246 190 14
56988 -246 190 14 246 190 14 246 190 14 246 190 14
56989 -246 190 14 246 190 14 246 190 14 246 190 14
56990 -246 190 14 236 178 12 216 158 10 175 118 6
56991 - 80 54 7 2 2 6 6 6 6 30 30 30
56992 - 54 54 54 62 62 62 50 50 50 38 38 38
56993 - 14 14 14 2 2 6 2 2 6 2 2 6
56994 - 2 2 6 2 2 6 2 2 6 2 2 6
56995 - 2 2 6 6 6 6 80 54 7 167 114 7
56996 -213 154 11 236 178 12 246 190 14 246 190 14
56997 -246 190 14 246 190 14 246 190 14 246 190 14
56998 -246 190 14 242 186 14 239 182 13 239 182 13
56999 -230 174 11 210 150 10 174 135 50 124 112 88
57000 - 82 82 82 54 54 54 34 34 34 18 18 18
57001 - 6 6 6 0 0 0 0 0 0 0 0 0
57002 - 0 0 0 0 0 0 0 0 0 0 0 0
57003 - 0 0 0 0 0 0 0 0 0 0 0 0
57004 - 0 0 0 0 0 0 6 6 6 18 18 18
57005 - 50 50 50 158 118 36 192 133 9 200 144 11
57006 -216 158 10 219 162 10 224 166 10 226 170 11
57007 -230 174 11 236 178 12 239 182 13 239 182 13
57008 -242 186 14 246 186 14 246 190 14 246 190 14
57009 -246 190 14 246 190 14 246 190 14 246 190 14
57010 -246 186 14 230 174 11 210 150 10 163 110 8
57011 -104 69 6 10 10 10 2 2 6 2 2 6
57012 - 2 2 6 2 2 6 2 2 6 2 2 6
57013 - 2 2 6 2 2 6 2 2 6 2 2 6
57014 - 2 2 6 2 2 6 2 2 6 2 2 6
57015 - 2 2 6 6 6 6 91 60 6 167 114 7
57016 -206 145 10 230 174 11 242 186 14 246 190 14
57017 -246 190 14 246 190 14 246 186 14 242 186 14
57018 -239 182 13 230 174 11 224 166 10 213 154 11
57019 -180 133 36 124 112 88 86 86 86 58 58 58
57020 - 38 38 38 22 22 22 10 10 10 6 6 6
57021 - 0 0 0 0 0 0 0 0 0 0 0 0
57022 - 0 0 0 0 0 0 0 0 0 0 0 0
57023 - 0 0 0 0 0 0 0 0 0 0 0 0
57024 - 0 0 0 0 0 0 0 0 0 14 14 14
57025 - 34 34 34 70 70 70 138 110 50 158 118 36
57026 -167 114 7 180 123 7 192 133 9 197 138 11
57027 -200 144 11 206 145 10 213 154 11 219 162 10
57028 -224 166 10 230 174 11 239 182 13 242 186 14
57029 -246 186 14 246 186 14 246 186 14 246 186 14
57030 -239 182 13 216 158 10 185 133 11 152 99 6
57031 -104 69 6 18 14 6 2 2 6 2 2 6
57032 - 2 2 6 2 2 6 2 2 6 2 2 6
57033 - 2 2 6 2 2 6 2 2 6 2 2 6
57034 - 2 2 6 2 2 6 2 2 6 2 2 6
57035 - 2 2 6 6 6 6 80 54 7 152 99 6
57036 -192 133 9 219 162 10 236 178 12 239 182 13
57037 -246 186 14 242 186 14 239 182 13 236 178 12
57038 -224 166 10 206 145 10 192 133 9 154 121 60
57039 - 94 94 94 62 62 62 42 42 42 22 22 22
57040 - 14 14 14 6 6 6 0 0 0 0 0 0
57041 - 0 0 0 0 0 0 0 0 0 0 0 0
57042 - 0 0 0 0 0 0 0 0 0 0 0 0
57043 - 0 0 0 0 0 0 0 0 0 0 0 0
57044 - 0 0 0 0 0 0 0 0 0 6 6 6
57045 - 18 18 18 34 34 34 58 58 58 78 78 78
57046 -101 98 89 124 112 88 142 110 46 156 107 11
57047 -163 110 8 167 114 7 175 118 6 180 123 7
57048 -185 133 11 197 138 11 210 150 10 219 162 10
57049 -226 170 11 236 178 12 236 178 12 234 174 13
57050 -219 162 10 197 138 11 163 110 8 130 83 6
57051 - 91 60 6 10 10 10 2 2 6 2 2 6
57052 - 18 18 18 38 38 38 38 38 38 38 38 38
57053 - 38 38 38 38 38 38 38 38 38 38 38 38
57054 - 38 38 38 38 38 38 26 26 26 2 2 6
57055 - 2 2 6 6 6 6 70 47 6 137 92 6
57056 -175 118 6 200 144 11 219 162 10 230 174 11
57057 -234 174 13 230 174 11 219 162 10 210 150 10
57058 -192 133 9 163 110 8 124 112 88 82 82 82
57059 - 50 50 50 30 30 30 14 14 14 6 6 6
57060 - 0 0 0 0 0 0 0 0 0 0 0 0
57061 - 0 0 0 0 0 0 0 0 0 0 0 0
57062 - 0 0 0 0 0 0 0 0 0 0 0 0
57063 - 0 0 0 0 0 0 0 0 0 0 0 0
57064 - 0 0 0 0 0 0 0 0 0 0 0 0
57065 - 6 6 6 14 14 14 22 22 22 34 34 34
57066 - 42 42 42 58 58 58 74 74 74 86 86 86
57067 -101 98 89 122 102 70 130 98 46 121 87 25
57068 -137 92 6 152 99 6 163 110 8 180 123 7
57069 -185 133 11 197 138 11 206 145 10 200 144 11
57070 -180 123 7 156 107 11 130 83 6 104 69 6
57071 - 50 34 6 54 54 54 110 110 110 101 98 89
57072 - 86 86 86 82 82 82 78 78 78 78 78 78
57073 - 78 78 78 78 78 78 78 78 78 78 78 78
57074 - 78 78 78 82 82 82 86 86 86 94 94 94
57075 -106 106 106 101 101 101 86 66 34 124 80 6
57076 -156 107 11 180 123 7 192 133 9 200 144 11
57077 -206 145 10 200 144 11 192 133 9 175 118 6
57078 -139 102 15 109 106 95 70 70 70 42 42 42
57079 - 22 22 22 10 10 10 0 0 0 0 0 0
57080 - 0 0 0 0 0 0 0 0 0 0 0 0
57081 - 0 0 0 0 0 0 0 0 0 0 0 0
57082 - 0 0 0 0 0 0 0 0 0 0 0 0
57083 - 0 0 0 0 0 0 0 0 0 0 0 0
57084 - 0 0 0 0 0 0 0 0 0 0 0 0
57085 - 0 0 0 0 0 0 6 6 6 10 10 10
57086 - 14 14 14 22 22 22 30 30 30 38 38 38
57087 - 50 50 50 62 62 62 74 74 74 90 90 90
57088 -101 98 89 112 100 78 121 87 25 124 80 6
57089 -137 92 6 152 99 6 152 99 6 152 99 6
57090 -138 86 6 124 80 6 98 70 6 86 66 30
57091 -101 98 89 82 82 82 58 58 58 46 46 46
57092 - 38 38 38 34 34 34 34 34 34 34 34 34
57093 - 34 34 34 34 34 34 34 34 34 34 34 34
57094 - 34 34 34 34 34 34 38 38 38 42 42 42
57095 - 54 54 54 82 82 82 94 86 76 91 60 6
57096 -134 86 6 156 107 11 167 114 7 175 118 6
57097 -175 118 6 167 114 7 152 99 6 121 87 25
57098 -101 98 89 62 62 62 34 34 34 18 18 18
57099 - 6 6 6 0 0 0 0 0 0 0 0 0
57100 - 0 0 0 0 0 0 0 0 0 0 0 0
57101 - 0 0 0 0 0 0 0 0 0 0 0 0
57102 - 0 0 0 0 0 0 0 0 0 0 0 0
57103 - 0 0 0 0 0 0 0 0 0 0 0 0
57104 - 0 0 0 0 0 0 0 0 0 0 0 0
57105 - 0 0 0 0 0 0 0 0 0 0 0 0
57106 - 0 0 0 6 6 6 6 6 6 10 10 10
57107 - 18 18 18 22 22 22 30 30 30 42 42 42
57108 - 50 50 50 66 66 66 86 86 86 101 98 89
57109 -106 86 58 98 70 6 104 69 6 104 69 6
57110 -104 69 6 91 60 6 82 62 34 90 90 90
57111 - 62 62 62 38 38 38 22 22 22 14 14 14
57112 - 10 10 10 10 10 10 10 10 10 10 10 10
57113 - 10 10 10 10 10 10 6 6 6 10 10 10
57114 - 10 10 10 10 10 10 10 10 10 14 14 14
57115 - 22 22 22 42 42 42 70 70 70 89 81 66
57116 - 80 54 7 104 69 6 124 80 6 137 92 6
57117 -134 86 6 116 81 8 100 82 52 86 86 86
57118 - 58 58 58 30 30 30 14 14 14 6 6 6
57119 - 0 0 0 0 0 0 0 0 0 0 0 0
57120 - 0 0 0 0 0 0 0 0 0 0 0 0
57121 - 0 0 0 0 0 0 0 0 0 0 0 0
57122 - 0 0 0 0 0 0 0 0 0 0 0 0
57123 - 0 0 0 0 0 0 0 0 0 0 0 0
57124 - 0 0 0 0 0 0 0 0 0 0 0 0
57125 - 0 0 0 0 0 0 0 0 0 0 0 0
57126 - 0 0 0 0 0 0 0 0 0 0 0 0
57127 - 0 0 0 6 6 6 10 10 10 14 14 14
57128 - 18 18 18 26 26 26 38 38 38 54 54 54
57129 - 70 70 70 86 86 86 94 86 76 89 81 66
57130 - 89 81 66 86 86 86 74 74 74 50 50 50
57131 - 30 30 30 14 14 14 6 6 6 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 - 6 6 6 18 18 18 34 34 34 58 58 58
57136 - 82 82 82 89 81 66 89 81 66 89 81 66
57137 - 94 86 66 94 86 76 74 74 74 50 50 50
57138 - 26 26 26 14 14 14 6 6 6 0 0 0
57139 - 0 0 0 0 0 0 0 0 0 0 0 0
57140 - 0 0 0 0 0 0 0 0 0 0 0 0
57141 - 0 0 0 0 0 0 0 0 0 0 0 0
57142 - 0 0 0 0 0 0 0 0 0 0 0 0
57143 - 0 0 0 0 0 0 0 0 0 0 0 0
57144 - 0 0 0 0 0 0 0 0 0 0 0 0
57145 - 0 0 0 0 0 0 0 0 0 0 0 0
57146 - 0 0 0 0 0 0 0 0 0 0 0 0
57147 - 0 0 0 0 0 0 0 0 0 0 0 0
57148 - 6 6 6 6 6 6 14 14 14 18 18 18
57149 - 30 30 30 38 38 38 46 46 46 54 54 54
57150 - 50 50 50 42 42 42 30 30 30 18 18 18
57151 - 10 10 10 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 6 6 6 14 14 14 26 26 26
57156 - 38 38 38 50 50 50 58 58 58 58 58 58
57157 - 54 54 54 42 42 42 30 30 30 18 18 18
57158 - 10 10 10 0 0 0 0 0 0 0 0 0
57159 - 0 0 0 0 0 0 0 0 0 0 0 0
57160 - 0 0 0 0 0 0 0 0 0 0 0 0
57161 - 0 0 0 0 0 0 0 0 0 0 0 0
57162 - 0 0 0 0 0 0 0 0 0 0 0 0
57163 - 0 0 0 0 0 0 0 0 0 0 0 0
57164 - 0 0 0 0 0 0 0 0 0 0 0 0
57165 - 0 0 0 0 0 0 0 0 0 0 0 0
57166 - 0 0 0 0 0 0 0 0 0 0 0 0
57167 - 0 0 0 0 0 0 0 0 0 0 0 0
57168 - 0 0 0 0 0 0 0 0 0 6 6 6
57169 - 6 6 6 10 10 10 14 14 14 18 18 18
57170 - 18 18 18 14 14 14 10 10 10 6 6 6
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 - 0 0 0 0 0 0 0 0 0 6 6 6
57176 - 14 14 14 18 18 18 22 22 22 22 22 22
57177 - 18 18 18 14 14 14 10 10 10 6 6 6
57178 - 0 0 0 0 0 0 0 0 0 0 0 0
57179 - 0 0 0 0 0 0 0 0 0 0 0 0
57180 - 0 0 0 0 0 0 0 0 0 0 0 0
57181 - 0 0 0 0 0 0 0 0 0 0 0 0
57182 - 0 0 0 0 0 0 0 0 0 0 0 0
57183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57194 +4 4 4 4 4 4 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
57197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57208 +4 4 4 4 4 4 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
57211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57222 +4 4 4 4 4 4 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
57225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57236 +4 4 4 4 4 4 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
57239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57250 +4 4 4 4 4 4 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
57253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57266 +4 4 4 4 4 4
57267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57271 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57272 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
57277 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57278 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57280 +4 4 4 4 4 4
57281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57285 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57286 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57287 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
57291 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57292 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57293 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57294 +4 4 4 4 4 4
57295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57299 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57300 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57301 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
57305 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57306 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57307 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57308 +4 4 4 4 4 4
57309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57312 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57313 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57314 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57315 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
57318 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57319 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57320 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57321 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57322 +4 4 4 4 4 4
57323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57326 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57327 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57328 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57329 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57330 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57331 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57332 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57333 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57334 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57335 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57336 +4 4 4 4 4 4
57337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57340 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57341 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57342 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57343 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57344 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57345 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57346 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57347 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57348 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57349 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57350 +4 4 4 4 4 4
57351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57353 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57354 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57355 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57356 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57357 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57358 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57359 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57360 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57361 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57362 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57363 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57364 +4 4 4 4 4 4
57365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57367 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57368 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57369 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57370 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57371 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57372 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57373 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57374 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57375 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57376 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57377 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57378 +4 4 4 4 4 4
57379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57381 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57382 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57383 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57384 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57385 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57386 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57387 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57388 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57389 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57390 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57391 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57392 +4 4 4 4 4 4
57393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57395 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57396 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57397 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57398 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57399 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57400 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57401 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57402 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57403 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57404 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57405 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57406 +4 4 4 4 4 4
57407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57408 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57409 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57410 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57411 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57412 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57413 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57414 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57415 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57416 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57417 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57418 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57419 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57420 +4 4 4 4 4 4
57421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57422 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57423 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57424 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57425 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57426 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57427 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57428 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57429 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57430 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57431 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57432 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57433 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57434 +0 0 0 4 4 4
57435 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57436 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57437 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57438 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57439 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57440 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57441 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57442 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57443 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57444 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57445 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57446 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57447 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57448 +2 0 0 0 0 0
57449 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57450 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57451 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57452 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57453 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57454 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57455 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57456 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57457 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57458 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57459 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57460 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57461 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57462 +37 38 37 0 0 0
57463 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57464 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57465 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57466 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57467 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57468 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57469 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57470 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57471 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57472 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57473 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57474 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57475 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57476 +85 115 134 4 0 0
57477 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57478 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57479 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57480 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57481 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57482 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57483 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57484 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57485 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57486 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57487 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57488 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57489 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57490 +60 73 81 4 0 0
57491 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57492 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57493 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57494 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57495 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57496 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57497 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57498 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57499 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57500 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57501 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57502 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57503 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57504 +16 19 21 4 0 0
57505 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57506 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57507 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57508 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57509 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57510 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57511 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57512 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57513 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57514 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57515 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57516 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57517 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57518 +4 0 0 4 3 3
57519 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57520 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57521 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57523 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57524 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57525 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57526 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57527 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57528 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57529 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57530 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57531 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57532 +3 2 2 4 4 4
57533 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57534 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57535 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57536 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57537 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57538 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57539 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57540 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57541 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57542 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57543 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57544 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57545 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57546 +4 4 4 4 4 4
57547 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57548 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57549 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57550 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57551 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57552 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57553 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57554 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57555 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57556 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57557 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57558 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57559 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57560 +4 4 4 4 4 4
57561 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57562 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57563 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57564 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57565 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57566 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57567 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57568 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57569 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57570 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57571 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57572 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57573 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57574 +5 5 5 5 5 5
57575 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57576 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57577 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57578 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57579 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57580 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57581 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57582 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57583 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57584 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57585 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57586 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57587 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57588 +5 5 5 4 4 4
57589 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57590 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57591 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57592 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57593 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57594 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57595 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57596 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57597 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57598 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57599 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57600 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57602 +4 4 4 4 4 4
57603 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57604 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57605 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57606 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57607 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57608 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57609 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57610 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57611 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57612 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57613 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57614 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57616 +4 4 4 4 4 4
57617 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57618 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57619 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57620 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57621 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57622 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57623 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57624 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57625 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57626 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57627 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57630 +4 4 4 4 4 4
57631 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57632 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57633 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57634 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57635 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57636 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57637 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57638 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57639 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57640 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57641 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57644 +4 4 4 4 4 4
57645 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57646 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57647 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57648 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57649 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57650 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57651 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57652 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57653 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57654 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57655 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57658 +4 4 4 4 4 4
57659 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57660 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57661 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57662 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57663 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57664 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57665 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57666 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57667 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57668 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57669 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57672 +4 4 4 4 4 4
57673 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57674 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57675 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57676 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57677 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57678 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57679 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57680 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57681 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57682 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57683 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57686 +4 4 4 4 4 4
57687 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57688 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57689 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57690 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57691 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57692 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57693 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57694 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57695 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57696 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57697 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57700 +4 4 4 4 4 4
57701 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57702 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57703 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57704 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57705 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57706 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57707 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57708 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57709 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57710 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57711 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57714 +4 4 4 4 4 4
57715 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57716 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57717 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57718 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57719 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57720 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57721 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57722 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57723 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57724 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57725 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57728 +4 4 4 4 4 4
57729 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57730 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57731 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57732 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57733 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57734 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57735 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57736 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57737 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57738 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57739 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57742 +4 4 4 4 4 4
57743 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57744 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57745 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57746 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57747 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57748 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57749 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57750 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57751 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57752 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57753 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57756 +4 4 4 4 4 4
57757 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57758 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57759 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57760 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57761 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57762 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57763 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57764 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57765 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57766 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57767 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57770 +4 4 4 4 4 4
57771 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57772 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57773 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57774 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57775 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57776 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57777 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57778 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57779 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57780 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57781 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57784 +4 4 4 4 4 4
57785 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57786 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57787 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57788 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57789 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57790 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57791 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57792 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57793 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57794 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57795 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57798 +4 4 4 4 4 4
57799 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57800 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57801 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57802 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57803 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57804 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57805 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57806 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57807 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57808 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57809 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57812 +4 4 4 4 4 4
57813 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57814 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57815 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57816 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57817 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57818 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57819 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57820 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57821 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57822 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57823 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57826 +4 4 4 4 4 4
57827 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57828 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57829 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57830 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57831 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57832 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57833 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57834 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57835 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57836 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57837 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57840 +4 4 4 4 4 4
57841 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57842 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57843 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57844 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57845 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57846 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57847 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57848 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57849 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57850 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57851 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57854 +4 4 4 4 4 4
57855 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57856 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57857 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57858 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57859 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57860 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57861 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57862 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57863 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57864 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57865 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57868 +4 4 4 4 4 4
57869 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57870 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57871 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57872 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57873 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57874 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57875 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57876 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57877 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57878 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57879 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57882 +4 4 4 4 4 4
57883 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57884 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57885 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57886 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57887 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57888 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57889 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57890 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57891 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57892 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57893 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57896 +4 4 4 4 4 4
57897 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57898 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57899 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57900 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57901 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57902 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57903 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57904 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57905 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57906 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57907 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57910 +4 4 4 4 4 4
57911 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57912 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57913 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57914 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57915 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57916 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57917 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57918 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57919 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57920 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57921 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57924 +4 4 4 4 4 4
57925 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57926 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57927 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57928 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57929 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57930 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57931 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57932 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57933 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57934 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57935 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57938 +4 4 4 4 4 4
57939 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57940 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57941 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57942 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57943 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57944 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57945 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57946 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57947 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57948 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57949 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57952 +4 4 4 4 4 4
57953 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57954 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57955 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57956 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57957 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57958 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57959 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57960 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57961 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57962 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57963 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966 +4 4 4 4 4 4
57967 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57968 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57969 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57970 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57971 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57972 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57973 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57974 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57975 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57976 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57977 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57980 +4 4 4 4 4 4
57981 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57982 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57983 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57984 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57985 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57986 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57987 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57988 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57989 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57990 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57991 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57994 +4 4 4 4 4 4
57995 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57996 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57997 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57998 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57999 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58000 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58001 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58002 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58003 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58004 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58008 +4 4 4 4 4 4
58009 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58010 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58011 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58012 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58013 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58014 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58015 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58016 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58017 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58018 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58022 +4 4 4 4 4 4
58023 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58024 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58025 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58026 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58027 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58028 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58029 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58030 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58031 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58032 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58036 +4 4 4 4 4 4
58037 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58038 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58039 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58040 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58041 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58042 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58043 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58044 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58045 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58046 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58050 +4 4 4 4 4 4
58051 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58052 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58053 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58054 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58055 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58056 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58057 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58058 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58059 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58064 +4 4 4 4 4 4
58065 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58066 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58067 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58068 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58069 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58070 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58071 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58072 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58073 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078 +4 4 4 4 4 4
58079 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58080 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58081 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58082 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58083 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58084 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58085 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58086 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58087 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092 +4 4 4 4 4 4
58093 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58094 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58095 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58096 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58097 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58098 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58099 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58100 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106 +4 4 4 4 4 4
58107 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58108 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58109 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58110 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58111 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58112 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58113 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58114 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120 +4 4 4 4 4 4
58121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58122 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58123 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58124 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58125 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58126 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58127 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58128 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134 +4 4 4 4 4 4
58135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58136 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58137 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58138 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58139 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58140 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58141 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58142 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
58151 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58152 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58153 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58154 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58155 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58156 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58162 +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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58166 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58167 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58168 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58169 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58170 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58176 +4 4 4 4 4 4
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 5 5 5
58180 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58181 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58182 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58183 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58190 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58195 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58196 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58197 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58204 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
58209 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58210 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58211 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58218 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
58223 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58224 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58225 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58232 +4 4 4 4 4 4
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 5 5 5
58237 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58238 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58239 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58246 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58252 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58253 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58266 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58267 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274 +4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
58280 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58286 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3
58294 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58302 +4 4 4 4 4 4
58303 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58304 index fef20db..d28b1ab 100644
58305 --- a/drivers/xen/xenfs/xenstored.c
58306 +++ b/drivers/xen/xenfs/xenstored.c
58307 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58308 static int xsd_kva_open(struct inode *inode, struct file *file)
58309 {
58310 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58312 + NULL);
58313 +#else
58314 xen_store_interface);
58315 +#endif
58316 +
58317 if (!file->private_data)
58318 return -ENOMEM;
58319 return 0;
58320 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58321 index eb14e05..5156de7 100644
58322 --- a/fs/9p/vfs_addr.c
58323 +++ b/fs/9p/vfs_addr.c
58324 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58325
58326 retval = v9fs_file_write_internal(inode,
58327 v9inode->writeback_fid,
58328 - (__force const char __user *)buffer,
58329 + (const char __force_user *)buffer,
58330 len, &offset, 0);
58331 if (retval > 0)
58332 retval = 0;
58333 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58334 index 296482f..183ddc3 100644
58335 --- a/fs/9p/vfs_inode.c
58336 +++ b/fs/9p/vfs_inode.c
58337 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58338 void
58339 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58340 {
58341 - char *s = nd_get_link(nd);
58342 + const char *s = nd_get_link(nd);
58343
58344 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58345 dentry, IS_ERR(s) ? "<error>" : s);
58346 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58347 index 370b24c..ff0be7b 100644
58348 --- a/fs/Kconfig.binfmt
58349 +++ b/fs/Kconfig.binfmt
58350 @@ -103,7 +103,7 @@ config HAVE_AOUT
58351
58352 config BINFMT_AOUT
58353 tristate "Kernel support for a.out and ECOFF binaries"
58354 - depends on HAVE_AOUT
58355 + depends on HAVE_AOUT && BROKEN
58356 ---help---
58357 A.out (Assembler.OUTput) is a set of formats for libraries and
58358 executables used in the earliest versions of UNIX. Linux used
58359 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58360 index 2946712..f737435 100644
58361 --- a/fs/afs/inode.c
58362 +++ b/fs/afs/inode.c
58363 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58364 struct afs_vnode *vnode;
58365 struct super_block *sb;
58366 struct inode *inode;
58367 - static atomic_t afs_autocell_ino;
58368 + static atomic_unchecked_t afs_autocell_ino;
58369
58370 _enter("{%x:%u},%*.*s,",
58371 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58372 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58373 data.fid.unique = 0;
58374 data.fid.vnode = 0;
58375
58376 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58377 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58378 afs_iget5_autocell_test, afs_iget5_set,
58379 &data);
58380 if (!inode) {
58381 diff --git a/fs/aio.c b/fs/aio.c
58382 index 14b9315..365980f 100644
58383 --- a/fs/aio.c
58384 +++ b/fs/aio.c
58385 @@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58386 size += sizeof(struct io_event) * nr_events;
58387
58388 nr_pages = PFN_UP(size);
58389 - if (nr_pages < 0)
58390 + if (nr_pages <= 0)
58391 return -EINVAL;
58392
58393 file = aio_private_file(ctx, nr_pages);
58394 diff --git a/fs/attr.c b/fs/attr.c
58395 index 6530ced..4a827e2 100644
58396 --- a/fs/attr.c
58397 +++ b/fs/attr.c
58398 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58399 unsigned long limit;
58400
58401 limit = rlimit(RLIMIT_FSIZE);
58402 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58403 if (limit != RLIM_INFINITY && offset > limit)
58404 goto out_sig;
58405 if (offset > inode->i_sb->s_maxbytes)
58406 diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
58407 index aaf96cb..ac7d921 100644
58408 --- a/fs/autofs4/dev-ioctl.c
58409 +++ b/fs/autofs4/dev-ioctl.c
58410 @@ -95,7 +95,7 @@ static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
58411 */
58412 static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in)
58413 {
58414 - struct autofs_dev_ioctl tmp;
58415 + struct autofs_dev_ioctl tmp, *res;
58416
58417 if (copy_from_user(&tmp, in, sizeof(tmp)))
58418 return ERR_PTR(-EFAULT);
58419 @@ -106,7 +106,11 @@ static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *i
58420 if (tmp.size > (PATH_MAX + sizeof(tmp)))
58421 return ERR_PTR(-ENAMETOOLONG);
58422
58423 - return memdup_user(in, tmp.size);
58424 + res = memdup_user(in, tmp.size);
58425 + if (!IS_ERR(res))
58426 + res->size = tmp.size;
58427 +
58428 + return res;
58429 }
58430
58431 static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)
58432 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58433 index 116fd38..c04182da 100644
58434 --- a/fs/autofs4/waitq.c
58435 +++ b/fs/autofs4/waitq.c
58436 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58437 {
58438 unsigned long sigpipe, flags;
58439 mm_segment_t fs;
58440 - const char *data = (const char *)addr;
58441 + const char __user *data = (const char __force_user *)addr;
58442 ssize_t wr = 0;
58443
58444 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58445 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58446 return 1;
58447 }
58448
58449 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58450 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58451 +#endif
58452 +
58453 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58454 enum autofs_notify notify)
58455 {
58456 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58457
58458 /* If this is a direct mount request create a dummy name */
58459 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58460 +#ifdef CONFIG_GRKERNSEC_HIDESYM
58461 + /* this name does get written to userland via autofs4_write() */
58462 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58463 +#else
58464 qstr.len = sprintf(name, "%p", dentry);
58465 +#endif
58466 else {
58467 qstr.len = autofs4_getpath(sbi, dentry, &name);
58468 if (!qstr.len) {
58469 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58470 index 2722387..56059b5 100644
58471 --- a/fs/befs/endian.h
58472 +++ b/fs/befs/endian.h
58473 @@ -11,7 +11,7 @@
58474
58475 #include <asm/byteorder.h>
58476
58477 -static inline u64
58478 +static inline u64 __intentional_overflow(-1)
58479 fs64_to_cpu(const struct super_block *sb, fs64 n)
58480 {
58481 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58482 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58483 return (__force fs64)cpu_to_be64(n);
58484 }
58485
58486 -static inline u32
58487 +static inline u32 __intentional_overflow(-1)
58488 fs32_to_cpu(const struct super_block *sb, fs32 n)
58489 {
58490 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58491 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58492 return (__force fs32)cpu_to_be32(n);
58493 }
58494
58495 -static inline u16
58496 +static inline u16 __intentional_overflow(-1)
58497 fs16_to_cpu(const struct super_block *sb, fs16 n)
58498 {
58499 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58500 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58501 index 929dec0..84bd914 100644
58502 --- a/fs/binfmt_aout.c
58503 +++ b/fs/binfmt_aout.c
58504 @@ -16,6 +16,7 @@
58505 #include <linux/string.h>
58506 #include <linux/fs.h>
58507 #include <linux/file.h>
58508 +#include <linux/security.h>
58509 #include <linux/stat.h>
58510 #include <linux/fcntl.h>
58511 #include <linux/ptrace.h>
58512 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58513 #endif
58514 # define START_STACK(u) ((void __user *)u.start_stack)
58515
58516 + memset(&dump, 0, sizeof(dump));
58517 +
58518 fs = get_fs();
58519 set_fs(KERNEL_DS);
58520 has_dumped = 1;
58521 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58522
58523 /* If the size of the dump file exceeds the rlimit, then see what would happen
58524 if we wrote the stack, but not the data area. */
58525 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58526 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58527 dump.u_dsize = 0;
58528
58529 /* Make sure we have enough room to write the stack and data areas. */
58530 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58531 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58532 dump.u_ssize = 0;
58533
58534 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58535 rlim = rlimit(RLIMIT_DATA);
58536 if (rlim >= RLIM_INFINITY)
58537 rlim = ~0;
58538 +
58539 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58540 if (ex.a_data + ex.a_bss > rlim)
58541 return -ENOMEM;
58542
58543 @@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58544
58545 install_exec_creds(bprm);
58546
58547 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58548 + current->mm->pax_flags = 0UL;
58549 +#endif
58550 +
58551 +#ifdef CONFIG_PAX_PAGEEXEC
58552 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58553 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58554 +
58555 +#ifdef CONFIG_PAX_EMUTRAMP
58556 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58557 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58558 +#endif
58559 +
58560 +#ifdef CONFIG_PAX_MPROTECT
58561 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58562 + current->mm->pax_flags |= MF_PAX_MPROTECT;
58563 +#endif
58564 +
58565 + }
58566 +#endif
58567 +
58568 if (N_MAGIC(ex) == OMAGIC) {
58569 unsigned long text_addr, map_size;
58570 loff_t pos;
58571 @@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58572 return error;
58573
58574 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58575 - PROT_READ | PROT_WRITE | PROT_EXEC,
58576 + PROT_READ | PROT_WRITE,
58577 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58578 fd_offset + ex.a_text);
58579 if (error != N_DATADDR(ex))
58580 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58581 index e1efcaa..ff55158 100644
58582 --- a/fs/binfmt_elf.c
58583 +++ b/fs/binfmt_elf.c
58584 @@ -34,6 +34,7 @@
58585 #include <linux/utsname.h>
58586 #include <linux/coredump.h>
58587 #include <linux/sched.h>
58588 +#include <linux/xattr.h>
58589 #include <asm/uaccess.h>
58590 #include <asm/param.h>
58591 #include <asm/page.h>
58592 @@ -47,7 +48,7 @@
58593
58594 static int load_elf_binary(struct linux_binprm *bprm);
58595 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58596 - int, int, unsigned long);
58597 + int, int, unsigned long) __intentional_overflow(-1);
58598
58599 #ifdef CONFIG_USELIB
58600 static int load_elf_library(struct file *);
58601 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58602 #define elf_core_dump NULL
58603 #endif
58604
58605 +#ifdef CONFIG_PAX_MPROTECT
58606 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58607 +#endif
58608 +
58609 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58610 +static void elf_handle_mmap(struct file *file);
58611 +#endif
58612 +
58613 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58614 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58615 #else
58616 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58617 .load_binary = load_elf_binary,
58618 .load_shlib = load_elf_library,
58619 .core_dump = elf_core_dump,
58620 +
58621 +#ifdef CONFIG_PAX_MPROTECT
58622 + .handle_mprotect= elf_handle_mprotect,
58623 +#endif
58624 +
58625 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58626 + .handle_mmap = elf_handle_mmap,
58627 +#endif
58628 +
58629 .min_coredump = ELF_EXEC_PAGESIZE,
58630 };
58631
58632 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58633
58634 static int set_brk(unsigned long start, unsigned long end)
58635 {
58636 + unsigned long e = end;
58637 +
58638 start = ELF_PAGEALIGN(start);
58639 end = ELF_PAGEALIGN(end);
58640 if (end > start) {
58641 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58642 if (BAD_ADDR(addr))
58643 return addr;
58644 }
58645 - current->mm->start_brk = current->mm->brk = end;
58646 + current->mm->start_brk = current->mm->brk = e;
58647 return 0;
58648 }
58649
58650 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58651 elf_addr_t __user *u_rand_bytes;
58652 const char *k_platform = ELF_PLATFORM;
58653 const char *k_base_platform = ELF_BASE_PLATFORM;
58654 - unsigned char k_rand_bytes[16];
58655 + u32 k_rand_bytes[4];
58656 int items;
58657 elf_addr_t *elf_info;
58658 int ei_index = 0;
58659 const struct cred *cred = current_cred();
58660 struct vm_area_struct *vma;
58661 + unsigned long saved_auxv[AT_VECTOR_SIZE];
58662
58663 /*
58664 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58665 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58666 * Generate 16 random bytes for userspace PRNG seeding.
58667 */
58668 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58669 - u_rand_bytes = (elf_addr_t __user *)
58670 - STACK_ALLOC(p, sizeof(k_rand_bytes));
58671 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58672 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58673 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58674 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58675 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
58676 + u_rand_bytes = (elf_addr_t __user *) p;
58677 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58678 return -EFAULT;
58679
58680 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58681 return -EFAULT;
58682 current->mm->env_end = p;
58683
58684 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58685 +
58686 /* Put the elf_info on the stack in the right place. */
58687 sp = (elf_addr_t __user *)envp + 1;
58688 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58689 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58690 return -EFAULT;
58691 return 0;
58692 }
58693 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58694 an ELF header */
58695
58696 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58697 - struct file *interpreter, unsigned long *interp_map_addr,
58698 - unsigned long no_base)
58699 + struct file *interpreter, unsigned long no_base)
58700 {
58701 struct elf_phdr *elf_phdata;
58702 struct elf_phdr *eppnt;
58703 - unsigned long load_addr = 0;
58704 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58705 int load_addr_set = 0;
58706 unsigned long last_bss = 0, elf_bss = 0;
58707 - unsigned long error = ~0UL;
58708 + unsigned long error = -EINVAL;
58709 unsigned long total_size;
58710 int retval, i, size;
58711
58712 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58713 goto out_close;
58714 }
58715
58716 +#ifdef CONFIG_PAX_SEGMEXEC
58717 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58718 + pax_task_size = SEGMEXEC_TASK_SIZE;
58719 +#endif
58720 +
58721 eppnt = elf_phdata;
58722 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58723 if (eppnt->p_type == PT_LOAD) {
58724 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58725 map_addr = elf_map(interpreter, load_addr + vaddr,
58726 eppnt, elf_prot, elf_type, total_size);
58727 total_size = 0;
58728 - if (!*interp_map_addr)
58729 - *interp_map_addr = map_addr;
58730 error = map_addr;
58731 if (BAD_ADDR(map_addr))
58732 goto out_close;
58733 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58734 k = load_addr + eppnt->p_vaddr;
58735 if (BAD_ADDR(k) ||
58736 eppnt->p_filesz > eppnt->p_memsz ||
58737 - eppnt->p_memsz > TASK_SIZE ||
58738 - TASK_SIZE - eppnt->p_memsz < k) {
58739 + eppnt->p_memsz > pax_task_size ||
58740 + pax_task_size - eppnt->p_memsz < k) {
58741 error = -ENOMEM;
58742 goto out_close;
58743 }
58744 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58745 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58746
58747 /* Map the last of the bss segment */
58748 - error = vm_brk(elf_bss, last_bss - elf_bss);
58749 - if (BAD_ADDR(error))
58750 - goto out_close;
58751 + if (last_bss > elf_bss) {
58752 + error = vm_brk(elf_bss, last_bss - elf_bss);
58753 + if (BAD_ADDR(error))
58754 + goto out_close;
58755 + }
58756 }
58757
58758 error = load_addr;
58759 @@ -543,6 +574,336 @@ out:
58760 return error;
58761 }
58762
58763 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58764 +#ifdef CONFIG_PAX_SOFTMODE
58765 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58766 +{
58767 + unsigned long pax_flags = 0UL;
58768 +
58769 +#ifdef CONFIG_PAX_PAGEEXEC
58770 + if (elf_phdata->p_flags & PF_PAGEEXEC)
58771 + pax_flags |= MF_PAX_PAGEEXEC;
58772 +#endif
58773 +
58774 +#ifdef CONFIG_PAX_SEGMEXEC
58775 + if (elf_phdata->p_flags & PF_SEGMEXEC)
58776 + pax_flags |= MF_PAX_SEGMEXEC;
58777 +#endif
58778 +
58779 +#ifdef CONFIG_PAX_EMUTRAMP
58780 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58781 + pax_flags |= MF_PAX_EMUTRAMP;
58782 +#endif
58783 +
58784 +#ifdef CONFIG_PAX_MPROTECT
58785 + if (elf_phdata->p_flags & PF_MPROTECT)
58786 + pax_flags |= MF_PAX_MPROTECT;
58787 +#endif
58788 +
58789 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58790 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58791 + pax_flags |= MF_PAX_RANDMMAP;
58792 +#endif
58793 +
58794 + return pax_flags;
58795 +}
58796 +#endif
58797 +
58798 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58799 +{
58800 + unsigned long pax_flags = 0UL;
58801 +
58802 +#ifdef CONFIG_PAX_PAGEEXEC
58803 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58804 + pax_flags |= MF_PAX_PAGEEXEC;
58805 +#endif
58806 +
58807 +#ifdef CONFIG_PAX_SEGMEXEC
58808 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58809 + pax_flags |= MF_PAX_SEGMEXEC;
58810 +#endif
58811 +
58812 +#ifdef CONFIG_PAX_EMUTRAMP
58813 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58814 + pax_flags |= MF_PAX_EMUTRAMP;
58815 +#endif
58816 +
58817 +#ifdef CONFIG_PAX_MPROTECT
58818 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58819 + pax_flags |= MF_PAX_MPROTECT;
58820 +#endif
58821 +
58822 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58823 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58824 + pax_flags |= MF_PAX_RANDMMAP;
58825 +#endif
58826 +
58827 + return pax_flags;
58828 +}
58829 +#endif
58830 +
58831 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58832 +#ifdef CONFIG_PAX_SOFTMODE
58833 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58834 +{
58835 + unsigned long pax_flags = 0UL;
58836 +
58837 +#ifdef CONFIG_PAX_PAGEEXEC
58838 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58839 + pax_flags |= MF_PAX_PAGEEXEC;
58840 +#endif
58841 +
58842 +#ifdef CONFIG_PAX_SEGMEXEC
58843 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58844 + pax_flags |= MF_PAX_SEGMEXEC;
58845 +#endif
58846 +
58847 +#ifdef CONFIG_PAX_EMUTRAMP
58848 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58849 + pax_flags |= MF_PAX_EMUTRAMP;
58850 +#endif
58851 +
58852 +#ifdef CONFIG_PAX_MPROTECT
58853 + if (pax_flags_softmode & MF_PAX_MPROTECT)
58854 + pax_flags |= MF_PAX_MPROTECT;
58855 +#endif
58856 +
58857 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58858 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58859 + pax_flags |= MF_PAX_RANDMMAP;
58860 +#endif
58861 +
58862 + return pax_flags;
58863 +}
58864 +#endif
58865 +
58866 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58867 +{
58868 + unsigned long pax_flags = 0UL;
58869 +
58870 +#ifdef CONFIG_PAX_PAGEEXEC
58871 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58872 + pax_flags |= MF_PAX_PAGEEXEC;
58873 +#endif
58874 +
58875 +#ifdef CONFIG_PAX_SEGMEXEC
58876 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58877 + pax_flags |= MF_PAX_SEGMEXEC;
58878 +#endif
58879 +
58880 +#ifdef CONFIG_PAX_EMUTRAMP
58881 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58882 + pax_flags |= MF_PAX_EMUTRAMP;
58883 +#endif
58884 +
58885 +#ifdef CONFIG_PAX_MPROTECT
58886 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58887 + pax_flags |= MF_PAX_MPROTECT;
58888 +#endif
58889 +
58890 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58891 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58892 + pax_flags |= MF_PAX_RANDMMAP;
58893 +#endif
58894 +
58895 + return pax_flags;
58896 +}
58897 +#endif
58898 +
58899 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58900 +static unsigned long pax_parse_defaults(void)
58901 +{
58902 + unsigned long pax_flags = 0UL;
58903 +
58904 +#ifdef CONFIG_PAX_SOFTMODE
58905 + if (pax_softmode)
58906 + return pax_flags;
58907 +#endif
58908 +
58909 +#ifdef CONFIG_PAX_PAGEEXEC
58910 + pax_flags |= MF_PAX_PAGEEXEC;
58911 +#endif
58912 +
58913 +#ifdef CONFIG_PAX_SEGMEXEC
58914 + pax_flags |= MF_PAX_SEGMEXEC;
58915 +#endif
58916 +
58917 +#ifdef CONFIG_PAX_MPROTECT
58918 + pax_flags |= MF_PAX_MPROTECT;
58919 +#endif
58920 +
58921 +#ifdef CONFIG_PAX_RANDMMAP
58922 + if (randomize_va_space)
58923 + pax_flags |= MF_PAX_RANDMMAP;
58924 +#endif
58925 +
58926 + return pax_flags;
58927 +}
58928 +
58929 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58930 +{
58931 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58932 +
58933 +#ifdef CONFIG_PAX_EI_PAX
58934 +
58935 +#ifdef CONFIG_PAX_SOFTMODE
58936 + if (pax_softmode)
58937 + return pax_flags;
58938 +#endif
58939 +
58940 + pax_flags = 0UL;
58941 +
58942 +#ifdef CONFIG_PAX_PAGEEXEC
58943 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58944 + pax_flags |= MF_PAX_PAGEEXEC;
58945 +#endif
58946 +
58947 +#ifdef CONFIG_PAX_SEGMEXEC
58948 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58949 + pax_flags |= MF_PAX_SEGMEXEC;
58950 +#endif
58951 +
58952 +#ifdef CONFIG_PAX_EMUTRAMP
58953 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58954 + pax_flags |= MF_PAX_EMUTRAMP;
58955 +#endif
58956 +
58957 +#ifdef CONFIG_PAX_MPROTECT
58958 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58959 + pax_flags |= MF_PAX_MPROTECT;
58960 +#endif
58961 +
58962 +#ifdef CONFIG_PAX_ASLR
58963 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58964 + pax_flags |= MF_PAX_RANDMMAP;
58965 +#endif
58966 +
58967 +#endif
58968 +
58969 + return pax_flags;
58970 +
58971 +}
58972 +
58973 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58974 +{
58975 +
58976 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
58977 + unsigned long i;
58978 +
58979 + for (i = 0UL; i < elf_ex->e_phnum; i++)
58980 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58981 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58982 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58983 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58984 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58985 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58986 + return PAX_PARSE_FLAGS_FALLBACK;
58987 +
58988 +#ifdef CONFIG_PAX_SOFTMODE
58989 + if (pax_softmode)
58990 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58991 + else
58992 +#endif
58993 +
58994 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58995 + break;
58996 + }
58997 +#endif
58998 +
58999 + return PAX_PARSE_FLAGS_FALLBACK;
59000 +}
59001 +
59002 +static unsigned long pax_parse_xattr_pax(struct file * const file)
59003 +{
59004 +
59005 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59006 + ssize_t xattr_size, i;
59007 + unsigned char xattr_value[sizeof("pemrs") - 1];
59008 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59009 +
59010 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59011 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59012 + return PAX_PARSE_FLAGS_FALLBACK;
59013 +
59014 + for (i = 0; i < xattr_size; i++)
59015 + switch (xattr_value[i]) {
59016 + default:
59017 + return PAX_PARSE_FLAGS_FALLBACK;
59018 +
59019 +#define parse_flag(option1, option2, flag) \
59020 + case option1: \
59021 + if (pax_flags_hardmode & MF_PAX_##flag) \
59022 + return PAX_PARSE_FLAGS_FALLBACK;\
59023 + pax_flags_hardmode |= MF_PAX_##flag; \
59024 + break; \
59025 + case option2: \
59026 + if (pax_flags_softmode & MF_PAX_##flag) \
59027 + return PAX_PARSE_FLAGS_FALLBACK;\
59028 + pax_flags_softmode |= MF_PAX_##flag; \
59029 + break;
59030 +
59031 + parse_flag('p', 'P', PAGEEXEC);
59032 + parse_flag('e', 'E', EMUTRAMP);
59033 + parse_flag('m', 'M', MPROTECT);
59034 + parse_flag('r', 'R', RANDMMAP);
59035 + parse_flag('s', 'S', SEGMEXEC);
59036 +
59037 +#undef parse_flag
59038 + }
59039 +
59040 + if (pax_flags_hardmode & pax_flags_softmode)
59041 + return PAX_PARSE_FLAGS_FALLBACK;
59042 +
59043 +#ifdef CONFIG_PAX_SOFTMODE
59044 + if (pax_softmode)
59045 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59046 + else
59047 +#endif
59048 +
59049 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59050 +#else
59051 + return PAX_PARSE_FLAGS_FALLBACK;
59052 +#endif
59053 +
59054 +}
59055 +
59056 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59057 +{
59058 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59059 +
59060 + pax_flags = pax_parse_defaults();
59061 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
59062 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59063 + xattr_pax_flags = pax_parse_xattr_pax(file);
59064 +
59065 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59066 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59067 + pt_pax_flags != xattr_pax_flags)
59068 + return -EINVAL;
59069 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59070 + pax_flags = xattr_pax_flags;
59071 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59072 + pax_flags = pt_pax_flags;
59073 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59074 + pax_flags = ei_pax_flags;
59075 +
59076 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59077 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59078 + if ((__supported_pte_mask & _PAGE_NX))
59079 + pax_flags &= ~MF_PAX_SEGMEXEC;
59080 + else
59081 + pax_flags &= ~MF_PAX_PAGEEXEC;
59082 + }
59083 +#endif
59084 +
59085 + if (0 > pax_check_flags(&pax_flags))
59086 + return -EINVAL;
59087 +
59088 + current->mm->pax_flags = pax_flags;
59089 + return 0;
59090 +}
59091 +#endif
59092 +
59093 /*
59094 * These are the functions used to load ELF style executables and shared
59095 * libraries. There is no binary dependent code anywhere else.
59096 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59097 {
59098 unsigned long random_variable = 0;
59099
59100 +#ifdef CONFIG_PAX_RANDUSTACK
59101 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59102 + return stack_top - current->mm->delta_stack;
59103 +#endif
59104 +
59105 if ((current->flags & PF_RANDOMIZE) &&
59106 !(current->personality & ADDR_NO_RANDOMIZE)) {
59107 random_variable = (unsigned long) get_random_int();
59108 @@ -575,7 +941,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59109 unsigned long load_addr = 0, load_bias = 0;
59110 int load_addr_set = 0;
59111 char * elf_interpreter = NULL;
59112 - unsigned long error;
59113 + unsigned long error = 0;
59114 struct elf_phdr *elf_ppnt, *elf_phdata;
59115 unsigned long elf_bss, elf_brk;
59116 int retval, i;
59117 @@ -590,6 +956,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59118 struct elfhdr elf_ex;
59119 struct elfhdr interp_elf_ex;
59120 } *loc;
59121 + unsigned long pax_task_size;
59122
59123 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59124 if (!loc) {
59125 @@ -727,6 +1094,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59126 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59127 may depend on the personality. */
59128 SET_PERSONALITY(loc->elf_ex);
59129 +
59130 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59131 + current->mm->pax_flags = 0UL;
59132 +#endif
59133 +
59134 +#ifdef CONFIG_PAX_DLRESOLVE
59135 + current->mm->call_dl_resolve = 0UL;
59136 +#endif
59137 +
59138 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59139 + current->mm->call_syscall = 0UL;
59140 +#endif
59141 +
59142 +#ifdef CONFIG_PAX_ASLR
59143 + current->mm->delta_mmap = 0UL;
59144 + current->mm->delta_stack = 0UL;
59145 +#endif
59146 +
59147 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59148 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59149 + send_sig(SIGKILL, current, 0);
59150 + goto out_free_dentry;
59151 + }
59152 +#endif
59153 +
59154 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59155 + pax_set_initial_flags(bprm);
59156 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59157 + if (pax_set_initial_flags_func)
59158 + (pax_set_initial_flags_func)(bprm);
59159 +#endif
59160 +
59161 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59162 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59163 + current->mm->context.user_cs_limit = PAGE_SIZE;
59164 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59165 + }
59166 +#endif
59167 +
59168 +#ifdef CONFIG_PAX_SEGMEXEC
59169 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59170 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59171 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59172 + pax_task_size = SEGMEXEC_TASK_SIZE;
59173 + current->mm->def_flags |= VM_NOHUGEPAGE;
59174 + } else
59175 +#endif
59176 +
59177 + pax_task_size = TASK_SIZE;
59178 +
59179 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59180 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59181 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59182 + put_cpu();
59183 + }
59184 +#endif
59185 +
59186 +#ifdef CONFIG_PAX_ASLR
59187 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59188 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59189 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59190 + }
59191 +#endif
59192 +
59193 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59194 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59195 + executable_stack = EXSTACK_DISABLE_X;
59196 + current->personality &= ~READ_IMPLIES_EXEC;
59197 + } else
59198 +#endif
59199 +
59200 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59201 current->personality |= READ_IMPLIES_EXEC;
59202
59203 @@ -812,6 +1250,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59204 #else
59205 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59206 #endif
59207 +
59208 +#ifdef CONFIG_PAX_RANDMMAP
59209 + /* PaX: randomize base address at the default exe base if requested */
59210 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59211 +#ifdef CONFIG_SPARC64
59212 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59213 +#else
59214 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59215 +#endif
59216 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59217 + elf_flags |= MAP_FIXED;
59218 + }
59219 +#endif
59220 +
59221 }
59222
59223 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59224 @@ -843,9 +1295,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59225 * allowed task size. Note that p_filesz must always be
59226 * <= p_memsz so it is only necessary to check p_memsz.
59227 */
59228 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59229 - elf_ppnt->p_memsz > TASK_SIZE ||
59230 - TASK_SIZE - elf_ppnt->p_memsz < k) {
59231 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59232 + elf_ppnt->p_memsz > pax_task_size ||
59233 + pax_task_size - elf_ppnt->p_memsz < k) {
59234 /* set_brk can never work. Avoid overflows. */
59235 retval = -EINVAL;
59236 goto out_free_dentry;
59237 @@ -881,16 +1333,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
59238 if (retval)
59239 goto out_free_dentry;
59240 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59241 - retval = -EFAULT; /* Nobody gets to see this, but.. */
59242 - goto out_free_dentry;
59243 + /*
59244 + * This bss-zeroing can fail if the ELF
59245 + * file specifies odd protections. So
59246 + * we don't check the return value
59247 + */
59248 }
59249
59250 +#ifdef CONFIG_PAX_RANDMMAP
59251 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59252 + unsigned long start, size, flags;
59253 + vm_flags_t vm_flags;
59254 +
59255 + start = ELF_PAGEALIGN(elf_brk);
59256 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59257 + flags = MAP_FIXED | MAP_PRIVATE;
59258 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59259 +
59260 + down_write(&current->mm->mmap_sem);
59261 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59262 + retval = -ENOMEM;
59263 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59264 +// if (current->personality & ADDR_NO_RANDOMIZE)
59265 +// vm_flags |= VM_READ | VM_MAYREAD;
59266 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59267 + retval = IS_ERR_VALUE(start) ? start : 0;
59268 + }
59269 + up_write(&current->mm->mmap_sem);
59270 + if (retval == 0)
59271 + retval = set_brk(start + size, start + size + PAGE_SIZE);
59272 + if (retval < 0)
59273 + goto out_free_dentry;
59274 + }
59275 +#endif
59276 +
59277 if (elf_interpreter) {
59278 - unsigned long interp_map_addr = 0;
59279 -
59280 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59281 interpreter,
59282 - &interp_map_addr,
59283 load_bias);
59284 if (!IS_ERR((void *)elf_entry)) {
59285 /*
59286 @@ -1116,7 +1595,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59287 * Decide what to dump of a segment, part, all or none.
59288 */
59289 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59290 - unsigned long mm_flags)
59291 + unsigned long mm_flags, long signr)
59292 {
59293 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59294
59295 @@ -1154,7 +1633,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59296 if (vma->vm_file == NULL)
59297 return 0;
59298
59299 - if (FILTER(MAPPED_PRIVATE))
59300 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59301 goto whole;
59302
59303 /*
59304 @@ -1361,9 +1840,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59305 {
59306 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59307 int i = 0;
59308 - do
59309 + do {
59310 i += 2;
59311 - while (auxv[i - 2] != AT_NULL);
59312 + } while (auxv[i - 2] != AT_NULL);
59313 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59314 }
59315
59316 @@ -1372,7 +1851,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59317 {
59318 mm_segment_t old_fs = get_fs();
59319 set_fs(KERNEL_DS);
59320 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59321 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59322 set_fs(old_fs);
59323 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59324 }
59325 @@ -1996,14 +2475,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59326 }
59327
59328 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59329 - unsigned long mm_flags)
59330 + struct coredump_params *cprm)
59331 {
59332 struct vm_area_struct *vma;
59333 size_t size = 0;
59334
59335 for (vma = first_vma(current, gate_vma); vma != NULL;
59336 vma = next_vma(vma, gate_vma))
59337 - size += vma_dump_size(vma, mm_flags);
59338 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59339 return size;
59340 }
59341
59342 @@ -2094,7 +2573,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59343
59344 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59345
59346 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59347 + offset += elf_core_vma_data_size(gate_vma, cprm);
59348 offset += elf_core_extra_data_size();
59349 e_shoff = offset;
59350
59351 @@ -2122,7 +2601,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59352 phdr.p_offset = offset;
59353 phdr.p_vaddr = vma->vm_start;
59354 phdr.p_paddr = 0;
59355 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59356 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59357 phdr.p_memsz = vma->vm_end - vma->vm_start;
59358 offset += phdr.p_filesz;
59359 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59360 @@ -2155,7 +2634,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59361 unsigned long addr;
59362 unsigned long end;
59363
59364 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59365 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59366
59367 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59368 struct page *page;
59369 @@ -2196,6 +2675,167 @@ out:
59370
59371 #endif /* CONFIG_ELF_CORE */
59372
59373 +#ifdef CONFIG_PAX_MPROTECT
59374 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
59375 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59376 + * we'll remove VM_MAYWRITE for good on RELRO segments.
59377 + *
59378 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59379 + * basis because we want to allow the common case and not the special ones.
59380 + */
59381 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59382 +{
59383 + struct elfhdr elf_h;
59384 + struct elf_phdr elf_p;
59385 + unsigned long i;
59386 + unsigned long oldflags;
59387 + bool is_textrel_rw, is_textrel_rx, is_relro;
59388 +
59389 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59390 + return;
59391 +
59392 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59393 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59394 +
59395 +#ifdef CONFIG_PAX_ELFRELOCS
59396 + /* possible TEXTREL */
59397 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59398 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59399 +#else
59400 + is_textrel_rw = false;
59401 + is_textrel_rx = false;
59402 +#endif
59403 +
59404 + /* possible RELRO */
59405 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59406 +
59407 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59408 + return;
59409 +
59410 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59411 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59412 +
59413 +#ifdef CONFIG_PAX_ETEXECRELOCS
59414 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59415 +#else
59416 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59417 +#endif
59418 +
59419 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59420 + !elf_check_arch(&elf_h) ||
59421 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59422 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59423 + return;
59424 +
59425 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59426 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59427 + return;
59428 + switch (elf_p.p_type) {
59429 + case PT_DYNAMIC:
59430 + if (!is_textrel_rw && !is_textrel_rx)
59431 + continue;
59432 + i = 0UL;
59433 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59434 + elf_dyn dyn;
59435 +
59436 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59437 + break;
59438 + if (dyn.d_tag == DT_NULL)
59439 + break;
59440 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59441 + gr_log_textrel(vma);
59442 + if (is_textrel_rw)
59443 + vma->vm_flags |= VM_MAYWRITE;
59444 + else
59445 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59446 + vma->vm_flags &= ~VM_MAYWRITE;
59447 + break;
59448 + }
59449 + i++;
59450 + }
59451 + is_textrel_rw = false;
59452 + is_textrel_rx = false;
59453 + continue;
59454 +
59455 + case PT_GNU_RELRO:
59456 + if (!is_relro)
59457 + continue;
59458 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59459 + vma->vm_flags &= ~VM_MAYWRITE;
59460 + is_relro = false;
59461 + continue;
59462 +
59463 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
59464 + case PT_PAX_FLAGS: {
59465 + const char *msg_mprotect = "", *msg_emutramp = "";
59466 + char *buffer_lib, *buffer_exe;
59467 +
59468 + if (elf_p.p_flags & PF_NOMPROTECT)
59469 + msg_mprotect = "MPROTECT disabled";
59470 +
59471 +#ifdef CONFIG_PAX_EMUTRAMP
59472 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59473 + msg_emutramp = "EMUTRAMP enabled";
59474 +#endif
59475 +
59476 + if (!msg_mprotect[0] && !msg_emutramp[0])
59477 + continue;
59478 +
59479 + if (!printk_ratelimit())
59480 + continue;
59481 +
59482 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59483 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59484 + if (buffer_lib && buffer_exe) {
59485 + char *path_lib, *path_exe;
59486 +
59487 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59488 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59489 +
59490 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59491 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59492 +
59493 + }
59494 + free_page((unsigned long)buffer_exe);
59495 + free_page((unsigned long)buffer_lib);
59496 + continue;
59497 + }
59498 +#endif
59499 +
59500 + }
59501 + }
59502 +}
59503 +#endif
59504 +
59505 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59506 +
59507 +extern int grsec_enable_log_rwxmaps;
59508 +
59509 +static void elf_handle_mmap(struct file *file)
59510 +{
59511 + struct elfhdr elf_h;
59512 + struct elf_phdr elf_p;
59513 + unsigned long i;
59514 +
59515 + if (!grsec_enable_log_rwxmaps)
59516 + return;
59517 +
59518 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59519 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59520 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59521 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59522 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59523 + return;
59524 +
59525 + for (i = 0UL; i < elf_h.e_phnum; i++) {
59526 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59527 + return;
59528 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59529 + gr_log_ptgnustack(file);
59530 + }
59531 +}
59532 +#endif
59533 +
59534 static int __init init_elf_binfmt(void)
59535 {
59536 register_binfmt(&elf_format);
59537 diff --git a/fs/block_dev.c b/fs/block_dev.c
59538 index 1d9c9f3..2905786 100644
59539 --- a/fs/block_dev.c
59540 +++ b/fs/block_dev.c
59541 @@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59542 else if (bdev->bd_contains == bdev)
59543 return true; /* is a whole device which isn't held */
59544
59545 - else if (whole->bd_holder == bd_may_claim)
59546 + else if (whole->bd_holder == (void *)bd_may_claim)
59547 return true; /* is a partition of a device that is being partitioned */
59548 else if (whole->bd_holder != NULL)
59549 return false; /* is a partition of a held device */
59550 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59551 index c81ce0c..0d23e5c 100644
59552 --- a/fs/btrfs/ctree.c
59553 +++ b/fs/btrfs/ctree.c
59554 @@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59555 free_extent_buffer(buf);
59556 add_root_to_dirty_list(root);
59557 } else {
59558 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59559 - parent_start = parent->start;
59560 - else
59561 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59562 + if (parent)
59563 + parent_start = parent->start;
59564 + else
59565 + parent_start = 0;
59566 + } else
59567 parent_start = 0;
59568
59569 WARN_ON(trans->transid != btrfs_header_generation(parent));
59570 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59571 index de4e70f..b41dc45 100644
59572 --- a/fs/btrfs/delayed-inode.c
59573 +++ b/fs/btrfs/delayed-inode.c
59574 @@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59575
59576 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59577 {
59578 - int seq = atomic_inc_return(&delayed_root->items_seq);
59579 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59580 if ((atomic_dec_return(&delayed_root->items) <
59581 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59582 waitqueue_active(&delayed_root->wait))
59583 @@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59584
59585 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59586 {
59587 - int val = atomic_read(&delayed_root->items_seq);
59588 + int val = atomic_read_unchecked(&delayed_root->items_seq);
59589
59590 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59591 return 1;
59592 @@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59593 int seq;
59594 int ret;
59595
59596 - seq = atomic_read(&delayed_root->items_seq);
59597 + seq = atomic_read_unchecked(&delayed_root->items_seq);
59598
59599 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59600 if (ret)
59601 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59602 index f70119f..ab5894d 100644
59603 --- a/fs/btrfs/delayed-inode.h
59604 +++ b/fs/btrfs/delayed-inode.h
59605 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59606 */
59607 struct list_head prepare_list;
59608 atomic_t items; /* for delayed items */
59609 - atomic_t items_seq; /* for delayed items */
59610 + atomic_unchecked_t items_seq; /* for delayed items */
59611 int nodes; /* for delayed nodes */
59612 wait_queue_head_t wait;
59613 };
59614 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59615 struct btrfs_delayed_root *delayed_root)
59616 {
59617 atomic_set(&delayed_root->items, 0);
59618 - atomic_set(&delayed_root->items_seq, 0);
59619 + atomic_set_unchecked(&delayed_root->items_seq, 0);
59620 delayed_root->nodes = 0;
59621 spin_lock_init(&delayed_root->lock);
59622 init_waitqueue_head(&delayed_root->wait);
59623 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59624 index 4399f0c..a34d8b4 100644
59625 --- a/fs/btrfs/ioctl.c
59626 +++ b/fs/btrfs/ioctl.c
59627 @@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59628 for (i = 0; i < num_types; i++) {
59629 struct btrfs_space_info *tmp;
59630
59631 + /* Don't copy in more than we allocated */
59632 if (!slot_count)
59633 break;
59634
59635 + slot_count--;
59636 +
59637 info = NULL;
59638 rcu_read_lock();
59639 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59640 @@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59641 memcpy(dest, &space, sizeof(space));
59642 dest++;
59643 space_args.total_spaces++;
59644 - slot_count--;
59645 }
59646 - if (!slot_count)
59647 - break;
59648 }
59649 up_read(&info->groups_sem);
59650 }
59651 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59652 index cde9c03..ad4d4db 100644
59653 --- a/fs/btrfs/super.c
59654 +++ b/fs/btrfs/super.c
59655 @@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59656 function, line, errstr);
59657 return;
59658 }
59659 - ACCESS_ONCE(trans->transaction->aborted) = errno;
59660 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59661 /* Wake up anybody who may be waiting on this transaction */
59662 wake_up(&root->fs_info->transaction_wait);
59663 wake_up(&root->fs_info->transaction_blocked_wait);
59664 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59665 index b2e7bb4..3719201 100644
59666 --- a/fs/btrfs/sysfs.c
59667 +++ b/fs/btrfs/sysfs.c
59668 @@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59669 for (set = 0; set < FEAT_MAX; set++) {
59670 int i;
59671 struct attribute *attrs[2];
59672 - struct attribute_group agroup = {
59673 + attribute_group_no_const agroup = {
59674 .name = "features",
59675 .attrs = attrs,
59676 };
59677 diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59678 index 2299bfd..4098e72 100644
59679 --- a/fs/btrfs/tests/free-space-tests.c
59680 +++ b/fs/btrfs/tests/free-space-tests.c
59681 @@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59682 * extent entry.
59683 */
59684 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59685 - cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59686 + pax_open_kernel();
59687 + *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59688 + pax_close_kernel();
59689
59690 /*
59691 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59692 @@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59693 if (ret)
59694 return ret;
59695
59696 - cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59697 + pax_open_kernel();
59698 + *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59699 + pax_close_kernel();
59700 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59701
59702 return 0;
59703 diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59704 index 154990c..d0cf699 100644
59705 --- a/fs/btrfs/tree-log.h
59706 +++ b/fs/btrfs/tree-log.h
59707 @@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59708 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59709 struct btrfs_trans_handle *trans)
59710 {
59711 - ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59712 + ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59713 }
59714
59715 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59716 diff --git a/fs/buffer.c b/fs/buffer.c
59717 index 20805db..2e8fc69 100644
59718 --- a/fs/buffer.c
59719 +++ b/fs/buffer.c
59720 @@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59721 bh_cachep = kmem_cache_create("buffer_head",
59722 sizeof(struct buffer_head), 0,
59723 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59724 - SLAB_MEM_SPREAD),
59725 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59726 NULL);
59727
59728 /*
59729 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59730 index fbb08e9..0fda764 100644
59731 --- a/fs/cachefiles/bind.c
59732 +++ b/fs/cachefiles/bind.c
59733 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59734 args);
59735
59736 /* start by checking things over */
59737 - ASSERT(cache->fstop_percent >= 0 &&
59738 - cache->fstop_percent < cache->fcull_percent &&
59739 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
59740 cache->fcull_percent < cache->frun_percent &&
59741 cache->frun_percent < 100);
59742
59743 - ASSERT(cache->bstop_percent >= 0 &&
59744 - cache->bstop_percent < cache->bcull_percent &&
59745 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
59746 cache->bcull_percent < cache->brun_percent &&
59747 cache->brun_percent < 100);
59748
59749 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59750 index ce1b115..4a6852c 100644
59751 --- a/fs/cachefiles/daemon.c
59752 +++ b/fs/cachefiles/daemon.c
59753 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59754 if (n > buflen)
59755 return -EMSGSIZE;
59756
59757 - if (copy_to_user(_buffer, buffer, n) != 0)
59758 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59759 return -EFAULT;
59760
59761 return n;
59762 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59763 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59764 return -EIO;
59765
59766 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
59767 + if (datalen > PAGE_SIZE - 1)
59768 return -EOPNOTSUPP;
59769
59770 /* drag the command string into the kernel so we can parse it */
59771 @@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59772 if (args[0] != '%' || args[1] != '\0')
59773 return -EINVAL;
59774
59775 - if (fstop < 0 || fstop >= cache->fcull_percent)
59776 + if (fstop >= cache->fcull_percent)
59777 return cachefiles_daemon_range_error(cache, args);
59778
59779 cache->fstop_percent = fstop;
59780 @@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59781 if (args[0] != '%' || args[1] != '\0')
59782 return -EINVAL;
59783
59784 - if (bstop < 0 || bstop >= cache->bcull_percent)
59785 + if (bstop >= cache->bcull_percent)
59786 return cachefiles_daemon_range_error(cache, args);
59787
59788 cache->bstop_percent = bstop;
59789 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59790 index 8c52472..c4e3a69 100644
59791 --- a/fs/cachefiles/internal.h
59792 +++ b/fs/cachefiles/internal.h
59793 @@ -66,7 +66,7 @@ struct cachefiles_cache {
59794 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59795 struct rb_root active_nodes; /* active nodes (can't be culled) */
59796 rwlock_t active_lock; /* lock for active_nodes */
59797 - atomic_t gravecounter; /* graveyard uniquifier */
59798 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59799 unsigned frun_percent; /* when to stop culling (% files) */
59800 unsigned fcull_percent; /* when to start culling (% files) */
59801 unsigned fstop_percent; /* when to stop allocating (% files) */
59802 @@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59803 * proc.c
59804 */
59805 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59806 -extern atomic_t cachefiles_lookup_histogram[HZ];
59807 -extern atomic_t cachefiles_mkdir_histogram[HZ];
59808 -extern atomic_t cachefiles_create_histogram[HZ];
59809 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59810 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59811 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59812
59813 extern int __init cachefiles_proc_init(void);
59814 extern void cachefiles_proc_cleanup(void);
59815 static inline
59816 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59817 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59818 {
59819 unsigned long jif = jiffies - start_jif;
59820 if (jif >= HZ)
59821 jif = HZ - 1;
59822 - atomic_inc(&histogram[jif]);
59823 + atomic_inc_unchecked(&histogram[jif]);
59824 }
59825
59826 #else
59827 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59828 index e12f189..ed17244 100644
59829 --- a/fs/cachefiles/namei.c
59830 +++ b/fs/cachefiles/namei.c
59831 @@ -312,7 +312,7 @@ try_again:
59832 /* first step is to make up a grave dentry in the graveyard */
59833 sprintf(nbuffer, "%08x%08x",
59834 (uint32_t) get_seconds(),
59835 - (uint32_t) atomic_inc_return(&cache->gravecounter));
59836 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59837
59838 /* do the multiway lock magic */
59839 trap = lock_rename(cache->graveyard, dir);
59840 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59841 index eccd339..4c1d995 100644
59842 --- a/fs/cachefiles/proc.c
59843 +++ b/fs/cachefiles/proc.c
59844 @@ -14,9 +14,9 @@
59845 #include <linux/seq_file.h>
59846 #include "internal.h"
59847
59848 -atomic_t cachefiles_lookup_histogram[HZ];
59849 -atomic_t cachefiles_mkdir_histogram[HZ];
59850 -atomic_t cachefiles_create_histogram[HZ];
59851 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59852 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59853 +atomic_unchecked_t cachefiles_create_histogram[HZ];
59854
59855 /*
59856 * display the latency histogram
59857 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59858 return 0;
59859 default:
59860 index = (unsigned long) v - 3;
59861 - x = atomic_read(&cachefiles_lookup_histogram[index]);
59862 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
59863 - z = atomic_read(&cachefiles_create_histogram[index]);
59864 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59865 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59866 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59867 if (x == 0 && y == 0 && z == 0)
59868 return 0;
59869
59870 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59871 index 695e788..f4a9d4d 100644
59872 --- a/fs/ceph/dir.c
59873 +++ b/fs/ceph/dir.c
59874 @@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59875 struct dentry *dentry, *last;
59876 struct ceph_dentry_info *di;
59877 int err = 0;
59878 + char d_name[DNAME_INLINE_LEN];
59879 + const unsigned char *name;
59880
59881 /* claim ref on last dentry we returned */
59882 last = fi->dentry;
59883 @@ -192,7 +194,12 @@ more:
59884
59885 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59886 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59887 - if (!dir_emit(ctx, dentry->d_name.name,
59888 + name = dentry->d_name.name;
59889 + if (name == dentry->d_iname) {
59890 + memcpy(d_name, name, dentry->d_name.len);
59891 + name = d_name;
59892 + }
59893 + if (!dir_emit(ctx, name,
59894 dentry->d_name.len,
59895 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59896 dentry->d_inode->i_mode >> 12)) {
59897 @@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59898 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59899 struct ceph_mds_client *mdsc = fsc->mdsc;
59900 unsigned frag = fpos_frag(ctx->pos);
59901 - int off = fpos_off(ctx->pos);
59902 + unsigned int off = fpos_off(ctx->pos);
59903 int err;
59904 u32 ftype;
59905 struct ceph_mds_reply_info_parsed *rinfo;
59906 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59907 index f6e1237..796ffd1 100644
59908 --- a/fs/ceph/super.c
59909 +++ b/fs/ceph/super.c
59910 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59911 /*
59912 * construct our own bdi so we can control readahead, etc.
59913 */
59914 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59915 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59916
59917 static int ceph_register_bdi(struct super_block *sb,
59918 struct ceph_fs_client *fsc)
59919 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59920 default_backing_dev_info.ra_pages;
59921
59922 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59923 - atomic_long_inc_return(&bdi_seq));
59924 + atomic_long_inc_return_unchecked(&bdi_seq));
59925 if (!err)
59926 sb->s_bdi = &fsc->backing_dev_info;
59927 return err;
59928 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59929 index 44ec726..11a056f 100644
59930 --- a/fs/cifs/cifs_debug.c
59931 +++ b/fs/cifs/cifs_debug.c
59932 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59933
59934 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59935 #ifdef CONFIG_CIFS_STATS2
59936 - atomic_set(&totBufAllocCount, 0);
59937 - atomic_set(&totSmBufAllocCount, 0);
59938 + atomic_set_unchecked(&totBufAllocCount, 0);
59939 + atomic_set_unchecked(&totSmBufAllocCount, 0);
59940 #endif /* CONFIG_CIFS_STATS2 */
59941 spin_lock(&cifs_tcp_ses_lock);
59942 list_for_each(tmp1, &cifs_tcp_ses_list) {
59943 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59944 tcon = list_entry(tmp3,
59945 struct cifs_tcon,
59946 tcon_list);
59947 - atomic_set(&tcon->num_smbs_sent, 0);
59948 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59949 if (server->ops->clear_stats)
59950 server->ops->clear_stats(tcon);
59951 }
59952 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59953 smBufAllocCount.counter, cifs_min_small);
59954 #ifdef CONFIG_CIFS_STATS2
59955 seq_printf(m, "Total Large %d Small %d Allocations\n",
59956 - atomic_read(&totBufAllocCount),
59957 - atomic_read(&totSmBufAllocCount));
59958 + atomic_read_unchecked(&totBufAllocCount),
59959 + atomic_read_unchecked(&totSmBufAllocCount));
59960 #endif /* CONFIG_CIFS_STATS2 */
59961
59962 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59963 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59964 if (tcon->need_reconnect)
59965 seq_puts(m, "\tDISCONNECTED ");
59966 seq_printf(m, "\nSMBs: %d",
59967 - atomic_read(&tcon->num_smbs_sent));
59968 + atomic_read_unchecked(&tcon->num_smbs_sent));
59969 if (server->ops->print_stats)
59970 server->ops->print_stats(m, tcon);
59971 }
59972 @@ -615,9 +615,11 @@ cifs_security_flags_handle_must_flags(unsigned int *flags)
59973 *flags = CIFSSEC_MUST_NTLMV2;
59974 else if ((*flags & CIFSSEC_MUST_NTLM) == CIFSSEC_MUST_NTLM)
59975 *flags = CIFSSEC_MUST_NTLM;
59976 - else if ((*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59977 + else if (CIFSSEC_MUST_LANMAN &&
59978 + (*flags & CIFSSEC_MUST_LANMAN) == CIFSSEC_MUST_LANMAN)
59979 *flags = CIFSSEC_MUST_LANMAN;
59980 - else if ((*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59981 + else if (CIFSSEC_MUST_PLNTXT &&
59982 + (*flags & CIFSSEC_MUST_PLNTXT) == CIFSSEC_MUST_PLNTXT)
59983 *flags = CIFSSEC_MUST_PLNTXT;
59984
59985 *flags |= signflags;
59986 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59987 index 9d7996e..35ad5cf4 100644
59988 --- a/fs/cifs/cifsfs.c
59989 +++ b/fs/cifs/cifsfs.c
59990 @@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59991 */
59992 cifs_req_cachep = kmem_cache_create("cifs_request",
59993 CIFSMaxBufSize + max_hdr_size, 0,
59994 - SLAB_HWCACHE_ALIGN, NULL);
59995 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59996 if (cifs_req_cachep == NULL)
59997 return -ENOMEM;
59998
59999 @@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
60000 efficient to alloc 1 per page off the slab compared to 17K (5page)
60001 alloc of large cifs buffers even when page debugging is on */
60002 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60003 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60004 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60005 NULL);
60006 if (cifs_sm_req_cachep == NULL) {
60007 mempool_destroy(cifs_req_poolp);
60008 @@ -1205,8 +1205,8 @@ init_cifs(void)
60009 atomic_set(&bufAllocCount, 0);
60010 atomic_set(&smBufAllocCount, 0);
60011 #ifdef CONFIG_CIFS_STATS2
60012 - atomic_set(&totBufAllocCount, 0);
60013 - atomic_set(&totSmBufAllocCount, 0);
60014 + atomic_set_unchecked(&totBufAllocCount, 0);
60015 + atomic_set_unchecked(&totSmBufAllocCount, 0);
60016 #endif /* CONFIG_CIFS_STATS2 */
60017
60018 atomic_set(&midCount, 0);
60019 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60020 index 02a33e5..3a28b5a 100644
60021 --- a/fs/cifs/cifsglob.h
60022 +++ b/fs/cifs/cifsglob.h
60023 @@ -823,35 +823,35 @@ struct cifs_tcon {
60024 __u16 Flags; /* optional support bits */
60025 enum statusEnum tidStatus;
60026 #ifdef CONFIG_CIFS_STATS
60027 - atomic_t num_smbs_sent;
60028 + atomic_unchecked_t num_smbs_sent;
60029 union {
60030 struct {
60031 - atomic_t num_writes;
60032 - atomic_t num_reads;
60033 - atomic_t num_flushes;
60034 - atomic_t num_oplock_brks;
60035 - atomic_t num_opens;
60036 - atomic_t num_closes;
60037 - atomic_t num_deletes;
60038 - atomic_t num_mkdirs;
60039 - atomic_t num_posixopens;
60040 - atomic_t num_posixmkdirs;
60041 - atomic_t num_rmdirs;
60042 - atomic_t num_renames;
60043 - atomic_t num_t2renames;
60044 - atomic_t num_ffirst;
60045 - atomic_t num_fnext;
60046 - atomic_t num_fclose;
60047 - atomic_t num_hardlinks;
60048 - atomic_t num_symlinks;
60049 - atomic_t num_locks;
60050 - atomic_t num_acl_get;
60051 - atomic_t num_acl_set;
60052 + atomic_unchecked_t num_writes;
60053 + atomic_unchecked_t num_reads;
60054 + atomic_unchecked_t num_flushes;
60055 + atomic_unchecked_t num_oplock_brks;
60056 + atomic_unchecked_t num_opens;
60057 + atomic_unchecked_t num_closes;
60058 + atomic_unchecked_t num_deletes;
60059 + atomic_unchecked_t num_mkdirs;
60060 + atomic_unchecked_t num_posixopens;
60061 + atomic_unchecked_t num_posixmkdirs;
60062 + atomic_unchecked_t num_rmdirs;
60063 + atomic_unchecked_t num_renames;
60064 + atomic_unchecked_t num_t2renames;
60065 + atomic_unchecked_t num_ffirst;
60066 + atomic_unchecked_t num_fnext;
60067 + atomic_unchecked_t num_fclose;
60068 + atomic_unchecked_t num_hardlinks;
60069 + atomic_unchecked_t num_symlinks;
60070 + atomic_unchecked_t num_locks;
60071 + atomic_unchecked_t num_acl_get;
60072 + atomic_unchecked_t num_acl_set;
60073 } cifs_stats;
60074 #ifdef CONFIG_CIFS_SMB2
60075 struct {
60076 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60077 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60078 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60079 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60080 } smb2_stats;
60081 #endif /* CONFIG_CIFS_SMB2 */
60082 } stats;
60083 @@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
60084 }
60085
60086 #ifdef CONFIG_CIFS_STATS
60087 -#define cifs_stats_inc atomic_inc
60088 +#define cifs_stats_inc atomic_inc_unchecked
60089
60090 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60091 unsigned int bytes)
60092 @@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60093 /* Various Debug counters */
60094 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60095 #ifdef CONFIG_CIFS_STATS2
60096 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60097 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60098 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60099 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60100 #endif
60101 GLOBAL_EXTERN atomic_t smBufAllocCount;
60102 GLOBAL_EXTERN atomic_t midCount;
60103 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60104 index 9a7b6947..4132187 100644
60105 --- a/fs/cifs/file.c
60106 +++ b/fs/cifs/file.c
60107 @@ -2060,10 +2060,14 @@ static int cifs_writepages(struct address_space *mapping,
60108 index = mapping->writeback_index; /* Start from prev offset */
60109 end = -1;
60110 } else {
60111 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
60112 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
60113 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60114 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60115 range_whole = true;
60116 + index = 0;
60117 + end = ULONG_MAX;
60118 + } else {
60119 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
60120 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
60121 + }
60122 scanned = true;
60123 }
60124 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60125 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60126 index b7415d5..3984ec0 100644
60127 --- a/fs/cifs/misc.c
60128 +++ b/fs/cifs/misc.c
60129 @@ -170,7 +170,7 @@ cifs_buf_get(void)
60130 memset(ret_buf, 0, buf_size + 3);
60131 atomic_inc(&bufAllocCount);
60132 #ifdef CONFIG_CIFS_STATS2
60133 - atomic_inc(&totBufAllocCount);
60134 + atomic_inc_unchecked(&totBufAllocCount);
60135 #endif /* CONFIG_CIFS_STATS2 */
60136 }
60137
60138 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60139 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60140 atomic_inc(&smBufAllocCount);
60141 #ifdef CONFIG_CIFS_STATS2
60142 - atomic_inc(&totSmBufAllocCount);
60143 + atomic_inc_unchecked(&totSmBufAllocCount);
60144 #endif /* CONFIG_CIFS_STATS2 */
60145
60146 }
60147 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60148 index d297903..1cb7516 100644
60149 --- a/fs/cifs/smb1ops.c
60150 +++ b/fs/cifs/smb1ops.c
60151 @@ -622,27 +622,27 @@ static void
60152 cifs_clear_stats(struct cifs_tcon *tcon)
60153 {
60154 #ifdef CONFIG_CIFS_STATS
60155 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60156 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60157 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60158 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60159 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60160 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60161 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60162 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60163 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60164 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60165 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60166 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60167 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60168 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60169 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60170 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60171 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60172 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60173 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60174 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60175 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60176 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60177 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60178 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60179 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60180 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60181 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60182 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60183 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60184 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60185 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60186 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60187 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60188 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60189 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60190 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60191 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60192 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60193 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60194 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60195 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60196 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60197 #endif
60198 }
60199
60200 @@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60201 {
60202 #ifdef CONFIG_CIFS_STATS
60203 seq_printf(m, " Oplocks breaks: %d",
60204 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60205 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60206 seq_printf(m, "\nReads: %d Bytes: %llu",
60207 - atomic_read(&tcon->stats.cifs_stats.num_reads),
60208 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60209 (long long)(tcon->bytes_read));
60210 seq_printf(m, "\nWrites: %d Bytes: %llu",
60211 - atomic_read(&tcon->stats.cifs_stats.num_writes),
60212 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60213 (long long)(tcon->bytes_written));
60214 seq_printf(m, "\nFlushes: %d",
60215 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
60216 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60217 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60218 - atomic_read(&tcon->stats.cifs_stats.num_locks),
60219 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60220 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60221 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60222 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60223 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60224 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60225 - atomic_read(&tcon->stats.cifs_stats.num_opens),
60226 - atomic_read(&tcon->stats.cifs_stats.num_closes),
60227 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
60228 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60229 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60230 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60231 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60232 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60233 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60234 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60235 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60236 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60237 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60238 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60239 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60240 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60241 seq_printf(m, "\nRenames: %d T2 Renames %d",
60242 - atomic_read(&tcon->stats.cifs_stats.num_renames),
60243 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60244 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60245 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60246 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60247 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60248 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
60249 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
60250 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60251 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60252 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60253 #endif
60254 }
60255
60256 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60257 index c5f521b..1a40865 100644
60258 --- a/fs/cifs/smb2ops.c
60259 +++ b/fs/cifs/smb2ops.c
60260 @@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60261 #ifdef CONFIG_CIFS_STATS
60262 int i;
60263 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60264 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60265 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60266 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60267 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60268 }
60269 #endif
60270 }
60271 @@ -458,65 +458,65 @@ static void
60272 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60273 {
60274 #ifdef CONFIG_CIFS_STATS
60275 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60276 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60277 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60278 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60279 seq_printf(m, "\nNegotiates: %d sent %d failed",
60280 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60281 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60282 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60283 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60284 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60285 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60286 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60287 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60288 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60289 seq_printf(m, "\nLogoffs: %d sent %d failed",
60290 - atomic_read(&sent[SMB2_LOGOFF_HE]),
60291 - atomic_read(&failed[SMB2_LOGOFF_HE]));
60292 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60293 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60294 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60295 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60296 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60297 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60298 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60299 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60300 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60301 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60302 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60303 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60304 seq_printf(m, "\nCreates: %d sent %d failed",
60305 - atomic_read(&sent[SMB2_CREATE_HE]),
60306 - atomic_read(&failed[SMB2_CREATE_HE]));
60307 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60308 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60309 seq_printf(m, "\nCloses: %d sent %d failed",
60310 - atomic_read(&sent[SMB2_CLOSE_HE]),
60311 - atomic_read(&failed[SMB2_CLOSE_HE]));
60312 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60313 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60314 seq_printf(m, "\nFlushes: %d sent %d failed",
60315 - atomic_read(&sent[SMB2_FLUSH_HE]),
60316 - atomic_read(&failed[SMB2_FLUSH_HE]));
60317 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60318 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60319 seq_printf(m, "\nReads: %d sent %d failed",
60320 - atomic_read(&sent[SMB2_READ_HE]),
60321 - atomic_read(&failed[SMB2_READ_HE]));
60322 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
60323 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
60324 seq_printf(m, "\nWrites: %d sent %d failed",
60325 - atomic_read(&sent[SMB2_WRITE_HE]),
60326 - atomic_read(&failed[SMB2_WRITE_HE]));
60327 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60328 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60329 seq_printf(m, "\nLocks: %d sent %d failed",
60330 - atomic_read(&sent[SMB2_LOCK_HE]),
60331 - atomic_read(&failed[SMB2_LOCK_HE]));
60332 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60333 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60334 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60335 - atomic_read(&sent[SMB2_IOCTL_HE]),
60336 - atomic_read(&failed[SMB2_IOCTL_HE]));
60337 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60338 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60339 seq_printf(m, "\nCancels: %d sent %d failed",
60340 - atomic_read(&sent[SMB2_CANCEL_HE]),
60341 - atomic_read(&failed[SMB2_CANCEL_HE]));
60342 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60343 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60344 seq_printf(m, "\nEchos: %d sent %d failed",
60345 - atomic_read(&sent[SMB2_ECHO_HE]),
60346 - atomic_read(&failed[SMB2_ECHO_HE]));
60347 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60348 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60349 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60350 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60351 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60352 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60353 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60354 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60355 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60356 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60357 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60358 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60359 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60360 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60361 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60362 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60363 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60364 seq_printf(m, "\nSetInfos: %d sent %d failed",
60365 - atomic_read(&sent[SMB2_SET_INFO_HE]),
60366 - atomic_read(&failed[SMB2_SET_INFO_HE]));
60367 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60368 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60369 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60370 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60371 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60372 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60373 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60374 #endif
60375 }
60376
60377 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60378 index 8f1672b..af339c07 100644
60379 --- a/fs/cifs/smb2pdu.c
60380 +++ b/fs/cifs/smb2pdu.c
60381 @@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60382 default:
60383 cifs_dbg(VFS, "info level %u isn't supported\n",
60384 srch_inf->info_level);
60385 - rc = -EINVAL;
60386 - goto qdir_exit;
60387 + return -EINVAL;
60388 }
60389
60390 req->FileIndex = cpu_to_le32(index);
60391 diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
60392 index 6c15663..a4232ec 100644
60393 --- a/fs/cifs/smbencrypt.c
60394 +++ b/fs/cifs/smbencrypt.c
60395 @@ -221,7 +221,7 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16,
60396 }
60397
60398 rc = mdfour(p16, (unsigned char *) wpwd, len * sizeof(__le16));
60399 - memset(wpwd, 0, 129 * sizeof(__le16));
60400 + memzero_explicit(wpwd, sizeof(wpwd));
60401
60402 return rc;
60403 }
60404 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60405 index 46ee6f2..89a9e7f 100644
60406 --- a/fs/coda/cache.c
60407 +++ b/fs/coda/cache.c
60408 @@ -24,7 +24,7 @@
60409 #include "coda_linux.h"
60410 #include "coda_cache.h"
60411
60412 -static atomic_t permission_epoch = ATOMIC_INIT(0);
60413 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60414
60415 /* replace or extend an acl cache hit */
60416 void coda_cache_enter(struct inode *inode, int mask)
60417 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60418 struct coda_inode_info *cii = ITOC(inode);
60419
60420 spin_lock(&cii->c_lock);
60421 - cii->c_cached_epoch = atomic_read(&permission_epoch);
60422 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60423 if (!uid_eq(cii->c_uid, current_fsuid())) {
60424 cii->c_uid = current_fsuid();
60425 cii->c_cached_perm = mask;
60426 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60427 {
60428 struct coda_inode_info *cii = ITOC(inode);
60429 spin_lock(&cii->c_lock);
60430 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60431 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60432 spin_unlock(&cii->c_lock);
60433 }
60434
60435 /* remove all acl caches */
60436 void coda_cache_clear_all(struct super_block *sb)
60437 {
60438 - atomic_inc(&permission_epoch);
60439 + atomic_inc_unchecked(&permission_epoch);
60440 }
60441
60442
60443 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60444 spin_lock(&cii->c_lock);
60445 hit = (mask & cii->c_cached_perm) == mask &&
60446 uid_eq(cii->c_uid, current_fsuid()) &&
60447 - cii->c_cached_epoch == atomic_read(&permission_epoch);
60448 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60449 spin_unlock(&cii->c_lock);
60450
60451 return hit;
60452 diff --git a/fs/compat.c b/fs/compat.c
60453 index b13df99..6f6f4a3 100644
60454 --- a/fs/compat.c
60455 +++ b/fs/compat.c
60456 @@ -54,7 +54,7 @@
60457 #include <asm/ioctls.h>
60458 #include "internal.h"
60459
60460 -int compat_log = 1;
60461 +int compat_log = 0;
60462
60463 int compat_printk(const char *fmt, ...)
60464 {
60465 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60466
60467 set_fs(KERNEL_DS);
60468 /* The __user pointer cast is valid because of the set_fs() */
60469 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60470 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60471 set_fs(oldfs);
60472 /* truncating is ok because it's a user address */
60473 if (!ret)
60474 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60475 goto out;
60476
60477 ret = -EINVAL;
60478 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60479 + if (nr_segs > UIO_MAXIOV)
60480 goto out;
60481 if (nr_segs > fast_segs) {
60482 ret = -ENOMEM;
60483 @@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60484 struct compat_readdir_callback {
60485 struct dir_context ctx;
60486 struct compat_old_linux_dirent __user *dirent;
60487 + struct file * file;
60488 int result;
60489 };
60490
60491 @@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60492 buf->result = -EOVERFLOW;
60493 return -EOVERFLOW;
60494 }
60495 +
60496 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60497 + return 0;
60498 +
60499 buf->result++;
60500 dirent = buf->dirent;
60501 if (!access_ok(VERIFY_WRITE, dirent,
60502 @@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60503 if (!f.file)
60504 return -EBADF;
60505
60506 + buf.file = f.file;
60507 error = iterate_dir(f.file, &buf.ctx);
60508 if (buf.result)
60509 error = buf.result;
60510 @@ -911,6 +917,7 @@ struct compat_getdents_callback {
60511 struct dir_context ctx;
60512 struct compat_linux_dirent __user *current_dir;
60513 struct compat_linux_dirent __user *previous;
60514 + struct file * file;
60515 int count;
60516 int error;
60517 };
60518 @@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60519 buf->error = -EOVERFLOW;
60520 return -EOVERFLOW;
60521 }
60522 +
60523 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60524 + return 0;
60525 +
60526 dirent = buf->previous;
60527 if (dirent) {
60528 if (__put_user(offset, &dirent->d_off))
60529 @@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60530 if (!f.file)
60531 return -EBADF;
60532
60533 + buf.file = f.file;
60534 error = iterate_dir(f.file, &buf.ctx);
60535 if (error >= 0)
60536 error = buf.error;
60537 @@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60538 struct dir_context ctx;
60539 struct linux_dirent64 __user *current_dir;
60540 struct linux_dirent64 __user *previous;
60541 + struct file * file;
60542 int count;
60543 int error;
60544 };
60545 @@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60546 buf->error = -EINVAL; /* only used if we fail.. */
60547 if (reclen > buf->count)
60548 return -EINVAL;
60549 +
60550 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60551 + return 0;
60552 +
60553 dirent = buf->previous;
60554
60555 if (dirent) {
60556 @@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60557 if (!f.file)
60558 return -EBADF;
60559
60560 + buf.file = f.file;
60561 error = iterate_dir(f.file, &buf.ctx);
60562 if (error >= 0)
60563 error = buf.error;
60564 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60565 index 4d24d17..4f8c09e 100644
60566 --- a/fs/compat_binfmt_elf.c
60567 +++ b/fs/compat_binfmt_elf.c
60568 @@ -30,11 +30,13 @@
60569 #undef elf_phdr
60570 #undef elf_shdr
60571 #undef elf_note
60572 +#undef elf_dyn
60573 #undef elf_addr_t
60574 #define elfhdr elf32_hdr
60575 #define elf_phdr elf32_phdr
60576 #define elf_shdr elf32_shdr
60577 #define elf_note elf32_note
60578 +#define elf_dyn Elf32_Dyn
60579 #define elf_addr_t Elf32_Addr
60580
60581 /*
60582 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60583 index afec645..9c65620 100644
60584 --- a/fs/compat_ioctl.c
60585 +++ b/fs/compat_ioctl.c
60586 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60587 return -EFAULT;
60588 if (__get_user(udata, &ss32->iomem_base))
60589 return -EFAULT;
60590 - ss.iomem_base = compat_ptr(udata);
60591 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60592 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60593 __get_user(ss.port_high, &ss32->port_high))
60594 return -EFAULT;
60595 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60596 for (i = 0; i < nmsgs; i++) {
60597 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60598 return -EFAULT;
60599 - if (get_user(datap, &umsgs[i].buf) ||
60600 - put_user(compat_ptr(datap), &tmsgs[i].buf))
60601 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60602 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60603 return -EFAULT;
60604 }
60605 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60606 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60607 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60608 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60609 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60610 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60611 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60612 return -EFAULT;
60613
60614 return ioctl_preallocate(file, p);
60615 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60616 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60617 {
60618 unsigned int a, b;
60619 - a = *(unsigned int *)p;
60620 - b = *(unsigned int *)q;
60621 + a = *(const unsigned int *)p;
60622 + b = *(const unsigned int *)q;
60623 if (a > b)
60624 return 1;
60625 if (a < b)
60626 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60627 index 668dcab..daebcd6 100644
60628 --- a/fs/configfs/dir.c
60629 +++ b/fs/configfs/dir.c
60630 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60631 }
60632 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60633 struct configfs_dirent *next;
60634 - const char *name;
60635 + const unsigned char * name;
60636 + char d_name[sizeof(next->s_dentry->d_iname)];
60637 int len;
60638 struct inode *inode = NULL;
60639
60640 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60641 continue;
60642
60643 name = configfs_get_name(next);
60644 - len = strlen(name);
60645 + if (next->s_dentry && name == next->s_dentry->d_iname) {
60646 + len = next->s_dentry->d_name.len;
60647 + memcpy(d_name, name, len);
60648 + name = d_name;
60649 + } else
60650 + len = strlen(name);
60651
60652 /*
60653 * We'll have a dentry and an inode for
60654 diff --git a/fs/coredump.c b/fs/coredump.c
60655 index b5c86ff..0dac262 100644
60656 --- a/fs/coredump.c
60657 +++ b/fs/coredump.c
60658 @@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60659 struct pipe_inode_info *pipe = file->private_data;
60660
60661 pipe_lock(pipe);
60662 - pipe->readers++;
60663 - pipe->writers--;
60664 + atomic_inc(&pipe->readers);
60665 + atomic_dec(&pipe->writers);
60666 wake_up_interruptible_sync(&pipe->wait);
60667 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60668 pipe_unlock(pipe);
60669 @@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60670 * We actually want wait_event_freezable() but then we need
60671 * to clear TIF_SIGPENDING and improve dump_interrupted().
60672 */
60673 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
60674 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60675
60676 pipe_lock(pipe);
60677 - pipe->readers--;
60678 - pipe->writers++;
60679 + atomic_dec(&pipe->readers);
60680 + atomic_inc(&pipe->writers);
60681 pipe_unlock(pipe);
60682 }
60683
60684 @@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60685 struct files_struct *displaced;
60686 bool need_nonrelative = false;
60687 bool core_dumped = false;
60688 - static atomic_t core_dump_count = ATOMIC_INIT(0);
60689 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60690 + long signr = siginfo->si_signo;
60691 + int dumpable;
60692 struct coredump_params cprm = {
60693 .siginfo = siginfo,
60694 .regs = signal_pt_regs(),
60695 @@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60696 .mm_flags = mm->flags,
60697 };
60698
60699 - audit_core_dumps(siginfo->si_signo);
60700 + audit_core_dumps(signr);
60701 +
60702 + dumpable = __get_dumpable(cprm.mm_flags);
60703 +
60704 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60705 + gr_handle_brute_attach(dumpable);
60706
60707 binfmt = mm->binfmt;
60708 if (!binfmt || !binfmt->core_dump)
60709 goto fail;
60710 - if (!__get_dumpable(cprm.mm_flags))
60711 + if (!dumpable)
60712 goto fail;
60713
60714 cred = prepare_creds();
60715 @@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60716 need_nonrelative = true;
60717 }
60718
60719 - retval = coredump_wait(siginfo->si_signo, &core_state);
60720 + retval = coredump_wait(signr, &core_state);
60721 if (retval < 0)
60722 goto fail_creds;
60723
60724 @@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60725 }
60726 cprm.limit = RLIM_INFINITY;
60727
60728 - dump_count = atomic_inc_return(&core_dump_count);
60729 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
60730 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60731 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60732 task_tgid_vnr(current), current->comm);
60733 @@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60734 } else {
60735 struct inode *inode;
60736
60737 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60738 +
60739 if (cprm.limit < binfmt->min_coredump)
60740 goto fail_unlock;
60741
60742 @@ -681,7 +690,7 @@ close_fail:
60743 filp_close(cprm.file, NULL);
60744 fail_dropcount:
60745 if (ispipe)
60746 - atomic_dec(&core_dump_count);
60747 + atomic_dec_unchecked(&core_dump_count);
60748 fail_unlock:
60749 kfree(cn.corename);
60750 coredump_finish(mm, core_dumped);
60751 @@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60752 struct file *file = cprm->file;
60753 loff_t pos = file->f_pos;
60754 ssize_t n;
60755 +
60756 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60757 if (cprm->written + nr > cprm->limit)
60758 return 0;
60759 while (nr) {
60760 diff --git a/fs/dcache.c b/fs/dcache.c
60761 index 03dca3c..15f326d 100644
60762 --- a/fs/dcache.c
60763 +++ b/fs/dcache.c
60764 @@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60765 * dentry_iput drops the locks, at which point nobody (except
60766 * transient RCU lookups) can reach this dentry.
60767 */
60768 - BUG_ON((int)dentry->d_lockref.count > 0);
60769 + BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60770 this_cpu_dec(nr_dentry);
60771 if (dentry->d_op && dentry->d_op->d_release)
60772 dentry->d_op->d_release(dentry);
60773 @@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60774 struct dentry *parent = dentry->d_parent;
60775 if (IS_ROOT(dentry))
60776 return NULL;
60777 - if (unlikely((int)dentry->d_lockref.count < 0))
60778 + if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60779 return NULL;
60780 if (likely(spin_trylock(&parent->d_lock)))
60781 return parent;
60782 @@ -638,7 +638,7 @@ repeat:
60783 dentry->d_flags |= DCACHE_REFERENCED;
60784 dentry_lru_add(dentry);
60785
60786 - dentry->d_lockref.count--;
60787 + __lockref_dec(&dentry->d_lockref);
60788 spin_unlock(&dentry->d_lock);
60789 return;
60790
60791 @@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60792 /* This must be called with d_lock held */
60793 static inline void __dget_dlock(struct dentry *dentry)
60794 {
60795 - dentry->d_lockref.count++;
60796 + __lockref_inc(&dentry->d_lockref);
60797 }
60798
60799 static inline void __dget(struct dentry *dentry)
60800 @@ -694,8 +694,8 @@ repeat:
60801 goto repeat;
60802 }
60803 rcu_read_unlock();
60804 - BUG_ON(!ret->d_lockref.count);
60805 - ret->d_lockref.count++;
60806 + BUG_ON(!__lockref_read(&ret->d_lockref));
60807 + __lockref_inc(&ret->d_lockref);
60808 spin_unlock(&ret->d_lock);
60809 return ret;
60810 }
60811 @@ -773,9 +773,9 @@ restart:
60812 spin_lock(&inode->i_lock);
60813 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60814 spin_lock(&dentry->d_lock);
60815 - if (!dentry->d_lockref.count) {
60816 + if (!__lockref_read(&dentry->d_lockref)) {
60817 struct dentry *parent = lock_parent(dentry);
60818 - if (likely(!dentry->d_lockref.count)) {
60819 + if (likely(!__lockref_read(&dentry->d_lockref))) {
60820 __dentry_kill(dentry);
60821 dput(parent);
60822 goto restart;
60823 @@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60824 * We found an inuse dentry which was not removed from
60825 * the LRU because of laziness during lookup. Do not free it.
60826 */
60827 - if ((int)dentry->d_lockref.count > 0) {
60828 + if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60829 spin_unlock(&dentry->d_lock);
60830 if (parent)
60831 spin_unlock(&parent->d_lock);
60832 @@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60833 dentry = parent;
60834 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60835 parent = lock_parent(dentry);
60836 - if (dentry->d_lockref.count != 1) {
60837 - dentry->d_lockref.count--;
60838 + if (__lockref_read(&dentry->d_lockref) != 1) {
60839 + __lockref_inc(&dentry->d_lockref);
60840 spin_unlock(&dentry->d_lock);
60841 if (parent)
60842 spin_unlock(&parent->d_lock);
60843 @@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60844 * counts, just remove them from the LRU. Otherwise give them
60845 * another pass through the LRU.
60846 */
60847 - if (dentry->d_lockref.count) {
60848 + if (__lockref_read(&dentry->d_lockref) > 0) {
60849 d_lru_isolate(dentry);
60850 spin_unlock(&dentry->d_lock);
60851 return LRU_REMOVED;
60852 @@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60853 } else {
60854 if (dentry->d_flags & DCACHE_LRU_LIST)
60855 d_lru_del(dentry);
60856 - if (!dentry->d_lockref.count) {
60857 + if (!__lockref_read(&dentry->d_lockref)) {
60858 d_shrink_add(dentry, &data->dispose);
60859 data->found++;
60860 }
60861 @@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60862 return D_WALK_CONTINUE;
60863
60864 /* root with refcount 1 is fine */
60865 - if (dentry == _data && dentry->d_lockref.count == 1)
60866 + if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60867 return D_WALK_CONTINUE;
60868
60869 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60870 @@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60871 dentry->d_inode ?
60872 dentry->d_inode->i_ino : 0UL,
60873 dentry,
60874 - dentry->d_lockref.count,
60875 + __lockref_read(&dentry->d_lockref),
60876 dentry->d_sb->s_type->name,
60877 dentry->d_sb->s_id);
60878 WARN_ON(1);
60879 @@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60880 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60881 if (name->len > DNAME_INLINE_LEN-1) {
60882 size_t size = offsetof(struct external_name, name[1]);
60883 - struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60884 + struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60885 if (!p) {
60886 kmem_cache_free(dentry_cache, dentry);
60887 return NULL;
60888 @@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60889 smp_wmb();
60890 dentry->d_name.name = dname;
60891
60892 - dentry->d_lockref.count = 1;
60893 + __lockref_set(&dentry->d_lockref, 1);
60894 dentry->d_flags = 0;
60895 spin_lock_init(&dentry->d_lock);
60896 seqcount_init(&dentry->d_seq);
60897 @@ -1452,6 +1452,9 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60898 dentry->d_sb = sb;
60899 dentry->d_op = NULL;
60900 dentry->d_fsdata = NULL;
60901 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
60902 + atomic_set(&dentry->chroot_refcnt, 0);
60903 +#endif
60904 INIT_HLIST_BL_NODE(&dentry->d_hash);
60905 INIT_LIST_HEAD(&dentry->d_lru);
60906 INIT_LIST_HEAD(&dentry->d_subdirs);
60907 @@ -2183,7 +2186,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60908 goto next;
60909 }
60910
60911 - dentry->d_lockref.count++;
60912 + __lockref_inc(&dentry->d_lockref);
60913 found = dentry;
60914 spin_unlock(&dentry->d_lock);
60915 break;
60916 @@ -2282,7 +2285,7 @@ again:
60917 spin_lock(&dentry->d_lock);
60918 inode = dentry->d_inode;
60919 isdir = S_ISDIR(inode->i_mode);
60920 - if (dentry->d_lockref.count == 1) {
60921 + if (__lockref_read(&dentry->d_lockref) == 1) {
60922 if (!spin_trylock(&inode->i_lock)) {
60923 spin_unlock(&dentry->d_lock);
60924 cpu_relax();
60925 @@ -3308,7 +3311,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60926
60927 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60928 dentry->d_flags |= DCACHE_GENOCIDE;
60929 - dentry->d_lockref.count--;
60930 + __lockref_dec(&dentry->d_lockref);
60931 }
60932 }
60933 return D_WALK_CONTINUE;
60934 @@ -3424,7 +3427,8 @@ void __init vfs_caches_init(unsigned long mempages)
60935 mempages -= reserve;
60936
60937 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60938 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60939 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60940 + SLAB_NO_SANITIZE, NULL);
60941
60942 dcache_init();
60943 inode_init();
60944 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60945 index 05f2960..780f4f8 100644
60946 --- a/fs/debugfs/inode.c
60947 +++ b/fs/debugfs/inode.c
60948 @@ -246,10 +246,19 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root)
60949 return 0;
60950 }
60951
60952 +static void debugfs_evict_inode(struct inode *inode)
60953 +{
60954 + truncate_inode_pages_final(&inode->i_data);
60955 + clear_inode(inode);
60956 + if (S_ISLNK(inode->i_mode))
60957 + kfree(inode->i_private);
60958 +}
60959 +
60960 static const struct super_operations debugfs_super_operations = {
60961 .statfs = simple_statfs,
60962 .remount_fs = debugfs_remount,
60963 .show_options = debugfs_show_options,
60964 + .evict_inode = debugfs_evict_inode,
60965 };
60966
60967 static int debug_fill_super(struct super_block *sb, void *data, int silent)
60968 @@ -416,7 +425,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60969 */
60970 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60971 {
60972 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60973 + return __create_file(name, S_IFDIR | S_IRWXU,
60974 +#else
60975 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60976 +#endif
60977 parent, NULL, NULL);
60978 }
60979 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60980 @@ -466,23 +479,14 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
60981 int ret = 0;
60982
60983 if (debugfs_positive(dentry)) {
60984 - if (dentry->d_inode) {
60985 - dget(dentry);
60986 - switch (dentry->d_inode->i_mode & S_IFMT) {
60987 - case S_IFDIR:
60988 - ret = simple_rmdir(parent->d_inode, dentry);
60989 - break;
60990 - case S_IFLNK:
60991 - kfree(dentry->d_inode->i_private);
60992 - /* fall through */
60993 - default:
60994 - simple_unlink(parent->d_inode, dentry);
60995 - break;
60996 - }
60997 - if (!ret)
60998 - d_delete(dentry);
60999 - dput(dentry);
61000 - }
61001 + dget(dentry);
61002 + if (S_ISDIR(dentry->d_inode->i_mode))
61003 + ret = simple_rmdir(parent->d_inode, dentry);
61004 + else
61005 + simple_unlink(parent->d_inode, dentry);
61006 + if (!ret)
61007 + d_delete(dentry);
61008 + dput(dentry);
61009 }
61010 return ret;
61011 }
61012 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61013 index 1686dc2..9611c50 100644
61014 --- a/fs/ecryptfs/inode.c
61015 +++ b/fs/ecryptfs/inode.c
61016 @@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61017 old_fs = get_fs();
61018 set_fs(get_ds());
61019 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61020 - (char __user *)lower_buf,
61021 + (char __force_user *)lower_buf,
61022 PATH_MAX);
61023 set_fs(old_fs);
61024 if (rc < 0)
61025 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61026 index e4141f2..d8263e8 100644
61027 --- a/fs/ecryptfs/miscdev.c
61028 +++ b/fs/ecryptfs/miscdev.c
61029 @@ -304,7 +304,7 @@ check_list:
61030 goto out_unlock_msg_ctx;
61031 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61032 if (msg_ctx->msg) {
61033 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
61034 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61035 goto out_unlock_msg_ctx;
61036 i += packet_length_size;
61037 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61038 diff --git a/fs/exec.c b/fs/exec.c
61039 index 7302b75..44eb2f8 100644
61040 --- a/fs/exec.c
61041 +++ b/fs/exec.c
61042 @@ -56,8 +56,20 @@
61043 #include <linux/pipe_fs_i.h>
61044 #include <linux/oom.h>
61045 #include <linux/compat.h>
61046 +#include <linux/random.h>
61047 +#include <linux/seq_file.h>
61048 +#include <linux/coredump.h>
61049 +#include <linux/mman.h>
61050 +
61051 +#ifdef CONFIG_PAX_REFCOUNT
61052 +#include <linux/kallsyms.h>
61053 +#include <linux/kdebug.h>
61054 +#endif
61055 +
61056 +#include <trace/events/fs.h>
61057
61058 #include <asm/uaccess.h>
61059 +#include <asm/sections.h>
61060 #include <asm/mmu_context.h>
61061 #include <asm/tlb.h>
61062
61063 @@ -66,19 +78,34 @@
61064
61065 #include <trace/events/sched.h>
61066
61067 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61068 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61069 +{
61070 + 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");
61071 +}
61072 +#endif
61073 +
61074 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61075 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61076 +EXPORT_SYMBOL(pax_set_initial_flags_func);
61077 +#endif
61078 +
61079 int suid_dumpable = 0;
61080
61081 static LIST_HEAD(formats);
61082 static DEFINE_RWLOCK(binfmt_lock);
61083
61084 +extern int gr_process_kernel_exec_ban(void);
61085 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61086 +
61087 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61088 {
61089 BUG_ON(!fmt);
61090 if (WARN_ON(!fmt->load_binary))
61091 return;
61092 write_lock(&binfmt_lock);
61093 - insert ? list_add(&fmt->lh, &formats) :
61094 - list_add_tail(&fmt->lh, &formats);
61095 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61096 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61097 write_unlock(&binfmt_lock);
61098 }
61099
61100 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61101 void unregister_binfmt(struct linux_binfmt * fmt)
61102 {
61103 write_lock(&binfmt_lock);
61104 - list_del(&fmt->lh);
61105 + pax_list_del((struct list_head *)&fmt->lh);
61106 write_unlock(&binfmt_lock);
61107 }
61108
61109 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61110 int write)
61111 {
61112 struct page *page;
61113 - int ret;
61114
61115 -#ifdef CONFIG_STACK_GROWSUP
61116 - if (write) {
61117 - ret = expand_downwards(bprm->vma, pos);
61118 - if (ret < 0)
61119 - return NULL;
61120 - }
61121 -#endif
61122 - ret = get_user_pages(current, bprm->mm, pos,
61123 - 1, write, 1, &page, NULL);
61124 - if (ret <= 0)
61125 + if (0 > expand_downwards(bprm->vma, pos))
61126 + return NULL;
61127 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61128 return NULL;
61129
61130 if (write) {
61131 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61132 if (size <= ARG_MAX)
61133 return page;
61134
61135 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61136 + // only allow 512KB for argv+env on suid/sgid binaries
61137 + // to prevent easy ASLR exhaustion
61138 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61139 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
61140 + (size > (512 * 1024))) {
61141 + put_page(page);
61142 + return NULL;
61143 + }
61144 +#endif
61145 +
61146 /*
61147 * Limit to 1/4-th the stack size for the argv+env strings.
61148 * This ensures that:
61149 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61150 vma->vm_end = STACK_TOP_MAX;
61151 vma->vm_start = vma->vm_end - PAGE_SIZE;
61152 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61153 +
61154 +#ifdef CONFIG_PAX_SEGMEXEC
61155 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61156 +#endif
61157 +
61158 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61159 INIT_LIST_HEAD(&vma->anon_vma_chain);
61160
61161 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61162 mm->stack_vm = mm->total_vm = 1;
61163 up_write(&mm->mmap_sem);
61164 bprm->p = vma->vm_end - sizeof(void *);
61165 +
61166 +#ifdef CONFIG_PAX_RANDUSTACK
61167 + if (randomize_va_space)
61168 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
61169 +#endif
61170 +
61171 return 0;
61172 err:
61173 up_write(&mm->mmap_sem);
61174 @@ -395,7 +436,7 @@ struct user_arg_ptr {
61175 } ptr;
61176 };
61177
61178 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61179 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61180 {
61181 const char __user *native;
61182
61183 @@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61184 compat_uptr_t compat;
61185
61186 if (get_user(compat, argv.ptr.compat + nr))
61187 - return ERR_PTR(-EFAULT);
61188 + return (const char __force_user *)ERR_PTR(-EFAULT);
61189
61190 return compat_ptr(compat);
61191 }
61192 #endif
61193
61194 if (get_user(native, argv.ptr.native + nr))
61195 - return ERR_PTR(-EFAULT);
61196 + return (const char __force_user *)ERR_PTR(-EFAULT);
61197
61198 return native;
61199 }
61200 @@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61201 if (!p)
61202 break;
61203
61204 - if (IS_ERR(p))
61205 + if (IS_ERR((const char __force_kernel *)p))
61206 return -EFAULT;
61207
61208 if (i >= max)
61209 @@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61210
61211 ret = -EFAULT;
61212 str = get_user_arg_ptr(argv, argc);
61213 - if (IS_ERR(str))
61214 + if (IS_ERR((const char __force_kernel *)str))
61215 goto out;
61216
61217 len = strnlen_user(str, MAX_ARG_STRLEN);
61218 @@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61219 int r;
61220 mm_segment_t oldfs = get_fs();
61221 struct user_arg_ptr argv = {
61222 - .ptr.native = (const char __user *const __user *)__argv,
61223 + .ptr.native = (const char __user * const __force_user *)__argv,
61224 };
61225
61226 set_fs(KERNEL_DS);
61227 @@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61228 unsigned long new_end = old_end - shift;
61229 struct mmu_gather tlb;
61230
61231 - BUG_ON(new_start > new_end);
61232 + if (new_start >= new_end || new_start < mmap_min_addr)
61233 + return -ENOMEM;
61234
61235 /*
61236 * ensure there are no vmas between where we want to go
61237 @@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61238 if (vma != find_vma(mm, new_start))
61239 return -EFAULT;
61240
61241 +#ifdef CONFIG_PAX_SEGMEXEC
61242 + BUG_ON(pax_find_mirror_vma(vma));
61243 +#endif
61244 +
61245 /*
61246 * cover the whole range: [new_start, old_end)
61247 */
61248 @@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61249 stack_top = arch_align_stack(stack_top);
61250 stack_top = PAGE_ALIGN(stack_top);
61251
61252 - if (unlikely(stack_top < mmap_min_addr) ||
61253 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61254 - return -ENOMEM;
61255 -
61256 stack_shift = vma->vm_end - stack_top;
61257
61258 bprm->p -= stack_shift;
61259 @@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61260 bprm->exec -= stack_shift;
61261
61262 down_write(&mm->mmap_sem);
61263 +
61264 + /* Move stack pages down in memory. */
61265 + if (stack_shift) {
61266 + ret = shift_arg_pages(vma, stack_shift);
61267 + if (ret)
61268 + goto out_unlock;
61269 + }
61270 +
61271 vm_flags = VM_STACK_FLAGS;
61272
61273 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61274 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61275 + vm_flags &= ~VM_EXEC;
61276 +
61277 +#ifdef CONFIG_PAX_MPROTECT
61278 + if (mm->pax_flags & MF_PAX_MPROTECT)
61279 + vm_flags &= ~VM_MAYEXEC;
61280 +#endif
61281 +
61282 + }
61283 +#endif
61284 +
61285 /*
61286 * Adjust stack execute permissions; explicitly enable for
61287 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61288 @@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61289 goto out_unlock;
61290 BUG_ON(prev != vma);
61291
61292 - /* Move stack pages down in memory. */
61293 - if (stack_shift) {
61294 - ret = shift_arg_pages(vma, stack_shift);
61295 - if (ret)
61296 - goto out_unlock;
61297 - }
61298 -
61299 /* mprotect_fixup is overkill to remove the temporary stack flags */
61300 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61301
61302 @@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61303 #endif
61304 current->mm->start_stack = bprm->p;
61305 ret = expand_stack(vma, stack_base);
61306 +
61307 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61308 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61309 + unsigned long size;
61310 + vm_flags_t vm_flags;
61311 +
61312 + size = STACK_TOP - vma->vm_end;
61313 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61314 +
61315 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61316 +
61317 +#ifdef CONFIG_X86
61318 + if (!ret) {
61319 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61320 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61321 + }
61322 +#endif
61323 +
61324 + }
61325 +#endif
61326 +
61327 if (ret)
61328 ret = -EFAULT;
61329
61330 @@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61331
61332 fsnotify_open(file);
61333
61334 + trace_open_exec(name->name);
61335 +
61336 err = deny_write_access(file);
61337 if (err)
61338 goto exit;
61339 @@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61340 old_fs = get_fs();
61341 set_fs(get_ds());
61342 /* The cast to a user pointer is valid due to the set_fs() */
61343 - result = vfs_read(file, (void __user *)addr, count, &pos);
61344 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
61345 set_fs(old_fs);
61346 return result;
61347 }
61348 @@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61349 tsk->mm = mm;
61350 tsk->active_mm = mm;
61351 activate_mm(active_mm, mm);
61352 + populate_stack();
61353 tsk->mm->vmacache_seqnum = 0;
61354 vmacache_flush(tsk);
61355 task_unlock(tsk);
61356 @@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61357 }
61358 rcu_read_unlock();
61359
61360 - if (p->fs->users > n_fs)
61361 + if (atomic_read(&p->fs->users) > n_fs)
61362 bprm->unsafe |= LSM_UNSAFE_SHARE;
61363 else
61364 p->fs->in_exec = 1;
61365 @@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61366 return ret;
61367 }
61368
61369 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61370 +static DEFINE_PER_CPU(u64, exec_counter);
61371 +static int __init init_exec_counters(void)
61372 +{
61373 + unsigned int cpu;
61374 +
61375 + for_each_possible_cpu(cpu) {
61376 + per_cpu(exec_counter, cpu) = (u64)cpu;
61377 + }
61378 +
61379 + return 0;
61380 +}
61381 +early_initcall(init_exec_counters);
61382 +static inline void increment_exec_counter(void)
61383 +{
61384 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
61385 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61386 +}
61387 +#else
61388 +static inline void increment_exec_counter(void) {}
61389 +#endif
61390 +
61391 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
61392 + struct user_arg_ptr argv);
61393 +
61394 /*
61395 * sys_execve() executes a new program.
61396 */
61397 @@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61398 struct user_arg_ptr argv,
61399 struct user_arg_ptr envp)
61400 {
61401 +#ifdef CONFIG_GRKERNSEC
61402 + struct file *old_exec_file;
61403 + struct acl_subject_label *old_acl;
61404 + struct rlimit old_rlim[RLIM_NLIMITS];
61405 +#endif
61406 struct linux_binprm *bprm;
61407 struct file *file;
61408 struct files_struct *displaced;
61409 @@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61410 if (IS_ERR(filename))
61411 return PTR_ERR(filename);
61412
61413 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61414 +
61415 /*
61416 * We move the actual failure in case of RLIMIT_NPROC excess from
61417 * set*uid() to execve() because too many poorly written programs
61418 @@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61419 if (IS_ERR(file))
61420 goto out_unmark;
61421
61422 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
61423 + retval = -EPERM;
61424 + goto out_unmark;
61425 + }
61426 +
61427 sched_exec();
61428
61429 bprm->file = file;
61430 bprm->filename = bprm->interp = filename->name;
61431
61432 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61433 + retval = -EACCES;
61434 + goto out_unmark;
61435 + }
61436 +
61437 retval = bprm_mm_init(bprm);
61438 if (retval)
61439 goto out_unmark;
61440 @@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61441 if (retval < 0)
61442 goto out;
61443
61444 +#ifdef CONFIG_GRKERNSEC
61445 + old_acl = current->acl;
61446 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61447 + old_exec_file = current->exec_file;
61448 + get_file(file);
61449 + current->exec_file = file;
61450 +#endif
61451 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61452 + /* limit suid stack to 8MB
61453 + * we saved the old limits above and will restore them if this exec fails
61454 + */
61455 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61456 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61457 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61458 +#endif
61459 +
61460 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61461 + retval = -EPERM;
61462 + goto out_fail;
61463 + }
61464 +
61465 + if (!gr_tpe_allow(file)) {
61466 + retval = -EACCES;
61467 + goto out_fail;
61468 + }
61469 +
61470 + if (gr_check_crash_exec(file)) {
61471 + retval = -EACCES;
61472 + goto out_fail;
61473 + }
61474 +
61475 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61476 + bprm->unsafe);
61477 + if (retval < 0)
61478 + goto out_fail;
61479 +
61480 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61481 if (retval < 0)
61482 - goto out;
61483 + goto out_fail;
61484
61485 bprm->exec = bprm->p;
61486 retval = copy_strings(bprm->envc, envp, bprm);
61487 if (retval < 0)
61488 - goto out;
61489 + goto out_fail;
61490
61491 retval = copy_strings(bprm->argc, argv, bprm);
61492 if (retval < 0)
61493 - goto out;
61494 + goto out_fail;
61495 +
61496 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61497 +
61498 + gr_handle_exec_args(bprm, argv);
61499
61500 retval = exec_binprm(bprm);
61501 if (retval < 0)
61502 - goto out;
61503 + goto out_fail;
61504 +#ifdef CONFIG_GRKERNSEC
61505 + if (old_exec_file)
61506 + fput(old_exec_file);
61507 +#endif
61508
61509 /* execve succeeded */
61510 +
61511 + increment_exec_counter();
61512 current->fs->in_exec = 0;
61513 current->in_execve = 0;
61514 acct_update_integrals(current);
61515 @@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61516 put_files_struct(displaced);
61517 return retval;
61518
61519 +out_fail:
61520 +#ifdef CONFIG_GRKERNSEC
61521 + current->acl = old_acl;
61522 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61523 + fput(current->exec_file);
61524 + current->exec_file = old_exec_file;
61525 +#endif
61526 +
61527 out:
61528 if (bprm->mm) {
61529 acct_arg_size(bprm, 0);
61530 @@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61531 return compat_do_execve(getname(filename), argv, envp);
61532 }
61533 #endif
61534 +
61535 +int pax_check_flags(unsigned long *flags)
61536 +{
61537 + int retval = 0;
61538 +
61539 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61540 + if (*flags & MF_PAX_SEGMEXEC)
61541 + {
61542 + *flags &= ~MF_PAX_SEGMEXEC;
61543 + retval = -EINVAL;
61544 + }
61545 +#endif
61546 +
61547 + if ((*flags & MF_PAX_PAGEEXEC)
61548 +
61549 +#ifdef CONFIG_PAX_PAGEEXEC
61550 + && (*flags & MF_PAX_SEGMEXEC)
61551 +#endif
61552 +
61553 + )
61554 + {
61555 + *flags &= ~MF_PAX_PAGEEXEC;
61556 + retval = -EINVAL;
61557 + }
61558 +
61559 + if ((*flags & MF_PAX_MPROTECT)
61560 +
61561 +#ifdef CONFIG_PAX_MPROTECT
61562 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61563 +#endif
61564 +
61565 + )
61566 + {
61567 + *flags &= ~MF_PAX_MPROTECT;
61568 + retval = -EINVAL;
61569 + }
61570 +
61571 + if ((*flags & MF_PAX_EMUTRAMP)
61572 +
61573 +#ifdef CONFIG_PAX_EMUTRAMP
61574 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61575 +#endif
61576 +
61577 + )
61578 + {
61579 + *flags &= ~MF_PAX_EMUTRAMP;
61580 + retval = -EINVAL;
61581 + }
61582 +
61583 + return retval;
61584 +}
61585 +
61586 +EXPORT_SYMBOL(pax_check_flags);
61587 +
61588 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61589 +char *pax_get_path(const struct path *path, char *buf, int buflen)
61590 +{
61591 + char *pathname = d_path(path, buf, buflen);
61592 +
61593 + if (IS_ERR(pathname))
61594 + goto toolong;
61595 +
61596 + pathname = mangle_path(buf, pathname, "\t\n\\");
61597 + if (!pathname)
61598 + goto toolong;
61599 +
61600 + *pathname = 0;
61601 + return buf;
61602 +
61603 +toolong:
61604 + return "<path too long>";
61605 +}
61606 +EXPORT_SYMBOL(pax_get_path);
61607 +
61608 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61609 +{
61610 + struct task_struct *tsk = current;
61611 + struct mm_struct *mm = current->mm;
61612 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61613 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61614 + char *path_exec = NULL;
61615 + char *path_fault = NULL;
61616 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
61617 + siginfo_t info = { };
61618 +
61619 + if (buffer_exec && buffer_fault) {
61620 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61621 +
61622 + down_read(&mm->mmap_sem);
61623 + vma = mm->mmap;
61624 + while (vma && (!vma_exec || !vma_fault)) {
61625 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61626 + vma_exec = vma;
61627 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61628 + vma_fault = vma;
61629 + vma = vma->vm_next;
61630 + }
61631 + if (vma_exec)
61632 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61633 + if (vma_fault) {
61634 + start = vma_fault->vm_start;
61635 + end = vma_fault->vm_end;
61636 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61637 + if (vma_fault->vm_file)
61638 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61639 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61640 + path_fault = "<heap>";
61641 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61642 + path_fault = "<stack>";
61643 + else
61644 + path_fault = "<anonymous mapping>";
61645 + }
61646 + up_read(&mm->mmap_sem);
61647 + }
61648 + if (tsk->signal->curr_ip)
61649 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61650 + else
61651 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61652 + 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),
61653 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61654 + free_page((unsigned long)buffer_exec);
61655 + free_page((unsigned long)buffer_fault);
61656 + pax_report_insns(regs, pc, sp);
61657 + info.si_signo = SIGKILL;
61658 + info.si_errno = 0;
61659 + info.si_code = SI_KERNEL;
61660 + info.si_pid = 0;
61661 + info.si_uid = 0;
61662 + do_coredump(&info);
61663 +}
61664 +#endif
61665 +
61666 +#ifdef CONFIG_PAX_REFCOUNT
61667 +void pax_report_refcount_overflow(struct pt_regs *regs)
61668 +{
61669 + if (current->signal->curr_ip)
61670 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61671 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
61672 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61673 + else
61674 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61675 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61676 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61677 + preempt_disable();
61678 + show_regs(regs);
61679 + preempt_enable();
61680 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61681 +}
61682 +#endif
61683 +
61684 +#ifdef CONFIG_PAX_USERCOPY
61685 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61686 +static noinline int check_stack_object(const void *obj, unsigned long len)
61687 +{
61688 + const void * const stack = task_stack_page(current);
61689 + const void * const stackend = stack + THREAD_SIZE;
61690 +
61691 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61692 + const void *frame = NULL;
61693 + const void *oldframe;
61694 +#endif
61695 +
61696 + if (obj + len < obj)
61697 + return -1;
61698 +
61699 + if (obj + len <= stack || stackend <= obj)
61700 + return 0;
61701 +
61702 + if (obj < stack || stackend < obj + len)
61703 + return -1;
61704 +
61705 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61706 + oldframe = __builtin_frame_address(1);
61707 + if (oldframe)
61708 + frame = __builtin_frame_address(2);
61709 + /*
61710 + low ----------------------------------------------> high
61711 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
61712 + ^----------------^
61713 + allow copies only within here
61714 + */
61715 + while (stack <= frame && frame < stackend) {
61716 + /* if obj + len extends past the last frame, this
61717 + check won't pass and the next frame will be 0,
61718 + causing us to bail out and correctly report
61719 + the copy as invalid
61720 + */
61721 + if (obj + len <= frame)
61722 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61723 + oldframe = frame;
61724 + frame = *(const void * const *)frame;
61725 + }
61726 + return -1;
61727 +#else
61728 + return 1;
61729 +#endif
61730 +}
61731 +
61732 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61733 +{
61734 + if (current->signal->curr_ip)
61735 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61736 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61737 + else
61738 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61739 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61740 + dump_stack();
61741 + gr_handle_kernel_exploit();
61742 + do_group_exit(SIGKILL);
61743 +}
61744 +#endif
61745 +
61746 +#ifdef CONFIG_PAX_USERCOPY
61747 +
61748 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61749 +{
61750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61751 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
61752 +#ifdef CONFIG_MODULES
61753 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61754 +#else
61755 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61756 +#endif
61757 +
61758 +#else
61759 + unsigned long textlow = (unsigned long)_stext;
61760 + unsigned long texthigh = (unsigned long)_etext;
61761 +
61762 +#ifdef CONFIG_X86_64
61763 + /* check against linear mapping as well */
61764 + if (high > (unsigned long)__va(__pa(textlow)) &&
61765 + low < (unsigned long)__va(__pa(texthigh)))
61766 + return true;
61767 +#endif
61768 +
61769 +#endif
61770 +
61771 + if (high <= textlow || low >= texthigh)
61772 + return false;
61773 + else
61774 + return true;
61775 +}
61776 +#endif
61777 +
61778 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61779 +{
61780 +#ifdef CONFIG_PAX_USERCOPY
61781 + const char *type;
61782 +#endif
61783 +
61784 +#if !defined(CONFIG_STACK_GROWSUP) && !defined(CONFIG_X86_64)
61785 + unsigned long stackstart = (unsigned long)task_stack_page(current);
61786 + unsigned long currentsp = (unsigned long)&stackstart;
61787 + if (unlikely((currentsp < stackstart + 512 ||
61788 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61789 + BUG();
61790 +#endif
61791 +
61792 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
61793 + if (const_size)
61794 + return;
61795 +#endif
61796 +
61797 +#ifdef CONFIG_PAX_USERCOPY
61798 + if (!n)
61799 + return;
61800 +
61801 + type = check_heap_object(ptr, n);
61802 + if (!type) {
61803 + int ret = check_stack_object(ptr, n);
61804 + if (ret == 1 || ret == 2)
61805 + return;
61806 + if (ret == 0) {
61807 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61808 + type = "<kernel text>";
61809 + else
61810 + return;
61811 + } else
61812 + type = "<process stack>";
61813 + }
61814 +
61815 + pax_report_usercopy(ptr, n, to_user, type);
61816 +#endif
61817 +
61818 +}
61819 +EXPORT_SYMBOL(__check_object_size);
61820 +
61821 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61822 +void pax_track_stack(void)
61823 +{
61824 + unsigned long sp = (unsigned long)&sp;
61825 + if (sp < current_thread_info()->lowest_stack &&
61826 + sp >= (unsigned long)task_stack_page(current) + 2 * sizeof(unsigned long))
61827 + current_thread_info()->lowest_stack = sp;
61828 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61829 + BUG();
61830 +}
61831 +EXPORT_SYMBOL(pax_track_stack);
61832 +#endif
61833 +
61834 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
61835 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61836 +{
61837 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61838 + dump_stack();
61839 + do_group_exit(SIGKILL);
61840 +}
61841 +EXPORT_SYMBOL(report_size_overflow);
61842 +#endif
61843 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61844 index 9f9992b..8b59411 100644
61845 --- a/fs/ext2/balloc.c
61846 +++ b/fs/ext2/balloc.c
61847 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61848
61849 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61850 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61851 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61852 + if (free_blocks < root_blocks + 1 &&
61853 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61854 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61855 - !in_group_p (sbi->s_resgid))) {
61856 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61857 return 0;
61858 }
61859 return 1;
61860 diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61861 index 170dc41..62f6b18 100644
61862 --- a/fs/ext2/super.c
61863 +++ b/fs/ext2/super.c
61864 @@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61865 #ifdef CONFIG_EXT2_FS_XATTR
61866 if (test_opt(sb, XATTR_USER))
61867 seq_puts(seq, ",user_xattr");
61868 - if (!test_opt(sb, XATTR_USER) &&
61869 - (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61870 + if (!test_opt(sb, XATTR_USER))
61871 seq_puts(seq, ",nouser_xattr");
61872 - }
61873 #endif
61874
61875 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61876 @@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61877 if (def_mount_opts & EXT2_DEFM_UID16)
61878 set_opt(sbi->s_mount_opt, NO_UID32);
61879 #ifdef CONFIG_EXT2_FS_XATTR
61880 - if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61881 - set_opt(sbi->s_mount_opt, XATTR_USER);
61882 + /* always enable user xattrs */
61883 + set_opt(sbi->s_mount_opt, XATTR_USER);
61884 #endif
61885 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61886 if (def_mount_opts & EXT2_DEFM_ACL)
61887 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61888 index 9142614..97484fa 100644
61889 --- a/fs/ext2/xattr.c
61890 +++ b/fs/ext2/xattr.c
61891 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61892 struct buffer_head *bh = NULL;
61893 struct ext2_xattr_entry *entry;
61894 char *end;
61895 - size_t rest = buffer_size;
61896 + size_t rest = buffer_size, total_size = 0;
61897 int error;
61898
61899 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61900 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61901 buffer += size;
61902 }
61903 rest -= size;
61904 + total_size += size;
61905 }
61906 }
61907 - error = buffer_size - rest; /* total size */
61908 + error = total_size;
61909
61910 cleanup:
61911 brelse(bh);
61912 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61913 index 158b5d4..2432610 100644
61914 --- a/fs/ext3/balloc.c
61915 +++ b/fs/ext3/balloc.c
61916 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61917
61918 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61919 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61920 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61921 + if (free_blocks < root_blocks + 1 &&
61922 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61923 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61924 - !in_group_p (sbi->s_resgid))) {
61925 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61926 return 0;
61927 }
61928 return 1;
61929 diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61930 index eb742d0..c19f705 100644
61931 --- a/fs/ext3/super.c
61932 +++ b/fs/ext3/super.c
61933 @@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61934 #ifdef CONFIG_EXT3_FS_XATTR
61935 if (test_opt(sb, XATTR_USER))
61936 seq_puts(seq, ",user_xattr");
61937 - if (!test_opt(sb, XATTR_USER) &&
61938 - (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61939 + if (!test_opt(sb, XATTR_USER))
61940 seq_puts(seq, ",nouser_xattr");
61941 - }
61942 #endif
61943 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61944 if (test_opt(sb, POSIX_ACL))
61945 @@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61946 if (def_mount_opts & EXT3_DEFM_UID16)
61947 set_opt(sbi->s_mount_opt, NO_UID32);
61948 #ifdef CONFIG_EXT3_FS_XATTR
61949 - if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61950 - set_opt(sbi->s_mount_opt, XATTR_USER);
61951 + /* always enable user xattrs */
61952 + set_opt(sbi->s_mount_opt, XATTR_USER);
61953 #endif
61954 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61955 if (def_mount_opts & EXT3_DEFM_ACL)
61956 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61957 index c6874be..f8a6ae8 100644
61958 --- a/fs/ext3/xattr.c
61959 +++ b/fs/ext3/xattr.c
61960 @@ -330,7 +330,7 @@ static int
61961 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61962 char *buffer, size_t buffer_size)
61963 {
61964 - size_t rest = buffer_size;
61965 + size_t rest = buffer_size, total_size = 0;
61966
61967 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61968 const struct xattr_handler *handler =
61969 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61970 buffer += size;
61971 }
61972 rest -= size;
61973 + total_size += size;
61974 }
61975 }
61976 - return buffer_size - rest;
61977 + return total_size;
61978 }
61979
61980 static int
61981 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61982 index 83a6f49..d4e4d03 100644
61983 --- a/fs/ext4/balloc.c
61984 +++ b/fs/ext4/balloc.c
61985 @@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61986 /* Hm, nope. Are (enough) root reserved clusters available? */
61987 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61988 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61989 - capable(CAP_SYS_RESOURCE) ||
61990 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61991 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61992 + capable_nolog(CAP_SYS_RESOURCE)) {
61993
61994 if (free_clusters >= (nclusters + dirty_clusters +
61995 resv_clusters))
61996 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61997 index c55a1fa..9904ebb 100644
61998 --- a/fs/ext4/ext4.h
61999 +++ b/fs/ext4/ext4.h
62000 @@ -1279,19 +1279,19 @@ struct ext4_sb_info {
62001 unsigned long s_mb_last_start;
62002
62003 /* stats for buddy allocator */
62004 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62005 - atomic_t s_bal_success; /* we found long enough chunks */
62006 - atomic_t s_bal_allocated; /* in blocks */
62007 - atomic_t s_bal_ex_scanned; /* total extents scanned */
62008 - atomic_t s_bal_goals; /* goal hits */
62009 - atomic_t s_bal_breaks; /* too long searches */
62010 - atomic_t s_bal_2orders; /* 2^order hits */
62011 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62012 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62013 + atomic_unchecked_t s_bal_allocated; /* in blocks */
62014 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62015 + atomic_unchecked_t s_bal_goals; /* goal hits */
62016 + atomic_unchecked_t s_bal_breaks; /* too long searches */
62017 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62018 spinlock_t s_bal_lock;
62019 unsigned long s_mb_buddies_generated;
62020 unsigned long long s_mb_generation_time;
62021 - atomic_t s_mb_lost_chunks;
62022 - atomic_t s_mb_preallocated;
62023 - atomic_t s_mb_discarded;
62024 + atomic_unchecked_t s_mb_lost_chunks;
62025 + atomic_unchecked_t s_mb_preallocated;
62026 + atomic_unchecked_t s_mb_discarded;
62027 atomic_t s_lock_busy;
62028
62029 /* locality groups */
62030 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62031 index dbfe15c..9a6ee8d 100644
62032 --- a/fs/ext4/mballoc.c
62033 +++ b/fs/ext4/mballoc.c
62034 @@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62035 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62036
62037 if (EXT4_SB(sb)->s_mb_stats)
62038 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62039 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62040
62041 break;
62042 }
62043 @@ -2211,7 +2211,7 @@ repeat:
62044 ac->ac_status = AC_STATUS_CONTINUE;
62045 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62046 cr = 3;
62047 - atomic_inc(&sbi->s_mb_lost_chunks);
62048 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62049 goto repeat;
62050 }
62051 }
62052 @@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62053 if (sbi->s_mb_stats) {
62054 ext4_msg(sb, KERN_INFO,
62055 "mballoc: %u blocks %u reqs (%u success)",
62056 - atomic_read(&sbi->s_bal_allocated),
62057 - atomic_read(&sbi->s_bal_reqs),
62058 - atomic_read(&sbi->s_bal_success));
62059 + atomic_read_unchecked(&sbi->s_bal_allocated),
62060 + atomic_read_unchecked(&sbi->s_bal_reqs),
62061 + atomic_read_unchecked(&sbi->s_bal_success));
62062 ext4_msg(sb, KERN_INFO,
62063 "mballoc: %u extents scanned, %u goal hits, "
62064 "%u 2^N hits, %u breaks, %u lost",
62065 - atomic_read(&sbi->s_bal_ex_scanned),
62066 - atomic_read(&sbi->s_bal_goals),
62067 - atomic_read(&sbi->s_bal_2orders),
62068 - atomic_read(&sbi->s_bal_breaks),
62069 - atomic_read(&sbi->s_mb_lost_chunks));
62070 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62071 + atomic_read_unchecked(&sbi->s_bal_goals),
62072 + atomic_read_unchecked(&sbi->s_bal_2orders),
62073 + atomic_read_unchecked(&sbi->s_bal_breaks),
62074 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62075 ext4_msg(sb, KERN_INFO,
62076 "mballoc: %lu generated and it took %Lu",
62077 sbi->s_mb_buddies_generated,
62078 sbi->s_mb_generation_time);
62079 ext4_msg(sb, KERN_INFO,
62080 "mballoc: %u preallocated, %u discarded",
62081 - atomic_read(&sbi->s_mb_preallocated),
62082 - atomic_read(&sbi->s_mb_discarded));
62083 + atomic_read_unchecked(&sbi->s_mb_preallocated),
62084 + atomic_read_unchecked(&sbi->s_mb_discarded));
62085 }
62086
62087 free_percpu(sbi->s_locality_groups);
62088 @@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62089 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62090
62091 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62092 - atomic_inc(&sbi->s_bal_reqs);
62093 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62094 + atomic_inc_unchecked(&sbi->s_bal_reqs);
62095 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62096 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62097 - atomic_inc(&sbi->s_bal_success);
62098 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62099 + atomic_inc_unchecked(&sbi->s_bal_success);
62100 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62101 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62102 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62103 - atomic_inc(&sbi->s_bal_goals);
62104 + atomic_inc_unchecked(&sbi->s_bal_goals);
62105 if (ac->ac_found > sbi->s_mb_max_to_scan)
62106 - atomic_inc(&sbi->s_bal_breaks);
62107 + atomic_inc_unchecked(&sbi->s_bal_breaks);
62108 }
62109
62110 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62111 @@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62112 trace_ext4_mb_new_inode_pa(ac, pa);
62113
62114 ext4_mb_use_inode_pa(ac, pa);
62115 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62116 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62117
62118 ei = EXT4_I(ac->ac_inode);
62119 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62120 @@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62121 trace_ext4_mb_new_group_pa(ac, pa);
62122
62123 ext4_mb_use_group_pa(ac, pa);
62124 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62125 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62126
62127 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62128 lg = ac->ac_lg;
62129 @@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62130 * from the bitmap and continue.
62131 */
62132 }
62133 - atomic_add(free, &sbi->s_mb_discarded);
62134 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
62135
62136 return err;
62137 }
62138 @@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62139 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62140 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62141 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62142 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62143 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62144 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62145
62146 return 0;
62147 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62148 index 8313ca3..8a37d08 100644
62149 --- a/fs/ext4/mmp.c
62150 +++ b/fs/ext4/mmp.c
62151 @@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62152 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62153 const char *function, unsigned int line, const char *msg)
62154 {
62155 - __ext4_warning(sb, function, line, msg);
62156 + __ext4_warning(sb, function, line, "%s", msg);
62157 __ext4_warning(sb, function, line,
62158 "MMP failure info: last update time: %llu, last update "
62159 "node: %s, last update device: %s\n",
62160 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62161 index fc7391e..1927b04 100644
62162 --- a/fs/ext4/super.c
62163 +++ b/fs/ext4/super.c
62164 @@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62165 }
62166
62167 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62168 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62169 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62170 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62171
62172 #ifdef CONFIG_QUOTA
62173 @@ -2434,7 +2434,7 @@ struct ext4_attr {
62174 int offset;
62175 int deprecated_val;
62176 } u;
62177 -};
62178 +} __do_const;
62179
62180 static int parse_strtoull(const char *buf,
62181 unsigned long long max, unsigned long long *value)
62182 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62183 index 1e09fc7..0400dd4 100644
62184 --- a/fs/ext4/xattr.c
62185 +++ b/fs/ext4/xattr.c
62186 @@ -399,7 +399,7 @@ static int
62187 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62188 char *buffer, size_t buffer_size)
62189 {
62190 - size_t rest = buffer_size;
62191 + size_t rest = buffer_size, total_size = 0;
62192
62193 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62194 const struct xattr_handler *handler =
62195 @@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62196 buffer += size;
62197 }
62198 rest -= size;
62199 + total_size += size;
62200 }
62201 }
62202 - return buffer_size - rest;
62203 + return total_size;
62204 }
62205
62206 static int
62207 diff --git a/fs/fcntl.c b/fs/fcntl.c
62208 index 99d440a..eb979d1 100644
62209 --- a/fs/fcntl.c
62210 +++ b/fs/fcntl.c
62211 @@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62212 int force)
62213 {
62214 security_file_set_fowner(filp);
62215 + if (gr_handle_chroot_fowner(pid, type))
62216 + return;
62217 + if (gr_check_protected_task_fowner(pid, type))
62218 + return;
62219 f_modown(filp, pid, type, force);
62220 }
62221 EXPORT_SYMBOL(__f_setown);
62222 diff --git a/fs/fhandle.c b/fs/fhandle.c
62223 index 999ff5c..2281df9 100644
62224 --- a/fs/fhandle.c
62225 +++ b/fs/fhandle.c
62226 @@ -8,6 +8,7 @@
62227 #include <linux/fs_struct.h>
62228 #include <linux/fsnotify.h>
62229 #include <linux/personality.h>
62230 +#include <linux/grsecurity.h>
62231 #include <asm/uaccess.h>
62232 #include "internal.h"
62233 #include "mount.h"
62234 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62235 } else
62236 retval = 0;
62237 /* copy the mount id */
62238 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62239 - sizeof(*mnt_id)) ||
62240 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62241 copy_to_user(ufh, handle,
62242 sizeof(struct file_handle) + handle_bytes))
62243 retval = -EFAULT;
62244 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62245 * the directory. Ideally we would like CAP_DAC_SEARCH.
62246 * But we don't have that
62247 */
62248 - if (!capable(CAP_DAC_READ_SEARCH)) {
62249 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62250 retval = -EPERM;
62251 goto out_err;
62252 }
62253 @@ -195,8 +195,9 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62254 goto out_err;
62255 }
62256 /* copy the full handle */
62257 - if (copy_from_user(handle, ufh,
62258 - sizeof(struct file_handle) +
62259 + *handle = f_handle;
62260 + if (copy_from_user(&handle->f_handle,
62261 + &ufh->f_handle,
62262 f_handle.handle_bytes)) {
62263 retval = -EFAULT;
62264 goto out_handle;
62265 diff --git a/fs/file.c b/fs/file.c
62266 index ab3eb6a..8de2392 100644
62267 --- a/fs/file.c
62268 +++ b/fs/file.c
62269 @@ -16,6 +16,7 @@
62270 #include <linux/slab.h>
62271 #include <linux/vmalloc.h>
62272 #include <linux/file.h>
62273 +#include <linux/security.h>
62274 #include <linux/fdtable.h>
62275 #include <linux/bitops.h>
62276 #include <linux/interrupt.h>
62277 @@ -139,7 +140,7 @@ out:
62278 * Return <0 error code on error; 1 on successful completion.
62279 * The files->file_lock should be held on entry, and will be held on exit.
62280 */
62281 -static int expand_fdtable(struct files_struct *files, int nr)
62282 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
62283 __releases(files->file_lock)
62284 __acquires(files->file_lock)
62285 {
62286 @@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62287 * expanded and execution may have blocked.
62288 * The files->file_lock should be held on entry, and will be held on exit.
62289 */
62290 -static int expand_files(struct files_struct *files, int nr)
62291 +static int expand_files(struct files_struct *files, unsigned int nr)
62292 {
62293 struct fdtable *fdt;
62294
62295 @@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62296 if (!file)
62297 return __close_fd(files, fd);
62298
62299 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62300 if (fd >= rlimit(RLIMIT_NOFILE))
62301 return -EBADF;
62302
62303 @@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62304 if (unlikely(oldfd == newfd))
62305 return -EINVAL;
62306
62307 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62308 if (newfd >= rlimit(RLIMIT_NOFILE))
62309 return -EBADF;
62310
62311 @@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62312 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62313 {
62314 int err;
62315 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62316 if (from >= rlimit(RLIMIT_NOFILE))
62317 return -EINVAL;
62318 err = alloc_fd(from, flags);
62319 diff --git a/fs/filesystems.c b/fs/filesystems.c
62320 index 5797d45..7d7d79a 100644
62321 --- a/fs/filesystems.c
62322 +++ b/fs/filesystems.c
62323 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62324 int len = dot ? dot - name : strlen(name);
62325
62326 fs = __get_fs_type(name, len);
62327 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
62328 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62329 +#else
62330 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62331 +#endif
62332 fs = __get_fs_type(name, len);
62333
62334 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62335 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62336 index 7dca743..2f2786d 100644
62337 --- a/fs/fs_struct.c
62338 +++ b/fs/fs_struct.c
62339 @@ -4,6 +4,7 @@
62340 #include <linux/path.h>
62341 #include <linux/slab.h>
62342 #include <linux/fs_struct.h>
62343 +#include <linux/grsecurity.h>
62344 #include "internal.h"
62345
62346 /*
62347 @@ -15,14 +16,18 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62348 struct path old_root;
62349
62350 path_get(path);
62351 + gr_inc_chroot_refcnts(path->dentry, path->mnt);
62352 spin_lock(&fs->lock);
62353 write_seqcount_begin(&fs->seq);
62354 old_root = fs->root;
62355 fs->root = *path;
62356 + gr_set_chroot_entries(current, path);
62357 write_seqcount_end(&fs->seq);
62358 spin_unlock(&fs->lock);
62359 - if (old_root.dentry)
62360 + if (old_root.dentry) {
62361 + gr_dec_chroot_refcnts(old_root.dentry, old_root.mnt);
62362 path_put(&old_root);
62363 + }
62364 }
62365
62366 /*
62367 @@ -67,6 +72,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62368 int hits = 0;
62369 spin_lock(&fs->lock);
62370 write_seqcount_begin(&fs->seq);
62371 + /* this root replacement is only done by pivot_root,
62372 + leave grsec's chroot tagging alone for this task
62373 + so that a pivoted root isn't treated as a chroot
62374 + */
62375 hits += replace_path(&fs->root, old_root, new_root);
62376 hits += replace_path(&fs->pwd, old_root, new_root);
62377 write_seqcount_end(&fs->seq);
62378 @@ -85,6 +94,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62379
62380 void free_fs_struct(struct fs_struct *fs)
62381 {
62382 + gr_dec_chroot_refcnts(fs->root.dentry, fs->root.mnt);
62383 path_put(&fs->root);
62384 path_put(&fs->pwd);
62385 kmem_cache_free(fs_cachep, fs);
62386 @@ -99,7 +109,8 @@ void exit_fs(struct task_struct *tsk)
62387 task_lock(tsk);
62388 spin_lock(&fs->lock);
62389 tsk->fs = NULL;
62390 - kill = !--fs->users;
62391 + gr_clear_chroot_entries(tsk);
62392 + kill = !atomic_dec_return(&fs->users);
62393 spin_unlock(&fs->lock);
62394 task_unlock(tsk);
62395 if (kill)
62396 @@ -112,7 +123,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62397 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62398 /* We don't need to lock fs - think why ;-) */
62399 if (fs) {
62400 - fs->users = 1;
62401 + atomic_set(&fs->users, 1);
62402 fs->in_exec = 0;
62403 spin_lock_init(&fs->lock);
62404 seqcount_init(&fs->seq);
62405 @@ -121,6 +132,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62406 spin_lock(&old->lock);
62407 fs->root = old->root;
62408 path_get(&fs->root);
62409 + /* instead of calling gr_set_chroot_entries here,
62410 + we call it from every caller of this function
62411 + */
62412 fs->pwd = old->pwd;
62413 path_get(&fs->pwd);
62414 spin_unlock(&old->lock);
62415 @@ -139,8 +153,9 @@ int unshare_fs_struct(void)
62416
62417 task_lock(current);
62418 spin_lock(&fs->lock);
62419 - kill = !--fs->users;
62420 + kill = !atomic_dec_return(&fs->users);
62421 current->fs = new_fs;
62422 + gr_set_chroot_entries(current, &new_fs->root);
62423 spin_unlock(&fs->lock);
62424 task_unlock(current);
62425
62426 @@ -153,13 +168,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62427
62428 int current_umask(void)
62429 {
62430 - return current->fs->umask;
62431 + return current->fs->umask | gr_acl_umask();
62432 }
62433 EXPORT_SYMBOL(current_umask);
62434
62435 /* to be mentioned only in INIT_TASK */
62436 struct fs_struct init_fs = {
62437 - .users = 1,
62438 + .users = ATOMIC_INIT(1),
62439 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62440 .seq = SEQCNT_ZERO(init_fs.seq),
62441 .umask = 0022,
62442 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62443 index 89acec7..a575262 100644
62444 --- a/fs/fscache/cookie.c
62445 +++ b/fs/fscache/cookie.c
62446 @@ -19,7 +19,7 @@
62447
62448 struct kmem_cache *fscache_cookie_jar;
62449
62450 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62451 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62452
62453 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62454 static int fscache_alloc_object(struct fscache_cache *cache,
62455 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62456 parent ? (char *) parent->def->name : "<no-parent>",
62457 def->name, netfs_data, enable);
62458
62459 - fscache_stat(&fscache_n_acquires);
62460 + fscache_stat_unchecked(&fscache_n_acquires);
62461
62462 /* if there's no parent cookie, then we don't create one here either */
62463 if (!parent) {
62464 - fscache_stat(&fscache_n_acquires_null);
62465 + fscache_stat_unchecked(&fscache_n_acquires_null);
62466 _leave(" [no parent]");
62467 return NULL;
62468 }
62469 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62470 /* allocate and initialise a cookie */
62471 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62472 if (!cookie) {
62473 - fscache_stat(&fscache_n_acquires_oom);
62474 + fscache_stat_unchecked(&fscache_n_acquires_oom);
62475 _leave(" [ENOMEM]");
62476 return NULL;
62477 }
62478 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62479
62480 switch (cookie->def->type) {
62481 case FSCACHE_COOKIE_TYPE_INDEX:
62482 - fscache_stat(&fscache_n_cookie_index);
62483 + fscache_stat_unchecked(&fscache_n_cookie_index);
62484 break;
62485 case FSCACHE_COOKIE_TYPE_DATAFILE:
62486 - fscache_stat(&fscache_n_cookie_data);
62487 + fscache_stat_unchecked(&fscache_n_cookie_data);
62488 break;
62489 default:
62490 - fscache_stat(&fscache_n_cookie_special);
62491 + fscache_stat_unchecked(&fscache_n_cookie_special);
62492 break;
62493 }
62494
62495 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62496 } else {
62497 atomic_dec(&parent->n_children);
62498 __fscache_cookie_put(cookie);
62499 - fscache_stat(&fscache_n_acquires_nobufs);
62500 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62501 _leave(" = NULL");
62502 return NULL;
62503 }
62504 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62505 }
62506 }
62507
62508 - fscache_stat(&fscache_n_acquires_ok);
62509 + fscache_stat_unchecked(&fscache_n_acquires_ok);
62510 _leave(" = %p", cookie);
62511 return cookie;
62512 }
62513 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62514 cache = fscache_select_cache_for_object(cookie->parent);
62515 if (!cache) {
62516 up_read(&fscache_addremove_sem);
62517 - fscache_stat(&fscache_n_acquires_no_cache);
62518 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62519 _leave(" = -ENOMEDIUM [no cache]");
62520 return -ENOMEDIUM;
62521 }
62522 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62523 object = cache->ops->alloc_object(cache, cookie);
62524 fscache_stat_d(&fscache_n_cop_alloc_object);
62525 if (IS_ERR(object)) {
62526 - fscache_stat(&fscache_n_object_no_alloc);
62527 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
62528 ret = PTR_ERR(object);
62529 goto error;
62530 }
62531
62532 - fscache_stat(&fscache_n_object_alloc);
62533 + fscache_stat_unchecked(&fscache_n_object_alloc);
62534
62535 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62536 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62537
62538 _debug("ALLOC OBJ%x: %s {%lx}",
62539 object->debug_id, cookie->def->name, object->events);
62540 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62541
62542 _enter("{%s}", cookie->def->name);
62543
62544 - fscache_stat(&fscache_n_invalidates);
62545 + fscache_stat_unchecked(&fscache_n_invalidates);
62546
62547 /* Only permit invalidation of data files. Invalidating an index will
62548 * require the caller to release all its attachments to the tree rooted
62549 @@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62550 {
62551 struct fscache_object *object;
62552
62553 - fscache_stat(&fscache_n_updates);
62554 + fscache_stat_unchecked(&fscache_n_updates);
62555
62556 if (!cookie) {
62557 - fscache_stat(&fscache_n_updates_null);
62558 + fscache_stat_unchecked(&fscache_n_updates_null);
62559 _leave(" [no cookie]");
62560 return;
62561 }
62562 @@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62563 */
62564 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62565 {
62566 - fscache_stat(&fscache_n_relinquishes);
62567 + fscache_stat_unchecked(&fscache_n_relinquishes);
62568 if (retire)
62569 - fscache_stat(&fscache_n_relinquishes_retire);
62570 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62571
62572 if (!cookie) {
62573 - fscache_stat(&fscache_n_relinquishes_null);
62574 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
62575 _leave(" [no cookie]");
62576 return;
62577 }
62578 @@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62579 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62580 goto inconsistent;
62581
62582 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62583 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62584
62585 __fscache_use_cookie(cookie);
62586 if (fscache_submit_op(object, op) < 0)
62587 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62588 index 7872a62..d91b19f 100644
62589 --- a/fs/fscache/internal.h
62590 +++ b/fs/fscache/internal.h
62591 @@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62592 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62593 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62594 struct fscache_operation *,
62595 - atomic_t *,
62596 - atomic_t *,
62597 + atomic_unchecked_t *,
62598 + atomic_unchecked_t *,
62599 void (*)(struct fscache_operation *));
62600 extern void fscache_invalidate_writes(struct fscache_cookie *);
62601
62602 @@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62603 * stats.c
62604 */
62605 #ifdef CONFIG_FSCACHE_STATS
62606 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62607 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62608 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62609 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62610
62611 -extern atomic_t fscache_n_op_pend;
62612 -extern atomic_t fscache_n_op_run;
62613 -extern atomic_t fscache_n_op_enqueue;
62614 -extern atomic_t fscache_n_op_deferred_release;
62615 -extern atomic_t fscache_n_op_release;
62616 -extern atomic_t fscache_n_op_gc;
62617 -extern atomic_t fscache_n_op_cancelled;
62618 -extern atomic_t fscache_n_op_rejected;
62619 +extern atomic_unchecked_t fscache_n_op_pend;
62620 +extern atomic_unchecked_t fscache_n_op_run;
62621 +extern atomic_unchecked_t fscache_n_op_enqueue;
62622 +extern atomic_unchecked_t fscache_n_op_deferred_release;
62623 +extern atomic_unchecked_t fscache_n_op_release;
62624 +extern atomic_unchecked_t fscache_n_op_gc;
62625 +extern atomic_unchecked_t fscache_n_op_cancelled;
62626 +extern atomic_unchecked_t fscache_n_op_rejected;
62627
62628 -extern atomic_t fscache_n_attr_changed;
62629 -extern atomic_t fscache_n_attr_changed_ok;
62630 -extern atomic_t fscache_n_attr_changed_nobufs;
62631 -extern atomic_t fscache_n_attr_changed_nomem;
62632 -extern atomic_t fscache_n_attr_changed_calls;
62633 +extern atomic_unchecked_t fscache_n_attr_changed;
62634 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
62635 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62636 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62637 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
62638
62639 -extern atomic_t fscache_n_allocs;
62640 -extern atomic_t fscache_n_allocs_ok;
62641 -extern atomic_t fscache_n_allocs_wait;
62642 -extern atomic_t fscache_n_allocs_nobufs;
62643 -extern atomic_t fscache_n_allocs_intr;
62644 -extern atomic_t fscache_n_allocs_object_dead;
62645 -extern atomic_t fscache_n_alloc_ops;
62646 -extern atomic_t fscache_n_alloc_op_waits;
62647 +extern atomic_unchecked_t fscache_n_allocs;
62648 +extern atomic_unchecked_t fscache_n_allocs_ok;
62649 +extern atomic_unchecked_t fscache_n_allocs_wait;
62650 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
62651 +extern atomic_unchecked_t fscache_n_allocs_intr;
62652 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
62653 +extern atomic_unchecked_t fscache_n_alloc_ops;
62654 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
62655
62656 -extern atomic_t fscache_n_retrievals;
62657 -extern atomic_t fscache_n_retrievals_ok;
62658 -extern atomic_t fscache_n_retrievals_wait;
62659 -extern atomic_t fscache_n_retrievals_nodata;
62660 -extern atomic_t fscache_n_retrievals_nobufs;
62661 -extern atomic_t fscache_n_retrievals_intr;
62662 -extern atomic_t fscache_n_retrievals_nomem;
62663 -extern atomic_t fscache_n_retrievals_object_dead;
62664 -extern atomic_t fscache_n_retrieval_ops;
62665 -extern atomic_t fscache_n_retrieval_op_waits;
62666 +extern atomic_unchecked_t fscache_n_retrievals;
62667 +extern atomic_unchecked_t fscache_n_retrievals_ok;
62668 +extern atomic_unchecked_t fscache_n_retrievals_wait;
62669 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
62670 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62671 +extern atomic_unchecked_t fscache_n_retrievals_intr;
62672 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
62673 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62674 +extern atomic_unchecked_t fscache_n_retrieval_ops;
62675 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62676
62677 -extern atomic_t fscache_n_stores;
62678 -extern atomic_t fscache_n_stores_ok;
62679 -extern atomic_t fscache_n_stores_again;
62680 -extern atomic_t fscache_n_stores_nobufs;
62681 -extern atomic_t fscache_n_stores_oom;
62682 -extern atomic_t fscache_n_store_ops;
62683 -extern atomic_t fscache_n_store_calls;
62684 -extern atomic_t fscache_n_store_pages;
62685 -extern atomic_t fscache_n_store_radix_deletes;
62686 -extern atomic_t fscache_n_store_pages_over_limit;
62687 +extern atomic_unchecked_t fscache_n_stores;
62688 +extern atomic_unchecked_t fscache_n_stores_ok;
62689 +extern atomic_unchecked_t fscache_n_stores_again;
62690 +extern atomic_unchecked_t fscache_n_stores_nobufs;
62691 +extern atomic_unchecked_t fscache_n_stores_oom;
62692 +extern atomic_unchecked_t fscache_n_store_ops;
62693 +extern atomic_unchecked_t fscache_n_store_calls;
62694 +extern atomic_unchecked_t fscache_n_store_pages;
62695 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
62696 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62697
62698 -extern atomic_t fscache_n_store_vmscan_not_storing;
62699 -extern atomic_t fscache_n_store_vmscan_gone;
62700 -extern atomic_t fscache_n_store_vmscan_busy;
62701 -extern atomic_t fscache_n_store_vmscan_cancelled;
62702 -extern atomic_t fscache_n_store_vmscan_wait;
62703 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62704 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62705 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62706 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62707 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62708
62709 -extern atomic_t fscache_n_marks;
62710 -extern atomic_t fscache_n_uncaches;
62711 +extern atomic_unchecked_t fscache_n_marks;
62712 +extern atomic_unchecked_t fscache_n_uncaches;
62713
62714 -extern atomic_t fscache_n_acquires;
62715 -extern atomic_t fscache_n_acquires_null;
62716 -extern atomic_t fscache_n_acquires_no_cache;
62717 -extern atomic_t fscache_n_acquires_ok;
62718 -extern atomic_t fscache_n_acquires_nobufs;
62719 -extern atomic_t fscache_n_acquires_oom;
62720 +extern atomic_unchecked_t fscache_n_acquires;
62721 +extern atomic_unchecked_t fscache_n_acquires_null;
62722 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
62723 +extern atomic_unchecked_t fscache_n_acquires_ok;
62724 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
62725 +extern atomic_unchecked_t fscache_n_acquires_oom;
62726
62727 -extern atomic_t fscache_n_invalidates;
62728 -extern atomic_t fscache_n_invalidates_run;
62729 +extern atomic_unchecked_t fscache_n_invalidates;
62730 +extern atomic_unchecked_t fscache_n_invalidates_run;
62731
62732 -extern atomic_t fscache_n_updates;
62733 -extern atomic_t fscache_n_updates_null;
62734 -extern atomic_t fscache_n_updates_run;
62735 +extern atomic_unchecked_t fscache_n_updates;
62736 +extern atomic_unchecked_t fscache_n_updates_null;
62737 +extern atomic_unchecked_t fscache_n_updates_run;
62738
62739 -extern atomic_t fscache_n_relinquishes;
62740 -extern atomic_t fscache_n_relinquishes_null;
62741 -extern atomic_t fscache_n_relinquishes_waitcrt;
62742 -extern atomic_t fscache_n_relinquishes_retire;
62743 +extern atomic_unchecked_t fscache_n_relinquishes;
62744 +extern atomic_unchecked_t fscache_n_relinquishes_null;
62745 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62746 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
62747
62748 -extern atomic_t fscache_n_cookie_index;
62749 -extern atomic_t fscache_n_cookie_data;
62750 -extern atomic_t fscache_n_cookie_special;
62751 +extern atomic_unchecked_t fscache_n_cookie_index;
62752 +extern atomic_unchecked_t fscache_n_cookie_data;
62753 +extern atomic_unchecked_t fscache_n_cookie_special;
62754
62755 -extern atomic_t fscache_n_object_alloc;
62756 -extern atomic_t fscache_n_object_no_alloc;
62757 -extern atomic_t fscache_n_object_lookups;
62758 -extern atomic_t fscache_n_object_lookups_negative;
62759 -extern atomic_t fscache_n_object_lookups_positive;
62760 -extern atomic_t fscache_n_object_lookups_timed_out;
62761 -extern atomic_t fscache_n_object_created;
62762 -extern atomic_t fscache_n_object_avail;
62763 -extern atomic_t fscache_n_object_dead;
62764 +extern atomic_unchecked_t fscache_n_object_alloc;
62765 +extern atomic_unchecked_t fscache_n_object_no_alloc;
62766 +extern atomic_unchecked_t fscache_n_object_lookups;
62767 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
62768 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
62769 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62770 +extern atomic_unchecked_t fscache_n_object_created;
62771 +extern atomic_unchecked_t fscache_n_object_avail;
62772 +extern atomic_unchecked_t fscache_n_object_dead;
62773
62774 -extern atomic_t fscache_n_checkaux_none;
62775 -extern atomic_t fscache_n_checkaux_okay;
62776 -extern atomic_t fscache_n_checkaux_update;
62777 -extern atomic_t fscache_n_checkaux_obsolete;
62778 +extern atomic_unchecked_t fscache_n_checkaux_none;
62779 +extern atomic_unchecked_t fscache_n_checkaux_okay;
62780 +extern atomic_unchecked_t fscache_n_checkaux_update;
62781 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62782
62783 extern atomic_t fscache_n_cop_alloc_object;
62784 extern atomic_t fscache_n_cop_lookup_object;
62785 @@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62786 atomic_inc(stat);
62787 }
62788
62789 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62790 +{
62791 + atomic_inc_unchecked(stat);
62792 +}
62793 +
62794 static inline void fscache_stat_d(atomic_t *stat)
62795 {
62796 atomic_dec(stat);
62797 @@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62798
62799 #define __fscache_stat(stat) (NULL)
62800 #define fscache_stat(stat) do {} while (0)
62801 +#define fscache_stat_unchecked(stat) do {} while (0)
62802 #define fscache_stat_d(stat) do {} while (0)
62803 #endif
62804
62805 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62806 index da032da..0076ce7 100644
62807 --- a/fs/fscache/object.c
62808 +++ b/fs/fscache/object.c
62809 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62810 _debug("LOOKUP \"%s\" in \"%s\"",
62811 cookie->def->name, object->cache->tag->name);
62812
62813 - fscache_stat(&fscache_n_object_lookups);
62814 + fscache_stat_unchecked(&fscache_n_object_lookups);
62815 fscache_stat(&fscache_n_cop_lookup_object);
62816 ret = object->cache->ops->lookup_object(object);
62817 fscache_stat_d(&fscache_n_cop_lookup_object);
62818 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62819 if (ret == -ETIMEDOUT) {
62820 /* probably stuck behind another object, so move this one to
62821 * the back of the queue */
62822 - fscache_stat(&fscache_n_object_lookups_timed_out);
62823 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62824 _leave(" [timeout]");
62825 return NO_TRANSIT;
62826 }
62827 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62828 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62829
62830 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62831 - fscache_stat(&fscache_n_object_lookups_negative);
62832 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62833
62834 /* Allow write requests to begin stacking up and read requests to begin
62835 * returning ENODATA.
62836 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62837 /* if we were still looking up, then we must have a positive lookup
62838 * result, in which case there may be data available */
62839 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62840 - fscache_stat(&fscache_n_object_lookups_positive);
62841 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62842
62843 /* We do (presumably) have data */
62844 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62845 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62846 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62847 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62848 } else {
62849 - fscache_stat(&fscache_n_object_created);
62850 + fscache_stat_unchecked(&fscache_n_object_created);
62851 }
62852
62853 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62854 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62855 fscache_stat_d(&fscache_n_cop_lookup_complete);
62856
62857 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62858 - fscache_stat(&fscache_n_object_avail);
62859 + fscache_stat_unchecked(&fscache_n_object_avail);
62860
62861 _leave("");
62862 return transit_to(JUMPSTART_DEPS);
62863 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62864
62865 /* this just shifts the object release to the work processor */
62866 fscache_put_object(object);
62867 - fscache_stat(&fscache_n_object_dead);
62868 + fscache_stat_unchecked(&fscache_n_object_dead);
62869
62870 _leave("");
62871 return transit_to(OBJECT_DEAD);
62872 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62873 enum fscache_checkaux result;
62874
62875 if (!object->cookie->def->check_aux) {
62876 - fscache_stat(&fscache_n_checkaux_none);
62877 + fscache_stat_unchecked(&fscache_n_checkaux_none);
62878 return FSCACHE_CHECKAUX_OKAY;
62879 }
62880
62881 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62882 switch (result) {
62883 /* entry okay as is */
62884 case FSCACHE_CHECKAUX_OKAY:
62885 - fscache_stat(&fscache_n_checkaux_okay);
62886 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
62887 break;
62888
62889 /* entry requires update */
62890 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62891 - fscache_stat(&fscache_n_checkaux_update);
62892 + fscache_stat_unchecked(&fscache_n_checkaux_update);
62893 break;
62894
62895 /* entry requires deletion */
62896 case FSCACHE_CHECKAUX_OBSOLETE:
62897 - fscache_stat(&fscache_n_checkaux_obsolete);
62898 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62899 break;
62900
62901 default:
62902 @@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62903 {
62904 const struct fscache_state *s;
62905
62906 - fscache_stat(&fscache_n_invalidates_run);
62907 + fscache_stat_unchecked(&fscache_n_invalidates_run);
62908 fscache_stat(&fscache_n_cop_invalidate_object);
62909 s = _fscache_invalidate_object(object, event);
62910 fscache_stat_d(&fscache_n_cop_invalidate_object);
62911 @@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62912 {
62913 _enter("{OBJ%x},%d", object->debug_id, event);
62914
62915 - fscache_stat(&fscache_n_updates_run);
62916 + fscache_stat_unchecked(&fscache_n_updates_run);
62917 fscache_stat(&fscache_n_cop_update_object);
62918 object->cache->ops->update_object(object);
62919 fscache_stat_d(&fscache_n_cop_update_object);
62920 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62921 index e7b87a0..a85d47a 100644
62922 --- a/fs/fscache/operation.c
62923 +++ b/fs/fscache/operation.c
62924 @@ -17,7 +17,7 @@
62925 #include <linux/slab.h>
62926 #include "internal.h"
62927
62928 -atomic_t fscache_op_debug_id;
62929 +atomic_unchecked_t fscache_op_debug_id;
62930 EXPORT_SYMBOL(fscache_op_debug_id);
62931
62932 /**
62933 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62934 ASSERTCMP(atomic_read(&op->usage), >, 0);
62935 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62936
62937 - fscache_stat(&fscache_n_op_enqueue);
62938 + fscache_stat_unchecked(&fscache_n_op_enqueue);
62939 switch (op->flags & FSCACHE_OP_TYPE) {
62940 case FSCACHE_OP_ASYNC:
62941 _debug("queue async");
62942 @@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62943 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62944 if (op->processor)
62945 fscache_enqueue_operation(op);
62946 - fscache_stat(&fscache_n_op_run);
62947 + fscache_stat_unchecked(&fscache_n_op_run);
62948 }
62949
62950 /*
62951 @@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62952 if (object->n_in_progress > 0) {
62953 atomic_inc(&op->usage);
62954 list_add_tail(&op->pend_link, &object->pending_ops);
62955 - fscache_stat(&fscache_n_op_pend);
62956 + fscache_stat_unchecked(&fscache_n_op_pend);
62957 } else if (!list_empty(&object->pending_ops)) {
62958 atomic_inc(&op->usage);
62959 list_add_tail(&op->pend_link, &object->pending_ops);
62960 - fscache_stat(&fscache_n_op_pend);
62961 + fscache_stat_unchecked(&fscache_n_op_pend);
62962 fscache_start_operations(object);
62963 } else {
62964 ASSERTCMP(object->n_in_progress, ==, 0);
62965 @@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62966 object->n_exclusive++; /* reads and writes must wait */
62967 atomic_inc(&op->usage);
62968 list_add_tail(&op->pend_link, &object->pending_ops);
62969 - fscache_stat(&fscache_n_op_pend);
62970 + fscache_stat_unchecked(&fscache_n_op_pend);
62971 ret = 0;
62972 } else {
62973 /* If we're in any other state, there must have been an I/O
62974 @@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62975 if (object->n_exclusive > 0) {
62976 atomic_inc(&op->usage);
62977 list_add_tail(&op->pend_link, &object->pending_ops);
62978 - fscache_stat(&fscache_n_op_pend);
62979 + fscache_stat_unchecked(&fscache_n_op_pend);
62980 } else if (!list_empty(&object->pending_ops)) {
62981 atomic_inc(&op->usage);
62982 list_add_tail(&op->pend_link, &object->pending_ops);
62983 - fscache_stat(&fscache_n_op_pend);
62984 + fscache_stat_unchecked(&fscache_n_op_pend);
62985 fscache_start_operations(object);
62986 } else {
62987 ASSERTCMP(object->n_exclusive, ==, 0);
62988 @@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62989 object->n_ops++;
62990 atomic_inc(&op->usage);
62991 list_add_tail(&op->pend_link, &object->pending_ops);
62992 - fscache_stat(&fscache_n_op_pend);
62993 + fscache_stat_unchecked(&fscache_n_op_pend);
62994 ret = 0;
62995 } else if (fscache_object_is_dying(object)) {
62996 - fscache_stat(&fscache_n_op_rejected);
62997 + fscache_stat_unchecked(&fscache_n_op_rejected);
62998 op->state = FSCACHE_OP_ST_CANCELLED;
62999 ret = -ENOBUFS;
63000 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63001 @@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63002 ret = -EBUSY;
63003 if (op->state == FSCACHE_OP_ST_PENDING) {
63004 ASSERT(!list_empty(&op->pend_link));
63005 - fscache_stat(&fscache_n_op_cancelled);
63006 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63007 list_del_init(&op->pend_link);
63008 if (do_cancel)
63009 do_cancel(op);
63010 @@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63011 while (!list_empty(&object->pending_ops)) {
63012 op = list_entry(object->pending_ops.next,
63013 struct fscache_operation, pend_link);
63014 - fscache_stat(&fscache_n_op_cancelled);
63015 + fscache_stat_unchecked(&fscache_n_op_cancelled);
63016 list_del_init(&op->pend_link);
63017
63018 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63019 @@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63020 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63021 op->state = FSCACHE_OP_ST_DEAD;
63022
63023 - fscache_stat(&fscache_n_op_release);
63024 + fscache_stat_unchecked(&fscache_n_op_release);
63025
63026 if (op->release) {
63027 op->release(op);
63028 @@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63029 * lock, and defer it otherwise */
63030 if (!spin_trylock(&object->lock)) {
63031 _debug("defer put");
63032 - fscache_stat(&fscache_n_op_deferred_release);
63033 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
63034
63035 cache = object->cache;
63036 spin_lock(&cache->op_gc_list_lock);
63037 @@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63038
63039 _debug("GC DEFERRED REL OBJ%x OP%x",
63040 object->debug_id, op->debug_id);
63041 - fscache_stat(&fscache_n_op_gc);
63042 + fscache_stat_unchecked(&fscache_n_op_gc);
63043
63044 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63045 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63046 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63047 index de33b3f..8be4d29 100644
63048 --- a/fs/fscache/page.c
63049 +++ b/fs/fscache/page.c
63050 @@ -74,7 +74,7 @@ try_again:
63051 val = radix_tree_lookup(&cookie->stores, page->index);
63052 if (!val) {
63053 rcu_read_unlock();
63054 - fscache_stat(&fscache_n_store_vmscan_not_storing);
63055 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63056 __fscache_uncache_page(cookie, page);
63057 return true;
63058 }
63059 @@ -104,11 +104,11 @@ try_again:
63060 spin_unlock(&cookie->stores_lock);
63061
63062 if (xpage) {
63063 - fscache_stat(&fscache_n_store_vmscan_cancelled);
63064 - fscache_stat(&fscache_n_store_radix_deletes);
63065 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63066 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63067 ASSERTCMP(xpage, ==, page);
63068 } else {
63069 - fscache_stat(&fscache_n_store_vmscan_gone);
63070 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63071 }
63072
63073 wake_up_bit(&cookie->flags, 0);
63074 @@ -123,11 +123,11 @@ page_busy:
63075 * sleeping on memory allocation, so we may need to impose a timeout
63076 * too. */
63077 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63078 - fscache_stat(&fscache_n_store_vmscan_busy);
63079 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63080 return false;
63081 }
63082
63083 - fscache_stat(&fscache_n_store_vmscan_wait);
63084 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63085 if (!release_page_wait_timeout(cookie, page))
63086 _debug("fscache writeout timeout page: %p{%lx}",
63087 page, page->index);
63088 @@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63089 FSCACHE_COOKIE_STORING_TAG);
63090 if (!radix_tree_tag_get(&cookie->stores, page->index,
63091 FSCACHE_COOKIE_PENDING_TAG)) {
63092 - fscache_stat(&fscache_n_store_radix_deletes);
63093 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63094 xpage = radix_tree_delete(&cookie->stores, page->index);
63095 }
63096 spin_unlock(&cookie->stores_lock);
63097 @@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63098
63099 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63100
63101 - fscache_stat(&fscache_n_attr_changed_calls);
63102 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63103
63104 if (fscache_object_is_active(object)) {
63105 fscache_stat(&fscache_n_cop_attr_changed);
63106 @@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63107
63108 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63109
63110 - fscache_stat(&fscache_n_attr_changed);
63111 + fscache_stat_unchecked(&fscache_n_attr_changed);
63112
63113 op = kzalloc(sizeof(*op), GFP_KERNEL);
63114 if (!op) {
63115 - fscache_stat(&fscache_n_attr_changed_nomem);
63116 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63117 _leave(" = -ENOMEM");
63118 return -ENOMEM;
63119 }
63120 @@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63121 if (fscache_submit_exclusive_op(object, op) < 0)
63122 goto nobufs_dec;
63123 spin_unlock(&cookie->lock);
63124 - fscache_stat(&fscache_n_attr_changed_ok);
63125 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63126 fscache_put_operation(op);
63127 _leave(" = 0");
63128 return 0;
63129 @@ -242,7 +242,7 @@ nobufs:
63130 kfree(op);
63131 if (wake_cookie)
63132 __fscache_wake_unused_cookie(cookie);
63133 - fscache_stat(&fscache_n_attr_changed_nobufs);
63134 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63135 _leave(" = %d", -ENOBUFS);
63136 return -ENOBUFS;
63137 }
63138 @@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63139 /* allocate a retrieval operation and attempt to submit it */
63140 op = kzalloc(sizeof(*op), GFP_NOIO);
63141 if (!op) {
63142 - fscache_stat(&fscache_n_retrievals_nomem);
63143 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63144 return NULL;
63145 }
63146
63147 @@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63148 return 0;
63149 }
63150
63151 - fscache_stat(&fscache_n_retrievals_wait);
63152 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
63153
63154 jif = jiffies;
63155 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63156 TASK_INTERRUPTIBLE) != 0) {
63157 - fscache_stat(&fscache_n_retrievals_intr);
63158 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63159 _leave(" = -ERESTARTSYS");
63160 return -ERESTARTSYS;
63161 }
63162 @@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63163 */
63164 int fscache_wait_for_operation_activation(struct fscache_object *object,
63165 struct fscache_operation *op,
63166 - atomic_t *stat_op_waits,
63167 - atomic_t *stat_object_dead,
63168 + atomic_unchecked_t *stat_op_waits,
63169 + atomic_unchecked_t *stat_object_dead,
63170 void (*do_cancel)(struct fscache_operation *))
63171 {
63172 int ret;
63173 @@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63174
63175 _debug(">>> WT");
63176 if (stat_op_waits)
63177 - fscache_stat(stat_op_waits);
63178 + fscache_stat_unchecked(stat_op_waits);
63179 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63180 TASK_INTERRUPTIBLE) != 0) {
63181 ret = fscache_cancel_op(op, do_cancel);
63182 @@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63183 check_if_dead:
63184 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63185 if (stat_object_dead)
63186 - fscache_stat(stat_object_dead);
63187 + fscache_stat_unchecked(stat_object_dead);
63188 _leave(" = -ENOBUFS [cancelled]");
63189 return -ENOBUFS;
63190 }
63191 @@ -381,7 +381,7 @@ check_if_dead:
63192 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63193 fscache_cancel_op(op, do_cancel);
63194 if (stat_object_dead)
63195 - fscache_stat(stat_object_dead);
63196 + fscache_stat_unchecked(stat_object_dead);
63197 return -ENOBUFS;
63198 }
63199 return 0;
63200 @@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63201
63202 _enter("%p,%p,,,", cookie, page);
63203
63204 - fscache_stat(&fscache_n_retrievals);
63205 + fscache_stat_unchecked(&fscache_n_retrievals);
63206
63207 if (hlist_empty(&cookie->backing_objects))
63208 goto nobufs;
63209 @@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63210 goto nobufs_unlock_dec;
63211 spin_unlock(&cookie->lock);
63212
63213 - fscache_stat(&fscache_n_retrieval_ops);
63214 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63215
63216 /* pin the netfs read context in case we need to do the actual netfs
63217 * read because we've encountered a cache read failure */
63218 @@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63219
63220 error:
63221 if (ret == -ENOMEM)
63222 - fscache_stat(&fscache_n_retrievals_nomem);
63223 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63224 else if (ret == -ERESTARTSYS)
63225 - fscache_stat(&fscache_n_retrievals_intr);
63226 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63227 else if (ret == -ENODATA)
63228 - fscache_stat(&fscache_n_retrievals_nodata);
63229 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63230 else if (ret < 0)
63231 - fscache_stat(&fscache_n_retrievals_nobufs);
63232 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63233 else
63234 - fscache_stat(&fscache_n_retrievals_ok);
63235 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63236
63237 fscache_put_retrieval(op);
63238 _leave(" = %d", ret);
63239 @@ -505,7 +505,7 @@ nobufs_unlock:
63240 __fscache_wake_unused_cookie(cookie);
63241 kfree(op);
63242 nobufs:
63243 - fscache_stat(&fscache_n_retrievals_nobufs);
63244 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63245 _leave(" = -ENOBUFS");
63246 return -ENOBUFS;
63247 }
63248 @@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63249
63250 _enter("%p,,%d,,,", cookie, *nr_pages);
63251
63252 - fscache_stat(&fscache_n_retrievals);
63253 + fscache_stat_unchecked(&fscache_n_retrievals);
63254
63255 if (hlist_empty(&cookie->backing_objects))
63256 goto nobufs;
63257 @@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63258 goto nobufs_unlock_dec;
63259 spin_unlock(&cookie->lock);
63260
63261 - fscache_stat(&fscache_n_retrieval_ops);
63262 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
63263
63264 /* pin the netfs read context in case we need to do the actual netfs
63265 * read because we've encountered a cache read failure */
63266 @@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63267
63268 error:
63269 if (ret == -ENOMEM)
63270 - fscache_stat(&fscache_n_retrievals_nomem);
63271 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63272 else if (ret == -ERESTARTSYS)
63273 - fscache_stat(&fscache_n_retrievals_intr);
63274 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
63275 else if (ret == -ENODATA)
63276 - fscache_stat(&fscache_n_retrievals_nodata);
63277 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63278 else if (ret < 0)
63279 - fscache_stat(&fscache_n_retrievals_nobufs);
63280 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63281 else
63282 - fscache_stat(&fscache_n_retrievals_ok);
63283 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
63284
63285 fscache_put_retrieval(op);
63286 _leave(" = %d", ret);
63287 @@ -636,7 +636,7 @@ nobufs_unlock:
63288 if (wake_cookie)
63289 __fscache_wake_unused_cookie(cookie);
63290 nobufs:
63291 - fscache_stat(&fscache_n_retrievals_nobufs);
63292 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63293 _leave(" = -ENOBUFS");
63294 return -ENOBUFS;
63295 }
63296 @@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63297
63298 _enter("%p,%p,,,", cookie, page);
63299
63300 - fscache_stat(&fscache_n_allocs);
63301 + fscache_stat_unchecked(&fscache_n_allocs);
63302
63303 if (hlist_empty(&cookie->backing_objects))
63304 goto nobufs;
63305 @@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63306 goto nobufs_unlock_dec;
63307 spin_unlock(&cookie->lock);
63308
63309 - fscache_stat(&fscache_n_alloc_ops);
63310 + fscache_stat_unchecked(&fscache_n_alloc_ops);
63311
63312 ret = fscache_wait_for_operation_activation(
63313 object, &op->op,
63314 @@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63315
63316 error:
63317 if (ret == -ERESTARTSYS)
63318 - fscache_stat(&fscache_n_allocs_intr);
63319 + fscache_stat_unchecked(&fscache_n_allocs_intr);
63320 else if (ret < 0)
63321 - fscache_stat(&fscache_n_allocs_nobufs);
63322 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63323 else
63324 - fscache_stat(&fscache_n_allocs_ok);
63325 + fscache_stat_unchecked(&fscache_n_allocs_ok);
63326
63327 fscache_put_retrieval(op);
63328 _leave(" = %d", ret);
63329 @@ -730,7 +730,7 @@ nobufs_unlock:
63330 if (wake_cookie)
63331 __fscache_wake_unused_cookie(cookie);
63332 nobufs:
63333 - fscache_stat(&fscache_n_allocs_nobufs);
63334 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63335 _leave(" = -ENOBUFS");
63336 return -ENOBUFS;
63337 }
63338 @@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63339
63340 spin_lock(&cookie->stores_lock);
63341
63342 - fscache_stat(&fscache_n_store_calls);
63343 + fscache_stat_unchecked(&fscache_n_store_calls);
63344
63345 /* find a page to store */
63346 page = NULL;
63347 @@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63348 page = results[0];
63349 _debug("gang %d [%lx]", n, page->index);
63350 if (page->index > op->store_limit) {
63351 - fscache_stat(&fscache_n_store_pages_over_limit);
63352 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63353 goto superseded;
63354 }
63355
63356 @@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63357 spin_unlock(&cookie->stores_lock);
63358 spin_unlock(&object->lock);
63359
63360 - fscache_stat(&fscache_n_store_pages);
63361 + fscache_stat_unchecked(&fscache_n_store_pages);
63362 fscache_stat(&fscache_n_cop_write_page);
63363 ret = object->cache->ops->write_page(op, page);
63364 fscache_stat_d(&fscache_n_cop_write_page);
63365 @@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63366 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63367 ASSERT(PageFsCache(page));
63368
63369 - fscache_stat(&fscache_n_stores);
63370 + fscache_stat_unchecked(&fscache_n_stores);
63371
63372 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63373 _leave(" = -ENOBUFS [invalidating]");
63374 @@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63375 spin_unlock(&cookie->stores_lock);
63376 spin_unlock(&object->lock);
63377
63378 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63379 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63380 op->store_limit = object->store_limit;
63381
63382 __fscache_use_cookie(cookie);
63383 @@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63384
63385 spin_unlock(&cookie->lock);
63386 radix_tree_preload_end();
63387 - fscache_stat(&fscache_n_store_ops);
63388 - fscache_stat(&fscache_n_stores_ok);
63389 + fscache_stat_unchecked(&fscache_n_store_ops);
63390 + fscache_stat_unchecked(&fscache_n_stores_ok);
63391
63392 /* the work queue now carries its own ref on the object */
63393 fscache_put_operation(&op->op);
63394 @@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63395 return 0;
63396
63397 already_queued:
63398 - fscache_stat(&fscache_n_stores_again);
63399 + fscache_stat_unchecked(&fscache_n_stores_again);
63400 already_pending:
63401 spin_unlock(&cookie->stores_lock);
63402 spin_unlock(&object->lock);
63403 spin_unlock(&cookie->lock);
63404 radix_tree_preload_end();
63405 kfree(op);
63406 - fscache_stat(&fscache_n_stores_ok);
63407 + fscache_stat_unchecked(&fscache_n_stores_ok);
63408 _leave(" = 0");
63409 return 0;
63410
63411 @@ -1039,14 +1039,14 @@ nobufs:
63412 kfree(op);
63413 if (wake_cookie)
63414 __fscache_wake_unused_cookie(cookie);
63415 - fscache_stat(&fscache_n_stores_nobufs);
63416 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
63417 _leave(" = -ENOBUFS");
63418 return -ENOBUFS;
63419
63420 nomem_free:
63421 kfree(op);
63422 nomem:
63423 - fscache_stat(&fscache_n_stores_oom);
63424 + fscache_stat_unchecked(&fscache_n_stores_oom);
63425 _leave(" = -ENOMEM");
63426 return -ENOMEM;
63427 }
63428 @@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63429 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63430 ASSERTCMP(page, !=, NULL);
63431
63432 - fscache_stat(&fscache_n_uncaches);
63433 + fscache_stat_unchecked(&fscache_n_uncaches);
63434
63435 /* cache withdrawal may beat us to it */
63436 if (!PageFsCache(page))
63437 @@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63438 struct fscache_cookie *cookie = op->op.object->cookie;
63439
63440 #ifdef CONFIG_FSCACHE_STATS
63441 - atomic_inc(&fscache_n_marks);
63442 + atomic_inc_unchecked(&fscache_n_marks);
63443 #endif
63444
63445 _debug("- mark %p{%lx}", page, page->index);
63446 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63447 index 40d13c7..ddf52b9 100644
63448 --- a/fs/fscache/stats.c
63449 +++ b/fs/fscache/stats.c
63450 @@ -18,99 +18,99 @@
63451 /*
63452 * operation counters
63453 */
63454 -atomic_t fscache_n_op_pend;
63455 -atomic_t fscache_n_op_run;
63456 -atomic_t fscache_n_op_enqueue;
63457 -atomic_t fscache_n_op_requeue;
63458 -atomic_t fscache_n_op_deferred_release;
63459 -atomic_t fscache_n_op_release;
63460 -atomic_t fscache_n_op_gc;
63461 -atomic_t fscache_n_op_cancelled;
63462 -atomic_t fscache_n_op_rejected;
63463 +atomic_unchecked_t fscache_n_op_pend;
63464 +atomic_unchecked_t fscache_n_op_run;
63465 +atomic_unchecked_t fscache_n_op_enqueue;
63466 +atomic_unchecked_t fscache_n_op_requeue;
63467 +atomic_unchecked_t fscache_n_op_deferred_release;
63468 +atomic_unchecked_t fscache_n_op_release;
63469 +atomic_unchecked_t fscache_n_op_gc;
63470 +atomic_unchecked_t fscache_n_op_cancelled;
63471 +atomic_unchecked_t fscache_n_op_rejected;
63472
63473 -atomic_t fscache_n_attr_changed;
63474 -atomic_t fscache_n_attr_changed_ok;
63475 -atomic_t fscache_n_attr_changed_nobufs;
63476 -atomic_t fscache_n_attr_changed_nomem;
63477 -atomic_t fscache_n_attr_changed_calls;
63478 +atomic_unchecked_t fscache_n_attr_changed;
63479 +atomic_unchecked_t fscache_n_attr_changed_ok;
63480 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
63481 +atomic_unchecked_t fscache_n_attr_changed_nomem;
63482 +atomic_unchecked_t fscache_n_attr_changed_calls;
63483
63484 -atomic_t fscache_n_allocs;
63485 -atomic_t fscache_n_allocs_ok;
63486 -atomic_t fscache_n_allocs_wait;
63487 -atomic_t fscache_n_allocs_nobufs;
63488 -atomic_t fscache_n_allocs_intr;
63489 -atomic_t fscache_n_allocs_object_dead;
63490 -atomic_t fscache_n_alloc_ops;
63491 -atomic_t fscache_n_alloc_op_waits;
63492 +atomic_unchecked_t fscache_n_allocs;
63493 +atomic_unchecked_t fscache_n_allocs_ok;
63494 +atomic_unchecked_t fscache_n_allocs_wait;
63495 +atomic_unchecked_t fscache_n_allocs_nobufs;
63496 +atomic_unchecked_t fscache_n_allocs_intr;
63497 +atomic_unchecked_t fscache_n_allocs_object_dead;
63498 +atomic_unchecked_t fscache_n_alloc_ops;
63499 +atomic_unchecked_t fscache_n_alloc_op_waits;
63500
63501 -atomic_t fscache_n_retrievals;
63502 -atomic_t fscache_n_retrievals_ok;
63503 -atomic_t fscache_n_retrievals_wait;
63504 -atomic_t fscache_n_retrievals_nodata;
63505 -atomic_t fscache_n_retrievals_nobufs;
63506 -atomic_t fscache_n_retrievals_intr;
63507 -atomic_t fscache_n_retrievals_nomem;
63508 -atomic_t fscache_n_retrievals_object_dead;
63509 -atomic_t fscache_n_retrieval_ops;
63510 -atomic_t fscache_n_retrieval_op_waits;
63511 +atomic_unchecked_t fscache_n_retrievals;
63512 +atomic_unchecked_t fscache_n_retrievals_ok;
63513 +atomic_unchecked_t fscache_n_retrievals_wait;
63514 +atomic_unchecked_t fscache_n_retrievals_nodata;
63515 +atomic_unchecked_t fscache_n_retrievals_nobufs;
63516 +atomic_unchecked_t fscache_n_retrievals_intr;
63517 +atomic_unchecked_t fscache_n_retrievals_nomem;
63518 +atomic_unchecked_t fscache_n_retrievals_object_dead;
63519 +atomic_unchecked_t fscache_n_retrieval_ops;
63520 +atomic_unchecked_t fscache_n_retrieval_op_waits;
63521
63522 -atomic_t fscache_n_stores;
63523 -atomic_t fscache_n_stores_ok;
63524 -atomic_t fscache_n_stores_again;
63525 -atomic_t fscache_n_stores_nobufs;
63526 -atomic_t fscache_n_stores_oom;
63527 -atomic_t fscache_n_store_ops;
63528 -atomic_t fscache_n_store_calls;
63529 -atomic_t fscache_n_store_pages;
63530 -atomic_t fscache_n_store_radix_deletes;
63531 -atomic_t fscache_n_store_pages_over_limit;
63532 +atomic_unchecked_t fscache_n_stores;
63533 +atomic_unchecked_t fscache_n_stores_ok;
63534 +atomic_unchecked_t fscache_n_stores_again;
63535 +atomic_unchecked_t fscache_n_stores_nobufs;
63536 +atomic_unchecked_t fscache_n_stores_oom;
63537 +atomic_unchecked_t fscache_n_store_ops;
63538 +atomic_unchecked_t fscache_n_store_calls;
63539 +atomic_unchecked_t fscache_n_store_pages;
63540 +atomic_unchecked_t fscache_n_store_radix_deletes;
63541 +atomic_unchecked_t fscache_n_store_pages_over_limit;
63542
63543 -atomic_t fscache_n_store_vmscan_not_storing;
63544 -atomic_t fscache_n_store_vmscan_gone;
63545 -atomic_t fscache_n_store_vmscan_busy;
63546 -atomic_t fscache_n_store_vmscan_cancelled;
63547 -atomic_t fscache_n_store_vmscan_wait;
63548 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63549 +atomic_unchecked_t fscache_n_store_vmscan_gone;
63550 +atomic_unchecked_t fscache_n_store_vmscan_busy;
63551 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63552 +atomic_unchecked_t fscache_n_store_vmscan_wait;
63553
63554 -atomic_t fscache_n_marks;
63555 -atomic_t fscache_n_uncaches;
63556 +atomic_unchecked_t fscache_n_marks;
63557 +atomic_unchecked_t fscache_n_uncaches;
63558
63559 -atomic_t fscache_n_acquires;
63560 -atomic_t fscache_n_acquires_null;
63561 -atomic_t fscache_n_acquires_no_cache;
63562 -atomic_t fscache_n_acquires_ok;
63563 -atomic_t fscache_n_acquires_nobufs;
63564 -atomic_t fscache_n_acquires_oom;
63565 +atomic_unchecked_t fscache_n_acquires;
63566 +atomic_unchecked_t fscache_n_acquires_null;
63567 +atomic_unchecked_t fscache_n_acquires_no_cache;
63568 +atomic_unchecked_t fscache_n_acquires_ok;
63569 +atomic_unchecked_t fscache_n_acquires_nobufs;
63570 +atomic_unchecked_t fscache_n_acquires_oom;
63571
63572 -atomic_t fscache_n_invalidates;
63573 -atomic_t fscache_n_invalidates_run;
63574 +atomic_unchecked_t fscache_n_invalidates;
63575 +atomic_unchecked_t fscache_n_invalidates_run;
63576
63577 -atomic_t fscache_n_updates;
63578 -atomic_t fscache_n_updates_null;
63579 -atomic_t fscache_n_updates_run;
63580 +atomic_unchecked_t fscache_n_updates;
63581 +atomic_unchecked_t fscache_n_updates_null;
63582 +atomic_unchecked_t fscache_n_updates_run;
63583
63584 -atomic_t fscache_n_relinquishes;
63585 -atomic_t fscache_n_relinquishes_null;
63586 -atomic_t fscache_n_relinquishes_waitcrt;
63587 -atomic_t fscache_n_relinquishes_retire;
63588 +atomic_unchecked_t fscache_n_relinquishes;
63589 +atomic_unchecked_t fscache_n_relinquishes_null;
63590 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63591 +atomic_unchecked_t fscache_n_relinquishes_retire;
63592
63593 -atomic_t fscache_n_cookie_index;
63594 -atomic_t fscache_n_cookie_data;
63595 -atomic_t fscache_n_cookie_special;
63596 +atomic_unchecked_t fscache_n_cookie_index;
63597 +atomic_unchecked_t fscache_n_cookie_data;
63598 +atomic_unchecked_t fscache_n_cookie_special;
63599
63600 -atomic_t fscache_n_object_alloc;
63601 -atomic_t fscache_n_object_no_alloc;
63602 -atomic_t fscache_n_object_lookups;
63603 -atomic_t fscache_n_object_lookups_negative;
63604 -atomic_t fscache_n_object_lookups_positive;
63605 -atomic_t fscache_n_object_lookups_timed_out;
63606 -atomic_t fscache_n_object_created;
63607 -atomic_t fscache_n_object_avail;
63608 -atomic_t fscache_n_object_dead;
63609 +atomic_unchecked_t fscache_n_object_alloc;
63610 +atomic_unchecked_t fscache_n_object_no_alloc;
63611 +atomic_unchecked_t fscache_n_object_lookups;
63612 +atomic_unchecked_t fscache_n_object_lookups_negative;
63613 +atomic_unchecked_t fscache_n_object_lookups_positive;
63614 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
63615 +atomic_unchecked_t fscache_n_object_created;
63616 +atomic_unchecked_t fscache_n_object_avail;
63617 +atomic_unchecked_t fscache_n_object_dead;
63618
63619 -atomic_t fscache_n_checkaux_none;
63620 -atomic_t fscache_n_checkaux_okay;
63621 -atomic_t fscache_n_checkaux_update;
63622 -atomic_t fscache_n_checkaux_obsolete;
63623 +atomic_unchecked_t fscache_n_checkaux_none;
63624 +atomic_unchecked_t fscache_n_checkaux_okay;
63625 +atomic_unchecked_t fscache_n_checkaux_update;
63626 +atomic_unchecked_t fscache_n_checkaux_obsolete;
63627
63628 atomic_t fscache_n_cop_alloc_object;
63629 atomic_t fscache_n_cop_lookup_object;
63630 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63631 seq_puts(m, "FS-Cache statistics\n");
63632
63633 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63634 - atomic_read(&fscache_n_cookie_index),
63635 - atomic_read(&fscache_n_cookie_data),
63636 - atomic_read(&fscache_n_cookie_special));
63637 + atomic_read_unchecked(&fscache_n_cookie_index),
63638 + atomic_read_unchecked(&fscache_n_cookie_data),
63639 + atomic_read_unchecked(&fscache_n_cookie_special));
63640
63641 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63642 - atomic_read(&fscache_n_object_alloc),
63643 - atomic_read(&fscache_n_object_no_alloc),
63644 - atomic_read(&fscache_n_object_avail),
63645 - atomic_read(&fscache_n_object_dead));
63646 + atomic_read_unchecked(&fscache_n_object_alloc),
63647 + atomic_read_unchecked(&fscache_n_object_no_alloc),
63648 + atomic_read_unchecked(&fscache_n_object_avail),
63649 + atomic_read_unchecked(&fscache_n_object_dead));
63650 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63651 - atomic_read(&fscache_n_checkaux_none),
63652 - atomic_read(&fscache_n_checkaux_okay),
63653 - atomic_read(&fscache_n_checkaux_update),
63654 - atomic_read(&fscache_n_checkaux_obsolete));
63655 + atomic_read_unchecked(&fscache_n_checkaux_none),
63656 + atomic_read_unchecked(&fscache_n_checkaux_okay),
63657 + atomic_read_unchecked(&fscache_n_checkaux_update),
63658 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63659
63660 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63661 - atomic_read(&fscache_n_marks),
63662 - atomic_read(&fscache_n_uncaches));
63663 + atomic_read_unchecked(&fscache_n_marks),
63664 + atomic_read_unchecked(&fscache_n_uncaches));
63665
63666 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63667 " oom=%u\n",
63668 - atomic_read(&fscache_n_acquires),
63669 - atomic_read(&fscache_n_acquires_null),
63670 - atomic_read(&fscache_n_acquires_no_cache),
63671 - atomic_read(&fscache_n_acquires_ok),
63672 - atomic_read(&fscache_n_acquires_nobufs),
63673 - atomic_read(&fscache_n_acquires_oom));
63674 + atomic_read_unchecked(&fscache_n_acquires),
63675 + atomic_read_unchecked(&fscache_n_acquires_null),
63676 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
63677 + atomic_read_unchecked(&fscache_n_acquires_ok),
63678 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
63679 + atomic_read_unchecked(&fscache_n_acquires_oom));
63680
63681 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63682 - atomic_read(&fscache_n_object_lookups),
63683 - atomic_read(&fscache_n_object_lookups_negative),
63684 - atomic_read(&fscache_n_object_lookups_positive),
63685 - atomic_read(&fscache_n_object_created),
63686 - atomic_read(&fscache_n_object_lookups_timed_out));
63687 + atomic_read_unchecked(&fscache_n_object_lookups),
63688 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
63689 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
63690 + atomic_read_unchecked(&fscache_n_object_created),
63691 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63692
63693 seq_printf(m, "Invals : n=%u run=%u\n",
63694 - atomic_read(&fscache_n_invalidates),
63695 - atomic_read(&fscache_n_invalidates_run));
63696 + atomic_read_unchecked(&fscache_n_invalidates),
63697 + atomic_read_unchecked(&fscache_n_invalidates_run));
63698
63699 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63700 - atomic_read(&fscache_n_updates),
63701 - atomic_read(&fscache_n_updates_null),
63702 - atomic_read(&fscache_n_updates_run));
63703 + atomic_read_unchecked(&fscache_n_updates),
63704 + atomic_read_unchecked(&fscache_n_updates_null),
63705 + atomic_read_unchecked(&fscache_n_updates_run));
63706
63707 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63708 - atomic_read(&fscache_n_relinquishes),
63709 - atomic_read(&fscache_n_relinquishes_null),
63710 - atomic_read(&fscache_n_relinquishes_waitcrt),
63711 - atomic_read(&fscache_n_relinquishes_retire));
63712 + atomic_read_unchecked(&fscache_n_relinquishes),
63713 + atomic_read_unchecked(&fscache_n_relinquishes_null),
63714 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63715 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
63716
63717 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63718 - atomic_read(&fscache_n_attr_changed),
63719 - atomic_read(&fscache_n_attr_changed_ok),
63720 - atomic_read(&fscache_n_attr_changed_nobufs),
63721 - atomic_read(&fscache_n_attr_changed_nomem),
63722 - atomic_read(&fscache_n_attr_changed_calls));
63723 + atomic_read_unchecked(&fscache_n_attr_changed),
63724 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
63725 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63726 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63727 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
63728
63729 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63730 - atomic_read(&fscache_n_allocs),
63731 - atomic_read(&fscache_n_allocs_ok),
63732 - atomic_read(&fscache_n_allocs_wait),
63733 - atomic_read(&fscache_n_allocs_nobufs),
63734 - atomic_read(&fscache_n_allocs_intr));
63735 + atomic_read_unchecked(&fscache_n_allocs),
63736 + atomic_read_unchecked(&fscache_n_allocs_ok),
63737 + atomic_read_unchecked(&fscache_n_allocs_wait),
63738 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
63739 + atomic_read_unchecked(&fscache_n_allocs_intr));
63740 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63741 - atomic_read(&fscache_n_alloc_ops),
63742 - atomic_read(&fscache_n_alloc_op_waits),
63743 - atomic_read(&fscache_n_allocs_object_dead));
63744 + atomic_read_unchecked(&fscache_n_alloc_ops),
63745 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
63746 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
63747
63748 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63749 " int=%u oom=%u\n",
63750 - atomic_read(&fscache_n_retrievals),
63751 - atomic_read(&fscache_n_retrievals_ok),
63752 - atomic_read(&fscache_n_retrievals_wait),
63753 - atomic_read(&fscache_n_retrievals_nodata),
63754 - atomic_read(&fscache_n_retrievals_nobufs),
63755 - atomic_read(&fscache_n_retrievals_intr),
63756 - atomic_read(&fscache_n_retrievals_nomem));
63757 + atomic_read_unchecked(&fscache_n_retrievals),
63758 + atomic_read_unchecked(&fscache_n_retrievals_ok),
63759 + atomic_read_unchecked(&fscache_n_retrievals_wait),
63760 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
63761 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63762 + atomic_read_unchecked(&fscache_n_retrievals_intr),
63763 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
63764 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63765 - atomic_read(&fscache_n_retrieval_ops),
63766 - atomic_read(&fscache_n_retrieval_op_waits),
63767 - atomic_read(&fscache_n_retrievals_object_dead));
63768 + atomic_read_unchecked(&fscache_n_retrieval_ops),
63769 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63770 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63771
63772 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63773 - atomic_read(&fscache_n_stores),
63774 - atomic_read(&fscache_n_stores_ok),
63775 - atomic_read(&fscache_n_stores_again),
63776 - atomic_read(&fscache_n_stores_nobufs),
63777 - atomic_read(&fscache_n_stores_oom));
63778 + atomic_read_unchecked(&fscache_n_stores),
63779 + atomic_read_unchecked(&fscache_n_stores_ok),
63780 + atomic_read_unchecked(&fscache_n_stores_again),
63781 + atomic_read_unchecked(&fscache_n_stores_nobufs),
63782 + atomic_read_unchecked(&fscache_n_stores_oom));
63783 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63784 - atomic_read(&fscache_n_store_ops),
63785 - atomic_read(&fscache_n_store_calls),
63786 - atomic_read(&fscache_n_store_pages),
63787 - atomic_read(&fscache_n_store_radix_deletes),
63788 - atomic_read(&fscache_n_store_pages_over_limit));
63789 + atomic_read_unchecked(&fscache_n_store_ops),
63790 + atomic_read_unchecked(&fscache_n_store_calls),
63791 + atomic_read_unchecked(&fscache_n_store_pages),
63792 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
63793 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63794
63795 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63796 - atomic_read(&fscache_n_store_vmscan_not_storing),
63797 - atomic_read(&fscache_n_store_vmscan_gone),
63798 - atomic_read(&fscache_n_store_vmscan_busy),
63799 - atomic_read(&fscache_n_store_vmscan_cancelled),
63800 - atomic_read(&fscache_n_store_vmscan_wait));
63801 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63802 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63803 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63804 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63805 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63806
63807 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63808 - atomic_read(&fscache_n_op_pend),
63809 - atomic_read(&fscache_n_op_run),
63810 - atomic_read(&fscache_n_op_enqueue),
63811 - atomic_read(&fscache_n_op_cancelled),
63812 - atomic_read(&fscache_n_op_rejected));
63813 + atomic_read_unchecked(&fscache_n_op_pend),
63814 + atomic_read_unchecked(&fscache_n_op_run),
63815 + atomic_read_unchecked(&fscache_n_op_enqueue),
63816 + atomic_read_unchecked(&fscache_n_op_cancelled),
63817 + atomic_read_unchecked(&fscache_n_op_rejected));
63818 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63819 - atomic_read(&fscache_n_op_deferred_release),
63820 - atomic_read(&fscache_n_op_release),
63821 - atomic_read(&fscache_n_op_gc));
63822 + atomic_read_unchecked(&fscache_n_op_deferred_release),
63823 + atomic_read_unchecked(&fscache_n_op_release),
63824 + atomic_read_unchecked(&fscache_n_op_gc));
63825
63826 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63827 atomic_read(&fscache_n_cop_alloc_object),
63828 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63829 index 966ace8..030a03a 100644
63830 --- a/fs/fuse/cuse.c
63831 +++ b/fs/fuse/cuse.c
63832 @@ -611,10 +611,12 @@ static int __init cuse_init(void)
63833 INIT_LIST_HEAD(&cuse_conntbl[i]);
63834
63835 /* inherit and extend fuse_dev_operations */
63836 - cuse_channel_fops = fuse_dev_operations;
63837 - cuse_channel_fops.owner = THIS_MODULE;
63838 - cuse_channel_fops.open = cuse_channel_open;
63839 - cuse_channel_fops.release = cuse_channel_release;
63840 + pax_open_kernel();
63841 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63842 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63843 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
63844 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
63845 + pax_close_kernel();
63846
63847 cuse_class = class_create(THIS_MODULE, "cuse");
63848 if (IS_ERR(cuse_class))
63849 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63850 index ca88731..8e9c55d 100644
63851 --- a/fs/fuse/dev.c
63852 +++ b/fs/fuse/dev.c
63853 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63854 ret = 0;
63855 pipe_lock(pipe);
63856
63857 - if (!pipe->readers) {
63858 + if (!atomic_read(&pipe->readers)) {
63859 send_sig(SIGPIPE, current, 0);
63860 if (!ret)
63861 ret = -EPIPE;
63862 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63863 page_nr++;
63864 ret += buf->len;
63865
63866 - if (pipe->files)
63867 + if (atomic_read(&pipe->files))
63868 do_wakeup = 1;
63869 }
63870
63871 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63872 index dbab798..fefa22b 100644
63873 --- a/fs/fuse/dir.c
63874 +++ b/fs/fuse/dir.c
63875 @@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63876 return link;
63877 }
63878
63879 -static void free_link(char *link)
63880 +static void free_link(const char *link)
63881 {
63882 if (!IS_ERR(link))
63883 free_page((unsigned long) link);
63884 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63885 index fd62cae..3494dfa 100644
63886 --- a/fs/hostfs/hostfs_kern.c
63887 +++ b/fs/hostfs/hostfs_kern.c
63888 @@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63889
63890 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63891 {
63892 - char *s = nd_get_link(nd);
63893 + const char *s = nd_get_link(nd);
63894 if (!IS_ERR(s))
63895 __putname(s);
63896 }
63897 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63898 index 1e2872b..7aea000 100644
63899 --- a/fs/hugetlbfs/inode.c
63900 +++ b/fs/hugetlbfs/inode.c
63901 @@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63902 struct mm_struct *mm = current->mm;
63903 struct vm_area_struct *vma;
63904 struct hstate *h = hstate_file(file);
63905 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63906 struct vm_unmapped_area_info info;
63907
63908 if (len & ~huge_page_mask(h))
63909 @@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63910 return addr;
63911 }
63912
63913 +#ifdef CONFIG_PAX_RANDMMAP
63914 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63915 +#endif
63916 +
63917 if (addr) {
63918 addr = ALIGN(addr, huge_page_size(h));
63919 vma = find_vma(mm, addr);
63920 - if (TASK_SIZE - len >= addr &&
63921 - (!vma || addr + len <= vma->vm_start))
63922 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63923 return addr;
63924 }
63925
63926 info.flags = 0;
63927 info.length = len;
63928 info.low_limit = TASK_UNMAPPED_BASE;
63929 +
63930 +#ifdef CONFIG_PAX_RANDMMAP
63931 + if (mm->pax_flags & MF_PAX_RANDMMAP)
63932 + info.low_limit += mm->delta_mmap;
63933 +#endif
63934 +
63935 info.high_limit = TASK_SIZE;
63936 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63937 info.align_offset = 0;
63938 @@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63939 };
63940 MODULE_ALIAS_FS("hugetlbfs");
63941
63942 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63943 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63944
63945 static int can_do_hugetlb_shm(void)
63946 {
63947 diff --git a/fs/inode.c b/fs/inode.c
63948 index 26753ba..d19eb34 100644
63949 --- a/fs/inode.c
63950 +++ b/fs/inode.c
63951 @@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63952 unsigned int *p = &get_cpu_var(last_ino);
63953 unsigned int res = *p;
63954
63955 +start:
63956 +
63957 #ifdef CONFIG_SMP
63958 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63959 - static atomic_t shared_last_ino;
63960 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63961 + static atomic_unchecked_t shared_last_ino;
63962 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63963
63964 res = next - LAST_INO_BATCH;
63965 }
63966 #endif
63967
63968 - *p = ++res;
63969 + if (unlikely(!++res))
63970 + goto start; /* never zero */
63971 + *p = res;
63972 put_cpu_var(last_ino);
63973 return res;
63974 }
63975 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63976 index 4a6cf28..d3a29d3 100644
63977 --- a/fs/jffs2/erase.c
63978 +++ b/fs/jffs2/erase.c
63979 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63980 struct jffs2_unknown_node marker = {
63981 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63982 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63983 - .totlen = cpu_to_je32(c->cleanmarker_size)
63984 + .totlen = cpu_to_je32(c->cleanmarker_size),
63985 + .hdr_crc = cpu_to_je32(0)
63986 };
63987
63988 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63989 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63990 index 09ed551..45684f8 100644
63991 --- a/fs/jffs2/wbuf.c
63992 +++ b/fs/jffs2/wbuf.c
63993 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63994 {
63995 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63996 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63997 - .totlen = constant_cpu_to_je32(8)
63998 + .totlen = constant_cpu_to_je32(8),
63999 + .hdr_crc = constant_cpu_to_je32(0)
64000 };
64001
64002 /*
64003 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64004 index 93e897e..a863de4 100644
64005 --- a/fs/jfs/super.c
64006 +++ b/fs/jfs/super.c
64007 @@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64008
64009 jfs_inode_cachep =
64010 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64011 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64012 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64013 init_once);
64014 if (jfs_inode_cachep == NULL)
64015 return -ENOMEM;
64016 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64017 index 1c77193..ba73e66 100644
64018 --- a/fs/kernfs/dir.c
64019 +++ b/fs/kernfs/dir.c
64020 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64021 *
64022 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64023 */
64024 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
64025 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64026 {
64027 unsigned long hash = init_name_hash();
64028 unsigned int len = strlen(name);
64029 @@ -829,6 +829,12 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
64030 ret = scops->mkdir(parent, dentry->d_name.name, mode);
64031
64032 kernfs_put_active(parent);
64033 +
64034 + if (!ret) {
64035 + struct dentry *dentry_ret = kernfs_iop_lookup(dir, dentry, 0);
64036 + ret = PTR_ERR_OR_ZERO(dentry_ret);
64037 + }
64038 +
64039 return ret;
64040 }
64041
64042 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64043 index 4429d6d..9831f52 100644
64044 --- a/fs/kernfs/file.c
64045 +++ b/fs/kernfs/file.c
64046 @@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64047
64048 struct kernfs_open_node {
64049 atomic_t refcnt;
64050 - atomic_t event;
64051 + atomic_unchecked_t event;
64052 wait_queue_head_t poll;
64053 struct list_head files; /* goes through kernfs_open_file.list */
64054 };
64055 @@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64056 {
64057 struct kernfs_open_file *of = sf->private;
64058
64059 - of->event = atomic_read(&of->kn->attr.open->event);
64060 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64061
64062 return of->kn->attr.ops->seq_show(sf, v);
64063 }
64064 @@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64065 return ret;
64066 }
64067
64068 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64069 - void *buf, int len, int write)
64070 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64071 + void *buf, size_t len, int write)
64072 {
64073 struct file *file = vma->vm_file;
64074 struct kernfs_open_file *of = kernfs_of(file);
64075 - int ret;
64076 + ssize_t ret;
64077
64078 if (!of->vm_ops)
64079 return -EINVAL;
64080 @@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64081 return -ENOMEM;
64082
64083 atomic_set(&new_on->refcnt, 0);
64084 - atomic_set(&new_on->event, 1);
64085 + atomic_set_unchecked(&new_on->event, 1);
64086 init_waitqueue_head(&new_on->poll);
64087 INIT_LIST_HEAD(&new_on->files);
64088 goto retry;
64089 @@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64090
64091 kernfs_put_active(kn);
64092
64093 - if (of->event != atomic_read(&on->event))
64094 + if (of->event != atomic_read_unchecked(&on->event))
64095 goto trigger;
64096
64097 return DEFAULT_POLLMASK;
64098 @@ -818,7 +818,7 @@ repeat:
64099
64100 on = kn->attr.open;
64101 if (on) {
64102 - atomic_inc(&on->event);
64103 + atomic_inc_unchecked(&on->event);
64104 wake_up_interruptible(&on->poll);
64105 }
64106
64107 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64108 index 8a19889..4c3069a 100644
64109 --- a/fs/kernfs/symlink.c
64110 +++ b/fs/kernfs/symlink.c
64111 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64112 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64113 void *cookie)
64114 {
64115 - char *page = nd_get_link(nd);
64116 + const char *page = nd_get_link(nd);
64117 if (!IS_ERR(page))
64118 free_page((unsigned long)page);
64119 }
64120 diff --git a/fs/libfs.c b/fs/libfs.c
64121 index 005843c..06c4191 100644
64122 --- a/fs/libfs.c
64123 +++ b/fs/libfs.c
64124 @@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64125
64126 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64127 struct dentry *next = list_entry(p, struct dentry, d_child);
64128 + char d_name[sizeof(next->d_iname)];
64129 + const unsigned char *name;
64130 +
64131 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64132 if (!simple_positive(next)) {
64133 spin_unlock(&next->d_lock);
64134 @@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64135
64136 spin_unlock(&next->d_lock);
64137 spin_unlock(&dentry->d_lock);
64138 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64139 + name = next->d_name.name;
64140 + if (name == next->d_iname) {
64141 + memcpy(d_name, name, next->d_name.len);
64142 + name = d_name;
64143 + }
64144 + if (!dir_emit(ctx, name, next->d_name.len,
64145 next->d_inode->i_ino, dt_type(next->d_inode)))
64146 return 0;
64147 spin_lock(&dentry->d_lock);
64148 @@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64149 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64150 void *cookie)
64151 {
64152 - char *s = nd_get_link(nd);
64153 + const char *s = nd_get_link(nd);
64154 if (!IS_ERR(s))
64155 kfree(s);
64156 }
64157 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64158 index acd3947..1f896e2 100644
64159 --- a/fs/lockd/clntproc.c
64160 +++ b/fs/lockd/clntproc.c
64161 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64162 /*
64163 * Cookie counter for NLM requests
64164 */
64165 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64166 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64167
64168 void nlmclnt_next_cookie(struct nlm_cookie *c)
64169 {
64170 - u32 cookie = atomic_inc_return(&nlm_cookie);
64171 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64172
64173 memcpy(c->data, &cookie, 4);
64174 c->len=4;
64175 diff --git a/fs/locks.c b/fs/locks.c
64176 index 59e2f90..bd69071 100644
64177 --- a/fs/locks.c
64178 +++ b/fs/locks.c
64179 @@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
64180 locks_remove_posix(filp, filp);
64181
64182 if (filp->f_op->flock) {
64183 - struct file_lock fl = {
64184 + struct file_lock flock = {
64185 .fl_owner = filp,
64186 .fl_pid = current->tgid,
64187 .fl_file = filp,
64188 @@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
64189 .fl_type = F_UNLCK,
64190 .fl_end = OFFSET_MAX,
64191 };
64192 - filp->f_op->flock(filp, F_SETLKW, &fl);
64193 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
64194 - fl.fl_ops->fl_release_private(&fl);
64195 + filp->f_op->flock(filp, F_SETLKW, &flock);
64196 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
64197 + flock.fl_ops->fl_release_private(&flock);
64198 }
64199
64200 spin_lock(&inode->i_lock);
64201 diff --git a/fs/mount.h b/fs/mount.h
64202 index f82c628..9492b99 100644
64203 --- a/fs/mount.h
64204 +++ b/fs/mount.h
64205 @@ -11,7 +11,7 @@ struct mnt_namespace {
64206 u64 seq; /* Sequence number to prevent loops */
64207 wait_queue_head_t poll;
64208 u64 event;
64209 -};
64210 +} __randomize_layout;
64211
64212 struct mnt_pcp {
64213 int mnt_count;
64214 @@ -62,7 +62,7 @@ struct mount {
64215 int mnt_expiry_mark; /* true if marked for expiry */
64216 struct hlist_head mnt_pins;
64217 struct path mnt_ex_mountpoint;
64218 -};
64219 +} __randomize_layout;
64220
64221 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64222
64223 diff --git a/fs/namei.c b/fs/namei.c
64224 index db5fe86..8bce5f0 100644
64225 --- a/fs/namei.c
64226 +++ b/fs/namei.c
64227 @@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64228 if (ret != -EACCES)
64229 return ret;
64230
64231 +#ifdef CONFIG_GRKERNSEC
64232 + /* we'll block if we have to log due to a denied capability use */
64233 + if (mask & MAY_NOT_BLOCK)
64234 + return -ECHILD;
64235 +#endif
64236 +
64237 if (S_ISDIR(inode->i_mode)) {
64238 /* DACs are overridable for directories */
64239 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64240 - return 0;
64241 if (!(mask & MAY_WRITE))
64242 - if (capable_wrt_inode_uidgid(inode,
64243 - CAP_DAC_READ_SEARCH))
64244 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64245 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64246 return 0;
64247 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64248 + return 0;
64249 return -EACCES;
64250 }
64251 /*
64252 + * Searching includes executable on directories, else just read.
64253 + */
64254 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64255 + if (mask == MAY_READ)
64256 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64257 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64258 + return 0;
64259 +
64260 + /*
64261 * Read/write DACs are always overridable.
64262 * Executable DACs are overridable when there is
64263 * at least one exec bit set.
64264 @@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64265 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64266 return 0;
64267
64268 - /*
64269 - * Searching includes executable on directories, else just read.
64270 - */
64271 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64272 - if (mask == MAY_READ)
64273 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64274 - return 0;
64275 -
64276 return -EACCES;
64277 }
64278 EXPORT_SYMBOL(generic_permission);
64279 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64280 {
64281 struct dentry *dentry = link->dentry;
64282 int error;
64283 - char *s;
64284 + const char *s;
64285
64286 BUG_ON(nd->flags & LOOKUP_RCU);
64287
64288 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64289 if (error)
64290 goto out_put_nd_path;
64291
64292 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
64293 + dentry->d_inode, dentry, nd->path.mnt)) {
64294 + error = -EACCES;
64295 + goto out_put_nd_path;
64296 + }
64297 +
64298 nd->last_type = LAST_BIND;
64299 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64300 error = PTR_ERR(*p);
64301 @@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64302 if (res)
64303 break;
64304 res = walk_component(nd, path, LOOKUP_FOLLOW);
64305 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64306 + res = -EACCES;
64307 put_link(nd, &link, cookie);
64308 } while (res > 0);
64309
64310 @@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
64311 static inline u64 hash_name(const char *name)
64312 {
64313 unsigned long a, b, adata, bdata, mask, hash, len;
64314 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64315 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64316
64317 hash = a = 0;
64318 len = -sizeof(unsigned long);
64319 @@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
64320 if (err)
64321 break;
64322 err = lookup_last(nd, &path);
64323 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
64324 + err = -EACCES;
64325 put_link(nd, &link, cookie);
64326 }
64327 }
64328 @@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
64329 if (!err)
64330 err = complete_walk(nd);
64331
64332 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
64333 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64334 + path_put(&nd->path);
64335 + err = -ENOENT;
64336 + }
64337 + }
64338 +
64339 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64340 if (!d_can_lookup(nd->path.dentry)) {
64341 path_put(&nd->path);
64342 @@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
64343 retval = path_lookupat(dfd, name->name,
64344 flags | LOOKUP_REVAL, nd);
64345
64346 - if (likely(!retval))
64347 + if (likely(!retval)) {
64348 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64349 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64350 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64351 + path_put(&nd->path);
64352 + return -ENOENT;
64353 + }
64354 + }
64355 + }
64356 return retval;
64357 }
64358
64359 @@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64360 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64361 return -EPERM;
64362
64363 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64364 + return -EPERM;
64365 + if (gr_handle_rawio(inode))
64366 + return -EPERM;
64367 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64368 + return -EACCES;
64369 +
64370 return 0;
64371 }
64372
64373 @@ -2813,7 +2851,7 @@ looked_up:
64374 * cleared otherwise prior to returning.
64375 */
64376 static int lookup_open(struct nameidata *nd, struct path *path,
64377 - struct file *file,
64378 + struct path *link, struct file *file,
64379 const struct open_flags *op,
64380 bool got_write, int *opened)
64381 {
64382 @@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64383 /* Negative dentry, just create the file */
64384 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64385 umode_t mode = op->mode;
64386 +
64387 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64388 + error = -EACCES;
64389 + goto out_dput;
64390 + }
64391 +
64392 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64393 + error = -EACCES;
64394 + goto out_dput;
64395 + }
64396 +
64397 if (!IS_POSIXACL(dir->d_inode))
64398 mode &= ~current_umask();
64399 /*
64400 @@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64401 nd->flags & LOOKUP_EXCL);
64402 if (error)
64403 goto out_dput;
64404 + else
64405 + gr_handle_create(dentry, nd->path.mnt);
64406 }
64407 out_no_open:
64408 path->dentry = dentry;
64409 @@ -2883,7 +2934,7 @@ out_dput:
64410 /*
64411 * Handle the last step of open()
64412 */
64413 -static int do_last(struct nameidata *nd, struct path *path,
64414 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64415 struct file *file, const struct open_flags *op,
64416 int *opened, struct filename *name)
64417 {
64418 @@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64419 if (error)
64420 return error;
64421
64422 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64423 + error = -ENOENT;
64424 + goto out;
64425 + }
64426 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64427 + error = -EACCES;
64428 + goto out;
64429 + }
64430 +
64431 audit_inode(name, dir, LOOKUP_PARENT);
64432 error = -EISDIR;
64433 /* trailing slashes? */
64434 @@ -2952,7 +3012,7 @@ retry_lookup:
64435 */
64436 }
64437 mutex_lock(&dir->d_inode->i_mutex);
64438 - error = lookup_open(nd, path, file, op, got_write, opened);
64439 + error = lookup_open(nd, path, link, file, op, got_write, opened);
64440 mutex_unlock(&dir->d_inode->i_mutex);
64441
64442 if (error <= 0) {
64443 @@ -2976,11 +3036,28 @@ retry_lookup:
64444 goto finish_open_created;
64445 }
64446
64447 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64448 + error = -ENOENT;
64449 + goto exit_dput;
64450 + }
64451 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64452 + error = -EACCES;
64453 + goto exit_dput;
64454 + }
64455 +
64456 /*
64457 * create/update audit record if it already exists.
64458 */
64459 - if (d_is_positive(path->dentry))
64460 + if (d_is_positive(path->dentry)) {
64461 + /* only check if O_CREAT is specified, all other checks need to go
64462 + into may_open */
64463 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64464 + error = -EACCES;
64465 + goto exit_dput;
64466 + }
64467 +
64468 audit_inode(name, path->dentry, 0);
64469 + }
64470
64471 /*
64472 * If atomic_open() acquired write access it is dropped now due to
64473 @@ -3021,6 +3098,11 @@ finish_lookup:
64474 }
64475 }
64476 BUG_ON(inode != path->dentry->d_inode);
64477 + /* if we're resolving a symlink to another symlink */
64478 + if (link && gr_handle_symlink_owner(link, inode)) {
64479 + error = -EACCES;
64480 + goto out;
64481 + }
64482 return 1;
64483 }
64484
64485 @@ -3040,7 +3122,18 @@ finish_open:
64486 path_put(&save_parent);
64487 return error;
64488 }
64489 +
64490 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64491 + error = -ENOENT;
64492 + goto out;
64493 + }
64494 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
64495 + error = -EACCES;
64496 + goto out;
64497 + }
64498 +
64499 audit_inode(name, nd->path.dentry, 0);
64500 +
64501 error = -EISDIR;
64502 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64503 goto out;
64504 @@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64505 if (unlikely(error))
64506 goto out;
64507
64508 - error = do_last(nd, &path, file, op, &opened, pathname);
64509 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64510 while (unlikely(error > 0)) { /* trailing symlink */
64511 struct path link = path;
64512 void *cookie;
64513 @@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64514 error = follow_link(&link, nd, &cookie);
64515 if (unlikely(error))
64516 break;
64517 - error = do_last(nd, &path, file, op, &opened, pathname);
64518 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
64519 put_link(nd, &link, cookie);
64520 }
64521 out:
64522 @@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64523 goto unlock;
64524
64525 error = -EEXIST;
64526 - if (d_is_positive(dentry))
64527 + if (d_is_positive(dentry)) {
64528 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64529 + error = -ENOENT;
64530 goto fail;
64531 -
64532 + }
64533 /*
64534 * Special case - lookup gave negative, but... we had foo/bar/
64535 * From the vfs_mknod() POV we just have a negative dentry -
64536 @@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64537 }
64538 EXPORT_SYMBOL(user_path_create);
64539
64540 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64541 +{
64542 + struct filename *tmp = getname(pathname);
64543 + struct dentry *res;
64544 + if (IS_ERR(tmp))
64545 + return ERR_CAST(tmp);
64546 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64547 + if (IS_ERR(res))
64548 + putname(tmp);
64549 + else
64550 + *to = tmp;
64551 + return res;
64552 +}
64553 +
64554 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64555 {
64556 int error = may_create(dir, dentry);
64557 @@ -3442,6 +3551,17 @@ retry:
64558
64559 if (!IS_POSIXACL(path.dentry->d_inode))
64560 mode &= ~current_umask();
64561 +
64562 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64563 + error = -EPERM;
64564 + goto out;
64565 + }
64566 +
64567 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64568 + error = -EACCES;
64569 + goto out;
64570 + }
64571 +
64572 error = security_path_mknod(&path, dentry, mode, dev);
64573 if (error)
64574 goto out;
64575 @@ -3457,6 +3577,8 @@ retry:
64576 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64577 break;
64578 }
64579 + if (!error)
64580 + gr_handle_create(dentry, path.mnt);
64581 out:
64582 done_path_create(&path, dentry);
64583 if (retry_estale(error, lookup_flags)) {
64584 @@ -3511,9 +3633,16 @@ retry:
64585
64586 if (!IS_POSIXACL(path.dentry->d_inode))
64587 mode &= ~current_umask();
64588 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64589 + error = -EACCES;
64590 + goto out;
64591 + }
64592 error = security_path_mkdir(&path, dentry, mode);
64593 if (!error)
64594 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64595 + if (!error)
64596 + gr_handle_create(dentry, path.mnt);
64597 +out:
64598 done_path_create(&path, dentry);
64599 if (retry_estale(error, lookup_flags)) {
64600 lookup_flags |= LOOKUP_REVAL;
64601 @@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64602 struct filename *name;
64603 struct dentry *dentry;
64604 struct nameidata nd;
64605 + u64 saved_ino = 0;
64606 + dev_t saved_dev = 0;
64607 unsigned int lookup_flags = 0;
64608 retry:
64609 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64610 @@ -3629,10 +3760,21 @@ retry:
64611 error = -ENOENT;
64612 goto exit3;
64613 }
64614 +
64615 + saved_ino = gr_get_ino_from_dentry(dentry);
64616 + saved_dev = gr_get_dev_from_dentry(dentry);
64617 +
64618 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64619 + error = -EACCES;
64620 + goto exit3;
64621 + }
64622 +
64623 error = security_path_rmdir(&nd.path, dentry);
64624 if (error)
64625 goto exit3;
64626 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64627 + if (!error && (saved_dev || saved_ino))
64628 + gr_handle_delete(saved_ino, saved_dev);
64629 exit3:
64630 dput(dentry);
64631 exit2:
64632 @@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64633 struct nameidata nd;
64634 struct inode *inode = NULL;
64635 struct inode *delegated_inode = NULL;
64636 + u64 saved_ino = 0;
64637 + dev_t saved_dev = 0;
64638 unsigned int lookup_flags = 0;
64639 retry:
64640 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64641 @@ -3751,10 +3895,22 @@ retry_deleg:
64642 if (d_is_negative(dentry))
64643 goto slashes;
64644 ihold(inode);
64645 +
64646 + if (inode->i_nlink <= 1) {
64647 + saved_ino = gr_get_ino_from_dentry(dentry);
64648 + saved_dev = gr_get_dev_from_dentry(dentry);
64649 + }
64650 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64651 + error = -EACCES;
64652 + goto exit2;
64653 + }
64654 +
64655 error = security_path_unlink(&nd.path, dentry);
64656 if (error)
64657 goto exit2;
64658 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64659 + if (!error && (saved_ino || saved_dev))
64660 + gr_handle_delete(saved_ino, saved_dev);
64661 exit2:
64662 dput(dentry);
64663 }
64664 @@ -3843,9 +3999,17 @@ retry:
64665 if (IS_ERR(dentry))
64666 goto out_putname;
64667
64668 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64669 + error = -EACCES;
64670 + goto out;
64671 + }
64672 +
64673 error = security_path_symlink(&path, dentry, from->name);
64674 if (!error)
64675 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64676 + if (!error)
64677 + gr_handle_create(dentry, path.mnt);
64678 +out:
64679 done_path_create(&path, dentry);
64680 if (retry_estale(error, lookup_flags)) {
64681 lookup_flags |= LOOKUP_REVAL;
64682 @@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64683 struct dentry *new_dentry;
64684 struct path old_path, new_path;
64685 struct inode *delegated_inode = NULL;
64686 + struct filename *to = NULL;
64687 int how = 0;
64688 int error;
64689
64690 @@ -3972,7 +4137,7 @@ retry:
64691 if (error)
64692 return error;
64693
64694 - new_dentry = user_path_create(newdfd, newname, &new_path,
64695 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64696 (how & LOOKUP_REVAL));
64697 error = PTR_ERR(new_dentry);
64698 if (IS_ERR(new_dentry))
64699 @@ -3984,11 +4149,28 @@ retry:
64700 error = may_linkat(&old_path);
64701 if (unlikely(error))
64702 goto out_dput;
64703 +
64704 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64705 + old_path.dentry->d_inode,
64706 + old_path.dentry->d_inode->i_mode, to)) {
64707 + error = -EACCES;
64708 + goto out_dput;
64709 + }
64710 +
64711 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64712 + old_path.dentry, old_path.mnt, to)) {
64713 + error = -EACCES;
64714 + goto out_dput;
64715 + }
64716 +
64717 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64718 if (error)
64719 goto out_dput;
64720 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64721 + if (!error)
64722 + gr_handle_create(new_dentry, new_path.mnt);
64723 out_dput:
64724 + putname(to);
64725 done_path_create(&new_path, new_dentry);
64726 if (delegated_inode) {
64727 error = break_deleg_wait(&delegated_inode);
64728 @@ -4304,6 +4486,20 @@ retry_deleg:
64729 if (new_dentry == trap)
64730 goto exit5;
64731
64732 + if (gr_bad_chroot_rename(old_dentry, oldnd.path.mnt, new_dentry, newnd.path.mnt)) {
64733 + /* use EXDEV error to cause 'mv' to switch to an alternative
64734 + * method for usability
64735 + */
64736 + error = -EXDEV;
64737 + goto exit5;
64738 + }
64739 +
64740 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64741 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
64742 + to, flags);
64743 + if (error)
64744 + goto exit5;
64745 +
64746 error = security_path_rename(&oldnd.path, old_dentry,
64747 &newnd.path, new_dentry, flags);
64748 if (error)
64749 @@ -4311,6 +4507,9 @@ retry_deleg:
64750 error = vfs_rename(old_dir->d_inode, old_dentry,
64751 new_dir->d_inode, new_dentry,
64752 &delegated_inode, flags);
64753 + if (!error)
64754 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64755 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64756 exit5:
64757 dput(new_dentry);
64758 exit4:
64759 @@ -4367,14 +4566,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64760
64761 int readlink_copy(char __user *buffer, int buflen, const char *link)
64762 {
64763 + char tmpbuf[64];
64764 + const char *newlink;
64765 int len = PTR_ERR(link);
64766 +
64767 if (IS_ERR(link))
64768 goto out;
64769
64770 len = strlen(link);
64771 if (len > (unsigned) buflen)
64772 len = buflen;
64773 - if (copy_to_user(buffer, link, len))
64774 +
64775 + if (len < sizeof(tmpbuf)) {
64776 + memcpy(tmpbuf, link, len);
64777 + newlink = tmpbuf;
64778 + } else
64779 + newlink = link;
64780 +
64781 + if (copy_to_user(buffer, newlink, len))
64782 len = -EFAULT;
64783 out:
64784 return len;
64785 diff --git a/fs/namespace.c b/fs/namespace.c
64786 index bbde147..f4deeba 100644
64787 --- a/fs/namespace.c
64788 +++ b/fs/namespace.c
64789 @@ -1447,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64790 if (!(sb->s_flags & MS_RDONLY))
64791 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64792 up_write(&sb->s_umount);
64793 +
64794 + gr_log_remount(mnt->mnt_devname, retval);
64795 +
64796 return retval;
64797 }
64798
64799 @@ -1469,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64800 }
64801 unlock_mount_hash();
64802 namespace_unlock();
64803 +
64804 + gr_log_unmount(mnt->mnt_devname, retval);
64805 +
64806 return retval;
64807 }
64808
64809 @@ -1519,7 +1525,7 @@ static inline bool may_mount(void)
64810 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64811 */
64812
64813 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64814 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64815 {
64816 struct path path;
64817 struct mount *mnt;
64818 @@ -1564,7 +1570,7 @@ out:
64819 /*
64820 * The 2.0 compatible umount. No flags.
64821 */
64822 -SYSCALL_DEFINE1(oldumount, char __user *, name)
64823 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
64824 {
64825 return sys_umount(name, 0);
64826 }
64827 @@ -2632,6 +2638,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64828 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64829 MS_STRICTATIME);
64830
64831 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64832 + retval = -EPERM;
64833 + goto dput_out;
64834 + }
64835 +
64836 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64837 + retval = -EPERM;
64838 + goto dput_out;
64839 + }
64840 +
64841 if (flags & MS_REMOUNT)
64842 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64843 data_page);
64844 @@ -2645,7 +2661,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64845 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64846 dev_name, data_page);
64847 dput_out:
64848 + gr_log_mount(dev_name, &path, retval);
64849 +
64850 path_put(&path);
64851 +
64852 return retval;
64853 }
64854
64855 @@ -2663,7 +2682,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64856 * number incrementing at 10Ghz will take 12,427 years to wrap which
64857 * is effectively never, so we can ignore the possibility.
64858 */
64859 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64860 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64861
64862 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64863 {
64864 @@ -2678,7 +2697,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64865 kfree(new_ns);
64866 return ERR_PTR(ret);
64867 }
64868 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64869 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64870 atomic_set(&new_ns->count, 1);
64871 new_ns->root = NULL;
64872 INIT_LIST_HEAD(&new_ns->list);
64873 @@ -2688,7 +2707,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64874 return new_ns;
64875 }
64876
64877 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64878 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64879 struct user_namespace *user_ns, struct fs_struct *new_fs)
64880 {
64881 struct mnt_namespace *new_ns;
64882 @@ -2809,8 +2828,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64883 }
64884 EXPORT_SYMBOL(mount_subtree);
64885
64886 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64887 - char __user *, type, unsigned long, flags, void __user *, data)
64888 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64889 + const char __user *, type, unsigned long, flags, void __user *, data)
64890 {
64891 int ret;
64892 char *kernel_type;
64893 @@ -2916,6 +2935,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64894 if (error)
64895 goto out2;
64896
64897 + if (gr_handle_chroot_pivot()) {
64898 + error = -EPERM;
64899 + goto out2;
64900 + }
64901 +
64902 get_fs_root(current->fs, &root);
64903 old_mp = lock_mount(&old);
64904 error = PTR_ERR(old_mp);
64905 @@ -3187,7 +3211,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64906 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64907 return -EPERM;
64908
64909 - if (fs->users != 1)
64910 + if (atomic_read(&fs->users) != 1)
64911 return -EINVAL;
64912
64913 get_mnt_ns(mnt_ns);
64914 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64915 index 02f8d09..a5c25d1 100644
64916 --- a/fs/nfs/callback_xdr.c
64917 +++ b/fs/nfs/callback_xdr.c
64918 @@ -51,7 +51,7 @@ struct callback_op {
64919 callback_decode_arg_t decode_args;
64920 callback_encode_res_t encode_res;
64921 long res_maxsize;
64922 -};
64923 +} __do_const;
64924
64925 static struct callback_op callback_ops[];
64926
64927 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64928 index 00689a8..b162632 100644
64929 --- a/fs/nfs/inode.c
64930 +++ b/fs/nfs/inode.c
64931 @@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64932 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64933 }
64934
64935 -static atomic_long_t nfs_attr_generation_counter;
64936 +static atomic_long_unchecked_t nfs_attr_generation_counter;
64937
64938 static unsigned long nfs_read_attr_generation_counter(void)
64939 {
64940 - return atomic_long_read(&nfs_attr_generation_counter);
64941 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64942 }
64943
64944 unsigned long nfs_inc_attr_generation_counter(void)
64945 {
64946 - return atomic_long_inc_return(&nfs_attr_generation_counter);
64947 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64948 }
64949
64950 void nfs_fattr_init(struct nfs_fattr *fattr)
64951 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64952 index 0beb023..3f685ec 100644
64953 --- a/fs/nfsd/nfs4proc.c
64954 +++ b/fs/nfsd/nfs4proc.c
64955 @@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64956 nfsd4op_rsize op_rsize_bop;
64957 stateid_getter op_get_currentstateid;
64958 stateid_setter op_set_currentstateid;
64959 -};
64960 +} __do_const;
64961
64962 static struct nfsd4_operation nfsd4_ops[];
64963
64964 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64965 index 2a77603..68e0e37 100644
64966 --- a/fs/nfsd/nfs4xdr.c
64967 +++ b/fs/nfsd/nfs4xdr.c
64968 @@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64969
64970 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64971
64972 -static nfsd4_dec nfsd4_dec_ops[] = {
64973 +static const nfsd4_dec nfsd4_dec_ops[] = {
64974 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64975 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64976 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64977 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64978 index 122f691..a00e2e0 100644
64979 --- a/fs/nfsd/nfscache.c
64980 +++ b/fs/nfsd/nfscache.c
64981 @@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64982 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64983 u32 hash;
64984 struct nfsd_drc_bucket *b;
64985 - int len;
64986 + long len;
64987 size_t bufsize = 0;
64988
64989 if (!rp)
64990 @@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64991 hash = nfsd_cache_hash(rp->c_xid);
64992 b = &drc_hashtbl[hash];
64993
64994 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64995 - len >>= 2;
64996 + if (statp) {
64997 + len = (char*)statp - (char*)resv->iov_base;
64998 + len = resv->iov_len - len;
64999 + len >>= 2;
65000 + }
65001
65002 /* Don't cache excessive amounts of data and XDR failures */
65003 - if (!statp || len > (256 >> 2)) {
65004 + if (!statp || len > (256 >> 2) || len < 0) {
65005 nfsd_reply_cache_free(b, rp);
65006 return;
65007 }
65008 @@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65009 switch (cachetype) {
65010 case RC_REPLSTAT:
65011 if (len != 1)
65012 - printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65013 + printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65014 rp->c_replstat = *statp;
65015 break;
65016 case RC_REPLBUFF:
65017 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65018 index 989129e..42e019e 100644
65019 --- a/fs/nfsd/vfs.c
65020 +++ b/fs/nfsd/vfs.c
65021 @@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65022
65023 oldfs = get_fs();
65024 set_fs(KERNEL_DS);
65025 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65026 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65027 set_fs(oldfs);
65028 return nfsd_finish_read(file, count, host_err);
65029 }
65030 @@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65031
65032 /* Write the data. */
65033 oldfs = get_fs(); set_fs(KERNEL_DS);
65034 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65035 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65036 set_fs(oldfs);
65037 if (host_err < 0)
65038 goto out_nfserr;
65039 @@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65040 */
65041
65042 oldfs = get_fs(); set_fs(KERNEL_DS);
65043 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65044 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65045 set_fs(oldfs);
65046
65047 if (host_err < 0)
65048 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65049 index 52ccd34..7a6b202 100644
65050 --- a/fs/nls/nls_base.c
65051 +++ b/fs/nls/nls_base.c
65052 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65053
65054 int __register_nls(struct nls_table *nls, struct module *owner)
65055 {
65056 - struct nls_table ** tmp = &tables;
65057 + struct nls_table *tmp = tables;
65058
65059 if (nls->next)
65060 return -EBUSY;
65061
65062 - nls->owner = owner;
65063 + pax_open_kernel();
65064 + *(void **)&nls->owner = owner;
65065 + pax_close_kernel();
65066 spin_lock(&nls_lock);
65067 - while (*tmp) {
65068 - if (nls == *tmp) {
65069 + while (tmp) {
65070 + if (nls == tmp) {
65071 spin_unlock(&nls_lock);
65072 return -EBUSY;
65073 }
65074 - tmp = &(*tmp)->next;
65075 + tmp = tmp->next;
65076 }
65077 - nls->next = tables;
65078 + pax_open_kernel();
65079 + *(struct nls_table **)&nls->next = tables;
65080 + pax_close_kernel();
65081 tables = nls;
65082 spin_unlock(&nls_lock);
65083 return 0;
65084 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65085
65086 int unregister_nls(struct nls_table * nls)
65087 {
65088 - struct nls_table ** tmp = &tables;
65089 + struct nls_table * const * tmp = &tables;
65090
65091 spin_lock(&nls_lock);
65092 while (*tmp) {
65093 if (nls == *tmp) {
65094 - *tmp = nls->next;
65095 + pax_open_kernel();
65096 + *(struct nls_table **)tmp = nls->next;
65097 + pax_close_kernel();
65098 spin_unlock(&nls_lock);
65099 return 0;
65100 }
65101 @@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65102 return -EINVAL;
65103 }
65104
65105 -static struct nls_table *find_nls(char *charset)
65106 +static struct nls_table *find_nls(const char *charset)
65107 {
65108 struct nls_table *nls;
65109 spin_lock(&nls_lock);
65110 @@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65111 return nls;
65112 }
65113
65114 -struct nls_table *load_nls(char *charset)
65115 +struct nls_table *load_nls(const char *charset)
65116 {
65117 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65118 }
65119 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65120 index 162b3f1..6076a7c 100644
65121 --- a/fs/nls/nls_euc-jp.c
65122 +++ b/fs/nls/nls_euc-jp.c
65123 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65124 p_nls = load_nls("cp932");
65125
65126 if (p_nls) {
65127 - table.charset2upper = p_nls->charset2upper;
65128 - table.charset2lower = p_nls->charset2lower;
65129 + pax_open_kernel();
65130 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65131 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65132 + pax_close_kernel();
65133 return register_nls(&table);
65134 }
65135
65136 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65137 index a80a741..7b96e1b 100644
65138 --- a/fs/nls/nls_koi8-ru.c
65139 +++ b/fs/nls/nls_koi8-ru.c
65140 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65141 p_nls = load_nls("koi8-u");
65142
65143 if (p_nls) {
65144 - table.charset2upper = p_nls->charset2upper;
65145 - table.charset2lower = p_nls->charset2lower;
65146 + pax_open_kernel();
65147 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65148 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65149 + pax_close_kernel();
65150 return register_nls(&table);
65151 }
65152
65153 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65154 index c991616..5ae51af 100644
65155 --- a/fs/notify/fanotify/fanotify_user.c
65156 +++ b/fs/notify/fanotify/fanotify_user.c
65157 @@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65158
65159 fd = fanotify_event_metadata.fd;
65160 ret = -EFAULT;
65161 - if (copy_to_user(buf, &fanotify_event_metadata,
65162 - fanotify_event_metadata.event_len))
65163 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65164 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65165 goto out_close_fd;
65166
65167 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65168 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65169 index a95d8e0..a91a5fd 100644
65170 --- a/fs/notify/notification.c
65171 +++ b/fs/notify/notification.c
65172 @@ -48,7 +48,7 @@
65173 #include <linux/fsnotify_backend.h>
65174 #include "fsnotify.h"
65175
65176 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65177 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65178
65179 /**
65180 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65181 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65182 */
65183 u32 fsnotify_get_cookie(void)
65184 {
65185 - return atomic_inc_return(&fsnotify_sync_cookie);
65186 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65187 }
65188 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65189
65190 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65191 index 9e38daf..5727cae 100644
65192 --- a/fs/ntfs/dir.c
65193 +++ b/fs/ntfs/dir.c
65194 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
65195 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65196 ~(s64)(ndir->itype.index.block_size - 1)));
65197 /* Bounds checks. */
65198 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65199 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65200 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65201 "inode 0x%lx or driver bug.", vdir->i_ino);
65202 goto err_out;
65203 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65204 index 643faa4..ef9027e 100644
65205 --- a/fs/ntfs/file.c
65206 +++ b/fs/ntfs/file.c
65207 @@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65208 char *addr;
65209 size_t total = 0;
65210 unsigned len;
65211 - int left;
65212 + unsigned left;
65213
65214 do {
65215 len = PAGE_CACHE_SIZE - ofs;
65216 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65217 index 9e1e112..241a52a 100644
65218 --- a/fs/ntfs/super.c
65219 +++ b/fs/ntfs/super.c
65220 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65221 if (!silent)
65222 ntfs_error(sb, "Primary boot sector is invalid.");
65223 } else if (!silent)
65224 - ntfs_error(sb, read_err_str, "primary");
65225 + ntfs_error(sb, read_err_str, "%s", "primary");
65226 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65227 if (bh_primary)
65228 brelse(bh_primary);
65229 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65230 goto hotfix_primary_boot_sector;
65231 brelse(bh_backup);
65232 } else if (!silent)
65233 - ntfs_error(sb, read_err_str, "backup");
65234 + ntfs_error(sb, read_err_str, "%s", "backup");
65235 /* Try to read NT3.51- backup boot sector. */
65236 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65237 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65238 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65239 "sector.");
65240 brelse(bh_backup);
65241 } else if (!silent)
65242 - ntfs_error(sb, read_err_str, "backup");
65243 + ntfs_error(sb, read_err_str, "%s", "backup");
65244 /* We failed. Cleanup and return. */
65245 if (bh_primary)
65246 brelse(bh_primary);
65247 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65248 index 0440134..d52c93a 100644
65249 --- a/fs/ocfs2/localalloc.c
65250 +++ b/fs/ocfs2/localalloc.c
65251 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65252 goto bail;
65253 }
65254
65255 - atomic_inc(&osb->alloc_stats.moves);
65256 + atomic_inc_unchecked(&osb->alloc_stats.moves);
65257
65258 bail:
65259 if (handle)
65260 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65261 index bbec539..7b266d5 100644
65262 --- a/fs/ocfs2/ocfs2.h
65263 +++ b/fs/ocfs2/ocfs2.h
65264 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
65265
65266 struct ocfs2_alloc_stats
65267 {
65268 - atomic_t moves;
65269 - atomic_t local_data;
65270 - atomic_t bitmap_data;
65271 - atomic_t bg_allocs;
65272 - atomic_t bg_extends;
65273 + atomic_unchecked_t moves;
65274 + atomic_unchecked_t local_data;
65275 + atomic_unchecked_t bitmap_data;
65276 + atomic_unchecked_t bg_allocs;
65277 + atomic_unchecked_t bg_extends;
65278 };
65279
65280 enum ocfs2_local_alloc_state
65281 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65282 index 0cb889a..6a26b24 100644
65283 --- a/fs/ocfs2/suballoc.c
65284 +++ b/fs/ocfs2/suballoc.c
65285 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65286 mlog_errno(status);
65287 goto bail;
65288 }
65289 - atomic_inc(&osb->alloc_stats.bg_extends);
65290 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65291
65292 /* You should never ask for this much metadata */
65293 BUG_ON(bits_wanted >
65294 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65295 mlog_errno(status);
65296 goto bail;
65297 }
65298 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65299 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65300
65301 *suballoc_loc = res.sr_bg_blkno;
65302 *suballoc_bit_start = res.sr_bit_offset;
65303 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65304 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65305 res->sr_bits);
65306
65307 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65308 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65309
65310 BUG_ON(res->sr_bits != 1);
65311
65312 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65313 mlog_errno(status);
65314 goto bail;
65315 }
65316 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65317 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65318
65319 BUG_ON(res.sr_bits != 1);
65320
65321 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65322 cluster_start,
65323 num_clusters);
65324 if (!status)
65325 - atomic_inc(&osb->alloc_stats.local_data);
65326 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
65327 } else {
65328 if (min_clusters > (osb->bitmap_cpg - 1)) {
65329 /* The only paths asking for contiguousness
65330 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65331 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65332 res.sr_bg_blkno,
65333 res.sr_bit_offset);
65334 - atomic_inc(&osb->alloc_stats.bitmap_data);
65335 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65336 *num_clusters = res.sr_bits;
65337 }
65338 }
65339 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65340 index 93c85bc..02f68a4 100644
65341 --- a/fs/ocfs2/super.c
65342 +++ b/fs/ocfs2/super.c
65343 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65344 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65345 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65346 "Stats",
65347 - atomic_read(&osb->alloc_stats.bitmap_data),
65348 - atomic_read(&osb->alloc_stats.local_data),
65349 - atomic_read(&osb->alloc_stats.bg_allocs),
65350 - atomic_read(&osb->alloc_stats.moves),
65351 - atomic_read(&osb->alloc_stats.bg_extends));
65352 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65353 + atomic_read_unchecked(&osb->alloc_stats.local_data),
65354 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65355 + atomic_read_unchecked(&osb->alloc_stats.moves),
65356 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65357
65358 out += snprintf(buf + out, len - out,
65359 "%10s => State: %u Descriptor: %llu Size: %u bits "
65360 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65361
65362 mutex_init(&osb->system_file_mutex);
65363
65364 - atomic_set(&osb->alloc_stats.moves, 0);
65365 - atomic_set(&osb->alloc_stats.local_data, 0);
65366 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
65367 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
65368 - atomic_set(&osb->alloc_stats.bg_extends, 0);
65369 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65370 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65371 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65372 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65373 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65374
65375 /* Copy the blockcheck stats from the superblock probe */
65376 osb->osb_ecc_stats = *stats;
65377 diff --git a/fs/open.c b/fs/open.c
65378 index de92c13..52d2a6c 100644
65379 --- a/fs/open.c
65380 +++ b/fs/open.c
65381 @@ -32,6 +32,8 @@
65382 #include <linux/dnotify.h>
65383 #include <linux/compat.h>
65384
65385 +#define CREATE_TRACE_POINTS
65386 +#include <trace/events/fs.h>
65387 #include "internal.h"
65388
65389 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65390 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65391 error = locks_verify_truncate(inode, NULL, length);
65392 if (!error)
65393 error = security_path_truncate(path);
65394 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65395 + error = -EACCES;
65396 if (!error)
65397 error = do_truncate(path->dentry, length, 0, NULL);
65398
65399 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65400 error = locks_verify_truncate(inode, f.file, length);
65401 if (!error)
65402 error = security_path_truncate(&f.file->f_path);
65403 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65404 + error = -EACCES;
65405 if (!error)
65406 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65407 sb_end_write(inode->i_sb);
65408 @@ -380,6 +386,9 @@ retry:
65409 if (__mnt_is_readonly(path.mnt))
65410 res = -EROFS;
65411
65412 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65413 + res = -EACCES;
65414 +
65415 out_path_release:
65416 path_put(&path);
65417 if (retry_estale(res, lookup_flags)) {
65418 @@ -411,6 +420,8 @@ retry:
65419 if (error)
65420 goto dput_and_out;
65421
65422 + gr_log_chdir(path.dentry, path.mnt);
65423 +
65424 set_fs_pwd(current->fs, &path);
65425
65426 dput_and_out:
65427 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65428 goto out_putf;
65429
65430 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65431 +
65432 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65433 + error = -EPERM;
65434 +
65435 + if (!error)
65436 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65437 +
65438 if (!error)
65439 set_fs_pwd(current->fs, &f.file->f_path);
65440 out_putf:
65441 @@ -469,7 +487,13 @@ retry:
65442 if (error)
65443 goto dput_and_out;
65444
65445 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65446 + goto dput_and_out;
65447 +
65448 set_fs_root(current->fs, &path);
65449 +
65450 + gr_handle_chroot_chdir(&path);
65451 +
65452 error = 0;
65453 dput_and_out:
65454 path_put(&path);
65455 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65456 return error;
65457 retry_deleg:
65458 mutex_lock(&inode->i_mutex);
65459 +
65460 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65461 + error = -EACCES;
65462 + goto out_unlock;
65463 + }
65464 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65465 + error = -EACCES;
65466 + goto out_unlock;
65467 + }
65468 +
65469 error = security_path_chmod(path, mode);
65470 if (error)
65471 goto out_unlock;
65472 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65473 uid = make_kuid(current_user_ns(), user);
65474 gid = make_kgid(current_user_ns(), group);
65475
65476 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
65477 + return -EACCES;
65478 +
65479 newattrs.ia_valid = ATTR_CTIME;
65480 if (user != (uid_t) -1) {
65481 if (!uid_valid(uid))
65482 @@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65483 } else {
65484 fsnotify_open(f);
65485 fd_install(fd, f);
65486 + trace_do_sys_open(tmp->name, flags, mode);
65487 }
65488 }
65489 putname(tmp);
65490 diff --git a/fs/pipe.c b/fs/pipe.c
65491 index 21981e5..3d5f55c 100644
65492 --- a/fs/pipe.c
65493 +++ b/fs/pipe.c
65494 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65495
65496 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65497 {
65498 - if (pipe->files)
65499 + if (atomic_read(&pipe->files))
65500 mutex_lock_nested(&pipe->mutex, subclass);
65501 }
65502
65503 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65504
65505 void pipe_unlock(struct pipe_inode_info *pipe)
65506 {
65507 - if (pipe->files)
65508 + if (atomic_read(&pipe->files))
65509 mutex_unlock(&pipe->mutex);
65510 }
65511 EXPORT_SYMBOL(pipe_unlock);
65512 @@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65513 }
65514 if (bufs) /* More to do? */
65515 continue;
65516 - if (!pipe->writers)
65517 + if (!atomic_read(&pipe->writers))
65518 break;
65519 - if (!pipe->waiting_writers) {
65520 + if (!atomic_read(&pipe->waiting_writers)) {
65521 /* syscall merging: Usually we must not sleep
65522 * if O_NONBLOCK is set, or if we got some data.
65523 * But if a writer sleeps in kernel space, then
65524 @@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65525
65526 __pipe_lock(pipe);
65527
65528 - if (!pipe->readers) {
65529 + if (!atomic_read(&pipe->readers)) {
65530 send_sig(SIGPIPE, current, 0);
65531 ret = -EPIPE;
65532 goto out;
65533 @@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65534 for (;;) {
65535 int bufs;
65536
65537 - if (!pipe->readers) {
65538 + if (!atomic_read(&pipe->readers)) {
65539 send_sig(SIGPIPE, current, 0);
65540 if (!ret)
65541 ret = -EPIPE;
65542 @@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65543 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65544 do_wakeup = 0;
65545 }
65546 - pipe->waiting_writers++;
65547 + atomic_inc(&pipe->waiting_writers);
65548 pipe_wait(pipe);
65549 - pipe->waiting_writers--;
65550 + atomic_dec(&pipe->waiting_writers);
65551 }
65552 out:
65553 __pipe_unlock(pipe);
65554 @@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65555 mask = 0;
65556 if (filp->f_mode & FMODE_READ) {
65557 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65558 - if (!pipe->writers && filp->f_version != pipe->w_counter)
65559 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65560 mask |= POLLHUP;
65561 }
65562
65563 @@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65564 * Most Unices do not set POLLERR for FIFOs but on Linux they
65565 * behave exactly like pipes for poll().
65566 */
65567 - if (!pipe->readers)
65568 + if (!atomic_read(&pipe->readers))
65569 mask |= POLLERR;
65570 }
65571
65572 @@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65573 int kill = 0;
65574
65575 spin_lock(&inode->i_lock);
65576 - if (!--pipe->files) {
65577 + if (atomic_dec_and_test(&pipe->files)) {
65578 inode->i_pipe = NULL;
65579 kill = 1;
65580 }
65581 @@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65582
65583 __pipe_lock(pipe);
65584 if (file->f_mode & FMODE_READ)
65585 - pipe->readers--;
65586 + atomic_dec(&pipe->readers);
65587 if (file->f_mode & FMODE_WRITE)
65588 - pipe->writers--;
65589 + atomic_dec(&pipe->writers);
65590
65591 - if (pipe->readers || pipe->writers) {
65592 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65593 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65594 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65595 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65596 @@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65597 kfree(pipe);
65598 }
65599
65600 -static struct vfsmount *pipe_mnt __read_mostly;
65601 +struct vfsmount *pipe_mnt __read_mostly;
65602
65603 /*
65604 * pipefs_dname() is called from d_path().
65605 @@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65606 goto fail_iput;
65607
65608 inode->i_pipe = pipe;
65609 - pipe->files = 2;
65610 - pipe->readers = pipe->writers = 1;
65611 + atomic_set(&pipe->files, 2);
65612 + atomic_set(&pipe->readers, 1);
65613 + atomic_set(&pipe->writers, 1);
65614 inode->i_fop = &pipefifo_fops;
65615
65616 /*
65617 @@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65618 spin_lock(&inode->i_lock);
65619 if (inode->i_pipe) {
65620 pipe = inode->i_pipe;
65621 - pipe->files++;
65622 + atomic_inc(&pipe->files);
65623 spin_unlock(&inode->i_lock);
65624 } else {
65625 spin_unlock(&inode->i_lock);
65626 pipe = alloc_pipe_info();
65627 if (!pipe)
65628 return -ENOMEM;
65629 - pipe->files = 1;
65630 + atomic_set(&pipe->files, 1);
65631 spin_lock(&inode->i_lock);
65632 if (unlikely(inode->i_pipe)) {
65633 - inode->i_pipe->files++;
65634 + atomic_inc(&inode->i_pipe->files);
65635 spin_unlock(&inode->i_lock);
65636 free_pipe_info(pipe);
65637 pipe = inode->i_pipe;
65638 @@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65639 * opened, even when there is no process writing the FIFO.
65640 */
65641 pipe->r_counter++;
65642 - if (pipe->readers++ == 0)
65643 + if (atomic_inc_return(&pipe->readers) == 1)
65644 wake_up_partner(pipe);
65645
65646 - if (!is_pipe && !pipe->writers) {
65647 + if (!is_pipe && !atomic_read(&pipe->writers)) {
65648 if ((filp->f_flags & O_NONBLOCK)) {
65649 /* suppress POLLHUP until we have
65650 * seen a writer */
65651 @@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65652 * errno=ENXIO when there is no process reading the FIFO.
65653 */
65654 ret = -ENXIO;
65655 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65656 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65657 goto err;
65658
65659 pipe->w_counter++;
65660 - if (!pipe->writers++)
65661 + if (atomic_inc_return(&pipe->writers) == 1)
65662 wake_up_partner(pipe);
65663
65664 - if (!is_pipe && !pipe->readers) {
65665 + if (!is_pipe && !atomic_read(&pipe->readers)) {
65666 if (wait_for_partner(pipe, &pipe->r_counter))
65667 goto err_wr;
65668 }
65669 @@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65670 * the process can at least talk to itself.
65671 */
65672
65673 - pipe->readers++;
65674 - pipe->writers++;
65675 + atomic_inc(&pipe->readers);
65676 + atomic_inc(&pipe->writers);
65677 pipe->r_counter++;
65678 pipe->w_counter++;
65679 - if (pipe->readers == 1 || pipe->writers == 1)
65680 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65681 wake_up_partner(pipe);
65682 break;
65683
65684 @@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65685 return 0;
65686
65687 err_rd:
65688 - if (!--pipe->readers)
65689 + if (atomic_dec_and_test(&pipe->readers))
65690 wake_up_interruptible(&pipe->wait);
65691 ret = -ERESTARTSYS;
65692 goto err;
65693
65694 err_wr:
65695 - if (!--pipe->writers)
65696 + if (atomic_dec_and_test(&pipe->writers))
65697 wake_up_interruptible(&pipe->wait);
65698 ret = -ERESTARTSYS;
65699 goto err;
65700 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65701 index 0855f77..6787d50 100644
65702 --- a/fs/posix_acl.c
65703 +++ b/fs/posix_acl.c
65704 @@ -20,6 +20,7 @@
65705 #include <linux/xattr.h>
65706 #include <linux/export.h>
65707 #include <linux/user_namespace.h>
65708 +#include <linux/grsecurity.h>
65709
65710 struct posix_acl **acl_by_type(struct inode *inode, int type)
65711 {
65712 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65713 }
65714 }
65715 if (mode_p)
65716 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65717 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65718 return not_equiv;
65719 }
65720 EXPORT_SYMBOL(posix_acl_equiv_mode);
65721 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65722 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65723 }
65724
65725 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65726 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65727 return not_equiv;
65728 }
65729
65730 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65731 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65732 int err = -ENOMEM;
65733 if (clone) {
65734 + *mode_p &= ~gr_acl_umask();
65735 +
65736 err = posix_acl_create_masq(clone, mode_p);
65737 if (err < 0) {
65738 posix_acl_release(clone);
65739 @@ -659,11 +662,12 @@ struct posix_acl *
65740 posix_acl_from_xattr(struct user_namespace *user_ns,
65741 const void *value, size_t size)
65742 {
65743 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65744 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65745 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65746 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65747 int count;
65748 struct posix_acl *acl;
65749 struct posix_acl_entry *acl_e;
65750 + umode_t umask = gr_acl_umask();
65751
65752 if (!value)
65753 return NULL;
65754 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65755
65756 switch(acl_e->e_tag) {
65757 case ACL_USER_OBJ:
65758 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65759 + break;
65760 case ACL_GROUP_OBJ:
65761 case ACL_MASK:
65762 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65763 + break;
65764 case ACL_OTHER:
65765 + acl_e->e_perm &= ~(umask & S_IRWXO);
65766 break;
65767
65768 case ACL_USER:
65769 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65770 acl_e->e_uid =
65771 make_kuid(user_ns,
65772 le32_to_cpu(entry->e_id));
65773 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65774 goto fail;
65775 break;
65776 case ACL_GROUP:
65777 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65778 acl_e->e_gid =
65779 make_kgid(user_ns,
65780 le32_to_cpu(entry->e_id));
65781 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65782 index 2183fcf..3c32a98 100644
65783 --- a/fs/proc/Kconfig
65784 +++ b/fs/proc/Kconfig
65785 @@ -30,7 +30,7 @@ config PROC_FS
65786
65787 config PROC_KCORE
65788 bool "/proc/kcore support" if !ARM
65789 - depends on PROC_FS && MMU
65790 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65791 help
65792 Provides a virtual ELF core file of the live kernel. This can
65793 be read with gdb and other ELF tools. No modifications can be
65794 @@ -38,8 +38,8 @@ config PROC_KCORE
65795
65796 config PROC_VMCORE
65797 bool "/proc/vmcore support"
65798 - depends on PROC_FS && CRASH_DUMP
65799 - default y
65800 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65801 + default n
65802 help
65803 Exports the dump image of crashed kernel in ELF format.
65804
65805 @@ -63,8 +63,8 @@ config PROC_SYSCTL
65806 limited in memory.
65807
65808 config PROC_PAGE_MONITOR
65809 - default y
65810 - depends on PROC_FS && MMU
65811 + default n
65812 + depends on PROC_FS && MMU && !GRKERNSEC
65813 bool "Enable /proc page monitoring" if EXPERT
65814 help
65815 Various /proc files exist to monitor process memory utilization:
65816 diff --git a/fs/proc/array.c b/fs/proc/array.c
65817 index cd3653e..9b9b79a 100644
65818 --- a/fs/proc/array.c
65819 +++ b/fs/proc/array.c
65820 @@ -60,6 +60,7 @@
65821 #include <linux/tty.h>
65822 #include <linux/string.h>
65823 #include <linux/mman.h>
65824 +#include <linux/grsecurity.h>
65825 #include <linux/proc_fs.h>
65826 #include <linux/ioport.h>
65827 #include <linux/uaccess.h>
65828 @@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65829 seq_putc(m, '\n');
65830 }
65831
65832 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65833 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
65834 +{
65835 + if (p->mm)
65836 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65837 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65838 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65839 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65840 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65841 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65842 + else
65843 + seq_printf(m, "PaX:\t-----\n");
65844 +}
65845 +#endif
65846 +
65847 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65848 struct pid *pid, struct task_struct *task)
65849 {
65850 @@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65851 task_cpus_allowed(m, task);
65852 cpuset_task_status_allowed(m, task);
65853 task_context_switch_counts(m, task);
65854 +
65855 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65856 + task_pax(m, task);
65857 +#endif
65858 +
65859 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65860 + task_grsec_rbac(m, task);
65861 +#endif
65862 +
65863 return 0;
65864 }
65865
65866 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65867 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65868 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
65869 + _mm->pax_flags & MF_PAX_SEGMEXEC))
65870 +#endif
65871 +
65872 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65873 struct pid *pid, struct task_struct *task, int whole)
65874 {
65875 @@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65876 char tcomm[sizeof(task->comm)];
65877 unsigned long flags;
65878
65879 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65880 + if (current->exec_id != m->exec_id) {
65881 + gr_log_badprocpid("stat");
65882 + return 0;
65883 + }
65884 +#endif
65885 +
65886 state = *get_task_state(task);
65887 vsize = eip = esp = 0;
65888 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65889 @@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65890 gtime = task_gtime(task);
65891 }
65892
65893 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65894 + if (PAX_RAND_FLAGS(mm)) {
65895 + eip = 0;
65896 + esp = 0;
65897 + wchan = 0;
65898 + }
65899 +#endif
65900 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65901 + wchan = 0;
65902 + eip =0;
65903 + esp =0;
65904 +#endif
65905 +
65906 /* scale priority and nice values from timeslices to -20..20 */
65907 /* to make it look like a "normal" Unix priority/nice value */
65908 priority = task_prio(task);
65909 @@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65910 seq_put_decimal_ull(m, ' ', vsize);
65911 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65912 seq_put_decimal_ull(m, ' ', rsslim);
65913 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65914 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65915 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65916 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65917 +#else
65918 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65919 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65920 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65921 +#endif
65922 seq_put_decimal_ull(m, ' ', esp);
65923 seq_put_decimal_ull(m, ' ', eip);
65924 /* The signal information here is obsolete.
65925 @@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65926 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65927 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65928
65929 - if (mm && permitted) {
65930 + if (mm && permitted
65931 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65932 + && !PAX_RAND_FLAGS(mm)
65933 +#endif
65934 + ) {
65935 seq_put_decimal_ull(m, ' ', mm->start_data);
65936 seq_put_decimal_ull(m, ' ', mm->end_data);
65937 seq_put_decimal_ull(m, ' ', mm->start_brk);
65938 @@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65939 struct pid *pid, struct task_struct *task)
65940 {
65941 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65942 - struct mm_struct *mm = get_task_mm(task);
65943 + struct mm_struct *mm;
65944
65945 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65946 + if (current->exec_id != m->exec_id) {
65947 + gr_log_badprocpid("statm");
65948 + return 0;
65949 + }
65950 +#endif
65951 + mm = get_task_mm(task);
65952 if (mm) {
65953 size = task_statm(mm, &shared, &text, &data, &resident);
65954 mmput(mm);
65955 @@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65956 return 0;
65957 }
65958
65959 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65960 +int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65961 +{
65962 + unsigned long flags;
65963 + u32 curr_ip = 0;
65964 +
65965 + if (lock_task_sighand(task, &flags)) {
65966 + curr_ip = task->signal->curr_ip;
65967 + unlock_task_sighand(task, &flags);
65968 + }
65969 + return seq_printf(m, "%pI4\n", &curr_ip);
65970 +}
65971 +#endif
65972 +
65973 #ifdef CONFIG_CHECKPOINT_RESTORE
65974 static struct pid *
65975 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65976 diff --git a/fs/proc/base.c b/fs/proc/base.c
65977 index 7dc3ea8..a08077e 100644
65978 --- a/fs/proc/base.c
65979 +++ b/fs/proc/base.c
65980 @@ -113,6 +113,14 @@ struct pid_entry {
65981 union proc_op op;
65982 };
65983
65984 +struct getdents_callback {
65985 + struct linux_dirent __user * current_dir;
65986 + struct linux_dirent __user * previous;
65987 + struct file * file;
65988 + int count;
65989 + int error;
65990 +};
65991 +
65992 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65993 .name = (NAME), \
65994 .len = sizeof(NAME) - 1, \
65995 @@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65996 return 0;
65997 }
65998
65999 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66000 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66001 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
66002 + _mm->pax_flags & MF_PAX_SEGMEXEC))
66003 +#endif
66004 +
66005 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66006 struct pid *pid, struct task_struct *task)
66007 {
66008 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66009 if (mm && !IS_ERR(mm)) {
66010 unsigned int nwords = 0;
66011 +
66012 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66013 + /* allow if we're currently ptracing this task */
66014 + if (PAX_RAND_FLAGS(mm) &&
66015 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66016 + mmput(mm);
66017 + return 0;
66018 + }
66019 +#endif
66020 +
66021 do {
66022 nwords += 2;
66023 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66024 @@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66025 }
66026
66027
66028 -#ifdef CONFIG_KALLSYMS
66029 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66030 /*
66031 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66032 * Returns the resolved symbol. If that fails, simply return the address.
66033 @@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66034 mutex_unlock(&task->signal->cred_guard_mutex);
66035 }
66036
66037 -#ifdef CONFIG_STACKTRACE
66038 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66039
66040 #define MAX_STACK_TRACE_DEPTH 64
66041
66042 @@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66043 return 0;
66044 }
66045
66046 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66047 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66048 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66049 struct pid *pid, struct task_struct *task)
66050 {
66051 @@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66052 /************************************************************************/
66053
66054 /* permission checks */
66055 -static int proc_fd_access_allowed(struct inode *inode)
66056 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66057 {
66058 struct task_struct *task;
66059 int allowed = 0;
66060 @@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66061 */
66062 task = get_proc_task(inode);
66063 if (task) {
66064 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66065 + if (log)
66066 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66067 + else
66068 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66069 put_task_struct(task);
66070 }
66071 return allowed;
66072 @@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66073 struct task_struct *task,
66074 int hide_pid_min)
66075 {
66076 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66077 + return false;
66078 +
66079 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66080 + rcu_read_lock();
66081 + {
66082 + const struct cred *tmpcred = current_cred();
66083 + const struct cred *cred = __task_cred(task);
66084 +
66085 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66086 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66087 + || in_group_p(grsec_proc_gid)
66088 +#endif
66089 + ) {
66090 + rcu_read_unlock();
66091 + return true;
66092 + }
66093 + }
66094 + rcu_read_unlock();
66095 +
66096 + if (!pid->hide_pid)
66097 + return false;
66098 +#endif
66099 +
66100 if (pid->hide_pid < hide_pid_min)
66101 return true;
66102 if (in_group_p(pid->pid_gid))
66103 return true;
66104 +
66105 return ptrace_may_access(task, PTRACE_MODE_READ);
66106 }
66107
66108 @@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66109 put_task_struct(task);
66110
66111 if (!has_perms) {
66112 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66113 + {
66114 +#else
66115 if (pid->hide_pid == 2) {
66116 +#endif
66117 /*
66118 * Let's make getdents(), stat(), and open()
66119 * consistent with each other. If a process
66120 @@ -609,6 +665,10 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
66121
66122 if (task) {
66123 mm = mm_access(task, mode);
66124 + if (!IS_ERR_OR_NULL(mm) && gr_acl_handle_procpidmem(task)) {
66125 + mmput(mm);
66126 + mm = ERR_PTR(-EPERM);
66127 + }
66128 put_task_struct(task);
66129
66130 if (!IS_ERR_OR_NULL(mm)) {
66131 @@ -630,6 +690,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66132 return PTR_ERR(mm);
66133
66134 file->private_data = mm;
66135 +
66136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66137 + file->f_version = current->exec_id;
66138 +#endif
66139 +
66140 return 0;
66141 }
66142
66143 @@ -651,6 +716,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66144 ssize_t copied;
66145 char *page;
66146
66147 +#ifdef CONFIG_GRKERNSEC
66148 + if (write)
66149 + return -EPERM;
66150 +#endif
66151 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66152 + if (file->f_version != current->exec_id) {
66153 + gr_log_badprocpid("mem");
66154 + return 0;
66155 + }
66156 +#endif
66157 +
66158 if (!mm)
66159 return 0;
66160
66161 @@ -663,7 +739,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66162 goto free;
66163
66164 while (count > 0) {
66165 - int this_len = min_t(int, count, PAGE_SIZE);
66166 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66167
66168 if (write && copy_from_user(page, buf, this_len)) {
66169 copied = -EFAULT;
66170 @@ -755,6 +831,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66171 if (!mm)
66172 return 0;
66173
66174 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66175 + if (file->f_version != current->exec_id) {
66176 + gr_log_badprocpid("environ");
66177 + return 0;
66178 + }
66179 +#endif
66180 +
66181 page = (char *)__get_free_page(GFP_TEMPORARY);
66182 if (!page)
66183 return -ENOMEM;
66184 @@ -764,7 +847,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66185 goto free;
66186 while (count > 0) {
66187 size_t this_len, max_len;
66188 - int retval;
66189 + ssize_t retval;
66190
66191 if (src >= (mm->env_end - mm->env_start))
66192 break;
66193 @@ -1378,7 +1461,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66194 int error = -EACCES;
66195
66196 /* Are we allowed to snoop on the tasks file descriptors? */
66197 - if (!proc_fd_access_allowed(inode))
66198 + if (!proc_fd_access_allowed(inode, 0))
66199 goto out;
66200
66201 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66202 @@ -1422,8 +1505,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66203 struct path path;
66204
66205 /* Are we allowed to snoop on the tasks file descriptors? */
66206 - if (!proc_fd_access_allowed(inode))
66207 - goto out;
66208 + /* logging this is needed for learning on chromium to work properly,
66209 + but we don't want to flood the logs from 'ps' which does a readlink
66210 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66211 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
66212 + */
66213 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66214 + if (!proc_fd_access_allowed(inode,0))
66215 + goto out;
66216 + } else {
66217 + if (!proc_fd_access_allowed(inode,1))
66218 + goto out;
66219 + }
66220
66221 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66222 if (error)
66223 @@ -1473,7 +1566,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66224 rcu_read_lock();
66225 cred = __task_cred(task);
66226 inode->i_uid = cred->euid;
66227 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66228 + inode->i_gid = grsec_proc_gid;
66229 +#else
66230 inode->i_gid = cred->egid;
66231 +#endif
66232 rcu_read_unlock();
66233 }
66234 security_task_to_inode(task, inode);
66235 @@ -1509,10 +1606,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66236 return -ENOENT;
66237 }
66238 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66239 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66240 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66241 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66242 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66243 +#endif
66244 task_dumpable(task)) {
66245 cred = __task_cred(task);
66246 stat->uid = cred->euid;
66247 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66248 + stat->gid = grsec_proc_gid;
66249 +#else
66250 stat->gid = cred->egid;
66251 +#endif
66252 }
66253 }
66254 rcu_read_unlock();
66255 @@ -1550,11 +1656,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66256
66257 if (task) {
66258 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66259 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66260 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66261 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66262 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66263 +#endif
66264 task_dumpable(task)) {
66265 rcu_read_lock();
66266 cred = __task_cred(task);
66267 inode->i_uid = cred->euid;
66268 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66269 + inode->i_gid = grsec_proc_gid;
66270 +#else
66271 inode->i_gid = cred->egid;
66272 +#endif
66273 rcu_read_unlock();
66274 } else {
66275 inode->i_uid = GLOBAL_ROOT_UID;
66276 @@ -2085,6 +2200,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66277 if (!task)
66278 goto out_no_task;
66279
66280 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66281 + goto out;
66282 +
66283 /*
66284 * Yes, it does not scale. And it should not. Don't add
66285 * new entries into /proc/<tgid>/ without very good reasons.
66286 @@ -2115,6 +2233,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66287 if (!task)
66288 return -ENOENT;
66289
66290 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66291 + goto out;
66292 +
66293 if (!dir_emit_dots(file, ctx))
66294 goto out;
66295
66296 @@ -2557,7 +2678,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66297 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66298 #endif
66299 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66300 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66301 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66302 ONE("syscall", S_IRUSR, proc_pid_syscall),
66303 #endif
66304 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66305 @@ -2582,10 +2703,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66306 #ifdef CONFIG_SECURITY
66307 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66308 #endif
66309 -#ifdef CONFIG_KALLSYMS
66310 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66311 ONE("wchan", S_IRUGO, proc_pid_wchan),
66312 #endif
66313 -#ifdef CONFIG_STACKTRACE
66314 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66315 ONE("stack", S_IRUSR, proc_pid_stack),
66316 #endif
66317 #ifdef CONFIG_SCHEDSTATS
66318 @@ -2619,6 +2740,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66319 #ifdef CONFIG_HARDWALL
66320 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66321 #endif
66322 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66323 + ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66324 +#endif
66325 #ifdef CONFIG_USER_NS
66326 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66327 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66328 @@ -2748,7 +2872,14 @@ static int proc_pid_instantiate(struct inode *dir,
66329 if (!inode)
66330 goto out;
66331
66332 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66333 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66334 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66335 + inode->i_gid = grsec_proc_gid;
66336 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66337 +#else
66338 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66339 +#endif
66340 inode->i_op = &proc_tgid_base_inode_operations;
66341 inode->i_fop = &proc_tgid_base_operations;
66342 inode->i_flags|=S_IMMUTABLE;
66343 @@ -2786,7 +2917,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66344 if (!task)
66345 goto out;
66346
66347 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66348 + goto out_put_task;
66349 +
66350 result = proc_pid_instantiate(dir, dentry, task, NULL);
66351 +out_put_task:
66352 put_task_struct(task);
66353 out:
66354 return ERR_PTR(result);
66355 @@ -2900,7 +3035,7 @@ static const struct pid_entry tid_base_stuff[] = {
66356 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66357 #endif
66358 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66359 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66360 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66361 ONE("syscall", S_IRUSR, proc_pid_syscall),
66362 #endif
66363 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66364 @@ -2927,10 +3062,10 @@ static const struct pid_entry tid_base_stuff[] = {
66365 #ifdef CONFIG_SECURITY
66366 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66367 #endif
66368 -#ifdef CONFIG_KALLSYMS
66369 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66370 ONE("wchan", S_IRUGO, proc_pid_wchan),
66371 #endif
66372 -#ifdef CONFIG_STACKTRACE
66373 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66374 ONE("stack", S_IRUSR, proc_pid_stack),
66375 #endif
66376 #ifdef CONFIG_SCHEDSTATS
66377 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66378 index cbd82df..c0407d2 100644
66379 --- a/fs/proc/cmdline.c
66380 +++ b/fs/proc/cmdline.c
66381 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66382
66383 static int __init proc_cmdline_init(void)
66384 {
66385 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66386 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66387 +#else
66388 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66389 +#endif
66390 return 0;
66391 }
66392 fs_initcall(proc_cmdline_init);
66393 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66394 index 50493ed..248166b 100644
66395 --- a/fs/proc/devices.c
66396 +++ b/fs/proc/devices.c
66397 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66398
66399 static int __init proc_devices_init(void)
66400 {
66401 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66402 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66403 +#else
66404 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66405 +#endif
66406 return 0;
66407 }
66408 fs_initcall(proc_devices_init);
66409 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66410 index e11d7c5..9128ce06 100644
66411 --- a/fs/proc/fd.c
66412 +++ b/fs/proc/fd.c
66413 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66414 if (!task)
66415 return -ENOENT;
66416
66417 - files = get_files_struct(task);
66418 + if (!gr_acl_handle_procpidmem(task))
66419 + files = get_files_struct(task);
66420 put_task_struct(task);
66421
66422 if (files) {
66423 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66424 */
66425 int proc_fd_permission(struct inode *inode, int mask)
66426 {
66427 + struct task_struct *task;
66428 int rv = generic_permission(inode, mask);
66429 - if (rv == 0)
66430 - return 0;
66431 +
66432 if (task_tgid(current) == proc_pid(inode))
66433 rv = 0;
66434 +
66435 + task = get_proc_task(inode);
66436 + if (task == NULL)
66437 + return rv;
66438 +
66439 + if (gr_acl_handle_procpidmem(task))
66440 + rv = -EACCES;
66441 +
66442 + put_task_struct(task);
66443 +
66444 return rv;
66445 }
66446
66447 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66448 index 317b726..e329aed 100644
66449 --- a/fs/proc/generic.c
66450 +++ b/fs/proc/generic.c
66451 @@ -23,6 +23,7 @@
66452 #include <linux/bitops.h>
66453 #include <linux/spinlock.h>
66454 #include <linux/completion.h>
66455 +#include <linux/grsecurity.h>
66456 #include <asm/uaccess.h>
66457
66458 #include "internal.h"
66459 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66460 return proc_lookup_de(PDE(dir), dir, dentry);
66461 }
66462
66463 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66464 + unsigned int flags)
66465 +{
66466 + if (gr_proc_is_restricted())
66467 + return ERR_PTR(-EACCES);
66468 +
66469 + return proc_lookup_de(PDE(dir), dir, dentry);
66470 +}
66471 +
66472 /*
66473 * This returns non-zero if at EOF, so that the /proc
66474 * root directory can use this and check if it should
66475 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66476 return proc_readdir_de(PDE(inode), file, ctx);
66477 }
66478
66479 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66480 +{
66481 + struct inode *inode = file_inode(file);
66482 +
66483 + if (gr_proc_is_restricted())
66484 + return -EACCES;
66485 +
66486 + return proc_readdir_de(PDE(inode), file, ctx);
66487 +}
66488 +
66489 /*
66490 * These are the generic /proc directory operations. They
66491 * use the in-memory "struct proc_dir_entry" tree to parse
66492 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66493 .iterate = proc_readdir,
66494 };
66495
66496 +static const struct file_operations proc_dir_restricted_operations = {
66497 + .llseek = generic_file_llseek,
66498 + .read = generic_read_dir,
66499 + .iterate = proc_readdir_restrict,
66500 +};
66501 +
66502 /*
66503 * proc directories can do almost nothing..
66504 */
66505 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66506 .setattr = proc_notify_change,
66507 };
66508
66509 +static const struct inode_operations proc_dir_restricted_inode_operations = {
66510 + .lookup = proc_lookup_restrict,
66511 + .getattr = proc_getattr,
66512 + .setattr = proc_notify_change,
66513 +};
66514 +
66515 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66516 {
66517 struct proc_dir_entry *tmp;
66518 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66519 return ret;
66520
66521 if (S_ISDIR(dp->mode)) {
66522 - dp->proc_fops = &proc_dir_operations;
66523 - dp->proc_iops = &proc_dir_inode_operations;
66524 + if (dp->restricted) {
66525 + dp->proc_fops = &proc_dir_restricted_operations;
66526 + dp->proc_iops = &proc_dir_restricted_inode_operations;
66527 + } else {
66528 + dp->proc_fops = &proc_dir_operations;
66529 + dp->proc_iops = &proc_dir_inode_operations;
66530 + }
66531 dir->nlink++;
66532 } else if (S_ISLNK(dp->mode)) {
66533 dp->proc_iops = &proc_link_inode_operations;
66534 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66535 }
66536 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66537
66538 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66539 + struct proc_dir_entry *parent, void *data)
66540 +{
66541 + struct proc_dir_entry *ent;
66542 +
66543 + if (mode == 0)
66544 + mode = S_IRUGO | S_IXUGO;
66545 +
66546 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66547 + if (ent) {
66548 + ent->data = data;
66549 + ent->restricted = 1;
66550 + if (proc_register(parent, ent) < 0) {
66551 + kfree(ent);
66552 + ent = NULL;
66553 + }
66554 + }
66555 + return ent;
66556 +}
66557 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66558 +
66559 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66560 struct proc_dir_entry *parent)
66561 {
66562 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66563 }
66564 EXPORT_SYMBOL(proc_mkdir);
66565
66566 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66567 + struct proc_dir_entry *parent)
66568 +{
66569 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
66570 +}
66571 +EXPORT_SYMBOL(proc_mkdir_restrict);
66572 +
66573 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66574 struct proc_dir_entry *parent,
66575 const struct file_operations *proc_fops,
66576 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66577 index 333080d..0a35ec4 100644
66578 --- a/fs/proc/inode.c
66579 +++ b/fs/proc/inode.c
66580 @@ -23,11 +23,17 @@
66581 #include <linux/slab.h>
66582 #include <linux/mount.h>
66583 #include <linux/magic.h>
66584 +#include <linux/grsecurity.h>
66585
66586 #include <asm/uaccess.h>
66587
66588 #include "internal.h"
66589
66590 +#ifdef CONFIG_PROC_SYSCTL
66591 +extern const struct inode_operations proc_sys_inode_operations;
66592 +extern const struct inode_operations proc_sys_dir_operations;
66593 +#endif
66594 +
66595 static void proc_evict_inode(struct inode *inode)
66596 {
66597 struct proc_dir_entry *de;
66598 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66599 ns = PROC_I(inode)->ns.ns;
66600 if (ns_ops && ns)
66601 ns_ops->put(ns);
66602 +
66603 +#ifdef CONFIG_PROC_SYSCTL
66604 + if (inode->i_op == &proc_sys_inode_operations ||
66605 + inode->i_op == &proc_sys_dir_operations)
66606 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66607 +#endif
66608 +
66609 }
66610
66611 static struct kmem_cache * proc_inode_cachep;
66612 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66613 if (de->mode) {
66614 inode->i_mode = de->mode;
66615 inode->i_uid = de->uid;
66616 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66617 + inode->i_gid = grsec_proc_gid;
66618 +#else
66619 inode->i_gid = de->gid;
66620 +#endif
66621 }
66622 if (de->size)
66623 inode->i_size = de->size;
66624 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66625 index aa7a0ee..f2318df 100644
66626 --- a/fs/proc/internal.h
66627 +++ b/fs/proc/internal.h
66628 @@ -46,9 +46,10 @@ struct proc_dir_entry {
66629 struct completion *pde_unload_completion;
66630 struct list_head pde_openers; /* who did ->open, but not ->release */
66631 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66632 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66633 u8 namelen;
66634 char name[];
66635 -};
66636 +} __randomize_layout;
66637
66638 union proc_op {
66639 int (*proc_get_link)(struct dentry *, struct path *);
66640 @@ -66,7 +67,7 @@ struct proc_inode {
66641 struct ctl_table *sysctl_entry;
66642 struct proc_ns ns;
66643 struct inode vfs_inode;
66644 -};
66645 +} __randomize_layout;
66646
66647 /*
66648 * General functions
66649 @@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66650 struct pid *, struct task_struct *);
66651 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66652 struct pid *, struct task_struct *);
66653 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66654 +extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66655 + struct pid *, struct task_struct *);
66656 +#endif
66657
66658 /*
66659 * base.c
66660 @@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66661 * generic.c
66662 */
66663 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66664 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66665 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66666 struct dentry *);
66667 extern int proc_readdir(struct file *, struct dir_context *);
66668 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
66669 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66670
66671 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66672 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66673 index a352d57..cb94a5c 100644
66674 --- a/fs/proc/interrupts.c
66675 +++ b/fs/proc/interrupts.c
66676 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66677
66678 static int __init proc_interrupts_init(void)
66679 {
66680 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66681 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66682 +#else
66683 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66684 +#endif
66685 return 0;
66686 }
66687 fs_initcall(proc_interrupts_init);
66688 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66689 index 91a4e64..cb007c0 100644
66690 --- a/fs/proc/kcore.c
66691 +++ b/fs/proc/kcore.c
66692 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66693 * the addresses in the elf_phdr on our list.
66694 */
66695 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66696 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66697 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66698 + if (tsz > buflen)
66699 tsz = buflen;
66700 -
66701 +
66702 while (buflen) {
66703 struct kcore_list *m;
66704
66705 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66706 kfree(elf_buf);
66707 } else {
66708 if (kern_addr_valid(start)) {
66709 - unsigned long n;
66710 + char *elf_buf;
66711 + mm_segment_t oldfs;
66712
66713 - n = copy_to_user(buffer, (char *)start, tsz);
66714 - /*
66715 - * We cannot distinguish between fault on source
66716 - * and fault on destination. When this happens
66717 - * we clear too and hope it will trigger the
66718 - * EFAULT again.
66719 - */
66720 - if (n) {
66721 - if (clear_user(buffer + tsz - n,
66722 - n))
66723 + elf_buf = kmalloc(tsz, GFP_KERNEL);
66724 + if (!elf_buf)
66725 + return -ENOMEM;
66726 + oldfs = get_fs();
66727 + set_fs(KERNEL_DS);
66728 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66729 + set_fs(oldfs);
66730 + if (copy_to_user(buffer, elf_buf, tsz)) {
66731 + kfree(elf_buf);
66732 return -EFAULT;
66733 + }
66734 }
66735 + set_fs(oldfs);
66736 + kfree(elf_buf);
66737 } else {
66738 if (clear_user(buffer, tsz))
66739 return -EFAULT;
66740 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66741
66742 static int open_kcore(struct inode *inode, struct file *filp)
66743 {
66744 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66745 + return -EPERM;
66746 +#endif
66747 if (!capable(CAP_SYS_RAWIO))
66748 return -EPERM;
66749 if (kcore_need_update)
66750 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66751 index aa1eee0..03dda72 100644
66752 --- a/fs/proc/meminfo.c
66753 +++ b/fs/proc/meminfo.c
66754 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66755 vmi.used >> 10,
66756 vmi.largest_chunk >> 10
66757 #ifdef CONFIG_MEMORY_FAILURE
66758 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66759 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66760 #endif
66761 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66762 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66763 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66764 index d4a3574..b421ce9 100644
66765 --- a/fs/proc/nommu.c
66766 +++ b/fs/proc/nommu.c
66767 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66768
66769 if (file) {
66770 seq_pad(m, ' ');
66771 - seq_path(m, &file->f_path, "");
66772 + seq_path(m, &file->f_path, "\n\\");
66773 }
66774
66775 seq_putc(m, '\n');
66776 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66777 index a63af3e..b4f262a 100644
66778 --- a/fs/proc/proc_net.c
66779 +++ b/fs/proc/proc_net.c
66780 @@ -23,9 +23,27 @@
66781 #include <linux/nsproxy.h>
66782 #include <net/net_namespace.h>
66783 #include <linux/seq_file.h>
66784 +#include <linux/grsecurity.h>
66785
66786 #include "internal.h"
66787
66788 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66789 +static struct seq_operations *ipv6_seq_ops_addr;
66790 +
66791 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66792 +{
66793 + ipv6_seq_ops_addr = addr;
66794 +}
66795 +
66796 +void unregister_ipv6_seq_ops_addr(void)
66797 +{
66798 + ipv6_seq_ops_addr = NULL;
66799 +}
66800 +
66801 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66802 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66803 +#endif
66804 +
66805 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66806 {
66807 return pde->parent->data;
66808 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66809 return maybe_get_net(PDE_NET(PDE(inode)));
66810 }
66811
66812 +extern const struct seq_operations dev_seq_ops;
66813 +
66814 int seq_open_net(struct inode *ino, struct file *f,
66815 const struct seq_operations *ops, int size)
66816 {
66817 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66818
66819 BUG_ON(size < sizeof(*p));
66820
66821 + /* only permit access to /proc/net/dev */
66822 + if (
66823 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66824 + ops != ipv6_seq_ops_addr &&
66825 +#endif
66826 + ops != &dev_seq_ops && gr_proc_is_restricted())
66827 + return -EACCES;
66828 +
66829 net = get_proc_net(ino);
66830 if (net == NULL)
66831 return -ENXIO;
66832 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66833 int err;
66834 struct net *net;
66835
66836 + if (gr_proc_is_restricted())
66837 + return -EACCES;
66838 +
66839 err = -ENXIO;
66840 net = get_proc_net(inode);
66841 if (net == NULL)
66842 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66843 index f92d5dd..26398ac 100644
66844 --- a/fs/proc/proc_sysctl.c
66845 +++ b/fs/proc/proc_sysctl.c
66846 @@ -11,13 +11,21 @@
66847 #include <linux/namei.h>
66848 #include <linux/mm.h>
66849 #include <linux/module.h>
66850 +#include <linux/nsproxy.h>
66851 +#ifdef CONFIG_GRKERNSEC
66852 +#include <net/net_namespace.h>
66853 +#endif
66854 #include "internal.h"
66855
66856 +extern int gr_handle_chroot_sysctl(const int op);
66857 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66858 + const int op);
66859 +
66860 static const struct dentry_operations proc_sys_dentry_operations;
66861 static const struct file_operations proc_sys_file_operations;
66862 -static const struct inode_operations proc_sys_inode_operations;
66863 +const struct inode_operations proc_sys_inode_operations;
66864 static const struct file_operations proc_sys_dir_file_operations;
66865 -static const struct inode_operations proc_sys_dir_operations;
66866 +const struct inode_operations proc_sys_dir_operations;
66867
66868 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66869 {
66870 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66871
66872 err = NULL;
66873 d_set_d_op(dentry, &proc_sys_dentry_operations);
66874 +
66875 + gr_handle_proc_create(dentry, inode);
66876 +
66877 d_add(dentry, inode);
66878
66879 out:
66880 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66881 struct inode *inode = file_inode(filp);
66882 struct ctl_table_header *head = grab_header(inode);
66883 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66884 + int op = write ? MAY_WRITE : MAY_READ;
66885 ssize_t error;
66886 size_t res;
66887
66888 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66889 * and won't be until we finish.
66890 */
66891 error = -EPERM;
66892 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66893 + if (sysctl_perm(head, table, op))
66894 goto out;
66895
66896 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66897 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66898 if (!table->proc_handler)
66899 goto out;
66900
66901 +#ifdef CONFIG_GRKERNSEC
66902 + error = -EPERM;
66903 + if (gr_handle_chroot_sysctl(op))
66904 + goto out;
66905 + dget(filp->f_path.dentry);
66906 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66907 + dput(filp->f_path.dentry);
66908 + goto out;
66909 + }
66910 + dput(filp->f_path.dentry);
66911 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66912 + goto out;
66913 + if (write) {
66914 + if (current->nsproxy->net_ns != table->extra2) {
66915 + if (!capable(CAP_SYS_ADMIN))
66916 + goto out;
66917 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66918 + goto out;
66919 + }
66920 +#endif
66921 +
66922 /* careful: calling conventions are nasty here */
66923 res = count;
66924 error = table->proc_handler(table, write, buf, &res, ppos);
66925 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66926 return false;
66927 } else {
66928 d_set_d_op(child, &proc_sys_dentry_operations);
66929 +
66930 + gr_handle_proc_create(child, inode);
66931 +
66932 d_add(child, inode);
66933 }
66934 } else {
66935 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66936 if ((*pos)++ < ctx->pos)
66937 return true;
66938
66939 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66940 + return 0;
66941 +
66942 if (unlikely(S_ISLNK(table->mode)))
66943 res = proc_sys_link_fill_cache(file, ctx, head, table);
66944 else
66945 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66946 if (IS_ERR(head))
66947 return PTR_ERR(head);
66948
66949 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66950 + return -ENOENT;
66951 +
66952 generic_fillattr(inode, stat);
66953 if (table)
66954 stat->mode = (stat->mode & S_IFMT) | table->mode;
66955 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66956 .llseek = generic_file_llseek,
66957 };
66958
66959 -static const struct inode_operations proc_sys_inode_operations = {
66960 +const struct inode_operations proc_sys_inode_operations = {
66961 .permission = proc_sys_permission,
66962 .setattr = proc_sys_setattr,
66963 .getattr = proc_sys_getattr,
66964 };
66965
66966 -static const struct inode_operations proc_sys_dir_operations = {
66967 +const struct inode_operations proc_sys_dir_operations = {
66968 .lookup = proc_sys_lookup,
66969 .permission = proc_sys_permission,
66970 .setattr = proc_sys_setattr,
66971 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66972 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66973 const char *name, int namelen)
66974 {
66975 - struct ctl_table *table;
66976 + ctl_table_no_const *table;
66977 struct ctl_dir *new;
66978 struct ctl_node *node;
66979 char *new_name;
66980 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66981 return NULL;
66982
66983 node = (struct ctl_node *)(new + 1);
66984 - table = (struct ctl_table *)(node + 1);
66985 + table = (ctl_table_no_const *)(node + 1);
66986 new_name = (char *)(table + 2);
66987 memcpy(new_name, name, namelen);
66988 new_name[namelen] = '\0';
66989 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66990 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66991 struct ctl_table_root *link_root)
66992 {
66993 - struct ctl_table *link_table, *entry, *link;
66994 + ctl_table_no_const *link_table, *link;
66995 + struct ctl_table *entry;
66996 struct ctl_table_header *links;
66997 struct ctl_node *node;
66998 char *link_name;
66999 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67000 return NULL;
67001
67002 node = (struct ctl_node *)(links + 1);
67003 - link_table = (struct ctl_table *)(node + nr_entries);
67004 + link_table = (ctl_table_no_const *)(node + nr_entries);
67005 link_name = (char *)&link_table[nr_entries + 1];
67006
67007 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67008 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67009 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67010 struct ctl_table *table)
67011 {
67012 - struct ctl_table *ctl_table_arg = NULL;
67013 - struct ctl_table *entry, *files;
67014 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67015 + struct ctl_table *entry;
67016 int nr_files = 0;
67017 int nr_dirs = 0;
67018 int err = -ENOMEM;
67019 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67020 nr_files++;
67021 }
67022
67023 - files = table;
67024 /* If there are mixed files and directories we need a new table */
67025 if (nr_dirs && nr_files) {
67026 - struct ctl_table *new;
67027 + ctl_table_no_const *new;
67028 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67029 GFP_KERNEL);
67030 if (!files)
67031 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67032 /* Register everything except a directory full of subdirectories */
67033 if (nr_files || !nr_dirs) {
67034 struct ctl_table_header *header;
67035 - header = __register_sysctl_table(set, path, files);
67036 + header = __register_sysctl_table(set, path, files ? files : table);
67037 if (!header) {
67038 kfree(ctl_table_arg);
67039 goto out;
67040 diff --git a/fs/proc/root.c b/fs/proc/root.c
67041 index 094e44d..085a877 100644
67042 --- a/fs/proc/root.c
67043 +++ b/fs/proc/root.c
67044 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
67045 proc_mkdir("openprom", NULL);
67046 #endif
67047 proc_tty_init();
67048 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67049 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67050 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67051 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67052 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67053 +#endif
67054 +#else
67055 proc_mkdir("bus", NULL);
67056 +#endif
67057 proc_sys_init();
67058 }
67059
67060 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67061 index 510413eb..34d9a8c 100644
67062 --- a/fs/proc/stat.c
67063 +++ b/fs/proc/stat.c
67064 @@ -11,6 +11,7 @@
67065 #include <linux/irqnr.h>
67066 #include <linux/cputime.h>
67067 #include <linux/tick.h>
67068 +#include <linux/grsecurity.h>
67069
67070 #ifndef arch_irq_stat_cpu
67071 #define arch_irq_stat_cpu(cpu) 0
67072 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67073 u64 sum_softirq = 0;
67074 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67075 struct timespec boottime;
67076 + int unrestricted = 1;
67077 +
67078 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67079 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67080 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67081 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67082 + && !in_group_p(grsec_proc_gid)
67083 +#endif
67084 + )
67085 + unrestricted = 0;
67086 +#endif
67087 +#endif
67088
67089 user = nice = system = idle = iowait =
67090 irq = softirq = steal = 0;
67091 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67092 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67093 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67094 idle += get_idle_time(i);
67095 - iowait += get_iowait_time(i);
67096 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67097 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67098 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67099 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67100 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67101 - sum += kstat_cpu_irqs_sum(i);
67102 - sum += arch_irq_stat_cpu(i);
67103 + if (unrestricted) {
67104 + iowait += get_iowait_time(i);
67105 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67106 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67107 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67108 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67109 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67110 + sum += kstat_cpu_irqs_sum(i);
67111 + sum += arch_irq_stat_cpu(i);
67112 + for (j = 0; j < NR_SOFTIRQS; j++) {
67113 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67114
67115 - for (j = 0; j < NR_SOFTIRQS; j++) {
67116 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67117 -
67118 - per_softirq_sums[j] += softirq_stat;
67119 - sum_softirq += softirq_stat;
67120 + per_softirq_sums[j] += softirq_stat;
67121 + sum_softirq += softirq_stat;
67122 + }
67123 }
67124 }
67125 - sum += arch_irq_stat();
67126 + if (unrestricted)
67127 + sum += arch_irq_stat();
67128
67129 seq_puts(p, "cpu ");
67130 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67131 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67132 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67133 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67134 idle = get_idle_time(i);
67135 - iowait = get_iowait_time(i);
67136 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67137 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67138 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67139 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67140 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67141 + if (unrestricted) {
67142 + iowait = get_iowait_time(i);
67143 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67144 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67145 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67146 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67147 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67148 + }
67149 seq_printf(p, "cpu%d", i);
67150 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67151 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67152 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67153
67154 /* sum again ? it could be updated? */
67155 for_each_irq_nr(j)
67156 - seq_put_decimal_ull(p, ' ', kstat_irqs_usr(j));
67157 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs_usr(j) : 0ULL);
67158
67159 seq_printf(p,
67160 "\nctxt %llu\n"
67161 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67162 "processes %lu\n"
67163 "procs_running %lu\n"
67164 "procs_blocked %lu\n",
67165 - nr_context_switches(),
67166 + unrestricted ? nr_context_switches() : 0ULL,
67167 (unsigned long)jif,
67168 - total_forks,
67169 - nr_running(),
67170 - nr_iowait());
67171 + unrestricted ? total_forks : 0UL,
67172 + unrestricted ? nr_running() : 0UL,
67173 + unrestricted ? nr_iowait() : 0UL);
67174
67175 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67176
67177 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67178 index e8972bc..64ee778 100644
67179 --- a/fs/proc/task_mmu.c
67180 +++ b/fs/proc/task_mmu.c
67181 @@ -13,12 +13,19 @@
67182 #include <linux/swap.h>
67183 #include <linux/swapops.h>
67184 #include <linux/mmu_notifier.h>
67185 +#include <linux/grsecurity.h>
67186
67187 #include <asm/elf.h>
67188 #include <asm/uaccess.h>
67189 #include <asm/tlbflush.h>
67190 #include "internal.h"
67191
67192 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67193 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67194 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
67195 + _mm->pax_flags & MF_PAX_SEGMEXEC))
67196 +#endif
67197 +
67198 void task_mem(struct seq_file *m, struct mm_struct *mm)
67199 {
67200 unsigned long data, text, lib, swap;
67201 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67202 "VmExe:\t%8lu kB\n"
67203 "VmLib:\t%8lu kB\n"
67204 "VmPTE:\t%8lu kB\n"
67205 - "VmSwap:\t%8lu kB\n",
67206 - hiwater_vm << (PAGE_SHIFT-10),
67207 + "VmSwap:\t%8lu kB\n"
67208 +
67209 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67210 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67211 +#endif
67212 +
67213 + ,hiwater_vm << (PAGE_SHIFT-10),
67214 total_vm << (PAGE_SHIFT-10),
67215 mm->locked_vm << (PAGE_SHIFT-10),
67216 mm->pinned_vm << (PAGE_SHIFT-10),
67217 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67218 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67219 (PTRS_PER_PTE * sizeof(pte_t) *
67220 atomic_long_read(&mm->nr_ptes)) >> 10,
67221 - swap << (PAGE_SHIFT-10));
67222 + swap << (PAGE_SHIFT-10)
67223 +
67224 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67225 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67226 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67227 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67228 +#else
67229 + , mm->context.user_cs_base
67230 + , mm->context.user_cs_limit
67231 +#endif
67232 +#endif
67233 +
67234 + );
67235 }
67236
67237 unsigned long task_vsize(struct mm_struct *mm)
67238 @@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67239 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67240 }
67241
67242 - /* We don't show the stack guard page in /proc/maps */
67243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67244 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67245 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67246 +#else
67247 start = vma->vm_start;
67248 - if (stack_guard_page_start(vma, start))
67249 - start += PAGE_SIZE;
67250 end = vma->vm_end;
67251 - if (stack_guard_page_end(vma, end))
67252 - end -= PAGE_SIZE;
67253 +#endif
67254
67255 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67256 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67257 @@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67258 flags & VM_WRITE ? 'w' : '-',
67259 flags & VM_EXEC ? 'x' : '-',
67260 flags & VM_MAYSHARE ? 's' : 'p',
67261 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67262 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67263 +#else
67264 pgoff,
67265 +#endif
67266 MAJOR(dev), MINOR(dev), ino);
67267
67268 /*
67269 @@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67270 */
67271 if (file) {
67272 seq_pad(m, ' ');
67273 - seq_path(m, &file->f_path, "\n");
67274 + seq_path(m, &file->f_path, "\n\\");
67275 goto done;
67276 }
67277
67278 @@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67279 * Thread stack in /proc/PID/task/TID/maps or
67280 * the main process stack.
67281 */
67282 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
67283 - vma->vm_end >= mm->start_stack)) {
67284 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67285 + (vma->vm_start <= mm->start_stack &&
67286 + vma->vm_end >= mm->start_stack)) {
67287 name = "[stack]";
67288 } else {
67289 /* Thread stack in /proc/PID/maps */
67290 @@ -359,6 +388,12 @@ done:
67291
67292 static int show_map(struct seq_file *m, void *v, int is_pid)
67293 {
67294 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67295 + if (current->exec_id != m->exec_id) {
67296 + gr_log_badprocpid("maps");
67297 + return 0;
67298 + }
67299 +#endif
67300 show_map_vma(m, v, is_pid);
67301 m_cache_vma(m, v);
67302 return 0;
67303 @@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67304 .private = &mss,
67305 };
67306
67307 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67308 + if (current->exec_id != m->exec_id) {
67309 + gr_log_badprocpid("smaps");
67310 + return 0;
67311 + }
67312 +#endif
67313 memset(&mss, 0, sizeof mss);
67314 - mss.vma = vma;
67315 - /* mmap_sem is held in m_start */
67316 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67317 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67318 -
67319 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67320 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67321 +#endif
67322 + mss.vma = vma;
67323 + /* mmap_sem is held in m_start */
67324 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67325 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67326 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67327 + }
67328 +#endif
67329 show_map_vma(m, vma, is_pid);
67330
67331 seq_printf(m,
67332 @@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67333 "KernelPageSize: %8lu kB\n"
67334 "MMUPageSize: %8lu kB\n"
67335 "Locked: %8lu kB\n",
67336 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67337 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67338 +#else
67339 (vma->vm_end - vma->vm_start) >> 10,
67340 +#endif
67341 mss.resident >> 10,
67342 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67343 mss.shared_clean >> 10,
67344 @@ -1451,6 +1501,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67345 char buffer[64];
67346 int nid;
67347
67348 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67349 + if (current->exec_id != m->exec_id) {
67350 + gr_log_badprocpid("numa_maps");
67351 + return 0;
67352 + }
67353 +#endif
67354 +
67355 if (!mm)
67356 return 0;
67357
67358 @@ -1472,11 +1529,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67359 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
67360 }
67361
67362 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67363 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67364 +#else
67365 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67366 +#endif
67367
67368 if (file) {
67369 seq_puts(m, " file=");
67370 - seq_path(m, &file->f_path, "\n\t= ");
67371 + seq_path(m, &file->f_path, "\n\t\\= ");
67372 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67373 seq_puts(m, " heap");
67374 } else {
67375 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67376 index 599ec2e..f1413ae 100644
67377 --- a/fs/proc/task_nommu.c
67378 +++ b/fs/proc/task_nommu.c
67379 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67380 else
67381 bytes += kobjsize(mm);
67382
67383 - if (current->fs && current->fs->users > 1)
67384 + if (current->fs && atomic_read(&current->fs->users) > 1)
67385 sbytes += kobjsize(current->fs);
67386 else
67387 bytes += kobjsize(current->fs);
67388 @@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67389
67390 if (file) {
67391 seq_pad(m, ' ');
67392 - seq_path(m, &file->f_path, "");
67393 + seq_path(m, &file->f_path, "\n\\");
67394 } else if (mm) {
67395 pid_t tid = pid_of_stack(priv, vma, is_pid);
67396
67397 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67398 index a90d6d35..d08047c 100644
67399 --- a/fs/proc/vmcore.c
67400 +++ b/fs/proc/vmcore.c
67401 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67402 nr_bytes = count;
67403
67404 /* If pfn is not ram, return zeros for sparse dump files */
67405 - if (pfn_is_ram(pfn) == 0)
67406 - memset(buf, 0, nr_bytes);
67407 - else {
67408 + if (pfn_is_ram(pfn) == 0) {
67409 + if (userbuf) {
67410 + if (clear_user((char __force_user *)buf, nr_bytes))
67411 + return -EFAULT;
67412 + } else
67413 + memset(buf, 0, nr_bytes);
67414 + } else {
67415 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67416 offset, userbuf);
67417 if (tmp < 0)
67418 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67419 static int copy_to(void *target, void *src, size_t size, int userbuf)
67420 {
67421 if (userbuf) {
67422 - if (copy_to_user((char __user *) target, src, size))
67423 + if (copy_to_user((char __force_user *) target, src, size))
67424 return -EFAULT;
67425 } else {
67426 memcpy(target, src, size);
67427 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67428 if (*fpos < m->offset + m->size) {
67429 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67430 start = m->paddr + *fpos - m->offset;
67431 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67432 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67433 if (tmp < 0)
67434 return tmp;
67435 buflen -= tsz;
67436 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67437 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67438 size_t buflen, loff_t *fpos)
67439 {
67440 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67441 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67442 }
67443
67444 /*
67445 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67446 index d3fb2b6..43a8140 100644
67447 --- a/fs/qnx6/qnx6.h
67448 +++ b/fs/qnx6/qnx6.h
67449 @@ -74,7 +74,7 @@ enum {
67450 BYTESEX_BE,
67451 };
67452
67453 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67454 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67455 {
67456 if (sbi->s_bytesex == BYTESEX_LE)
67457 return le64_to_cpu((__force __le64)n);
67458 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67459 return (__force __fs64)cpu_to_be64(n);
67460 }
67461
67462 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67463 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67464 {
67465 if (sbi->s_bytesex == BYTESEX_LE)
67466 return le32_to_cpu((__force __le32)n);
67467 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67468 index bb2869f..d34ada8 100644
67469 --- a/fs/quota/netlink.c
67470 +++ b/fs/quota/netlink.c
67471 @@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67472 void quota_send_warning(struct kqid qid, dev_t dev,
67473 const char warntype)
67474 {
67475 - static atomic_t seq;
67476 + static atomic_unchecked_t seq;
67477 struct sk_buff *skb;
67478 void *msg_head;
67479 int ret;
67480 @@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67481 "VFS: Not enough memory to send quota warning.\n");
67482 return;
67483 }
67484 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67485 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67486 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67487 if (!msg_head) {
67488 printk(KERN_ERR
67489 diff --git a/fs/read_write.c b/fs/read_write.c
67490 index 7d9318c..51b336f 100644
67491 --- a/fs/read_write.c
67492 +++ b/fs/read_write.c
67493 @@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67494
67495 old_fs = get_fs();
67496 set_fs(get_ds());
67497 - p = (__force const char __user *)buf;
67498 + p = (const char __force_user *)buf;
67499 if (count > MAX_RW_COUNT)
67500 count = MAX_RW_COUNT;
67501 if (file->f_op->write)
67502 diff --git a/fs/readdir.c b/fs/readdir.c
67503 index 33fd922..e0d6094 100644
67504 --- a/fs/readdir.c
67505 +++ b/fs/readdir.c
67506 @@ -18,6 +18,7 @@
67507 #include <linux/security.h>
67508 #include <linux/syscalls.h>
67509 #include <linux/unistd.h>
67510 +#include <linux/namei.h>
67511
67512 #include <asm/uaccess.h>
67513
67514 @@ -71,6 +72,7 @@ struct old_linux_dirent {
67515 struct readdir_callback {
67516 struct dir_context ctx;
67517 struct old_linux_dirent __user * dirent;
67518 + struct file * file;
67519 int result;
67520 };
67521
67522 @@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67523 buf->result = -EOVERFLOW;
67524 return -EOVERFLOW;
67525 }
67526 +
67527 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67528 + return 0;
67529 +
67530 buf->result++;
67531 dirent = buf->dirent;
67532 if (!access_ok(VERIFY_WRITE, dirent,
67533 @@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67534 if (!f.file)
67535 return -EBADF;
67536
67537 + buf.file = f.file;
67538 error = iterate_dir(f.file, &buf.ctx);
67539 if (buf.result)
67540 error = buf.result;
67541 @@ -144,6 +151,7 @@ struct getdents_callback {
67542 struct dir_context ctx;
67543 struct linux_dirent __user * current_dir;
67544 struct linux_dirent __user * previous;
67545 + struct file * file;
67546 int count;
67547 int error;
67548 };
67549 @@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67550 buf->error = -EOVERFLOW;
67551 return -EOVERFLOW;
67552 }
67553 +
67554 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67555 + return 0;
67556 +
67557 dirent = buf->previous;
67558 if (dirent) {
67559 if (__put_user(offset, &dirent->d_off))
67560 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67561 if (!f.file)
67562 return -EBADF;
67563
67564 + buf.file = f.file;
67565 error = iterate_dir(f.file, &buf.ctx);
67566 if (error >= 0)
67567 error = buf.error;
67568 @@ -228,6 +241,7 @@ struct getdents_callback64 {
67569 struct dir_context ctx;
67570 struct linux_dirent64 __user * current_dir;
67571 struct linux_dirent64 __user * previous;
67572 + struct file *file;
67573 int count;
67574 int error;
67575 };
67576 @@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67577 buf->error = -EINVAL; /* only used if we fail.. */
67578 if (reclen > buf->count)
67579 return -EINVAL;
67580 +
67581 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67582 + return 0;
67583 +
67584 dirent = buf->previous;
67585 if (dirent) {
67586 if (__put_user(offset, &dirent->d_off))
67587 @@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67588 if (!f.file)
67589 return -EBADF;
67590
67591 + buf.file = f.file;
67592 error = iterate_dir(f.file, &buf.ctx);
67593 if (error >= 0)
67594 error = buf.error;
67595 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67596 index 9c02d96..6562c10 100644
67597 --- a/fs/reiserfs/do_balan.c
67598 +++ b/fs/reiserfs/do_balan.c
67599 @@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67600 return;
67601 }
67602
67603 - atomic_inc(&fs_generation(tb->tb_sb));
67604 + atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67605 do_balance_starts(tb);
67606
67607 /*
67608 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67609 index aca73dd..e3c558d 100644
67610 --- a/fs/reiserfs/item_ops.c
67611 +++ b/fs/reiserfs/item_ops.c
67612 @@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67613 }
67614
67615 static struct item_operations errcatch_ops = {
67616 - errcatch_bytes_number,
67617 - errcatch_decrement_key,
67618 - errcatch_is_left_mergeable,
67619 - errcatch_print_item,
67620 - errcatch_check_item,
67621 + .bytes_number = errcatch_bytes_number,
67622 + .decrement_key = errcatch_decrement_key,
67623 + .is_left_mergeable = errcatch_is_left_mergeable,
67624 + .print_item = errcatch_print_item,
67625 + .check_item = errcatch_check_item,
67626
67627 - errcatch_create_vi,
67628 - errcatch_check_left,
67629 - errcatch_check_right,
67630 - errcatch_part_size,
67631 - errcatch_unit_num,
67632 - errcatch_print_vi
67633 + .create_vi = errcatch_create_vi,
67634 + .check_left = errcatch_check_left,
67635 + .check_right = errcatch_check_right,
67636 + .part_size = errcatch_part_size,
67637 + .unit_num = errcatch_unit_num,
67638 + .print_vi = errcatch_print_vi
67639 };
67640
67641 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67642 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67643 index 621b9f3..af527fd 100644
67644 --- a/fs/reiserfs/procfs.c
67645 +++ b/fs/reiserfs/procfs.c
67646 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67647 "SMALL_TAILS " : "NO_TAILS ",
67648 replay_only(sb) ? "REPLAY_ONLY " : "",
67649 convert_reiserfs(sb) ? "CONV " : "",
67650 - atomic_read(&r->s_generation_counter),
67651 + atomic_read_unchecked(&r->s_generation_counter),
67652 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67653 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67654 SF(s_good_search_by_key_reada), SF(s_bmaps),
67655 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67656 index 1894d96..1dfd1c2 100644
67657 --- a/fs/reiserfs/reiserfs.h
67658 +++ b/fs/reiserfs/reiserfs.h
67659 @@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67660 /* Comment? -Hans */
67661 wait_queue_head_t s_wait;
67662 /* increased by one every time the tree gets re-balanced */
67663 - atomic_t s_generation_counter;
67664 + atomic_unchecked_t s_generation_counter;
67665
67666 /* File system properties. Currently holds on-disk FS format */
67667 unsigned long s_properties;
67668 @@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67669 #define REISERFS_USER_MEM 1 /* user memory mode */
67670
67671 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67672 -#define get_generation(s) atomic_read (&fs_generation(s))
67673 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67674 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67675 #define __fs_changed(gen,s) (gen != get_generation (s))
67676 #define fs_changed(gen,s) \
67677 diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67678 index b27ef35..d9c6c18 100644
67679 --- a/fs/reiserfs/super.c
67680 +++ b/fs/reiserfs/super.c
67681 @@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67682 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67683 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67684 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67685 +#ifdef CONFIG_REISERFS_FS_XATTR
67686 + /* turn on user xattrs by default */
67687 + sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67688 +#endif
67689 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67690 sbi->s_alloc_options.preallocmin = 0;
67691 /* Preallocate by 16 blocks (17-1) at once */
67692 diff --git a/fs/select.c b/fs/select.c
67693 index 467bb1c..cf9d65a 100644
67694 --- a/fs/select.c
67695 +++ b/fs/select.c
67696 @@ -20,6 +20,7 @@
67697 #include <linux/export.h>
67698 #include <linux/slab.h>
67699 #include <linux/poll.h>
67700 +#include <linux/security.h>
67701 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67702 #include <linux/file.h>
67703 #include <linux/fdtable.h>
67704 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67705 struct poll_list *walk = head;
67706 unsigned long todo = nfds;
67707
67708 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67709 if (nfds > rlimit(RLIMIT_NOFILE))
67710 return -EINVAL;
67711
67712 diff --git a/fs/seq_file.c b/fs/seq_file.c
67713 index 3857b72..0b7281e 100644
67714 --- a/fs/seq_file.c
67715 +++ b/fs/seq_file.c
67716 @@ -12,6 +12,8 @@
67717 #include <linux/slab.h>
67718 #include <linux/cred.h>
67719 #include <linux/mm.h>
67720 +#include <linux/sched.h>
67721 +#include <linux/grsecurity.h>
67722
67723 #include <asm/uaccess.h>
67724 #include <asm/page.h>
67725 @@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67726
67727 static void *seq_buf_alloc(unsigned long size)
67728 {
67729 - void *buf;
67730 -
67731 - buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67732 - if (!buf && size > PAGE_SIZE)
67733 - buf = vmalloc(size);
67734 - return buf;
67735 + return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67736 }
67737
67738 /**
67739 @@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67740 #ifdef CONFIG_USER_NS
67741 p->user_ns = file->f_cred->user_ns;
67742 #endif
67743 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67744 + p->exec_id = current->exec_id;
67745 +#endif
67746
67747 /*
67748 * Wrappers around seq_open(e.g. swaps_open) need to be
67749 @@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67750 }
67751 EXPORT_SYMBOL(seq_open);
67752
67753 +
67754 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
67755 +{
67756 + if (gr_proc_is_restricted())
67757 + return -EACCES;
67758 +
67759 + return seq_open(file, op);
67760 +}
67761 +EXPORT_SYMBOL(seq_open_restrict);
67762 +
67763 static int traverse(struct seq_file *m, loff_t offset)
67764 {
67765 loff_t pos = 0, index;
67766 @@ -165,7 +175,7 @@ Eoverflow:
67767 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67768 {
67769 struct seq_file *m = file->private_data;
67770 - size_t copied = 0;
67771 + ssize_t copied = 0;
67772 loff_t pos;
67773 size_t n;
67774 void *p;
67775 @@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67776 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67777 void *data)
67778 {
67779 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67780 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67781 int res = -ENOMEM;
67782
67783 if (op) {
67784 @@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67785 }
67786 EXPORT_SYMBOL(single_open_size);
67787
67788 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67789 + void *data)
67790 +{
67791 + if (gr_proc_is_restricted())
67792 + return -EACCES;
67793 +
67794 + return single_open(file, show, data);
67795 +}
67796 +EXPORT_SYMBOL(single_open_restrict);
67797 +
67798 +
67799 int single_release(struct inode *inode, struct file *file)
67800 {
67801 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67802 diff --git a/fs/splice.c b/fs/splice.c
67803 index 75c6058..770d40c 100644
67804 --- a/fs/splice.c
67805 +++ b/fs/splice.c
67806 @@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67807 pipe_lock(pipe);
67808
67809 for (;;) {
67810 - if (!pipe->readers) {
67811 + if (!atomic_read(&pipe->readers)) {
67812 send_sig(SIGPIPE, current, 0);
67813 if (!ret)
67814 ret = -EPIPE;
67815 @@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67816 page_nr++;
67817 ret += buf->len;
67818
67819 - if (pipe->files)
67820 + if (atomic_read(&pipe->files))
67821 do_wakeup = 1;
67822
67823 if (!--spd->nr_pages)
67824 @@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67825 do_wakeup = 0;
67826 }
67827
67828 - pipe->waiting_writers++;
67829 + atomic_inc(&pipe->waiting_writers);
67830 pipe_wait(pipe);
67831 - pipe->waiting_writers--;
67832 + atomic_dec(&pipe->waiting_writers);
67833 }
67834
67835 pipe_unlock(pipe);
67836 @@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67837 old_fs = get_fs();
67838 set_fs(get_ds());
67839 /* The cast to a user pointer is valid due to the set_fs() */
67840 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67841 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67842 set_fs(old_fs);
67843
67844 return res;
67845 @@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67846 old_fs = get_fs();
67847 set_fs(get_ds());
67848 /* The cast to a user pointer is valid due to the set_fs() */
67849 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67850 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67851 set_fs(old_fs);
67852
67853 return res;
67854 @@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67855 goto err;
67856
67857 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67858 - vec[i].iov_base = (void __user *) page_address(page);
67859 + vec[i].iov_base = (void __force_user *) page_address(page);
67860 vec[i].iov_len = this_len;
67861 spd.pages[i] = page;
67862 spd.nr_pages++;
67863 @@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67864 ops->release(pipe, buf);
67865 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67866 pipe->nrbufs--;
67867 - if (pipe->files)
67868 + if (atomic_read(&pipe->files))
67869 sd->need_wakeup = true;
67870 }
67871
67872 @@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67873 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67874 {
67875 while (!pipe->nrbufs) {
67876 - if (!pipe->writers)
67877 + if (!atomic_read(&pipe->writers))
67878 return 0;
67879
67880 - if (!pipe->waiting_writers && sd->num_spliced)
67881 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67882 return 0;
67883
67884 if (sd->flags & SPLICE_F_NONBLOCK)
67885 @@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67886 ops->release(pipe, buf);
67887 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67888 pipe->nrbufs--;
67889 - if (pipe->files)
67890 + if (atomic_read(&pipe->files))
67891 sd.need_wakeup = true;
67892 } else {
67893 buf->offset += ret;
67894 @@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67895 * out of the pipe right after the splice_to_pipe(). So set
67896 * PIPE_READERS appropriately.
67897 */
67898 - pipe->readers = 1;
67899 + atomic_set(&pipe->readers, 1);
67900
67901 current->splice_pipe = pipe;
67902 }
67903 @@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67904
67905 partial[buffers].offset = off;
67906 partial[buffers].len = plen;
67907 + partial[buffers].private = 0;
67908
67909 off = 0;
67910 len -= plen;
67911 @@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67912 ret = -ERESTARTSYS;
67913 break;
67914 }
67915 - if (!pipe->writers)
67916 + if (!atomic_read(&pipe->writers))
67917 break;
67918 - if (!pipe->waiting_writers) {
67919 + if (!atomic_read(&pipe->waiting_writers)) {
67920 if (flags & SPLICE_F_NONBLOCK) {
67921 ret = -EAGAIN;
67922 break;
67923 @@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67924 pipe_lock(pipe);
67925
67926 while (pipe->nrbufs >= pipe->buffers) {
67927 - if (!pipe->readers) {
67928 + if (!atomic_read(&pipe->readers)) {
67929 send_sig(SIGPIPE, current, 0);
67930 ret = -EPIPE;
67931 break;
67932 @@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67933 ret = -ERESTARTSYS;
67934 break;
67935 }
67936 - pipe->waiting_writers++;
67937 + atomic_inc(&pipe->waiting_writers);
67938 pipe_wait(pipe);
67939 - pipe->waiting_writers--;
67940 + atomic_dec(&pipe->waiting_writers);
67941 }
67942
67943 pipe_unlock(pipe);
67944 @@ -1818,14 +1819,14 @@ retry:
67945 pipe_double_lock(ipipe, opipe);
67946
67947 do {
67948 - if (!opipe->readers) {
67949 + if (!atomic_read(&opipe->readers)) {
67950 send_sig(SIGPIPE, current, 0);
67951 if (!ret)
67952 ret = -EPIPE;
67953 break;
67954 }
67955
67956 - if (!ipipe->nrbufs && !ipipe->writers)
67957 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67958 break;
67959
67960 /*
67961 @@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67962 pipe_double_lock(ipipe, opipe);
67963
67964 do {
67965 - if (!opipe->readers) {
67966 + if (!atomic_read(&opipe->readers)) {
67967 send_sig(SIGPIPE, current, 0);
67968 if (!ret)
67969 ret = -EPIPE;
67970 @@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67971 * return EAGAIN if we have the potential of some data in the
67972 * future, otherwise just return 0
67973 */
67974 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67975 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67976 ret = -EAGAIN;
67977
67978 pipe_unlock(ipipe);
67979 diff --git a/fs/stat.c b/fs/stat.c
67980 index ae0c3ce..9ee641c 100644
67981 --- a/fs/stat.c
67982 +++ b/fs/stat.c
67983 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67984 stat->gid = inode->i_gid;
67985 stat->rdev = inode->i_rdev;
67986 stat->size = i_size_read(inode);
67987 - stat->atime = inode->i_atime;
67988 - stat->mtime = inode->i_mtime;
67989 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67990 + stat->atime = inode->i_ctime;
67991 + stat->mtime = inode->i_ctime;
67992 + } else {
67993 + stat->atime = inode->i_atime;
67994 + stat->mtime = inode->i_mtime;
67995 + }
67996 stat->ctime = inode->i_ctime;
67997 stat->blksize = (1 << inode->i_blkbits);
67998 stat->blocks = inode->i_blocks;
67999 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68000 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68001 {
68002 struct inode *inode = path->dentry->d_inode;
68003 + int retval;
68004
68005 - if (inode->i_op->getattr)
68006 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
68007 + if (inode->i_op->getattr) {
68008 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68009 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68010 + stat->atime = stat->ctime;
68011 + stat->mtime = stat->ctime;
68012 + }
68013 + return retval;
68014 + }
68015
68016 generic_fillattr(inode, stat);
68017 return 0;
68018 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68019 index 0b45ff4..847de5b 100644
68020 --- a/fs/sysfs/dir.c
68021 +++ b/fs/sysfs/dir.c
68022 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68023 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68024 {
68025 struct kernfs_node *parent, *kn;
68026 + const char *name;
68027 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68028 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68029 + const char *parent_name;
68030 +#endif
68031
68032 BUG_ON(!kobj);
68033
68034 + name = kobject_name(kobj);
68035 +
68036 if (kobj->parent)
68037 parent = kobj->parent->sd;
68038 else
68039 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68040 if (!parent)
68041 return -ENOENT;
68042
68043 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68044 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68045 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68046 + parent_name = parent->name;
68047 + mode = S_IRWXU;
68048 +
68049 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68050 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68051 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68052 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68053 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
68054 +#endif
68055 +
68056 + kn = kernfs_create_dir_ns(parent, name,
68057 + mode, kobj, ns);
68058 if (IS_ERR(kn)) {
68059 if (PTR_ERR(kn) == -EEXIST)
68060 - sysfs_warn_dup(parent, kobject_name(kobj));
68061 + sysfs_warn_dup(parent, name);
68062 return PTR_ERR(kn);
68063 }
68064
68065 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68066 index 69d4889..a810bd4 100644
68067 --- a/fs/sysv/sysv.h
68068 +++ b/fs/sysv/sysv.h
68069 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68070 #endif
68071 }
68072
68073 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68074 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68075 {
68076 if (sbi->s_bytesex == BYTESEX_PDP)
68077 return PDP_swab((__force __u32)n);
68078 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68079 index fb08b0c..65fcc7e 100644
68080 --- a/fs/ubifs/io.c
68081 +++ b/fs/ubifs/io.c
68082 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68083 return err;
68084 }
68085
68086 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68087 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68088 {
68089 int err;
68090
68091 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68092 index c175b4d..8f36a16 100644
68093 --- a/fs/udf/misc.c
68094 +++ b/fs/udf/misc.c
68095 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68096
68097 u8 udf_tag_checksum(const struct tag *t)
68098 {
68099 - u8 *data = (u8 *)t;
68100 + const u8 *data = (const u8 *)t;
68101 u8 checksum = 0;
68102 int i;
68103 for (i = 0; i < sizeof(struct tag); ++i)
68104 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68105 index 8d974c4..b82f6ec 100644
68106 --- a/fs/ufs/swab.h
68107 +++ b/fs/ufs/swab.h
68108 @@ -22,7 +22,7 @@ enum {
68109 BYTESEX_BE
68110 };
68111
68112 -static inline u64
68113 +static inline u64 __intentional_overflow(-1)
68114 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68115 {
68116 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68117 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68118 return (__force __fs64)cpu_to_be64(n);
68119 }
68120
68121 -static inline u32
68122 +static inline u32 __intentional_overflow(-1)
68123 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68124 {
68125 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68126 diff --git a/fs/utimes.c b/fs/utimes.c
68127 index aa138d6..5f3a811 100644
68128 --- a/fs/utimes.c
68129 +++ b/fs/utimes.c
68130 @@ -1,6 +1,7 @@
68131 #include <linux/compiler.h>
68132 #include <linux/file.h>
68133 #include <linux/fs.h>
68134 +#include <linux/security.h>
68135 #include <linux/linkage.h>
68136 #include <linux/mount.h>
68137 #include <linux/namei.h>
68138 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68139 }
68140 }
68141 retry_deleg:
68142 +
68143 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68144 + error = -EACCES;
68145 + goto mnt_drop_write_and_out;
68146 + }
68147 +
68148 mutex_lock(&inode->i_mutex);
68149 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68150 mutex_unlock(&inode->i_mutex);
68151 diff --git a/fs/xattr.c b/fs/xattr.c
68152 index 64e83ef..b6be154 100644
68153 --- a/fs/xattr.c
68154 +++ b/fs/xattr.c
68155 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68156 return rc;
68157 }
68158
68159 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68160 +ssize_t
68161 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
68162 +{
68163 + struct inode *inode = dentry->d_inode;
68164 + ssize_t error;
68165 +
68166 + error = inode_permission(inode, MAY_EXEC);
68167 + if (error)
68168 + return error;
68169 +
68170 + if (inode->i_op->getxattr)
68171 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68172 + else
68173 + error = -EOPNOTSUPP;
68174 +
68175 + return error;
68176 +}
68177 +EXPORT_SYMBOL(pax_getxattr);
68178 +#endif
68179 +
68180 ssize_t
68181 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68182 {
68183 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68184 * Extended attribute SET operations
68185 */
68186 static long
68187 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
68188 +setxattr(struct path *path, const char __user *name, const void __user *value,
68189 size_t size, int flags)
68190 {
68191 int error;
68192 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68193 posix_acl_fix_xattr_from_user(kvalue, size);
68194 }
68195
68196 - error = vfs_setxattr(d, kname, kvalue, size, flags);
68197 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68198 + error = -EACCES;
68199 + goto out;
68200 + }
68201 +
68202 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68203 out:
68204 if (vvalue)
68205 vfree(vvalue);
68206 @@ -376,7 +402,7 @@ retry:
68207 return error;
68208 error = mnt_want_write(path.mnt);
68209 if (!error) {
68210 - error = setxattr(path.dentry, name, value, size, flags);
68211 + error = setxattr(&path, name, value, size, flags);
68212 mnt_drop_write(path.mnt);
68213 }
68214 path_put(&path);
68215 @@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68216 const void __user *,value, size_t, size, int, flags)
68217 {
68218 struct fd f = fdget(fd);
68219 - struct dentry *dentry;
68220 int error = -EBADF;
68221
68222 if (!f.file)
68223 return error;
68224 - dentry = f.file->f_path.dentry;
68225 - audit_inode(NULL, dentry, 0);
68226 + audit_inode(NULL, f.file->f_path.dentry, 0);
68227 error = mnt_want_write_file(f.file);
68228 if (!error) {
68229 - error = setxattr(dentry, name, value, size, flags);
68230 + error = setxattr(&f.file->f_path, name, value, size, flags);
68231 mnt_drop_write_file(f.file);
68232 }
68233 fdput(f);
68234 @@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68235 * Extended attribute REMOVE operations
68236 */
68237 static long
68238 -removexattr(struct dentry *d, const char __user *name)
68239 +removexattr(struct path *path, const char __user *name)
68240 {
68241 int error;
68242 char kname[XATTR_NAME_MAX + 1];
68243 @@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68244 if (error < 0)
68245 return error;
68246
68247 - return vfs_removexattr(d, kname);
68248 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68249 + return -EACCES;
68250 +
68251 + return vfs_removexattr(path->dentry, kname);
68252 }
68253
68254 static int path_removexattr(const char __user *pathname,
68255 @@ -625,7 +652,7 @@ retry:
68256 return error;
68257 error = mnt_want_write(path.mnt);
68258 if (!error) {
68259 - error = removexattr(path.dentry, name);
68260 + error = removexattr(&path, name);
68261 mnt_drop_write(path.mnt);
68262 }
68263 path_put(&path);
68264 @@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68265 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68266 {
68267 struct fd f = fdget(fd);
68268 - struct dentry *dentry;
68269 + struct path *path;
68270 int error = -EBADF;
68271
68272 if (!f.file)
68273 return error;
68274 - dentry = f.file->f_path.dentry;
68275 - audit_inode(NULL, dentry, 0);
68276 + path = &f.file->f_path;
68277 + audit_inode(NULL, path->dentry, 0);
68278 error = mnt_want_write_file(f.file);
68279 if (!error) {
68280 - error = removexattr(dentry, name);
68281 + error = removexattr(path, name);
68282 mnt_drop_write_file(f.file);
68283 }
68284 fdput(f);
68285 diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68286 index 661666e..e1c7ec2 100644
68287 --- a/fs/xfs/libxfs/xfs_bmap.c
68288 +++ b/fs/xfs/libxfs/xfs_bmap.c
68289 @@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68290
68291 #else
68292 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68293 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68294 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68295 #endif /* DEBUG */
68296
68297 /*
68298 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68299 index f1b69ed..3d0222f 100644
68300 --- a/fs/xfs/xfs_dir2_readdir.c
68301 +++ b/fs/xfs/xfs_dir2_readdir.c
68302 @@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68303 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68304 filetype = dp->d_ops->sf_get_ftype(sfep);
68305 ctx->pos = off & 0x7fffffff;
68306 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68307 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68308 + char name[sfep->namelen];
68309 + memcpy(name, sfep->name, sfep->namelen);
68310 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68311 + return 0;
68312 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68313 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68314 return 0;
68315 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68316 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68317 index 24c926b6..8726af88 100644
68318 --- a/fs/xfs/xfs_ioctl.c
68319 +++ b/fs/xfs/xfs_ioctl.c
68320 @@ -122,7 +122,7 @@ xfs_find_handle(
68321 }
68322
68323 error = -EFAULT;
68324 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68325 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68326 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68327 goto out_put;
68328
68329 diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68330 index 6a51619..9592e1b 100644
68331 --- a/fs/xfs/xfs_linux.h
68332 +++ b/fs/xfs/xfs_linux.h
68333 @@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68334 * of the compiler which do not like us using do_div in the middle
68335 * of large functions.
68336 */
68337 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68338 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68339 {
68340 __u32 mod;
68341
68342 @@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68343 return 0;
68344 }
68345 #else
68346 -static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68347 +static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68348 {
68349 __u32 mod;
68350
68351 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68352 new file mode 100644
68353 index 0000000..31f8fe4
68354 --- /dev/null
68355 +++ b/grsecurity/Kconfig
68356 @@ -0,0 +1,1182 @@
68357 +#
68358 +# grecurity configuration
68359 +#
68360 +menu "Memory Protections"
68361 +depends on GRKERNSEC
68362 +
68363 +config GRKERNSEC_KMEM
68364 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68365 + default y if GRKERNSEC_CONFIG_AUTO
68366 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68367 + help
68368 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68369 + be written to or read from to modify or leak the contents of the running
68370 + kernel. /dev/port will also not be allowed to be opened, writing to
68371 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68372 + If you have module support disabled, enabling this will close up several
68373 + ways that are currently used to insert malicious code into the running
68374 + kernel.
68375 +
68376 + Even with this feature enabled, we still highly recommend that
68377 + you use the RBAC system, as it is still possible for an attacker to
68378 + modify the running kernel through other more obscure methods.
68379 +
68380 + It is highly recommended that you say Y here if you meet all the
68381 + conditions above.
68382 +
68383 +config GRKERNSEC_VM86
68384 + bool "Restrict VM86 mode"
68385 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68386 + depends on X86_32
68387 +
68388 + help
68389 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68390 + make use of a special execution mode on 32bit x86 processors called
68391 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68392 + video cards and will still work with this option enabled. The purpose
68393 + of the option is to prevent exploitation of emulation errors in
68394 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
68395 + Nearly all users should be able to enable this option.
68396 +
68397 +config GRKERNSEC_IO
68398 + bool "Disable privileged I/O"
68399 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68400 + depends on X86
68401 + select RTC_CLASS
68402 + select RTC_INTF_DEV
68403 + select RTC_DRV_CMOS
68404 +
68405 + help
68406 + If you say Y here, all ioperm and iopl calls will return an error.
68407 + Ioperm and iopl can be used to modify the running kernel.
68408 + Unfortunately, some programs need this access to operate properly,
68409 + the most notable of which are XFree86 and hwclock. hwclock can be
68410 + remedied by having RTC support in the kernel, so real-time
68411 + clock support is enabled if this option is enabled, to ensure
68412 + that hwclock operates correctly. If hwclock still does not work,
68413 + either update udev or symlink /dev/rtc to /dev/rtc0.
68414 +
68415 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
68416 + you may not be able to boot into a graphical environment with this
68417 + option enabled. In this case, you should use the RBAC system instead.
68418 +
68419 +config GRKERNSEC_BPF_HARDEN
68420 + bool "Harden BPF interpreter"
68421 + default y if GRKERNSEC_CONFIG_AUTO
68422 + help
68423 + Unlike previous versions of grsecurity that hardened both the BPF
68424 + interpreted code against corruption at rest as well as the JIT code
68425 + against JIT-spray attacks and attacker-controlled immediate values
68426 + for ROP, this feature will enforce disabling of the new eBPF JIT engine
68427 + and will ensure the interpreted code is read-only at rest. This feature
68428 + may be removed at a later time when eBPF stabilizes to entirely revert
68429 + back to the more secure pre-3.16 BPF interpreter/JIT.
68430 +
68431 + If you're using KERNEXEC, it's recommended that you enable this option
68432 + to supplement the hardening of the kernel.
68433 +
68434 +config GRKERNSEC_PERF_HARDEN
68435 + bool "Disable unprivileged PERF_EVENTS usage by default"
68436 + default y if GRKERNSEC_CONFIG_AUTO
68437 + depends on PERF_EVENTS
68438 + help
68439 + If you say Y here, the range of acceptable values for the
68440 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68441 + default to a new value: 3. When the sysctl is set to this value, no
68442 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68443 +
68444 + Though PERF_EVENTS can be used legitimately for performance monitoring
68445 + and low-level application profiling, it is forced on regardless of
68446 + configuration, has been at fault for several vulnerabilities, and
68447 + creates new opportunities for side channels and other information leaks.
68448 +
68449 + This feature puts PERF_EVENTS into a secure default state and permits
68450 + the administrator to change out of it temporarily if unprivileged
68451 + application profiling is needed.
68452 +
68453 +config GRKERNSEC_RAND_THREADSTACK
68454 + bool "Insert random gaps between thread stacks"
68455 + default y if GRKERNSEC_CONFIG_AUTO
68456 + depends on PAX_RANDMMAP && !PPC
68457 + help
68458 + If you say Y here, a random-sized gap will be enforced between allocated
68459 + thread stacks. Glibc's NPTL and other threading libraries that
68460 + pass MAP_STACK to the kernel for thread stack allocation are supported.
68461 + The implementation currently provides 8 bits of entropy for the gap.
68462 +
68463 + Many distributions do not compile threaded remote services with the
68464 + -fstack-check argument to GCC, causing the variable-sized stack-based
68465 + allocator, alloca(), to not probe the stack on allocation. This
68466 + permits an unbounded alloca() to skip over any guard page and potentially
68467 + modify another thread's stack reliably. An enforced random gap
68468 + reduces the reliability of such an attack and increases the chance
68469 + that such a read/write to another thread's stack instead lands in
68470 + an unmapped area, causing a crash and triggering grsecurity's
68471 + anti-bruteforcing logic.
68472 +
68473 +config GRKERNSEC_PROC_MEMMAP
68474 + bool "Harden ASLR against information leaks and entropy reduction"
68475 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68476 + depends on PAX_NOEXEC || PAX_ASLR
68477 + help
68478 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68479 + give no information about the addresses of its mappings if
68480 + PaX features that rely on random addresses are enabled on the task.
68481 + In addition to sanitizing this information and disabling other
68482 + dangerous sources of information, this option causes reads of sensitive
68483 + /proc/<pid> entries where the file descriptor was opened in a different
68484 + task than the one performing the read. Such attempts are logged.
68485 + This option also limits argv/env strings for suid/sgid binaries
68486 + to 512KB to prevent a complete exhaustion of the stack entropy provided
68487 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68488 + binaries to prevent alternative mmap layouts from being abused.
68489 +
68490 + If you use PaX it is essential that you say Y here as it closes up
68491 + several holes that make full ASLR useless locally.
68492 +
68493 +
68494 +config GRKERNSEC_KSTACKOVERFLOW
68495 + bool "Prevent kernel stack overflows"
68496 + default y if GRKERNSEC_CONFIG_AUTO
68497 + depends on !IA64 && 64BIT
68498 + help
68499 + If you say Y here, the kernel's process stacks will be allocated
68500 + with vmalloc instead of the kernel's default allocator. This
68501 + introduces guard pages that in combination with the alloca checking
68502 + of the STACKLEAK feature prevents all forms of kernel process stack
68503 + overflow abuse. Note that this is different from kernel stack
68504 + buffer overflows.
68505 +
68506 +config GRKERNSEC_BRUTE
68507 + bool "Deter exploit bruteforcing"
68508 + default y if GRKERNSEC_CONFIG_AUTO
68509 + help
68510 + If you say Y here, attempts to bruteforce exploits against forking
68511 + daemons such as apache or sshd, as well as against suid/sgid binaries
68512 + will be deterred. When a child of a forking daemon is killed by PaX
68513 + or crashes due to an illegal instruction or other suspicious signal,
68514 + the parent process will be delayed 30 seconds upon every subsequent
68515 + fork until the administrator is able to assess the situation and
68516 + restart the daemon.
68517 + In the suid/sgid case, the attempt is logged, the user has all their
68518 + existing instances of the suid/sgid binary terminated and will
68519 + be unable to execute any suid/sgid binaries for 15 minutes.
68520 +
68521 + It is recommended that you also enable signal logging in the auditing
68522 + section so that logs are generated when a process triggers a suspicious
68523 + signal.
68524 + If the sysctl option is enabled, a sysctl option with name
68525 + "deter_bruteforce" is created.
68526 +
68527 +config GRKERNSEC_MODHARDEN
68528 + bool "Harden module auto-loading"
68529 + default y if GRKERNSEC_CONFIG_AUTO
68530 + depends on MODULES
68531 + help
68532 + If you say Y here, module auto-loading in response to use of some
68533 + feature implemented by an unloaded module will be restricted to
68534 + root users. Enabling this option helps defend against attacks
68535 + by unprivileged users who abuse the auto-loading behavior to
68536 + cause a vulnerable module to load that is then exploited.
68537 +
68538 + If this option prevents a legitimate use of auto-loading for a
68539 + non-root user, the administrator can execute modprobe manually
68540 + with the exact name of the module mentioned in the alert log.
68541 + Alternatively, the administrator can add the module to the list
68542 + of modules loaded at boot by modifying init scripts.
68543 +
68544 + Modification of init scripts will most likely be needed on
68545 + Ubuntu servers with encrypted home directory support enabled,
68546 + as the first non-root user logging in will cause the ecb(aes),
68547 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68548 +
68549 +config GRKERNSEC_HIDESYM
68550 + bool "Hide kernel symbols"
68551 + default y if GRKERNSEC_CONFIG_AUTO
68552 + select PAX_USERCOPY_SLABS
68553 + help
68554 + If you say Y here, getting information on loaded modules, and
68555 + displaying all kernel symbols through a syscall will be restricted
68556 + to users with CAP_SYS_MODULE. For software compatibility reasons,
68557 + /proc/kallsyms will be restricted to the root user. The RBAC
68558 + system can hide that entry even from root.
68559 +
68560 + This option also prevents leaking of kernel addresses through
68561 + several /proc entries.
68562 +
68563 + Note that this option is only effective provided the following
68564 + conditions are met:
68565 + 1) The kernel using grsecurity is not precompiled by some distribution
68566 + 2) You have also enabled GRKERNSEC_DMESG
68567 + 3) You are using the RBAC system and hiding other files such as your
68568 + kernel image and System.map. Alternatively, enabling this option
68569 + causes the permissions on /boot, /lib/modules, and the kernel
68570 + source directory to change at compile time to prevent
68571 + reading by non-root users.
68572 + If the above conditions are met, this option will aid in providing a
68573 + useful protection against local kernel exploitation of overflows
68574 + and arbitrary read/write vulnerabilities.
68575 +
68576 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68577 + in addition to this feature.
68578 +
68579 +config GRKERNSEC_RANDSTRUCT
68580 + bool "Randomize layout of sensitive kernel structures"
68581 + default y if GRKERNSEC_CONFIG_AUTO
68582 + select GRKERNSEC_HIDESYM
68583 + select MODVERSIONS if MODULES
68584 + help
68585 + If you say Y here, the layouts of a number of sensitive kernel
68586 + structures (task, fs, cred, etc) and all structures composed entirely
68587 + of function pointers (aka "ops" structs) will be randomized at compile-time.
68588 + This can introduce the requirement of an additional infoleak
68589 + vulnerability for exploits targeting these structure types.
68590 +
68591 + Enabling this feature will introduce some performance impact, slightly
68592 + increase memory usage, and prevent the use of forensic tools like
68593 + Volatility against the system (unless the kernel source tree isn't
68594 + cleaned after kernel installation).
68595 +
68596 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68597 + It remains after a make clean to allow for external modules to be compiled
68598 + with the existing seed and will be removed by a make mrproper or
68599 + make distclean.
68600 +
68601 + Note that the implementation requires gcc 4.6.4. or newer. You may need
68602 + to install the supporting headers explicitly in addition to the normal
68603 + gcc package.
68604 +
68605 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68606 + bool "Use cacheline-aware structure randomization"
68607 + depends on GRKERNSEC_RANDSTRUCT
68608 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68609 + help
68610 + If you say Y here, the RANDSTRUCT randomization will make a best effort
68611 + at restricting randomization to cacheline-sized groups of elements. It
68612 + will further not randomize bitfields in structures. This reduces the
68613 + performance hit of RANDSTRUCT at the cost of weakened randomization.
68614 +
68615 +config GRKERNSEC_KERN_LOCKOUT
68616 + bool "Active kernel exploit response"
68617 + default y if GRKERNSEC_CONFIG_AUTO
68618 + depends on X86 || ARM || PPC || SPARC
68619 + help
68620 + If you say Y here, when a PaX alert is triggered due to suspicious
68621 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68622 + or an OOPS occurs due to bad memory accesses, instead of just
68623 + terminating the offending process (and potentially allowing
68624 + a subsequent exploit from the same user), we will take one of two
68625 + actions:
68626 + If the user was root, we will panic the system
68627 + If the user was non-root, we will log the attempt, terminate
68628 + all processes owned by the user, then prevent them from creating
68629 + any new processes until the system is restarted
68630 + This deters repeated kernel exploitation/bruteforcing attempts
68631 + and is useful for later forensics.
68632 +
68633 +config GRKERNSEC_OLD_ARM_USERLAND
68634 + bool "Old ARM userland compatibility"
68635 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68636 + help
68637 + If you say Y here, stubs of executable code to perform such operations
68638 + as "compare-exchange" will be placed at fixed locations in the ARM vector
68639 + table. This is unfortunately needed for old ARM userland meant to run
68640 + across a wide range of processors. Without this option enabled,
68641 + the get_tls and data memory barrier stubs will be emulated by the kernel,
68642 + which is enough for Linaro userlands or other userlands designed for v6
68643 + and newer ARM CPUs. It's recommended that you try without this option enabled
68644 + first, and only enable it if your userland does not boot (it will likely fail
68645 + at init time).
68646 +
68647 +endmenu
68648 +menu "Role Based Access Control Options"
68649 +depends on GRKERNSEC
68650 +
68651 +config GRKERNSEC_RBAC_DEBUG
68652 + bool
68653 +
68654 +config GRKERNSEC_NO_RBAC
68655 + bool "Disable RBAC system"
68656 + help
68657 + If you say Y here, the /dev/grsec device will be removed from the kernel,
68658 + preventing the RBAC system from being enabled. You should only say Y
68659 + here if you have no intention of using the RBAC system, so as to prevent
68660 + an attacker with root access from misusing the RBAC system to hide files
68661 + and processes when loadable module support and /dev/[k]mem have been
68662 + locked down.
68663 +
68664 +config GRKERNSEC_ACL_HIDEKERN
68665 + bool "Hide kernel processes"
68666 + help
68667 + If you say Y here, all kernel threads will be hidden to all
68668 + processes but those whose subject has the "view hidden processes"
68669 + flag.
68670 +
68671 +config GRKERNSEC_ACL_MAXTRIES
68672 + int "Maximum tries before password lockout"
68673 + default 3
68674 + help
68675 + This option enforces the maximum number of times a user can attempt
68676 + to authorize themselves with the grsecurity RBAC system before being
68677 + denied the ability to attempt authorization again for a specified time.
68678 + The lower the number, the harder it will be to brute-force a password.
68679 +
68680 +config GRKERNSEC_ACL_TIMEOUT
68681 + int "Time to wait after max password tries, in seconds"
68682 + default 30
68683 + help
68684 + This option specifies the time the user must wait after attempting to
68685 + authorize to the RBAC system with the maximum number of invalid
68686 + passwords. The higher the number, the harder it will be to brute-force
68687 + a password.
68688 +
68689 +endmenu
68690 +menu "Filesystem Protections"
68691 +depends on GRKERNSEC
68692 +
68693 +config GRKERNSEC_PROC
68694 + bool "Proc restrictions"
68695 + default y if GRKERNSEC_CONFIG_AUTO
68696 + help
68697 + If you say Y here, the permissions of the /proc filesystem
68698 + will be altered to enhance system security and privacy. You MUST
68699 + choose either a user only restriction or a user and group restriction.
68700 + Depending upon the option you choose, you can either restrict users to
68701 + see only the processes they themselves run, or choose a group that can
68702 + view all processes and files normally restricted to root if you choose
68703 + the "restrict to user only" option. NOTE: If you're running identd or
68704 + ntpd as a non-root user, you will have to run it as the group you
68705 + specify here.
68706 +
68707 +config GRKERNSEC_PROC_USER
68708 + bool "Restrict /proc to user only"
68709 + depends on GRKERNSEC_PROC
68710 + help
68711 + If you say Y here, non-root users will only be able to view their own
68712 + processes, and restricts them from viewing network-related information,
68713 + and viewing kernel symbol and module information.
68714 +
68715 +config GRKERNSEC_PROC_USERGROUP
68716 + bool "Allow special group"
68717 + default y if GRKERNSEC_CONFIG_AUTO
68718 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68719 + help
68720 + If you say Y here, you will be able to select a group that will be
68721 + able to view all processes and network-related information. If you've
68722 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68723 + remain hidden. This option is useful if you want to run identd as
68724 + a non-root user. The group you select may also be chosen at boot time
68725 + via "grsec_proc_gid=" on the kernel commandline.
68726 +
68727 +config GRKERNSEC_PROC_GID
68728 + int "GID for special group"
68729 + depends on GRKERNSEC_PROC_USERGROUP
68730 + default 1001
68731 +
68732 +config GRKERNSEC_PROC_ADD
68733 + bool "Additional restrictions"
68734 + default y if GRKERNSEC_CONFIG_AUTO
68735 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68736 + help
68737 + If you say Y here, additional restrictions will be placed on
68738 + /proc that keep normal users from viewing device information and
68739 + slabinfo information that could be useful for exploits.
68740 +
68741 +config GRKERNSEC_LINK
68742 + bool "Linking restrictions"
68743 + default y if GRKERNSEC_CONFIG_AUTO
68744 + help
68745 + If you say Y here, /tmp race exploits will be prevented, since users
68746 + will no longer be able to follow symlinks owned by other users in
68747 + world-writable +t directories (e.g. /tmp), unless the owner of the
68748 + symlink is the owner of the directory. users will also not be
68749 + able to hardlink to files they do not own. If the sysctl option is
68750 + enabled, a sysctl option with name "linking_restrictions" is created.
68751 +
68752 +config GRKERNSEC_SYMLINKOWN
68753 + bool "Kernel-enforced SymlinksIfOwnerMatch"
68754 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68755 + help
68756 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
68757 + that prevents it from being used as a security feature. As Apache
68758 + verifies the symlink by performing a stat() against the target of
68759 + the symlink before it is followed, an attacker can setup a symlink
68760 + to point to a same-owned file, then replace the symlink with one
68761 + that targets another user's file just after Apache "validates" the
68762 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
68763 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68764 + will be in place for the group you specify. If the sysctl option
68765 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
68766 + created.
68767 +
68768 +config GRKERNSEC_SYMLINKOWN_GID
68769 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68770 + depends on GRKERNSEC_SYMLINKOWN
68771 + default 1006
68772 + help
68773 + Setting this GID determines what group kernel-enforced
68774 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68775 + is enabled, a sysctl option with name "symlinkown_gid" is created.
68776 +
68777 +config GRKERNSEC_FIFO
68778 + bool "FIFO restrictions"
68779 + default y if GRKERNSEC_CONFIG_AUTO
68780 + help
68781 + If you say Y here, users will not be able to write to FIFOs they don't
68782 + own in world-writable +t directories (e.g. /tmp), unless the owner of
68783 + the FIFO is the same owner of the directory it's held in. If the sysctl
68784 + option is enabled, a sysctl option with name "fifo_restrictions" is
68785 + created.
68786 +
68787 +config GRKERNSEC_SYSFS_RESTRICT
68788 + bool "Sysfs/debugfs restriction"
68789 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68790 + depends on SYSFS
68791 + help
68792 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68793 + any filesystem normally mounted under it (e.g. debugfs) will be
68794 + mostly accessible only by root. These filesystems generally provide access
68795 + to hardware and debug information that isn't appropriate for unprivileged
68796 + users of the system. Sysfs and debugfs have also become a large source
68797 + of new vulnerabilities, ranging from infoleaks to local compromise.
68798 + There has been very little oversight with an eye toward security involved
68799 + in adding new exporters of information to these filesystems, so their
68800 + use is discouraged.
68801 + For reasons of compatibility, a few directories have been whitelisted
68802 + for access by non-root users:
68803 + /sys/fs/selinux
68804 + /sys/fs/fuse
68805 + /sys/devices/system/cpu
68806 +
68807 +config GRKERNSEC_ROFS
68808 + bool "Runtime read-only mount protection"
68809 + depends on SYSCTL
68810 + help
68811 + If you say Y here, a sysctl option with name "romount_protect" will
68812 + be created. By setting this option to 1 at runtime, filesystems
68813 + will be protected in the following ways:
68814 + * No new writable mounts will be allowed
68815 + * Existing read-only mounts won't be able to be remounted read/write
68816 + * Write operations will be denied on all block devices
68817 + This option acts independently of grsec_lock: once it is set to 1,
68818 + it cannot be turned off. Therefore, please be mindful of the resulting
68819 + behavior if this option is enabled in an init script on a read-only
68820 + filesystem.
68821 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68822 + and GRKERNSEC_IO should be enabled and module loading disabled via
68823 + config or at runtime.
68824 + This feature is mainly intended for secure embedded systems.
68825 +
68826 +
68827 +config GRKERNSEC_DEVICE_SIDECHANNEL
68828 + bool "Eliminate stat/notify-based device sidechannels"
68829 + default y if GRKERNSEC_CONFIG_AUTO
68830 + help
68831 + If you say Y here, timing analyses on block or character
68832 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68833 + will be thwarted for unprivileged users. If a process without
68834 + CAP_MKNOD stats such a device, the last access and last modify times
68835 + will match the device's create time. No access or modify events
68836 + will be triggered through inotify/dnotify/fanotify for such devices.
68837 + This feature will prevent attacks that may at a minimum
68838 + allow an attacker to determine the administrator's password length.
68839 +
68840 +config GRKERNSEC_CHROOT
68841 + bool "Chroot jail restrictions"
68842 + default y if GRKERNSEC_CONFIG_AUTO
68843 + help
68844 + If you say Y here, you will be able to choose several options that will
68845 + make breaking out of a chrooted jail much more difficult. If you
68846 + encounter no software incompatibilities with the following options, it
68847 + is recommended that you enable each one.
68848 +
68849 + Note that the chroot restrictions are not intended to apply to "chroots"
68850 + to directories that are simple bind mounts of the global root filesystem.
68851 + For several other reasons, a user shouldn't expect any significant
68852 + security by performing such a chroot.
68853 +
68854 +config GRKERNSEC_CHROOT_MOUNT
68855 + bool "Deny mounts"
68856 + default y if GRKERNSEC_CONFIG_AUTO
68857 + depends on GRKERNSEC_CHROOT
68858 + help
68859 + If you say Y here, processes inside a chroot will not be able to
68860 + mount or remount filesystems. If the sysctl option is enabled, a
68861 + sysctl option with name "chroot_deny_mount" is created.
68862 +
68863 +config GRKERNSEC_CHROOT_DOUBLE
68864 + bool "Deny double-chroots"
68865 + default y if GRKERNSEC_CONFIG_AUTO
68866 + depends on GRKERNSEC_CHROOT
68867 + help
68868 + If you say Y here, processes inside a chroot will not be able to chroot
68869 + again outside the chroot. This is a widely used method of breaking
68870 + out of a chroot jail and should not be allowed. If the sysctl
68871 + option is enabled, a sysctl option with name
68872 + "chroot_deny_chroot" is created.
68873 +
68874 +config GRKERNSEC_CHROOT_PIVOT
68875 + bool "Deny pivot_root in chroot"
68876 + default y if GRKERNSEC_CONFIG_AUTO
68877 + depends on GRKERNSEC_CHROOT
68878 + help
68879 + If you say Y here, processes inside a chroot will not be able to use
68880 + a function called pivot_root() that was introduced in Linux 2.3.41. It
68881 + works similar to chroot in that it changes the root filesystem. This
68882 + function could be misused in a chrooted process to attempt to break out
68883 + of the chroot, and therefore should not be allowed. If the sysctl
68884 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
68885 + created.
68886 +
68887 +config GRKERNSEC_CHROOT_CHDIR
68888 + bool "Enforce chdir(\"/\") on all chroots"
68889 + default y if GRKERNSEC_CONFIG_AUTO
68890 + depends on GRKERNSEC_CHROOT
68891 + help
68892 + If you say Y here, the current working directory of all newly-chrooted
68893 + applications will be set to the the root directory of the chroot.
68894 + The man page on chroot(2) states:
68895 + Note that this call does not change the current working
68896 + directory, so that `.' can be outside the tree rooted at
68897 + `/'. In particular, the super-user can escape from a
68898 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68899 +
68900 + It is recommended that you say Y here, since it's not known to break
68901 + any software. If the sysctl option is enabled, a sysctl option with
68902 + name "chroot_enforce_chdir" is created.
68903 +
68904 +config GRKERNSEC_CHROOT_CHMOD
68905 + bool "Deny (f)chmod +s"
68906 + default y if GRKERNSEC_CONFIG_AUTO
68907 + depends on GRKERNSEC_CHROOT
68908 + help
68909 + If you say Y here, processes inside a chroot will not be able to chmod
68910 + or fchmod files to make them have suid or sgid bits. This protects
68911 + against another published method of breaking a chroot. If the sysctl
68912 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
68913 + created.
68914 +
68915 +config GRKERNSEC_CHROOT_FCHDIR
68916 + bool "Deny fchdir and fhandle out of chroot"
68917 + default y if GRKERNSEC_CONFIG_AUTO
68918 + depends on GRKERNSEC_CHROOT
68919 + help
68920 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
68921 + to a file descriptor of the chrooting process that points to a directory
68922 + outside the filesystem will be stopped. Additionally, this option prevents
68923 + use of the recently-created syscall for opening files by a guessable "file
68924 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68925 + with name "chroot_deny_fchdir" is created.
68926 +
68927 +config GRKERNSEC_CHROOT_MKNOD
68928 + bool "Deny mknod"
68929 + default y if GRKERNSEC_CONFIG_AUTO
68930 + depends on GRKERNSEC_CHROOT
68931 + help
68932 + If you say Y here, processes inside a chroot will not be allowed to
68933 + mknod. The problem with using mknod inside a chroot is that it
68934 + would allow an attacker to create a device entry that is the same
68935 + as one on the physical root of your system, which could range from
68936 + anything from the console device to a device for your harddrive (which
68937 + they could then use to wipe the drive or steal data). It is recommended
68938 + that you say Y here, unless you run into software incompatibilities.
68939 + If the sysctl option is enabled, a sysctl option with name
68940 + "chroot_deny_mknod" is created.
68941 +
68942 +config GRKERNSEC_CHROOT_SHMAT
68943 + bool "Deny shmat() out of chroot"
68944 + default y if GRKERNSEC_CONFIG_AUTO
68945 + depends on GRKERNSEC_CHROOT
68946 + help
68947 + If you say Y here, processes inside a chroot will not be able to attach
68948 + to shared memory segments that were created outside of the chroot jail.
68949 + It is recommended that you say Y here. If the sysctl option is enabled,
68950 + a sysctl option with name "chroot_deny_shmat" is created.
68951 +
68952 +config GRKERNSEC_CHROOT_UNIX
68953 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
68954 + default y if GRKERNSEC_CONFIG_AUTO
68955 + depends on GRKERNSEC_CHROOT
68956 + help
68957 + If you say Y here, processes inside a chroot will not be able to
68958 + connect to abstract (meaning not belonging to a filesystem) Unix
68959 + domain sockets that were bound outside of a chroot. It is recommended
68960 + that you say Y here. If the sysctl option is enabled, a sysctl option
68961 + with name "chroot_deny_unix" is created.
68962 +
68963 +config GRKERNSEC_CHROOT_FINDTASK
68964 + bool "Protect outside processes"
68965 + default y if GRKERNSEC_CONFIG_AUTO
68966 + depends on GRKERNSEC_CHROOT
68967 + help
68968 + If you say Y here, processes inside a chroot will not be able to
68969 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68970 + getsid, or view any process outside of the chroot. If the sysctl
68971 + option is enabled, a sysctl option with name "chroot_findtask" is
68972 + created.
68973 +
68974 +config GRKERNSEC_CHROOT_NICE
68975 + bool "Restrict priority changes"
68976 + default y if GRKERNSEC_CONFIG_AUTO
68977 + depends on GRKERNSEC_CHROOT
68978 + help
68979 + If you say Y here, processes inside a chroot will not be able to raise
68980 + the priority of processes in the chroot, or alter the priority of
68981 + processes outside the chroot. This provides more security than simply
68982 + removing CAP_SYS_NICE from the process' capability set. If the
68983 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68984 + is created.
68985 +
68986 +config GRKERNSEC_CHROOT_SYSCTL
68987 + bool "Deny sysctl writes"
68988 + default y if GRKERNSEC_CONFIG_AUTO
68989 + depends on GRKERNSEC_CHROOT
68990 + help
68991 + If you say Y here, an attacker in a chroot will not be able to
68992 + write to sysctl entries, either by sysctl(2) or through a /proc
68993 + interface. It is strongly recommended that you say Y here. If the
68994 + sysctl option is enabled, a sysctl option with name
68995 + "chroot_deny_sysctl" is created.
68996 +
68997 +config GRKERNSEC_CHROOT_RENAME
68998 + bool "Deny bad renames"
68999 + default y if GRKERNSEC_CONFIG_AUTO
69000 + depends on GRKERNSEC_CHROOT
69001 + help
69002 + If you say Y here, an attacker in a chroot will not be able to
69003 + abuse the ability to create double chroots to break out of the
69004 + chroot by exploiting a race condition between a rename of a directory
69005 + within a chroot against an open of a symlink with relative path
69006 + components. This feature will likewise prevent an accomplice outside
69007 + a chroot from enabling a user inside the chroot to break out and make
69008 + use of their credentials on the global filesystem. Enabling this
69009 + feature is essential to prevent root users from breaking out of a
69010 + chroot. If the sysctl option is enabled, a sysctl option with name
69011 + "chroot_deny_bad_rename" is created.
69012 +
69013 +config GRKERNSEC_CHROOT_CAPS
69014 + bool "Capability restrictions"
69015 + default y if GRKERNSEC_CONFIG_AUTO
69016 + depends on GRKERNSEC_CHROOT
69017 + help
69018 + If you say Y here, the capabilities on all processes within a
69019 + chroot jail will be lowered to stop module insertion, raw i/o,
69020 + system and net admin tasks, rebooting the system, modifying immutable
69021 + files, modifying IPC owned by another, and changing the system time.
69022 + This is left an option because it can break some apps. Disable this
69023 + if your chrooted apps are having problems performing those kinds of
69024 + tasks. If the sysctl option is enabled, a sysctl option with
69025 + name "chroot_caps" is created.
69026 +
69027 +config GRKERNSEC_CHROOT_INITRD
69028 + bool "Exempt initrd tasks from restrictions"
69029 + default y if GRKERNSEC_CONFIG_AUTO
69030 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69031 + help
69032 + If you say Y here, tasks started prior to init will be exempted from
69033 + grsecurity's chroot restrictions. This option is mainly meant to
69034 + resolve Plymouth's performing privileged operations unnecessarily
69035 + in a chroot.
69036 +
69037 +endmenu
69038 +menu "Kernel Auditing"
69039 +depends on GRKERNSEC
69040 +
69041 +config GRKERNSEC_AUDIT_GROUP
69042 + bool "Single group for auditing"
69043 + help
69044 + If you say Y here, the exec and chdir logging features will only operate
69045 + on a group you specify. This option is recommended if you only want to
69046 + watch certain users instead of having a large amount of logs from the
69047 + entire system. If the sysctl option is enabled, a sysctl option with
69048 + name "audit_group" is created.
69049 +
69050 +config GRKERNSEC_AUDIT_GID
69051 + int "GID for auditing"
69052 + depends on GRKERNSEC_AUDIT_GROUP
69053 + default 1007
69054 +
69055 +config GRKERNSEC_EXECLOG
69056 + bool "Exec logging"
69057 + help
69058 + If you say Y here, all execve() calls will be logged (since the
69059 + other exec*() calls are frontends to execve(), all execution
69060 + will be logged). Useful for shell-servers that like to keep track
69061 + of their users. If the sysctl option is enabled, a sysctl option with
69062 + name "exec_logging" is created.
69063 + WARNING: This option when enabled will produce a LOT of logs, especially
69064 + on an active system.
69065 +
69066 +config GRKERNSEC_RESLOG
69067 + bool "Resource logging"
69068 + default y if GRKERNSEC_CONFIG_AUTO
69069 + help
69070 + If you say Y here, all attempts to overstep resource limits will
69071 + be logged with the resource name, the requested size, and the current
69072 + limit. It is highly recommended that you say Y here. If the sysctl
69073 + option is enabled, a sysctl option with name "resource_logging" is
69074 + created. If the RBAC system is enabled, the sysctl value is ignored.
69075 +
69076 +config GRKERNSEC_CHROOT_EXECLOG
69077 + bool "Log execs within chroot"
69078 + help
69079 + If you say Y here, all executions inside a chroot jail will be logged
69080 + to syslog. This can cause a large amount of logs if certain
69081 + applications (eg. djb's daemontools) are installed on the system, and
69082 + is therefore left as an option. If the sysctl option is enabled, a
69083 + sysctl option with name "chroot_execlog" is created.
69084 +
69085 +config GRKERNSEC_AUDIT_PTRACE
69086 + bool "Ptrace logging"
69087 + help
69088 + If you say Y here, all attempts to attach to a process via ptrace
69089 + will be logged. If the sysctl option is enabled, a sysctl option
69090 + with name "audit_ptrace" is created.
69091 +
69092 +config GRKERNSEC_AUDIT_CHDIR
69093 + bool "Chdir logging"
69094 + help
69095 + If you say Y here, all chdir() calls will be logged. If the sysctl
69096 + option is enabled, a sysctl option with name "audit_chdir" is created.
69097 +
69098 +config GRKERNSEC_AUDIT_MOUNT
69099 + bool "(Un)Mount logging"
69100 + help
69101 + If you say Y here, all mounts and unmounts will be logged. If the
69102 + sysctl option is enabled, a sysctl option with name "audit_mount" is
69103 + created.
69104 +
69105 +config GRKERNSEC_SIGNAL
69106 + bool "Signal logging"
69107 + default y if GRKERNSEC_CONFIG_AUTO
69108 + help
69109 + If you say Y here, certain important signals will be logged, such as
69110 + SIGSEGV, which will as a result inform you of when a error in a program
69111 + occurred, which in some cases could mean a possible exploit attempt.
69112 + If the sysctl option is enabled, a sysctl option with name
69113 + "signal_logging" is created.
69114 +
69115 +config GRKERNSEC_FORKFAIL
69116 + bool "Fork failure logging"
69117 + help
69118 + If you say Y here, all failed fork() attempts will be logged.
69119 + This could suggest a fork bomb, or someone attempting to overstep
69120 + their process limit. If the sysctl option is enabled, a sysctl option
69121 + with name "forkfail_logging" is created.
69122 +
69123 +config GRKERNSEC_TIME
69124 + bool "Time change logging"
69125 + default y if GRKERNSEC_CONFIG_AUTO
69126 + help
69127 + If you say Y here, any changes of the system clock will be logged.
69128 + If the sysctl option is enabled, a sysctl option with name
69129 + "timechange_logging" is created.
69130 +
69131 +config GRKERNSEC_PROC_IPADDR
69132 + bool "/proc/<pid>/ipaddr support"
69133 + default y if GRKERNSEC_CONFIG_AUTO
69134 + help
69135 + If you say Y here, a new entry will be added to each /proc/<pid>
69136 + directory that contains the IP address of the person using the task.
69137 + The IP is carried across local TCP and AF_UNIX stream sockets.
69138 + This information can be useful for IDS/IPSes to perform remote response
69139 + to a local attack. The entry is readable by only the owner of the
69140 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69141 + the RBAC system), and thus does not create privacy concerns.
69142 +
69143 +config GRKERNSEC_RWXMAP_LOG
69144 + bool 'Denied RWX mmap/mprotect logging'
69145 + default y if GRKERNSEC_CONFIG_AUTO
69146 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69147 + help
69148 + If you say Y here, calls to mmap() and mprotect() with explicit
69149 + usage of PROT_WRITE and PROT_EXEC together will be logged when
69150 + denied by the PAX_MPROTECT feature. This feature will also
69151 + log other problematic scenarios that can occur when PAX_MPROTECT
69152 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
69153 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69154 + is created.
69155 +
69156 +endmenu
69157 +
69158 +menu "Executable Protections"
69159 +depends on GRKERNSEC
69160 +
69161 +config GRKERNSEC_DMESG
69162 + bool "Dmesg(8) restriction"
69163 + default y if GRKERNSEC_CONFIG_AUTO
69164 + help
69165 + If you say Y here, non-root users will not be able to use dmesg(8)
69166 + to view the contents of the kernel's circular log buffer.
69167 + The kernel's log buffer often contains kernel addresses and other
69168 + identifying information useful to an attacker in fingerprinting a
69169 + system for a targeted exploit.
69170 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
69171 + created.
69172 +
69173 +config GRKERNSEC_HARDEN_PTRACE
69174 + bool "Deter ptrace-based process snooping"
69175 + default y if GRKERNSEC_CONFIG_AUTO
69176 + help
69177 + If you say Y here, TTY sniffers and other malicious monitoring
69178 + programs implemented through ptrace will be defeated. If you
69179 + have been using the RBAC system, this option has already been
69180 + enabled for several years for all users, with the ability to make
69181 + fine-grained exceptions.
69182 +
69183 + This option only affects the ability of non-root users to ptrace
69184 + processes that are not a descendent of the ptracing process.
69185 + This means that strace ./binary and gdb ./binary will still work,
69186 + but attaching to arbitrary processes will not. If the sysctl
69187 + option is enabled, a sysctl option with name "harden_ptrace" is
69188 + created.
69189 +
69190 +config GRKERNSEC_PTRACE_READEXEC
69191 + bool "Require read access to ptrace sensitive binaries"
69192 + default y if GRKERNSEC_CONFIG_AUTO
69193 + help
69194 + If you say Y here, unprivileged users will not be able to ptrace unreadable
69195 + binaries. This option is useful in environments that
69196 + remove the read bits (e.g. file mode 4711) from suid binaries to
69197 + prevent infoleaking of their contents. This option adds
69198 + consistency to the use of that file mode, as the binary could normally
69199 + be read out when run without privileges while ptracing.
69200 +
69201 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69202 + is created.
69203 +
69204 +config GRKERNSEC_SETXID
69205 + bool "Enforce consistent multithreaded privileges"
69206 + default y if GRKERNSEC_CONFIG_AUTO
69207 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69208 + help
69209 + If you say Y here, a change from a root uid to a non-root uid
69210 + in a multithreaded application will cause the resulting uids,
69211 + gids, supplementary groups, and capabilities in that thread
69212 + to be propagated to the other threads of the process. In most
69213 + cases this is unnecessary, as glibc will emulate this behavior
69214 + on behalf of the application. Other libcs do not act in the
69215 + same way, allowing the other threads of the process to continue
69216 + running with root privileges. If the sysctl option is enabled,
69217 + a sysctl option with name "consistent_setxid" is created.
69218 +
69219 +config GRKERNSEC_HARDEN_IPC
69220 + bool "Disallow access to overly-permissive IPC objects"
69221 + default y if GRKERNSEC_CONFIG_AUTO
69222 + depends on SYSVIPC
69223 + help
69224 + If you say Y here, access to overly-permissive IPC objects (shared
69225 + memory, message queues, and semaphores) will be denied for processes
69226 + given the following criteria beyond normal permission checks:
69227 + 1) If the IPC object is world-accessible and the euid doesn't match
69228 + that of the creator or current uid for the IPC object
69229 + 2) If the IPC object is group-accessible and the egid doesn't
69230 + match that of the creator or current gid for the IPC object
69231 + It's a common error to grant too much permission to these objects,
69232 + with impact ranging from denial of service and information leaking to
69233 + privilege escalation. This feature was developed in response to
69234 + research by Tim Brown:
69235 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69236 + who found hundreds of such insecure usages. Processes with
69237 + CAP_IPC_OWNER are still permitted to access these IPC objects.
69238 + If the sysctl option is enabled, a sysctl option with name
69239 + "harden_ipc" is created.
69240 +
69241 +config GRKERNSEC_TPE
69242 + bool "Trusted Path Execution (TPE)"
69243 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69244 + help
69245 + If you say Y here, you will be able to choose a gid to add to the
69246 + supplementary groups of users you want to mark as "untrusted."
69247 + These users will not be able to execute any files that are not in
69248 + root-owned directories writable only by root. If the sysctl option
69249 + is enabled, a sysctl option with name "tpe" is created.
69250 +
69251 +config GRKERNSEC_TPE_ALL
69252 + bool "Partially restrict all non-root users"
69253 + depends on GRKERNSEC_TPE
69254 + help
69255 + If you say Y here, all non-root users will be covered under
69256 + a weaker TPE restriction. This is separate from, and in addition to,
69257 + the main TPE options that you have selected elsewhere. Thus, if a
69258 + "trusted" GID is chosen, this restriction applies to even that GID.
69259 + Under this restriction, all non-root users will only be allowed to
69260 + execute files in directories they own that are not group or
69261 + world-writable, or in directories owned by root and writable only by
69262 + root. If the sysctl option is enabled, a sysctl option with name
69263 + "tpe_restrict_all" is created.
69264 +
69265 +config GRKERNSEC_TPE_INVERT
69266 + bool "Invert GID option"
69267 + depends on GRKERNSEC_TPE
69268 + help
69269 + If you say Y here, the group you specify in the TPE configuration will
69270 + decide what group TPE restrictions will be *disabled* for. This
69271 + option is useful if you want TPE restrictions to be applied to most
69272 + users on the system. If the sysctl option is enabled, a sysctl option
69273 + with name "tpe_invert" is created. Unlike other sysctl options, this
69274 + entry will default to on for backward-compatibility.
69275 +
69276 +config GRKERNSEC_TPE_GID
69277 + int
69278 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69279 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69280 +
69281 +config GRKERNSEC_TPE_UNTRUSTED_GID
69282 + int "GID for TPE-untrusted users"
69283 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69284 + default 1005
69285 + help
69286 + Setting this GID determines what group TPE restrictions will be
69287 + *enabled* for. If the sysctl option is enabled, a sysctl option
69288 + with name "tpe_gid" is created.
69289 +
69290 +config GRKERNSEC_TPE_TRUSTED_GID
69291 + int "GID for TPE-trusted users"
69292 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69293 + default 1005
69294 + help
69295 + Setting this GID determines what group TPE restrictions will be
69296 + *disabled* for. If the sysctl option is enabled, a sysctl option
69297 + with name "tpe_gid" is created.
69298 +
69299 +endmenu
69300 +menu "Network Protections"
69301 +depends on GRKERNSEC
69302 +
69303 +config GRKERNSEC_BLACKHOLE
69304 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69305 + default y if GRKERNSEC_CONFIG_AUTO
69306 + depends on NET
69307 + help
69308 + If you say Y here, neither TCP resets nor ICMP
69309 + destination-unreachable packets will be sent in response to packets
69310 + sent to ports for which no associated listening process exists.
69311 + It will also prevent the sending of ICMP protocol unreachable packets
69312 + in response to packets with unknown protocols.
69313 + This feature supports both IPV4 and IPV6 and exempts the
69314 + loopback interface from blackholing. Enabling this feature
69315 + makes a host more resilient to DoS attacks and reduces network
69316 + visibility against scanners.
69317 +
69318 + The blackhole feature as-implemented is equivalent to the FreeBSD
69319 + blackhole feature, as it prevents RST responses to all packets, not
69320 + just SYNs. Under most application behavior this causes no
69321 + problems, but applications (like haproxy) may not close certain
69322 + connections in a way that cleanly terminates them on the remote
69323 + end, leaving the remote host in LAST_ACK state. Because of this
69324 + side-effect and to prevent intentional LAST_ACK DoSes, this
69325 + feature also adds automatic mitigation against such attacks.
69326 + The mitigation drastically reduces the amount of time a socket
69327 + can spend in LAST_ACK state. If you're using haproxy and not
69328 + all servers it connects to have this option enabled, consider
69329 + disabling this feature on the haproxy host.
69330 +
69331 + If the sysctl option is enabled, two sysctl options with names
69332 + "ip_blackhole" and "lastack_retries" will be created.
69333 + While "ip_blackhole" takes the standard zero/non-zero on/off
69334 + toggle, "lastack_retries" uses the same kinds of values as
69335 + "tcp_retries1" and "tcp_retries2". The default value of 4
69336 + prevents a socket from lasting more than 45 seconds in LAST_ACK
69337 + state.
69338 +
69339 +config GRKERNSEC_NO_SIMULT_CONNECT
69340 + bool "Disable TCP Simultaneous Connect"
69341 + default y if GRKERNSEC_CONFIG_AUTO
69342 + depends on NET
69343 + help
69344 + If you say Y here, a feature by Willy Tarreau will be enabled that
69345 + removes a weakness in Linux's strict implementation of TCP that
69346 + allows two clients to connect to each other without either entering
69347 + a listening state. The weakness allows an attacker to easily prevent
69348 + a client from connecting to a known server provided the source port
69349 + for the connection is guessed correctly.
69350 +
69351 + As the weakness could be used to prevent an antivirus or IPS from
69352 + fetching updates, or prevent an SSL gateway from fetching a CRL,
69353 + it should be eliminated by enabling this option. Though Linux is
69354 + one of few operating systems supporting simultaneous connect, it
69355 + has no legitimate use in practice and is rarely supported by firewalls.
69356 +
69357 +config GRKERNSEC_SOCKET
69358 + bool "Socket restrictions"
69359 + depends on NET
69360 + help
69361 + If you say Y here, you will be able to choose from several options.
69362 + If you assign a GID on your system and add it to the supplementary
69363 + groups of users you want to restrict socket access to, this patch
69364 + will perform up to three things, based on the option(s) you choose.
69365 +
69366 +config GRKERNSEC_SOCKET_ALL
69367 + bool "Deny any sockets to group"
69368 + depends on GRKERNSEC_SOCKET
69369 + help
69370 + If you say Y here, you will be able to choose a GID of whose users will
69371 + be unable to connect to other hosts from your machine or run server
69372 + applications from your machine. If the sysctl option is enabled, a
69373 + sysctl option with name "socket_all" is created.
69374 +
69375 +config GRKERNSEC_SOCKET_ALL_GID
69376 + int "GID to deny all sockets for"
69377 + depends on GRKERNSEC_SOCKET_ALL
69378 + default 1004
69379 + help
69380 + Here you can choose the GID to disable socket access for. Remember to
69381 + add the users you want socket access disabled for to the GID
69382 + specified here. If the sysctl option is enabled, a sysctl option
69383 + with name "socket_all_gid" is created.
69384 +
69385 +config GRKERNSEC_SOCKET_CLIENT
69386 + bool "Deny client sockets to group"
69387 + depends on GRKERNSEC_SOCKET
69388 + help
69389 + If you say Y here, you will be able to choose a GID of whose users will
69390 + be unable to connect to other hosts from your machine, but will be
69391 + able to run servers. If this option is enabled, all users in the group
69392 + you specify will have to use passive mode when initiating ftp transfers
69393 + from the shell on your machine. If the sysctl option is enabled, a
69394 + sysctl option with name "socket_client" is created.
69395 +
69396 +config GRKERNSEC_SOCKET_CLIENT_GID
69397 + int "GID to deny client sockets for"
69398 + depends on GRKERNSEC_SOCKET_CLIENT
69399 + default 1003
69400 + help
69401 + Here you can choose the GID to disable client socket access for.
69402 + Remember to add the users you want client socket access disabled for to
69403 + the GID specified here. If the sysctl option is enabled, a sysctl
69404 + option with name "socket_client_gid" is created.
69405 +
69406 +config GRKERNSEC_SOCKET_SERVER
69407 + bool "Deny server sockets to group"
69408 + depends on GRKERNSEC_SOCKET
69409 + help
69410 + If you say Y here, you will be able to choose a GID of whose users will
69411 + be unable to run server applications from your machine. If the sysctl
69412 + option is enabled, a sysctl option with name "socket_server" is created.
69413 +
69414 +config GRKERNSEC_SOCKET_SERVER_GID
69415 + int "GID to deny server sockets for"
69416 + depends on GRKERNSEC_SOCKET_SERVER
69417 + default 1002
69418 + help
69419 + Here you can choose the GID to disable server socket access for.
69420 + Remember to add the users you want server socket access disabled for to
69421 + the GID specified here. If the sysctl option is enabled, a sysctl
69422 + option with name "socket_server_gid" is created.
69423 +
69424 +endmenu
69425 +
69426 +menu "Physical Protections"
69427 +depends on GRKERNSEC
69428 +
69429 +config GRKERNSEC_DENYUSB
69430 + bool "Deny new USB connections after toggle"
69431 + default y if GRKERNSEC_CONFIG_AUTO
69432 + depends on SYSCTL && USB_SUPPORT
69433 + help
69434 + If you say Y here, a new sysctl option with name "deny_new_usb"
69435 + will be created. Setting its value to 1 will prevent any new
69436 + USB devices from being recognized by the OS. Any attempted USB
69437 + device insertion will be logged. This option is intended to be
69438 + used against custom USB devices designed to exploit vulnerabilities
69439 + in various USB device drivers.
69440 +
69441 + For greatest effectiveness, this sysctl should be set after any
69442 + relevant init scripts. This option is safe to enable in distros
69443 + as each user can choose whether or not to toggle the sysctl.
69444 +
69445 +config GRKERNSEC_DENYUSB_FORCE
69446 + bool "Reject all USB devices not connected at boot"
69447 + select USB
69448 + depends on GRKERNSEC_DENYUSB
69449 + help
69450 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69451 + that doesn't involve a sysctl entry. This option should only be
69452 + enabled if you're sure you want to deny all new USB connections
69453 + at runtime and don't want to modify init scripts. This should not
69454 + be enabled by distros. It forces the core USB code to be built
69455 + into the kernel image so that all devices connected at boot time
69456 + can be recognized and new USB device connections can be prevented
69457 + prior to init running.
69458 +
69459 +endmenu
69460 +
69461 +menu "Sysctl Support"
69462 +depends on GRKERNSEC && SYSCTL
69463 +
69464 +config GRKERNSEC_SYSCTL
69465 + bool "Sysctl support"
69466 + default y if GRKERNSEC_CONFIG_AUTO
69467 + help
69468 + If you say Y here, you will be able to change the options that
69469 + grsecurity runs with at bootup, without having to recompile your
69470 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69471 + to enable (1) or disable (0) various features. All the sysctl entries
69472 + are mutable until the "grsec_lock" entry is set to a non-zero value.
69473 + All features enabled in the kernel configuration are disabled at boot
69474 + if you do not say Y to the "Turn on features by default" option.
69475 + All options should be set at startup, and the grsec_lock entry should
69476 + be set to a non-zero value after all the options are set.
69477 + *THIS IS EXTREMELY IMPORTANT*
69478 +
69479 +config GRKERNSEC_SYSCTL_DISTRO
69480 + bool "Extra sysctl support for distro makers (READ HELP)"
69481 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69482 + help
69483 + If you say Y here, additional sysctl options will be created
69484 + for features that affect processes running as root. Therefore,
69485 + it is critical when using this option that the grsec_lock entry be
69486 + enabled after boot. Only distros with prebuilt kernel packages
69487 + with this option enabled that can ensure grsec_lock is enabled
69488 + after boot should use this option.
69489 + *Failure to set grsec_lock after boot makes all grsec features
69490 + this option covers useless*
69491 +
69492 + Currently this option creates the following sysctl entries:
69493 + "Disable Privileged I/O": "disable_priv_io"
69494 +
69495 +config GRKERNSEC_SYSCTL_ON
69496 + bool "Turn on features by default"
69497 + default y if GRKERNSEC_CONFIG_AUTO
69498 + depends on GRKERNSEC_SYSCTL
69499 + help
69500 + If you say Y here, instead of having all features enabled in the
69501 + kernel configuration disabled at boot time, the features will be
69502 + enabled at boot time. It is recommended you say Y here unless
69503 + there is some reason you would want all sysctl-tunable features to
69504 + be disabled by default. As mentioned elsewhere, it is important
69505 + to enable the grsec_lock entry once you have finished modifying
69506 + the sysctl entries.
69507 +
69508 +endmenu
69509 +menu "Logging Options"
69510 +depends on GRKERNSEC
69511 +
69512 +config GRKERNSEC_FLOODTIME
69513 + int "Seconds in between log messages (minimum)"
69514 + default 10
69515 + help
69516 + This option allows you to enforce the number of seconds between
69517 + grsecurity log messages. The default should be suitable for most
69518 + people, however, if you choose to change it, choose a value small enough
69519 + to allow informative logs to be produced, but large enough to
69520 + prevent flooding.
69521 +
69522 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69523 + any rate limiting on grsecurity log messages.
69524 +
69525 +config GRKERNSEC_FLOODBURST
69526 + int "Number of messages in a burst (maximum)"
69527 + default 6
69528 + help
69529 + This option allows you to choose the maximum number of messages allowed
69530 + within the flood time interval you chose in a separate option. The
69531 + default should be suitable for most people, however if you find that
69532 + many of your logs are being interpreted as flooding, you may want to
69533 + raise this value.
69534 +
69535 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69536 + any rate limiting on grsecurity log messages.
69537 +
69538 +endmenu
69539 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69540 new file mode 100644
69541 index 0000000..30ababb
69542 --- /dev/null
69543 +++ b/grsecurity/Makefile
69544 @@ -0,0 +1,54 @@
69545 +# grsecurity – access control and security hardening for Linux
69546 +# All code in this directory and various hooks located throughout the Linux kernel are
69547 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69548 +# http://www.grsecurity.net spender@grsecurity.net
69549 +#
69550 +# This program is free software; you can redistribute it and/or
69551 +# modify it under the terms of the GNU General Public License version 2
69552 +# as published by the Free Software Foundation.
69553 +#
69554 +# This program is distributed in the hope that it will be useful,
69555 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
69556 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69557 +# GNU General Public License for more details.
69558 +#
69559 +# You should have received a copy of the GNU General Public License
69560 +# along with this program; if not, write to the Free Software
69561 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69562 +
69563 +KBUILD_CFLAGS += -Werror
69564 +
69565 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69566 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
69567 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69568 + grsec_usb.o grsec_ipc.o grsec_proc.o
69569 +
69570 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69571 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69572 + gracl_learn.o grsec_log.o gracl_policy.o
69573 +ifdef CONFIG_COMPAT
69574 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69575 +endif
69576 +
69577 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69578 +
69579 +ifdef CONFIG_NET
69580 +obj-y += grsec_sock.o
69581 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69582 +endif
69583 +
69584 +ifndef CONFIG_GRKERNSEC
69585 +obj-y += grsec_disabled.o
69586 +endif
69587 +
69588 +ifdef CONFIG_GRKERNSEC_HIDESYM
69589 +extra-y := grsec_hidesym.o
69590 +$(obj)/grsec_hidesym.o:
69591 + @-chmod -f 500 /boot
69592 + @-chmod -f 500 /lib/modules
69593 + @-chmod -f 500 /lib64/modules
69594 + @-chmod -f 500 /lib32/modules
69595 + @-chmod -f 700 .
69596 + @-chmod -f 700 $(objtree)
69597 + @echo ' grsec: protected kernel image paths'
69598 +endif
69599 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69600 new file mode 100644
69601 index 0000000..6c1e154
69602 --- /dev/null
69603 +++ b/grsecurity/gracl.c
69604 @@ -0,0 +1,2749 @@
69605 +#include <linux/kernel.h>
69606 +#include <linux/module.h>
69607 +#include <linux/sched.h>
69608 +#include <linux/mm.h>
69609 +#include <linux/file.h>
69610 +#include <linux/fs.h>
69611 +#include <linux/namei.h>
69612 +#include <linux/mount.h>
69613 +#include <linux/tty.h>
69614 +#include <linux/proc_fs.h>
69615 +#include <linux/lglock.h>
69616 +#include <linux/slab.h>
69617 +#include <linux/vmalloc.h>
69618 +#include <linux/types.h>
69619 +#include <linux/sysctl.h>
69620 +#include <linux/netdevice.h>
69621 +#include <linux/ptrace.h>
69622 +#include <linux/gracl.h>
69623 +#include <linux/gralloc.h>
69624 +#include <linux/security.h>
69625 +#include <linux/grinternal.h>
69626 +#include <linux/pid_namespace.h>
69627 +#include <linux/stop_machine.h>
69628 +#include <linux/fdtable.h>
69629 +#include <linux/percpu.h>
69630 +#include <linux/lglock.h>
69631 +#include <linux/hugetlb.h>
69632 +#include <linux/posix-timers.h>
69633 +#include <linux/prefetch.h>
69634 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69635 +#include <linux/magic.h>
69636 +#include <linux/pagemap.h>
69637 +#include "../fs/btrfs/async-thread.h"
69638 +#include "../fs/btrfs/ctree.h"
69639 +#include "../fs/btrfs/btrfs_inode.h"
69640 +#endif
69641 +#include "../fs/mount.h"
69642 +
69643 +#include <asm/uaccess.h>
69644 +#include <asm/errno.h>
69645 +#include <asm/mman.h>
69646 +
69647 +#define FOR_EACH_ROLE_START(role) \
69648 + role = running_polstate.role_list; \
69649 + while (role) {
69650 +
69651 +#define FOR_EACH_ROLE_END(role) \
69652 + role = role->prev; \
69653 + }
69654 +
69655 +extern struct path gr_real_root;
69656 +
69657 +static struct gr_policy_state running_polstate;
69658 +struct gr_policy_state *polstate = &running_polstate;
69659 +extern struct gr_alloc_state *current_alloc_state;
69660 +
69661 +extern char *gr_shared_page[4];
69662 +DEFINE_RWLOCK(gr_inode_lock);
69663 +
69664 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
69665 +
69666 +#ifdef CONFIG_NET
69667 +extern struct vfsmount *sock_mnt;
69668 +#endif
69669 +
69670 +extern struct vfsmount *pipe_mnt;
69671 +extern struct vfsmount *shm_mnt;
69672 +
69673 +#ifdef CONFIG_HUGETLBFS
69674 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69675 +#endif
69676 +
69677 +extern u16 acl_sp_role_value;
69678 +extern struct acl_object_label *fakefs_obj_rw;
69679 +extern struct acl_object_label *fakefs_obj_rwx;
69680 +
69681 +int gr_acl_is_enabled(void)
69682 +{
69683 + return (gr_status & GR_READY);
69684 +}
69685 +
69686 +void gr_enable_rbac_system(void)
69687 +{
69688 + pax_open_kernel();
69689 + gr_status |= GR_READY;
69690 + pax_close_kernel();
69691 +}
69692 +
69693 +int gr_rbac_disable(void *unused)
69694 +{
69695 + pax_open_kernel();
69696 + gr_status &= ~GR_READY;
69697 + pax_close_kernel();
69698 +
69699 + return 0;
69700 +}
69701 +
69702 +static inline dev_t __get_dev(const struct dentry *dentry)
69703 +{
69704 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69705 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69706 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
69707 + else
69708 +#endif
69709 + return dentry->d_sb->s_dev;
69710 +}
69711 +
69712 +static inline u64 __get_ino(const struct dentry *dentry)
69713 +{
69714 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69715 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69716 + return btrfs_ino(dentry->d_inode);
69717 + else
69718 +#endif
69719 + return dentry->d_inode->i_ino;
69720 +}
69721 +
69722 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69723 +{
69724 + return __get_dev(dentry);
69725 +}
69726 +
69727 +u64 gr_get_ino_from_dentry(struct dentry *dentry)
69728 +{
69729 + return __get_ino(dentry);
69730 +}
69731 +
69732 +static char gr_task_roletype_to_char(struct task_struct *task)
69733 +{
69734 + switch (task->role->roletype &
69735 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69736 + GR_ROLE_SPECIAL)) {
69737 + case GR_ROLE_DEFAULT:
69738 + return 'D';
69739 + case GR_ROLE_USER:
69740 + return 'U';
69741 + case GR_ROLE_GROUP:
69742 + return 'G';
69743 + case GR_ROLE_SPECIAL:
69744 + return 'S';
69745 + }
69746 +
69747 + return 'X';
69748 +}
69749 +
69750 +char gr_roletype_to_char(void)
69751 +{
69752 + return gr_task_roletype_to_char(current);
69753 +}
69754 +
69755 +__inline__ int
69756 +gr_acl_tpe_check(void)
69757 +{
69758 + if (unlikely(!(gr_status & GR_READY)))
69759 + return 0;
69760 + if (current->role->roletype & GR_ROLE_TPE)
69761 + return 1;
69762 + else
69763 + return 0;
69764 +}
69765 +
69766 +int
69767 +gr_handle_rawio(const struct inode *inode)
69768 +{
69769 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69770 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69771 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69772 + !capable(CAP_SYS_RAWIO))
69773 + return 1;
69774 +#endif
69775 + return 0;
69776 +}
69777 +
69778 +int
69779 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69780 +{
69781 + if (likely(lena != lenb))
69782 + return 0;
69783 +
69784 + return !memcmp(a, b, lena);
69785 +}
69786 +
69787 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69788 +{
69789 + *buflen -= namelen;
69790 + if (*buflen < 0)
69791 + return -ENAMETOOLONG;
69792 + *buffer -= namelen;
69793 + memcpy(*buffer, str, namelen);
69794 + return 0;
69795 +}
69796 +
69797 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69798 +{
69799 + return prepend(buffer, buflen, name->name, name->len);
69800 +}
69801 +
69802 +static int prepend_path(const struct path *path, struct path *root,
69803 + char **buffer, int *buflen)
69804 +{
69805 + struct dentry *dentry = path->dentry;
69806 + struct vfsmount *vfsmnt = path->mnt;
69807 + struct mount *mnt = real_mount(vfsmnt);
69808 + bool slash = false;
69809 + int error = 0;
69810 +
69811 + while (dentry != root->dentry || vfsmnt != root->mnt) {
69812 + struct dentry * parent;
69813 +
69814 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69815 + /* Global root? */
69816 + if (!mnt_has_parent(mnt)) {
69817 + goto out;
69818 + }
69819 + dentry = mnt->mnt_mountpoint;
69820 + mnt = mnt->mnt_parent;
69821 + vfsmnt = &mnt->mnt;
69822 + continue;
69823 + }
69824 + parent = dentry->d_parent;
69825 + prefetch(parent);
69826 + spin_lock(&dentry->d_lock);
69827 + error = prepend_name(buffer, buflen, &dentry->d_name);
69828 + spin_unlock(&dentry->d_lock);
69829 + if (!error)
69830 + error = prepend(buffer, buflen, "/", 1);
69831 + if (error)
69832 + break;
69833 +
69834 + slash = true;
69835 + dentry = parent;
69836 + }
69837 +
69838 +out:
69839 + if (!error && !slash)
69840 + error = prepend(buffer, buflen, "/", 1);
69841 +
69842 + return error;
69843 +}
69844 +
69845 +/* this must be called with mount_lock and rename_lock held */
69846 +
69847 +static char *__our_d_path(const struct path *path, struct path *root,
69848 + char *buf, int buflen)
69849 +{
69850 + char *res = buf + buflen;
69851 + int error;
69852 +
69853 + prepend(&res, &buflen, "\0", 1);
69854 + error = prepend_path(path, root, &res, &buflen);
69855 + if (error)
69856 + return ERR_PTR(error);
69857 +
69858 + return res;
69859 +}
69860 +
69861 +static char *
69862 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69863 +{
69864 + char *retval;
69865 +
69866 + retval = __our_d_path(path, root, buf, buflen);
69867 + if (unlikely(IS_ERR(retval)))
69868 + retval = strcpy(buf, "<path too long>");
69869 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69870 + retval[1] = '\0';
69871 +
69872 + return retval;
69873 +}
69874 +
69875 +static char *
69876 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69877 + char *buf, int buflen)
69878 +{
69879 + struct path path;
69880 + char *res;
69881 +
69882 + path.dentry = (struct dentry *)dentry;
69883 + path.mnt = (struct vfsmount *)vfsmnt;
69884 +
69885 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69886 + by the RBAC system */
69887 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
69888 +
69889 + return res;
69890 +}
69891 +
69892 +static char *
69893 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69894 + char *buf, int buflen)
69895 +{
69896 + char *res;
69897 + struct path path;
69898 + struct path root;
69899 + struct task_struct *reaper = init_pid_ns.child_reaper;
69900 +
69901 + path.dentry = (struct dentry *)dentry;
69902 + path.mnt = (struct vfsmount *)vfsmnt;
69903 +
69904 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69905 + get_fs_root(reaper->fs, &root);
69906 +
69907 + read_seqlock_excl(&mount_lock);
69908 + write_seqlock(&rename_lock);
69909 + res = gen_full_path(&path, &root, buf, buflen);
69910 + write_sequnlock(&rename_lock);
69911 + read_sequnlock_excl(&mount_lock);
69912 +
69913 + path_put(&root);
69914 + return res;
69915 +}
69916 +
69917 +char *
69918 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69919 +{
69920 + char *ret;
69921 + read_seqlock_excl(&mount_lock);
69922 + write_seqlock(&rename_lock);
69923 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69924 + PAGE_SIZE);
69925 + write_sequnlock(&rename_lock);
69926 + read_sequnlock_excl(&mount_lock);
69927 + return ret;
69928 +}
69929 +
69930 +static char *
69931 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69932 +{
69933 + char *ret;
69934 + char *buf;
69935 + int buflen;
69936 +
69937 + read_seqlock_excl(&mount_lock);
69938 + write_seqlock(&rename_lock);
69939 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69940 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69941 + buflen = (int)(ret - buf);
69942 + if (buflen >= 5)
69943 + prepend(&ret, &buflen, "/proc", 5);
69944 + else
69945 + ret = strcpy(buf, "<path too long>");
69946 + write_sequnlock(&rename_lock);
69947 + read_sequnlock_excl(&mount_lock);
69948 + return ret;
69949 +}
69950 +
69951 +char *
69952 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69953 +{
69954 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69955 + PAGE_SIZE);
69956 +}
69957 +
69958 +char *
69959 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69960 +{
69961 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69962 + PAGE_SIZE);
69963 +}
69964 +
69965 +char *
69966 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69967 +{
69968 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69969 + PAGE_SIZE);
69970 +}
69971 +
69972 +char *
69973 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69974 +{
69975 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69976 + PAGE_SIZE);
69977 +}
69978 +
69979 +char *
69980 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69981 +{
69982 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69983 + PAGE_SIZE);
69984 +}
69985 +
69986 +__inline__ __u32
69987 +to_gr_audit(const __u32 reqmode)
69988 +{
69989 + /* masks off auditable permission flags, then shifts them to create
69990 + auditing flags, and adds the special case of append auditing if
69991 + we're requesting write */
69992 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69993 +}
69994 +
69995 +struct acl_role_label *
69996 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69997 + const gid_t gid)
69998 +{
69999 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70000 + struct acl_role_label *match;
70001 + struct role_allowed_ip *ipp;
70002 + unsigned int x;
70003 + u32 curr_ip = task->signal->saved_ip;
70004 +
70005 + match = state->acl_role_set.r_hash[index];
70006 +
70007 + while (match) {
70008 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70009 + for (x = 0; x < match->domain_child_num; x++) {
70010 + if (match->domain_children[x] == uid)
70011 + goto found;
70012 + }
70013 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70014 + break;
70015 + match = match->next;
70016 + }
70017 +found:
70018 + if (match == NULL) {
70019 + try_group:
70020 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70021 + match = state->acl_role_set.r_hash[index];
70022 +
70023 + while (match) {
70024 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70025 + for (x = 0; x < match->domain_child_num; x++) {
70026 + if (match->domain_children[x] == gid)
70027 + goto found2;
70028 + }
70029 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70030 + break;
70031 + match = match->next;
70032 + }
70033 +found2:
70034 + if (match == NULL)
70035 + match = state->default_role;
70036 + if (match->allowed_ips == NULL)
70037 + return match;
70038 + else {
70039 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70040 + if (likely
70041 + ((ntohl(curr_ip) & ipp->netmask) ==
70042 + (ntohl(ipp->addr) & ipp->netmask)))
70043 + return match;
70044 + }
70045 + match = state->default_role;
70046 + }
70047 + } else if (match->allowed_ips == NULL) {
70048 + return match;
70049 + } else {
70050 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70051 + if (likely
70052 + ((ntohl(curr_ip) & ipp->netmask) ==
70053 + (ntohl(ipp->addr) & ipp->netmask)))
70054 + return match;
70055 + }
70056 + goto try_group;
70057 + }
70058 +
70059 + return match;
70060 +}
70061 +
70062 +static struct acl_role_label *
70063 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70064 + const gid_t gid)
70065 +{
70066 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70067 +}
70068 +
70069 +struct acl_subject_label *
70070 +lookup_acl_subj_label(const u64 ino, const dev_t dev,
70071 + const struct acl_role_label *role)
70072 +{
70073 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70074 + struct acl_subject_label *match;
70075 +
70076 + match = role->subj_hash[index];
70077 +
70078 + while (match && (match->inode != ino || match->device != dev ||
70079 + (match->mode & GR_DELETED))) {
70080 + match = match->next;
70081 + }
70082 +
70083 + if (match && !(match->mode & GR_DELETED))
70084 + return match;
70085 + else
70086 + return NULL;
70087 +}
70088 +
70089 +struct acl_subject_label *
70090 +lookup_acl_subj_label_deleted(const u64 ino, const dev_t dev,
70091 + const struct acl_role_label *role)
70092 +{
70093 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70094 + struct acl_subject_label *match;
70095 +
70096 + match = role->subj_hash[index];
70097 +
70098 + while (match && (match->inode != ino || match->device != dev ||
70099 + !(match->mode & GR_DELETED))) {
70100 + match = match->next;
70101 + }
70102 +
70103 + if (match && (match->mode & GR_DELETED))
70104 + return match;
70105 + else
70106 + return NULL;
70107 +}
70108 +
70109 +static struct acl_object_label *
70110 +lookup_acl_obj_label(const u64 ino, const dev_t dev,
70111 + const struct acl_subject_label *subj)
70112 +{
70113 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70114 + struct acl_object_label *match;
70115 +
70116 + match = subj->obj_hash[index];
70117 +
70118 + while (match && (match->inode != ino || match->device != dev ||
70119 + (match->mode & GR_DELETED))) {
70120 + match = match->next;
70121 + }
70122 +
70123 + if (match && !(match->mode & GR_DELETED))
70124 + return match;
70125 + else
70126 + return NULL;
70127 +}
70128 +
70129 +static struct acl_object_label *
70130 +lookup_acl_obj_label_create(const u64 ino, const dev_t dev,
70131 + const struct acl_subject_label *subj)
70132 +{
70133 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70134 + struct acl_object_label *match;
70135 +
70136 + match = subj->obj_hash[index];
70137 +
70138 + while (match && (match->inode != ino || match->device != dev ||
70139 + !(match->mode & GR_DELETED))) {
70140 + match = match->next;
70141 + }
70142 +
70143 + if (match && (match->mode & GR_DELETED))
70144 + return match;
70145 +
70146 + match = subj->obj_hash[index];
70147 +
70148 + while (match && (match->inode != ino || match->device != dev ||
70149 + (match->mode & GR_DELETED))) {
70150 + match = match->next;
70151 + }
70152 +
70153 + if (match && !(match->mode & GR_DELETED))
70154 + return match;
70155 + else
70156 + return NULL;
70157 +}
70158 +
70159 +struct name_entry *
70160 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70161 +{
70162 + unsigned int len = strlen(name);
70163 + unsigned int key = full_name_hash(name, len);
70164 + unsigned int index = key % state->name_set.n_size;
70165 + struct name_entry *match;
70166 +
70167 + match = state->name_set.n_hash[index];
70168 +
70169 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70170 + match = match->next;
70171 +
70172 + return match;
70173 +}
70174 +
70175 +static struct name_entry *
70176 +lookup_name_entry(const char *name)
70177 +{
70178 + return __lookup_name_entry(&running_polstate, name);
70179 +}
70180 +
70181 +static struct name_entry *
70182 +lookup_name_entry_create(const char *name)
70183 +{
70184 + unsigned int len = strlen(name);
70185 + unsigned int key = full_name_hash(name, len);
70186 + unsigned int index = key % running_polstate.name_set.n_size;
70187 + struct name_entry *match;
70188 +
70189 + match = running_polstate.name_set.n_hash[index];
70190 +
70191 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70192 + !match->deleted))
70193 + match = match->next;
70194 +
70195 + if (match && match->deleted)
70196 + return match;
70197 +
70198 + match = running_polstate.name_set.n_hash[index];
70199 +
70200 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70201 + match->deleted))
70202 + match = match->next;
70203 +
70204 + if (match && !match->deleted)
70205 + return match;
70206 + else
70207 + return NULL;
70208 +}
70209 +
70210 +static struct inodev_entry *
70211 +lookup_inodev_entry(const u64 ino, const dev_t dev)
70212 +{
70213 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70214 + struct inodev_entry *match;
70215 +
70216 + match = running_polstate.inodev_set.i_hash[index];
70217 +
70218 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70219 + match = match->next;
70220 +
70221 + return match;
70222 +}
70223 +
70224 +void
70225 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70226 +{
70227 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70228 + state->inodev_set.i_size);
70229 + struct inodev_entry **curr;
70230 +
70231 + entry->prev = NULL;
70232 +
70233 + curr = &state->inodev_set.i_hash[index];
70234 + if (*curr != NULL)
70235 + (*curr)->prev = entry;
70236 +
70237 + entry->next = *curr;
70238 + *curr = entry;
70239 +
70240 + return;
70241 +}
70242 +
70243 +static void
70244 +insert_inodev_entry(struct inodev_entry *entry)
70245 +{
70246 + __insert_inodev_entry(&running_polstate, entry);
70247 +}
70248 +
70249 +void
70250 +insert_acl_obj_label(struct acl_object_label *obj,
70251 + struct acl_subject_label *subj)
70252 +{
70253 + unsigned int index =
70254 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70255 + struct acl_object_label **curr;
70256 +
70257 + obj->prev = NULL;
70258 +
70259 + curr = &subj->obj_hash[index];
70260 + if (*curr != NULL)
70261 + (*curr)->prev = obj;
70262 +
70263 + obj->next = *curr;
70264 + *curr = obj;
70265 +
70266 + return;
70267 +}
70268 +
70269 +void
70270 +insert_acl_subj_label(struct acl_subject_label *obj,
70271 + struct acl_role_label *role)
70272 +{
70273 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70274 + struct acl_subject_label **curr;
70275 +
70276 + obj->prev = NULL;
70277 +
70278 + curr = &role->subj_hash[index];
70279 + if (*curr != NULL)
70280 + (*curr)->prev = obj;
70281 +
70282 + obj->next = *curr;
70283 + *curr = obj;
70284 +
70285 + return;
70286 +}
70287 +
70288 +/* derived from glibc fnmatch() 0: match, 1: no match*/
70289 +
70290 +static int
70291 +glob_match(const char *p, const char *n)
70292 +{
70293 + char c;
70294 +
70295 + while ((c = *p++) != '\0') {
70296 + switch (c) {
70297 + case '?':
70298 + if (*n == '\0')
70299 + return 1;
70300 + else if (*n == '/')
70301 + return 1;
70302 + break;
70303 + case '\\':
70304 + if (*n != c)
70305 + return 1;
70306 + break;
70307 + case '*':
70308 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
70309 + if (*n == '/')
70310 + return 1;
70311 + else if (c == '?') {
70312 + if (*n == '\0')
70313 + return 1;
70314 + else
70315 + ++n;
70316 + }
70317 + }
70318 + if (c == '\0') {
70319 + return 0;
70320 + } else {
70321 + const char *endp;
70322 +
70323 + if ((endp = strchr(n, '/')) == NULL)
70324 + endp = n + strlen(n);
70325 +
70326 + if (c == '[') {
70327 + for (--p; n < endp; ++n)
70328 + if (!glob_match(p, n))
70329 + return 0;
70330 + } else if (c == '/') {
70331 + while (*n != '\0' && *n != '/')
70332 + ++n;
70333 + if (*n == '/' && !glob_match(p, n + 1))
70334 + return 0;
70335 + } else {
70336 + for (--p; n < endp; ++n)
70337 + if (*n == c && !glob_match(p, n))
70338 + return 0;
70339 + }
70340 +
70341 + return 1;
70342 + }
70343 + case '[':
70344 + {
70345 + int not;
70346 + char cold;
70347 +
70348 + if (*n == '\0' || *n == '/')
70349 + return 1;
70350 +
70351 + not = (*p == '!' || *p == '^');
70352 + if (not)
70353 + ++p;
70354 +
70355 + c = *p++;
70356 + for (;;) {
70357 + unsigned char fn = (unsigned char)*n;
70358 +
70359 + if (c == '\0')
70360 + return 1;
70361 + else {
70362 + if (c == fn)
70363 + goto matched;
70364 + cold = c;
70365 + c = *p++;
70366 +
70367 + if (c == '-' && *p != ']') {
70368 + unsigned char cend = *p++;
70369 +
70370 + if (cend == '\0')
70371 + return 1;
70372 +
70373 + if (cold <= fn && fn <= cend)
70374 + goto matched;
70375 +
70376 + c = *p++;
70377 + }
70378 + }
70379 +
70380 + if (c == ']')
70381 + break;
70382 + }
70383 + if (!not)
70384 + return 1;
70385 + break;
70386 + matched:
70387 + while (c != ']') {
70388 + if (c == '\0')
70389 + return 1;
70390 +
70391 + c = *p++;
70392 + }
70393 + if (not)
70394 + return 1;
70395 + }
70396 + break;
70397 + default:
70398 + if (c != *n)
70399 + return 1;
70400 + }
70401 +
70402 + ++n;
70403 + }
70404 +
70405 + if (*n == '\0')
70406 + return 0;
70407 +
70408 + if (*n == '/')
70409 + return 0;
70410 +
70411 + return 1;
70412 +}
70413 +
70414 +static struct acl_object_label *
70415 +chk_glob_label(struct acl_object_label *globbed,
70416 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70417 +{
70418 + struct acl_object_label *tmp;
70419 +
70420 + if (*path == NULL)
70421 + *path = gr_to_filename_nolock(dentry, mnt);
70422 +
70423 + tmp = globbed;
70424 +
70425 + while (tmp) {
70426 + if (!glob_match(tmp->filename, *path))
70427 + return tmp;
70428 + tmp = tmp->next;
70429 + }
70430 +
70431 + return NULL;
70432 +}
70433 +
70434 +static struct acl_object_label *
70435 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70436 + const u64 curr_ino, const dev_t curr_dev,
70437 + const struct acl_subject_label *subj, char **path, const int checkglob)
70438 +{
70439 + struct acl_subject_label *tmpsubj;
70440 + struct acl_object_label *retval;
70441 + struct acl_object_label *retval2;
70442 +
70443 + tmpsubj = (struct acl_subject_label *) subj;
70444 + read_lock(&gr_inode_lock);
70445 + do {
70446 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70447 + if (retval) {
70448 + if (checkglob && retval->globbed) {
70449 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70450 + if (retval2)
70451 + retval = retval2;
70452 + }
70453 + break;
70454 + }
70455 + } while ((tmpsubj = tmpsubj->parent_subject));
70456 + read_unlock(&gr_inode_lock);
70457 +
70458 + return retval;
70459 +}
70460 +
70461 +static __inline__ struct acl_object_label *
70462 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70463 + struct dentry *curr_dentry,
70464 + const struct acl_subject_label *subj, char **path, const int checkglob)
70465 +{
70466 + int newglob = checkglob;
70467 + u64 inode;
70468 + dev_t device;
70469 +
70470 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70471 + as we don't want a / * rule to match instead of the / object
70472 + don't do this for create lookups that call this function though, since they're looking up
70473 + on the parent and thus need globbing checks on all paths
70474 + */
70475 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70476 + newglob = GR_NO_GLOB;
70477 +
70478 + spin_lock(&curr_dentry->d_lock);
70479 + inode = __get_ino(curr_dentry);
70480 + device = __get_dev(curr_dentry);
70481 + spin_unlock(&curr_dentry->d_lock);
70482 +
70483 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70484 +}
70485 +
70486 +#ifdef CONFIG_HUGETLBFS
70487 +static inline bool
70488 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
70489 +{
70490 + int i;
70491 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70492 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70493 + return true;
70494 + }
70495 +
70496 + return false;
70497 +}
70498 +#endif
70499 +
70500 +static struct acl_object_label *
70501 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70502 + const struct acl_subject_label *subj, char *path, const int checkglob)
70503 +{
70504 + struct dentry *dentry = (struct dentry *) l_dentry;
70505 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70506 + struct mount *real_mnt = real_mount(mnt);
70507 + struct acl_object_label *retval;
70508 + struct dentry *parent;
70509 +
70510 + read_seqlock_excl(&mount_lock);
70511 + write_seqlock(&rename_lock);
70512 +
70513 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70514 +#ifdef CONFIG_NET
70515 + mnt == sock_mnt ||
70516 +#endif
70517 +#ifdef CONFIG_HUGETLBFS
70518 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70519 +#endif
70520 + /* ignore Eric Biederman */
70521 + IS_PRIVATE(l_dentry->d_inode))) {
70522 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70523 + goto out;
70524 + }
70525 +
70526 + for (;;) {
70527 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70528 + break;
70529 +
70530 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70531 + if (!mnt_has_parent(real_mnt))
70532 + break;
70533 +
70534 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70535 + if (retval != NULL)
70536 + goto out;
70537 +
70538 + dentry = real_mnt->mnt_mountpoint;
70539 + real_mnt = real_mnt->mnt_parent;
70540 + mnt = &real_mnt->mnt;
70541 + continue;
70542 + }
70543 +
70544 + parent = dentry->d_parent;
70545 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70546 + if (retval != NULL)
70547 + goto out;
70548 +
70549 + dentry = parent;
70550 + }
70551 +
70552 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70553 +
70554 + /* gr_real_root is pinned so we don't have to hold a reference */
70555 + if (retval == NULL)
70556 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70557 +out:
70558 + write_sequnlock(&rename_lock);
70559 + read_sequnlock_excl(&mount_lock);
70560 +
70561 + BUG_ON(retval == NULL);
70562 +
70563 + return retval;
70564 +}
70565 +
70566 +static __inline__ struct acl_object_label *
70567 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70568 + const struct acl_subject_label *subj)
70569 +{
70570 + char *path = NULL;
70571 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70572 +}
70573 +
70574 +static __inline__ struct acl_object_label *
70575 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70576 + const struct acl_subject_label *subj)
70577 +{
70578 + char *path = NULL;
70579 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70580 +}
70581 +
70582 +static __inline__ struct acl_object_label *
70583 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70584 + const struct acl_subject_label *subj, char *path)
70585 +{
70586 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70587 +}
70588 +
70589 +struct acl_subject_label *
70590 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70591 + const struct acl_role_label *role)
70592 +{
70593 + struct dentry *dentry = (struct dentry *) l_dentry;
70594 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70595 + struct mount *real_mnt = real_mount(mnt);
70596 + struct acl_subject_label *retval;
70597 + struct dentry *parent;
70598 +
70599 + read_seqlock_excl(&mount_lock);
70600 + write_seqlock(&rename_lock);
70601 +
70602 + for (;;) {
70603 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70604 + break;
70605 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70606 + if (!mnt_has_parent(real_mnt))
70607 + break;
70608 +
70609 + spin_lock(&dentry->d_lock);
70610 + read_lock(&gr_inode_lock);
70611 + retval =
70612 + lookup_acl_subj_label(__get_ino(dentry),
70613 + __get_dev(dentry), role);
70614 + read_unlock(&gr_inode_lock);
70615 + spin_unlock(&dentry->d_lock);
70616 + if (retval != NULL)
70617 + goto out;
70618 +
70619 + dentry = real_mnt->mnt_mountpoint;
70620 + real_mnt = real_mnt->mnt_parent;
70621 + mnt = &real_mnt->mnt;
70622 + continue;
70623 + }
70624 +
70625 + spin_lock(&dentry->d_lock);
70626 + read_lock(&gr_inode_lock);
70627 + retval = lookup_acl_subj_label(__get_ino(dentry),
70628 + __get_dev(dentry), role);
70629 + read_unlock(&gr_inode_lock);
70630 + parent = dentry->d_parent;
70631 + spin_unlock(&dentry->d_lock);
70632 +
70633 + if (retval != NULL)
70634 + goto out;
70635 +
70636 + dentry = parent;
70637 + }
70638 +
70639 + spin_lock(&dentry->d_lock);
70640 + read_lock(&gr_inode_lock);
70641 + retval = lookup_acl_subj_label(__get_ino(dentry),
70642 + __get_dev(dentry), role);
70643 + read_unlock(&gr_inode_lock);
70644 + spin_unlock(&dentry->d_lock);
70645 +
70646 + if (unlikely(retval == NULL)) {
70647 + /* gr_real_root is pinned, we don't need to hold a reference */
70648 + read_lock(&gr_inode_lock);
70649 + retval = lookup_acl_subj_label(__get_ino(gr_real_root.dentry),
70650 + __get_dev(gr_real_root.dentry), role);
70651 + read_unlock(&gr_inode_lock);
70652 + }
70653 +out:
70654 + write_sequnlock(&rename_lock);
70655 + read_sequnlock_excl(&mount_lock);
70656 +
70657 + BUG_ON(retval == NULL);
70658 +
70659 + return retval;
70660 +}
70661 +
70662 +void
70663 +assign_special_role(const char *rolename)
70664 +{
70665 + struct acl_object_label *obj;
70666 + struct acl_role_label *r;
70667 + struct acl_role_label *assigned = NULL;
70668 + struct task_struct *tsk;
70669 + struct file *filp;
70670 +
70671 + FOR_EACH_ROLE_START(r)
70672 + if (!strcmp(rolename, r->rolename) &&
70673 + (r->roletype & GR_ROLE_SPECIAL)) {
70674 + assigned = r;
70675 + break;
70676 + }
70677 + FOR_EACH_ROLE_END(r)
70678 +
70679 + if (!assigned)
70680 + return;
70681 +
70682 + read_lock(&tasklist_lock);
70683 + read_lock(&grsec_exec_file_lock);
70684 +
70685 + tsk = current->real_parent;
70686 + if (tsk == NULL)
70687 + goto out_unlock;
70688 +
70689 + filp = tsk->exec_file;
70690 + if (filp == NULL)
70691 + goto out_unlock;
70692 +
70693 + tsk->is_writable = 0;
70694 + tsk->inherited = 0;
70695 +
70696 + tsk->acl_sp_role = 1;
70697 + tsk->acl_role_id = ++acl_sp_role_value;
70698 + tsk->role = assigned;
70699 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70700 +
70701 + /* ignore additional mmap checks for processes that are writable
70702 + by the default ACL */
70703 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70704 + if (unlikely(obj->mode & GR_WRITE))
70705 + tsk->is_writable = 1;
70706 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70707 + if (unlikely(obj->mode & GR_WRITE))
70708 + tsk->is_writable = 1;
70709 +
70710 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70711 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70712 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70713 +#endif
70714 +
70715 +out_unlock:
70716 + read_unlock(&grsec_exec_file_lock);
70717 + read_unlock(&tasklist_lock);
70718 + return;
70719 +}
70720 +
70721 +
70722 +static void
70723 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70724 +{
70725 + struct task_struct *task = current;
70726 + const struct cred *cred = current_cred();
70727 +
70728 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70729 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70730 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70731 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70732 +
70733 + return;
70734 +}
70735 +
70736 +static void
70737 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70738 +{
70739 + struct task_struct *task = current;
70740 + const struct cred *cred = current_cred();
70741 +
70742 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70743 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70744 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70745 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70746 +
70747 + return;
70748 +}
70749 +
70750 +static void
70751 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70752 +{
70753 + struct task_struct *task = current;
70754 + const struct cred *cred = current_cred();
70755 +
70756 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70757 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70758 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70759 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70760 +
70761 + return;
70762 +}
70763 +
70764 +static void
70765 +gr_set_proc_res(struct task_struct *task)
70766 +{
70767 + struct acl_subject_label *proc;
70768 + unsigned short i;
70769 +
70770 + proc = task->acl;
70771 +
70772 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70773 + return;
70774 +
70775 + for (i = 0; i < RLIM_NLIMITS; i++) {
70776 + unsigned long rlim_cur, rlim_max;
70777 +
70778 + if (!(proc->resmask & (1U << i)))
70779 + continue;
70780 +
70781 + rlim_cur = proc->res[i].rlim_cur;
70782 + rlim_max = proc->res[i].rlim_max;
70783 +
70784 + if (i == RLIMIT_NOFILE) {
70785 + unsigned long saved_sysctl_nr_open = sysctl_nr_open;
70786 + if (rlim_cur > saved_sysctl_nr_open)
70787 + rlim_cur = saved_sysctl_nr_open;
70788 + if (rlim_max > saved_sysctl_nr_open)
70789 + rlim_max = saved_sysctl_nr_open;
70790 + }
70791 +
70792 + task->signal->rlim[i].rlim_cur = rlim_cur;
70793 + task->signal->rlim[i].rlim_max = rlim_max;
70794 +
70795 + if (i == RLIMIT_CPU)
70796 + update_rlimit_cpu(task, rlim_cur);
70797 + }
70798 +
70799 + return;
70800 +}
70801 +
70802 +/* both of the below must be called with
70803 + rcu_read_lock();
70804 + read_lock(&tasklist_lock);
70805 + read_lock(&grsec_exec_file_lock);
70806 + except in the case of gr_set_role_label() (for __gr_get_subject_for_task)
70807 +*/
70808 +
70809 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename, int fallback)
70810 +{
70811 + char *tmpname;
70812 + struct acl_subject_label *tmpsubj;
70813 + struct file *filp;
70814 + struct name_entry *nmatch;
70815 +
70816 + filp = task->exec_file;
70817 + if (filp == NULL)
70818 + return NULL;
70819 +
70820 + /* the following is to apply the correct subject
70821 + on binaries running when the RBAC system
70822 + is enabled, when the binaries have been
70823 + replaced or deleted since their execution
70824 + -----
70825 + when the RBAC system starts, the inode/dev
70826 + from exec_file will be one the RBAC system
70827 + is unaware of. It only knows the inode/dev
70828 + of the present file on disk, or the absence
70829 + of it.
70830 + */
70831 +
70832 + if (filename)
70833 + nmatch = __lookup_name_entry(state, filename);
70834 + else {
70835 + preempt_disable();
70836 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70837 +
70838 + nmatch = __lookup_name_entry(state, tmpname);
70839 + preempt_enable();
70840 + }
70841 + tmpsubj = NULL;
70842 + if (nmatch) {
70843 + if (nmatch->deleted)
70844 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70845 + else
70846 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70847 + }
70848 + /* this also works for the reload case -- if we don't match a potentially inherited subject
70849 + then we fall back to a normal lookup based on the binary's ino/dev
70850 + */
70851 + if (tmpsubj == NULL && fallback)
70852 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70853 +
70854 + return tmpsubj;
70855 +}
70856 +
70857 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename, int fallback)
70858 +{
70859 + return __gr_get_subject_for_task(&running_polstate, task, filename, fallback);
70860 +}
70861 +
70862 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70863 +{
70864 + struct acl_object_label *obj;
70865 + struct file *filp;
70866 +
70867 + filp = task->exec_file;
70868 +
70869 + task->acl = subj;
70870 + task->is_writable = 0;
70871 + /* ignore additional mmap checks for processes that are writable
70872 + by the default ACL */
70873 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70874 + if (unlikely(obj->mode & GR_WRITE))
70875 + task->is_writable = 1;
70876 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70877 + if (unlikely(obj->mode & GR_WRITE))
70878 + task->is_writable = 1;
70879 +
70880 + gr_set_proc_res(task);
70881 +
70882 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70883 + 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);
70884 +#endif
70885 +}
70886 +
70887 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70888 +{
70889 + __gr_apply_subject_to_task(&running_polstate, task, subj);
70890 +}
70891 +
70892 +__u32
70893 +gr_search_file(const struct dentry * dentry, const __u32 mode,
70894 + const struct vfsmount * mnt)
70895 +{
70896 + __u32 retval = mode;
70897 + struct acl_subject_label *curracl;
70898 + struct acl_object_label *currobj;
70899 +
70900 + if (unlikely(!(gr_status & GR_READY)))
70901 + return (mode & ~GR_AUDITS);
70902 +
70903 + curracl = current->acl;
70904 +
70905 + currobj = chk_obj_label(dentry, mnt, curracl);
70906 + retval = currobj->mode & mode;
70907 +
70908 + /* if we're opening a specified transfer file for writing
70909 + (e.g. /dev/initctl), then transfer our role to init
70910 + */
70911 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70912 + current->role->roletype & GR_ROLE_PERSIST)) {
70913 + struct task_struct *task = init_pid_ns.child_reaper;
70914 +
70915 + if (task->role != current->role) {
70916 + struct acl_subject_label *subj;
70917 +
70918 + task->acl_sp_role = 0;
70919 + task->acl_role_id = current->acl_role_id;
70920 + task->role = current->role;
70921 + rcu_read_lock();
70922 + read_lock(&grsec_exec_file_lock);
70923 + subj = gr_get_subject_for_task(task, NULL, 1);
70924 + gr_apply_subject_to_task(task, subj);
70925 + read_unlock(&grsec_exec_file_lock);
70926 + rcu_read_unlock();
70927 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70928 + }
70929 + }
70930 +
70931 + if (unlikely
70932 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70933 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70934 + __u32 new_mode = mode;
70935 +
70936 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70937 +
70938 + retval = new_mode;
70939 +
70940 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70941 + new_mode |= GR_INHERIT;
70942 +
70943 + if (!(mode & GR_NOLEARN))
70944 + gr_log_learn(dentry, mnt, new_mode);
70945 + }
70946 +
70947 + return retval;
70948 +}
70949 +
70950 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70951 + const struct dentry *parent,
70952 + const struct vfsmount *mnt)
70953 +{
70954 + struct name_entry *match;
70955 + struct acl_object_label *matchpo;
70956 + struct acl_subject_label *curracl;
70957 + char *path;
70958 +
70959 + if (unlikely(!(gr_status & GR_READY)))
70960 + return NULL;
70961 +
70962 + preempt_disable();
70963 + path = gr_to_filename_rbac(new_dentry, mnt);
70964 + match = lookup_name_entry_create(path);
70965 +
70966 + curracl = current->acl;
70967 +
70968 + if (match) {
70969 + read_lock(&gr_inode_lock);
70970 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70971 + read_unlock(&gr_inode_lock);
70972 +
70973 + if (matchpo) {
70974 + preempt_enable();
70975 + return matchpo;
70976 + }
70977 + }
70978 +
70979 + // lookup parent
70980 +
70981 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70982 +
70983 + preempt_enable();
70984 + return matchpo;
70985 +}
70986 +
70987 +__u32
70988 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70989 + const struct vfsmount * mnt, const __u32 mode)
70990 +{
70991 + struct acl_object_label *matchpo;
70992 + __u32 retval;
70993 +
70994 + if (unlikely(!(gr_status & GR_READY)))
70995 + return (mode & ~GR_AUDITS);
70996 +
70997 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
70998 +
70999 + retval = matchpo->mode & mode;
71000 +
71001 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71002 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71003 + __u32 new_mode = mode;
71004 +
71005 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71006 +
71007 + gr_log_learn(new_dentry, mnt, new_mode);
71008 + return new_mode;
71009 + }
71010 +
71011 + return retval;
71012 +}
71013 +
71014 +__u32
71015 +gr_check_link(const struct dentry * new_dentry,
71016 + const struct dentry * parent_dentry,
71017 + const struct vfsmount * parent_mnt,
71018 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71019 +{
71020 + struct acl_object_label *obj;
71021 + __u32 oldmode, newmode;
71022 + __u32 needmode;
71023 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71024 + GR_DELETE | GR_INHERIT;
71025 +
71026 + if (unlikely(!(gr_status & GR_READY)))
71027 + return (GR_CREATE | GR_LINK);
71028 +
71029 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71030 + oldmode = obj->mode;
71031 +
71032 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71033 + newmode = obj->mode;
71034 +
71035 + needmode = newmode & checkmodes;
71036 +
71037 + // old name for hardlink must have at least the permissions of the new name
71038 + if ((oldmode & needmode) != needmode)
71039 + goto bad;
71040 +
71041 + // if old name had restrictions/auditing, make sure the new name does as well
71042 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71043 +
71044 + // don't allow hardlinking of suid/sgid/fcapped files without permission
71045 + if (is_privileged_binary(old_dentry))
71046 + needmode |= GR_SETID;
71047 +
71048 + if ((newmode & needmode) != needmode)
71049 + goto bad;
71050 +
71051 + // enforce minimum permissions
71052 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71053 + return newmode;
71054 +bad:
71055 + needmode = oldmode;
71056 + if (is_privileged_binary(old_dentry))
71057 + needmode |= GR_SETID;
71058 +
71059 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71060 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71061 + return (GR_CREATE | GR_LINK);
71062 + } else if (newmode & GR_SUPPRESS)
71063 + return GR_SUPPRESS;
71064 + else
71065 + return 0;
71066 +}
71067 +
71068 +int
71069 +gr_check_hidden_task(const struct task_struct *task)
71070 +{
71071 + if (unlikely(!(gr_status & GR_READY)))
71072 + return 0;
71073 +
71074 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71075 + return 1;
71076 +
71077 + return 0;
71078 +}
71079 +
71080 +int
71081 +gr_check_protected_task(const struct task_struct *task)
71082 +{
71083 + if (unlikely(!(gr_status & GR_READY) || !task))
71084 + return 0;
71085 +
71086 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71087 + task->acl != current->acl)
71088 + return 1;
71089 +
71090 + return 0;
71091 +}
71092 +
71093 +int
71094 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71095 +{
71096 + struct task_struct *p;
71097 + int ret = 0;
71098 +
71099 + if (unlikely(!(gr_status & GR_READY) || !pid))
71100 + return ret;
71101 +
71102 + read_lock(&tasklist_lock);
71103 + do_each_pid_task(pid, type, p) {
71104 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71105 + p->acl != current->acl) {
71106 + ret = 1;
71107 + goto out;
71108 + }
71109 + } while_each_pid_task(pid, type, p);
71110 +out:
71111 + read_unlock(&tasklist_lock);
71112 +
71113 + return ret;
71114 +}
71115 +
71116 +void
71117 +gr_copy_label(struct task_struct *tsk)
71118 +{
71119 + struct task_struct *p = current;
71120 +
71121 + tsk->inherited = p->inherited;
71122 + tsk->acl_sp_role = 0;
71123 + tsk->acl_role_id = p->acl_role_id;
71124 + tsk->acl = p->acl;
71125 + tsk->role = p->role;
71126 + tsk->signal->used_accept = 0;
71127 + tsk->signal->curr_ip = p->signal->curr_ip;
71128 + tsk->signal->saved_ip = p->signal->saved_ip;
71129 + if (p->exec_file)
71130 + get_file(p->exec_file);
71131 + tsk->exec_file = p->exec_file;
71132 + tsk->is_writable = p->is_writable;
71133 + if (unlikely(p->signal->used_accept)) {
71134 + p->signal->curr_ip = 0;
71135 + p->signal->saved_ip = 0;
71136 + }
71137 +
71138 + return;
71139 +}
71140 +
71141 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71142 +
71143 +int
71144 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71145 +{
71146 + unsigned int i;
71147 + __u16 num;
71148 + uid_t *uidlist;
71149 + uid_t curuid;
71150 + int realok = 0;
71151 + int effectiveok = 0;
71152 + int fsok = 0;
71153 + uid_t globalreal, globaleffective, globalfs;
71154 +
71155 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71156 + struct user_struct *user;
71157 +
71158 + if (!uid_valid(real))
71159 + goto skipit;
71160 +
71161 + /* find user based on global namespace */
71162 +
71163 + globalreal = GR_GLOBAL_UID(real);
71164 +
71165 + user = find_user(make_kuid(&init_user_ns, globalreal));
71166 + if (user == NULL)
71167 + goto skipit;
71168 +
71169 + if (gr_process_kernel_setuid_ban(user)) {
71170 + /* for find_user */
71171 + free_uid(user);
71172 + return 1;
71173 + }
71174 +
71175 + /* for find_user */
71176 + free_uid(user);
71177 +
71178 +skipit:
71179 +#endif
71180 +
71181 + if (unlikely(!(gr_status & GR_READY)))
71182 + return 0;
71183 +
71184 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71185 + gr_log_learn_uid_change(real, effective, fs);
71186 +
71187 + num = current->acl->user_trans_num;
71188 + uidlist = current->acl->user_transitions;
71189 +
71190 + if (uidlist == NULL)
71191 + return 0;
71192 +
71193 + if (!uid_valid(real)) {
71194 + realok = 1;
71195 + globalreal = (uid_t)-1;
71196 + } else {
71197 + globalreal = GR_GLOBAL_UID(real);
71198 + }
71199 + if (!uid_valid(effective)) {
71200 + effectiveok = 1;
71201 + globaleffective = (uid_t)-1;
71202 + } else {
71203 + globaleffective = GR_GLOBAL_UID(effective);
71204 + }
71205 + if (!uid_valid(fs)) {
71206 + fsok = 1;
71207 + globalfs = (uid_t)-1;
71208 + } else {
71209 + globalfs = GR_GLOBAL_UID(fs);
71210 + }
71211 +
71212 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
71213 + for (i = 0; i < num; i++) {
71214 + curuid = uidlist[i];
71215 + if (globalreal == curuid)
71216 + realok = 1;
71217 + if (globaleffective == curuid)
71218 + effectiveok = 1;
71219 + if (globalfs == curuid)
71220 + fsok = 1;
71221 + }
71222 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
71223 + for (i = 0; i < num; i++) {
71224 + curuid = uidlist[i];
71225 + if (globalreal == curuid)
71226 + break;
71227 + if (globaleffective == curuid)
71228 + break;
71229 + if (globalfs == curuid)
71230 + break;
71231 + }
71232 + /* not in deny list */
71233 + if (i == num) {
71234 + realok = 1;
71235 + effectiveok = 1;
71236 + fsok = 1;
71237 + }
71238 + }
71239 +
71240 + if (realok && effectiveok && fsok)
71241 + return 0;
71242 + else {
71243 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71244 + return 1;
71245 + }
71246 +}
71247 +
71248 +int
71249 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71250 +{
71251 + unsigned int i;
71252 + __u16 num;
71253 + gid_t *gidlist;
71254 + gid_t curgid;
71255 + int realok = 0;
71256 + int effectiveok = 0;
71257 + int fsok = 0;
71258 + gid_t globalreal, globaleffective, globalfs;
71259 +
71260 + if (unlikely(!(gr_status & GR_READY)))
71261 + return 0;
71262 +
71263 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71264 + gr_log_learn_gid_change(real, effective, fs);
71265 +
71266 + num = current->acl->group_trans_num;
71267 + gidlist = current->acl->group_transitions;
71268 +
71269 + if (gidlist == NULL)
71270 + return 0;
71271 +
71272 + if (!gid_valid(real)) {
71273 + realok = 1;
71274 + globalreal = (gid_t)-1;
71275 + } else {
71276 + globalreal = GR_GLOBAL_GID(real);
71277 + }
71278 + if (!gid_valid(effective)) {
71279 + effectiveok = 1;
71280 + globaleffective = (gid_t)-1;
71281 + } else {
71282 + globaleffective = GR_GLOBAL_GID(effective);
71283 + }
71284 + if (!gid_valid(fs)) {
71285 + fsok = 1;
71286 + globalfs = (gid_t)-1;
71287 + } else {
71288 + globalfs = GR_GLOBAL_GID(fs);
71289 + }
71290 +
71291 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
71292 + for (i = 0; i < num; i++) {
71293 + curgid = gidlist[i];
71294 + if (globalreal == curgid)
71295 + realok = 1;
71296 + if (globaleffective == curgid)
71297 + effectiveok = 1;
71298 + if (globalfs == curgid)
71299 + fsok = 1;
71300 + }
71301 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
71302 + for (i = 0; i < num; i++) {
71303 + curgid = gidlist[i];
71304 + if (globalreal == curgid)
71305 + break;
71306 + if (globaleffective == curgid)
71307 + break;
71308 + if (globalfs == curgid)
71309 + break;
71310 + }
71311 + /* not in deny list */
71312 + if (i == num) {
71313 + realok = 1;
71314 + effectiveok = 1;
71315 + fsok = 1;
71316 + }
71317 + }
71318 +
71319 + if (realok && effectiveok && fsok)
71320 + return 0;
71321 + else {
71322 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71323 + return 1;
71324 + }
71325 +}
71326 +
71327 +extern int gr_acl_is_capable(const int cap);
71328 +
71329 +void
71330 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71331 +{
71332 + struct acl_role_label *role = task->role;
71333 + struct acl_role_label *origrole = role;
71334 + struct acl_subject_label *subj = NULL;
71335 + struct acl_object_label *obj;
71336 + struct file *filp;
71337 + uid_t uid;
71338 + gid_t gid;
71339 +
71340 + if (unlikely(!(gr_status & GR_READY)))
71341 + return;
71342 +
71343 + uid = GR_GLOBAL_UID(kuid);
71344 + gid = GR_GLOBAL_GID(kgid);
71345 +
71346 + filp = task->exec_file;
71347 +
71348 + /* kernel process, we'll give them the kernel role */
71349 + if (unlikely(!filp)) {
71350 + task->role = running_polstate.kernel_role;
71351 + task->acl = running_polstate.kernel_role->root_label;
71352 + return;
71353 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71354 + /* save the current ip at time of role lookup so that the proper
71355 + IP will be learned for role_allowed_ip */
71356 + task->signal->saved_ip = task->signal->curr_ip;
71357 + role = lookup_acl_role_label(task, uid, gid);
71358 + }
71359 +
71360 + /* don't change the role if we're not a privileged process */
71361 + if (role && task->role != role &&
71362 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71363 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71364 + return;
71365 +
71366 + task->role = role;
71367 +
71368 + if (task->inherited) {
71369 + /* if we reached our subject through inheritance, then first see
71370 + if there's a subject of the same name in the new role that has
71371 + an object that would result in the same inherited subject
71372 + */
71373 + subj = gr_get_subject_for_task(task, task->acl->filename, 0);
71374 + if (subj) {
71375 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, subj);
71376 + if (!(obj->mode & GR_INHERIT))
71377 + subj = NULL;
71378 + }
71379 +
71380 + }
71381 + if (subj == NULL) {
71382 + /* otherwise:
71383 + perform subject lookup in possibly new role
71384 + we can use this result below in the case where role == task->role
71385 + */
71386 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71387 + }
71388 +
71389 + /* if we changed uid/gid, but result in the same role
71390 + and are using inheritance, don't lose the inherited subject
71391 + if current subject is other than what normal lookup
71392 + would result in, we arrived via inheritance, don't
71393 + lose subject
71394 + */
71395 + if (role != origrole || (!(task->acl->mode & GR_INHERITLEARN) &&
71396 + (subj == task->acl)))
71397 + task->acl = subj;
71398 +
71399 + /* leave task->inherited unaffected */
71400 +
71401 + task->is_writable = 0;
71402 +
71403 + /* ignore additional mmap checks for processes that are writable
71404 + by the default ACL */
71405 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71406 + if (unlikely(obj->mode & GR_WRITE))
71407 + task->is_writable = 1;
71408 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71409 + if (unlikely(obj->mode & GR_WRITE))
71410 + task->is_writable = 1;
71411 +
71412 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71413 + 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);
71414 +#endif
71415 +
71416 + gr_set_proc_res(task);
71417 +
71418 + return;
71419 +}
71420 +
71421 +int
71422 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71423 + const int unsafe_flags)
71424 +{
71425 + struct task_struct *task = current;
71426 + struct acl_subject_label *newacl;
71427 + struct acl_object_label *obj;
71428 + __u32 retmode;
71429 +
71430 + if (unlikely(!(gr_status & GR_READY)))
71431 + return 0;
71432 +
71433 + newacl = chk_subj_label(dentry, mnt, task->role);
71434 +
71435 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71436 + did an exec
71437 + */
71438 + rcu_read_lock();
71439 + read_lock(&tasklist_lock);
71440 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71441 + (task->parent->acl->mode & GR_POVERRIDE))) {
71442 + read_unlock(&tasklist_lock);
71443 + rcu_read_unlock();
71444 + goto skip_check;
71445 + }
71446 + read_unlock(&tasklist_lock);
71447 + rcu_read_unlock();
71448 +
71449 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71450 + !(task->role->roletype & GR_ROLE_GOD) &&
71451 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71452 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71453 + if (unsafe_flags & LSM_UNSAFE_SHARE)
71454 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71455 + else
71456 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71457 + return -EACCES;
71458 + }
71459 +
71460 +skip_check:
71461 +
71462 + obj = chk_obj_label(dentry, mnt, task->acl);
71463 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71464 +
71465 + if (!(task->acl->mode & GR_INHERITLEARN) &&
71466 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71467 + if (obj->nested)
71468 + task->acl = obj->nested;
71469 + else
71470 + task->acl = newacl;
71471 + task->inherited = 0;
71472 + } else {
71473 + task->inherited = 1;
71474 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71475 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71476 + }
71477 +
71478 + task->is_writable = 0;
71479 +
71480 + /* ignore additional mmap checks for processes that are writable
71481 + by the default ACL */
71482 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71483 + if (unlikely(obj->mode & GR_WRITE))
71484 + task->is_writable = 1;
71485 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
71486 + if (unlikely(obj->mode & GR_WRITE))
71487 + task->is_writable = 1;
71488 +
71489 + gr_set_proc_res(task);
71490 +
71491 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71492 + 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);
71493 +#endif
71494 + return 0;
71495 +}
71496 +
71497 +/* always called with valid inodev ptr */
71498 +static void
71499 +do_handle_delete(struct inodev_entry *inodev, const u64 ino, const dev_t dev)
71500 +{
71501 + struct acl_object_label *matchpo;
71502 + struct acl_subject_label *matchps;
71503 + struct acl_subject_label *subj;
71504 + struct acl_role_label *role;
71505 + unsigned int x;
71506 +
71507 + FOR_EACH_ROLE_START(role)
71508 + FOR_EACH_SUBJECT_START(role, subj, x)
71509 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71510 + matchpo->mode |= GR_DELETED;
71511 + FOR_EACH_SUBJECT_END(subj,x)
71512 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71513 + /* nested subjects aren't in the role's subj_hash table */
71514 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71515 + matchpo->mode |= GR_DELETED;
71516 + FOR_EACH_NESTED_SUBJECT_END(subj)
71517 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71518 + matchps->mode |= GR_DELETED;
71519 + FOR_EACH_ROLE_END(role)
71520 +
71521 + inodev->nentry->deleted = 1;
71522 +
71523 + return;
71524 +}
71525 +
71526 +void
71527 +gr_handle_delete(const u64 ino, const dev_t dev)
71528 +{
71529 + struct inodev_entry *inodev;
71530 +
71531 + if (unlikely(!(gr_status & GR_READY)))
71532 + return;
71533 +
71534 + write_lock(&gr_inode_lock);
71535 + inodev = lookup_inodev_entry(ino, dev);
71536 + if (inodev != NULL)
71537 + do_handle_delete(inodev, ino, dev);
71538 + write_unlock(&gr_inode_lock);
71539 +
71540 + return;
71541 +}
71542 +
71543 +static void
71544 +update_acl_obj_label(const u64 oldinode, const dev_t olddevice,
71545 + const u64 newinode, const dev_t newdevice,
71546 + struct acl_subject_label *subj)
71547 +{
71548 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71549 + struct acl_object_label *match;
71550 +
71551 + match = subj->obj_hash[index];
71552 +
71553 + while (match && (match->inode != oldinode ||
71554 + match->device != olddevice ||
71555 + !(match->mode & GR_DELETED)))
71556 + match = match->next;
71557 +
71558 + if (match && (match->inode == oldinode)
71559 + && (match->device == olddevice)
71560 + && (match->mode & GR_DELETED)) {
71561 + if (match->prev == NULL) {
71562 + subj->obj_hash[index] = match->next;
71563 + if (match->next != NULL)
71564 + match->next->prev = NULL;
71565 + } else {
71566 + match->prev->next = match->next;
71567 + if (match->next != NULL)
71568 + match->next->prev = match->prev;
71569 + }
71570 + match->prev = NULL;
71571 + match->next = NULL;
71572 + match->inode = newinode;
71573 + match->device = newdevice;
71574 + match->mode &= ~GR_DELETED;
71575 +
71576 + insert_acl_obj_label(match, subj);
71577 + }
71578 +
71579 + return;
71580 +}
71581 +
71582 +static void
71583 +update_acl_subj_label(const u64 oldinode, const dev_t olddevice,
71584 + const u64 newinode, const dev_t newdevice,
71585 + struct acl_role_label *role)
71586 +{
71587 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71588 + struct acl_subject_label *match;
71589 +
71590 + match = role->subj_hash[index];
71591 +
71592 + while (match && (match->inode != oldinode ||
71593 + match->device != olddevice ||
71594 + !(match->mode & GR_DELETED)))
71595 + match = match->next;
71596 +
71597 + if (match && (match->inode == oldinode)
71598 + && (match->device == olddevice)
71599 + && (match->mode & GR_DELETED)) {
71600 + if (match->prev == NULL) {
71601 + role->subj_hash[index] = match->next;
71602 + if (match->next != NULL)
71603 + match->next->prev = NULL;
71604 + } else {
71605 + match->prev->next = match->next;
71606 + if (match->next != NULL)
71607 + match->next->prev = match->prev;
71608 + }
71609 + match->prev = NULL;
71610 + match->next = NULL;
71611 + match->inode = newinode;
71612 + match->device = newdevice;
71613 + match->mode &= ~GR_DELETED;
71614 +
71615 + insert_acl_subj_label(match, role);
71616 + }
71617 +
71618 + return;
71619 +}
71620 +
71621 +static void
71622 +update_inodev_entry(const u64 oldinode, const dev_t olddevice,
71623 + const u64 newinode, const dev_t newdevice)
71624 +{
71625 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71626 + struct inodev_entry *match;
71627 +
71628 + match = running_polstate.inodev_set.i_hash[index];
71629 +
71630 + while (match && (match->nentry->inode != oldinode ||
71631 + match->nentry->device != olddevice || !match->nentry->deleted))
71632 + match = match->next;
71633 +
71634 + if (match && (match->nentry->inode == oldinode)
71635 + && (match->nentry->device == olddevice) &&
71636 + match->nentry->deleted) {
71637 + if (match->prev == NULL) {
71638 + running_polstate.inodev_set.i_hash[index] = match->next;
71639 + if (match->next != NULL)
71640 + match->next->prev = NULL;
71641 + } else {
71642 + match->prev->next = match->next;
71643 + if (match->next != NULL)
71644 + match->next->prev = match->prev;
71645 + }
71646 + match->prev = NULL;
71647 + match->next = NULL;
71648 + match->nentry->inode = newinode;
71649 + match->nentry->device = newdevice;
71650 + match->nentry->deleted = 0;
71651 +
71652 + insert_inodev_entry(match);
71653 + }
71654 +
71655 + return;
71656 +}
71657 +
71658 +static void
71659 +__do_handle_create(const struct name_entry *matchn, u64 ino, dev_t dev)
71660 +{
71661 + struct acl_subject_label *subj;
71662 + struct acl_role_label *role;
71663 + unsigned int x;
71664 +
71665 + FOR_EACH_ROLE_START(role)
71666 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71667 +
71668 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
71669 + if ((subj->inode == ino) && (subj->device == dev)) {
71670 + subj->inode = ino;
71671 + subj->device = dev;
71672 + }
71673 + /* nested subjects aren't in the role's subj_hash table */
71674 + update_acl_obj_label(matchn->inode, matchn->device,
71675 + ino, dev, subj);
71676 + FOR_EACH_NESTED_SUBJECT_END(subj)
71677 + FOR_EACH_SUBJECT_START(role, subj, x)
71678 + update_acl_obj_label(matchn->inode, matchn->device,
71679 + ino, dev, subj);
71680 + FOR_EACH_SUBJECT_END(subj,x)
71681 + FOR_EACH_ROLE_END(role)
71682 +
71683 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71684 +
71685 + return;
71686 +}
71687 +
71688 +static void
71689 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71690 + const struct vfsmount *mnt)
71691 +{
71692 + u64 ino = __get_ino(dentry);
71693 + dev_t dev = __get_dev(dentry);
71694 +
71695 + __do_handle_create(matchn, ino, dev);
71696 +
71697 + return;
71698 +}
71699 +
71700 +void
71701 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71702 +{
71703 + struct name_entry *matchn;
71704 +
71705 + if (unlikely(!(gr_status & GR_READY)))
71706 + return;
71707 +
71708 + preempt_disable();
71709 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71710 +
71711 + if (unlikely((unsigned long)matchn)) {
71712 + write_lock(&gr_inode_lock);
71713 + do_handle_create(matchn, dentry, mnt);
71714 + write_unlock(&gr_inode_lock);
71715 + }
71716 + preempt_enable();
71717 +
71718 + return;
71719 +}
71720 +
71721 +void
71722 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71723 +{
71724 + struct name_entry *matchn;
71725 +
71726 + if (unlikely(!(gr_status & GR_READY)))
71727 + return;
71728 +
71729 + preempt_disable();
71730 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71731 +
71732 + if (unlikely((unsigned long)matchn)) {
71733 + write_lock(&gr_inode_lock);
71734 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71735 + write_unlock(&gr_inode_lock);
71736 + }
71737 + preempt_enable();
71738 +
71739 + return;
71740 +}
71741 +
71742 +void
71743 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71744 + struct dentry *old_dentry,
71745 + struct dentry *new_dentry,
71746 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71747 +{
71748 + struct name_entry *matchn;
71749 + struct name_entry *matchn2 = NULL;
71750 + struct inodev_entry *inodev;
71751 + struct inode *inode = new_dentry->d_inode;
71752 + u64 old_ino = __get_ino(old_dentry);
71753 + dev_t old_dev = __get_dev(old_dentry);
71754 + unsigned int exchange = flags & RENAME_EXCHANGE;
71755 +
71756 + /* vfs_rename swaps the name and parent link for old_dentry and
71757 + new_dentry
71758 + at this point, old_dentry has the new name, parent link, and inode
71759 + for the renamed file
71760 + if a file is being replaced by a rename, new_dentry has the inode
71761 + and name for the replaced file
71762 + */
71763 +
71764 + if (unlikely(!(gr_status & GR_READY)))
71765 + return;
71766 +
71767 + preempt_disable();
71768 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71769 +
71770 + /* exchange cases:
71771 + a filename exists for the source, but not dest
71772 + do a recreate on source
71773 + a filename exists for the dest, but not source
71774 + do a recreate on dest
71775 + a filename exists for both source and dest
71776 + delete source and dest, then create source and dest
71777 + a filename exists for neither source nor dest
71778 + no updates needed
71779 +
71780 + the name entry lookups get us the old inode/dev associated with
71781 + each name, so do the deletes first (if possible) so that when
71782 + we do the create, we pick up on the right entries
71783 + */
71784 +
71785 + if (exchange)
71786 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71787 +
71788 + /* we wouldn't have to check d_inode if it weren't for
71789 + NFS silly-renaming
71790 + */
71791 +
71792 + write_lock(&gr_inode_lock);
71793 + if (unlikely((replace || exchange) && inode)) {
71794 + u64 new_ino = __get_ino(new_dentry);
71795 + dev_t new_dev = __get_dev(new_dentry);
71796 +
71797 + inodev = lookup_inodev_entry(new_ino, new_dev);
71798 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71799 + do_handle_delete(inodev, new_ino, new_dev);
71800 + }
71801 +
71802 + inodev = lookup_inodev_entry(old_ino, old_dev);
71803 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71804 + do_handle_delete(inodev, old_ino, old_dev);
71805 +
71806 + if (unlikely(matchn != NULL))
71807 + do_handle_create(matchn, old_dentry, mnt);
71808 +
71809 + if (unlikely(matchn2 != NULL))
71810 + do_handle_create(matchn2, new_dentry, mnt);
71811 +
71812 + write_unlock(&gr_inode_lock);
71813 + preempt_enable();
71814 +
71815 + return;
71816 +}
71817 +
71818 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71819 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71820 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71821 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71822 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71823 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71824 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71825 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71826 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71827 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71828 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71829 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71830 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71831 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71832 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71833 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71834 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71835 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71836 +};
71837 +
71838 +void
71839 +gr_learn_resource(const struct task_struct *task,
71840 + const int res, const unsigned long wanted, const int gt)
71841 +{
71842 + struct acl_subject_label *acl;
71843 + const struct cred *cred;
71844 +
71845 + if (unlikely((gr_status & GR_READY) &&
71846 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71847 + goto skip_reslog;
71848 +
71849 + gr_log_resource(task, res, wanted, gt);
71850 +skip_reslog:
71851 +
71852 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71853 + return;
71854 +
71855 + acl = task->acl;
71856 +
71857 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71858 + !(acl->resmask & (1U << (unsigned short) res))))
71859 + return;
71860 +
71861 + if (wanted >= acl->res[res].rlim_cur) {
71862 + unsigned long res_add;
71863 +
71864 + res_add = wanted + res_learn_bumps[res];
71865 +
71866 + acl->res[res].rlim_cur = res_add;
71867 +
71868 + if (wanted > acl->res[res].rlim_max)
71869 + acl->res[res].rlim_max = res_add;
71870 +
71871 + /* only log the subject filename, since resource logging is supported for
71872 + single-subject learning only */
71873 + rcu_read_lock();
71874 + cred = __task_cred(task);
71875 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71876 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71877 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71878 + "", (unsigned long) res, &task->signal->saved_ip);
71879 + rcu_read_unlock();
71880 + }
71881 +
71882 + return;
71883 +}
71884 +EXPORT_SYMBOL_GPL(gr_learn_resource);
71885 +#endif
71886 +
71887 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71888 +void
71889 +pax_set_initial_flags(struct linux_binprm *bprm)
71890 +{
71891 + struct task_struct *task = current;
71892 + struct acl_subject_label *proc;
71893 + unsigned long flags;
71894 +
71895 + if (unlikely(!(gr_status & GR_READY)))
71896 + return;
71897 +
71898 + flags = pax_get_flags(task);
71899 +
71900 + proc = task->acl;
71901 +
71902 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71903 + flags &= ~MF_PAX_PAGEEXEC;
71904 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71905 + flags &= ~MF_PAX_SEGMEXEC;
71906 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71907 + flags &= ~MF_PAX_RANDMMAP;
71908 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71909 + flags &= ~MF_PAX_EMUTRAMP;
71910 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71911 + flags &= ~MF_PAX_MPROTECT;
71912 +
71913 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71914 + flags |= MF_PAX_PAGEEXEC;
71915 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71916 + flags |= MF_PAX_SEGMEXEC;
71917 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71918 + flags |= MF_PAX_RANDMMAP;
71919 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71920 + flags |= MF_PAX_EMUTRAMP;
71921 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71922 + flags |= MF_PAX_MPROTECT;
71923 +
71924 + pax_set_flags(task, flags);
71925 +
71926 + return;
71927 +}
71928 +#endif
71929 +
71930 +int
71931 +gr_handle_proc_ptrace(struct task_struct *task)
71932 +{
71933 + struct file *filp;
71934 + struct task_struct *tmp = task;
71935 + struct task_struct *curtemp = current;
71936 + __u32 retmode;
71937 +
71938 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71939 + if (unlikely(!(gr_status & GR_READY)))
71940 + return 0;
71941 +#endif
71942 +
71943 + read_lock(&tasklist_lock);
71944 + read_lock(&grsec_exec_file_lock);
71945 + filp = task->exec_file;
71946 +
71947 + while (task_pid_nr(tmp) > 0) {
71948 + if (tmp == curtemp)
71949 + break;
71950 + tmp = tmp->real_parent;
71951 + }
71952 +
71953 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71954 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71955 + read_unlock(&grsec_exec_file_lock);
71956 + read_unlock(&tasklist_lock);
71957 + return 1;
71958 + }
71959 +
71960 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71961 + if (!(gr_status & GR_READY)) {
71962 + read_unlock(&grsec_exec_file_lock);
71963 + read_unlock(&tasklist_lock);
71964 + return 0;
71965 + }
71966 +#endif
71967 +
71968 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71969 + read_unlock(&grsec_exec_file_lock);
71970 + read_unlock(&tasklist_lock);
71971 +
71972 + if (retmode & GR_NOPTRACE)
71973 + return 1;
71974 +
71975 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71976 + && (current->acl != task->acl || (current->acl != current->role->root_label
71977 + && task_pid_nr(current) != task_pid_nr(task))))
71978 + return 1;
71979 +
71980 + return 0;
71981 +}
71982 +
71983 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71984 +{
71985 + if (unlikely(!(gr_status & GR_READY)))
71986 + return;
71987 +
71988 + if (!(current->role->roletype & GR_ROLE_GOD))
71989 + return;
71990 +
71991 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71992 + p->role->rolename, gr_task_roletype_to_char(p),
71993 + p->acl->filename);
71994 +}
71995 +
71996 +int
71997 +gr_handle_ptrace(struct task_struct *task, const long request)
71998 +{
71999 + struct task_struct *tmp = task;
72000 + struct task_struct *curtemp = current;
72001 + __u32 retmode;
72002 +
72003 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72004 + if (unlikely(!(gr_status & GR_READY)))
72005 + return 0;
72006 +#endif
72007 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72008 + read_lock(&tasklist_lock);
72009 + while (task_pid_nr(tmp) > 0) {
72010 + if (tmp == curtemp)
72011 + break;
72012 + tmp = tmp->real_parent;
72013 + }
72014 +
72015 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72016 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72017 + read_unlock(&tasklist_lock);
72018 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72019 + return 1;
72020 + }
72021 + read_unlock(&tasklist_lock);
72022 + }
72023 +
72024 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72025 + if (!(gr_status & GR_READY))
72026 + return 0;
72027 +#endif
72028 +
72029 + read_lock(&grsec_exec_file_lock);
72030 + if (unlikely(!task->exec_file)) {
72031 + read_unlock(&grsec_exec_file_lock);
72032 + return 0;
72033 + }
72034 +
72035 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72036 + read_unlock(&grsec_exec_file_lock);
72037 +
72038 + if (retmode & GR_NOPTRACE) {
72039 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72040 + return 1;
72041 + }
72042 +
72043 + if (retmode & GR_PTRACERD) {
72044 + switch (request) {
72045 + case PTRACE_SEIZE:
72046 + case PTRACE_POKETEXT:
72047 + case PTRACE_POKEDATA:
72048 + case PTRACE_POKEUSR:
72049 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72050 + case PTRACE_SETREGS:
72051 + case PTRACE_SETFPREGS:
72052 +#endif
72053 +#ifdef CONFIG_X86
72054 + case PTRACE_SETFPXREGS:
72055 +#endif
72056 +#ifdef CONFIG_ALTIVEC
72057 + case PTRACE_SETVRREGS:
72058 +#endif
72059 + return 1;
72060 + default:
72061 + return 0;
72062 + }
72063 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
72064 + !(current->role->roletype & GR_ROLE_GOD) &&
72065 + (current->acl != task->acl)) {
72066 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72067 + return 1;
72068 + }
72069 +
72070 + return 0;
72071 +}
72072 +
72073 +static int is_writable_mmap(const struct file *filp)
72074 +{
72075 + struct task_struct *task = current;
72076 + struct acl_object_label *obj, *obj2;
72077 +
72078 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72079 + !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))) {
72080 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72081 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72082 + task->role->root_label);
72083 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72084 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72085 + return 1;
72086 + }
72087 + }
72088 + return 0;
72089 +}
72090 +
72091 +int
72092 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72093 +{
72094 + __u32 mode;
72095 +
72096 + if (unlikely(!file || !(prot & PROT_EXEC)))
72097 + return 1;
72098 +
72099 + if (is_writable_mmap(file))
72100 + return 0;
72101 +
72102 + mode =
72103 + gr_search_file(file->f_path.dentry,
72104 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72105 + file->f_path.mnt);
72106 +
72107 + if (!gr_tpe_allow(file))
72108 + return 0;
72109 +
72110 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72111 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72112 + return 0;
72113 + } else if (unlikely(!(mode & GR_EXEC))) {
72114 + return 0;
72115 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72116 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72117 + return 1;
72118 + }
72119 +
72120 + return 1;
72121 +}
72122 +
72123 +int
72124 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72125 +{
72126 + __u32 mode;
72127 +
72128 + if (unlikely(!file || !(prot & PROT_EXEC)))
72129 + return 1;
72130 +
72131 + if (is_writable_mmap(file))
72132 + return 0;
72133 +
72134 + mode =
72135 + gr_search_file(file->f_path.dentry,
72136 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72137 + file->f_path.mnt);
72138 +
72139 + if (!gr_tpe_allow(file))
72140 + return 0;
72141 +
72142 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72143 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72144 + return 0;
72145 + } else if (unlikely(!(mode & GR_EXEC))) {
72146 + return 0;
72147 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72148 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72149 + return 1;
72150 + }
72151 +
72152 + return 1;
72153 +}
72154 +
72155 +void
72156 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72157 +{
72158 + unsigned long runtime, cputime;
72159 + cputime_t utime, stime;
72160 + unsigned int wday, cday;
72161 + __u8 whr, chr;
72162 + __u8 wmin, cmin;
72163 + __u8 wsec, csec;
72164 + struct timespec curtime, starttime;
72165 +
72166 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72167 + !(task->acl->mode & GR_PROCACCT)))
72168 + return;
72169 +
72170 + curtime = ns_to_timespec(ktime_get_ns());
72171 + starttime = ns_to_timespec(task->start_time);
72172 + runtime = curtime.tv_sec - starttime.tv_sec;
72173 + wday = runtime / (60 * 60 * 24);
72174 + runtime -= wday * (60 * 60 * 24);
72175 + whr = runtime / (60 * 60);
72176 + runtime -= whr * (60 * 60);
72177 + wmin = runtime / 60;
72178 + runtime -= wmin * 60;
72179 + wsec = runtime;
72180 +
72181 + task_cputime(task, &utime, &stime);
72182 + cputime = cputime_to_secs(utime + stime);
72183 + cday = cputime / (60 * 60 * 24);
72184 + cputime -= cday * (60 * 60 * 24);
72185 + chr = cputime / (60 * 60);
72186 + cputime -= chr * (60 * 60);
72187 + cmin = cputime / 60;
72188 + cputime -= cmin * 60;
72189 + csec = cputime;
72190 +
72191 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72192 +
72193 + return;
72194 +}
72195 +
72196 +#ifdef CONFIG_TASKSTATS
72197 +int gr_is_taskstats_denied(int pid)
72198 +{
72199 + struct task_struct *task;
72200 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72201 + const struct cred *cred;
72202 +#endif
72203 + int ret = 0;
72204 +
72205 + /* restrict taskstats viewing to un-chrooted root users
72206 + who have the 'view' subject flag if the RBAC system is enabled
72207 + */
72208 +
72209 + rcu_read_lock();
72210 + read_lock(&tasklist_lock);
72211 + task = find_task_by_vpid(pid);
72212 + if (task) {
72213 +#ifdef CONFIG_GRKERNSEC_CHROOT
72214 + if (proc_is_chrooted(task))
72215 + ret = -EACCES;
72216 +#endif
72217 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72218 + cred = __task_cred(task);
72219 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72220 + if (gr_is_global_nonroot(cred->uid))
72221 + ret = -EACCES;
72222 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72223 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72224 + ret = -EACCES;
72225 +#endif
72226 +#endif
72227 + if (gr_status & GR_READY) {
72228 + if (!(task->acl->mode & GR_VIEW))
72229 + ret = -EACCES;
72230 + }
72231 + } else
72232 + ret = -ENOENT;
72233 +
72234 + read_unlock(&tasklist_lock);
72235 + rcu_read_unlock();
72236 +
72237 + return ret;
72238 +}
72239 +#endif
72240 +
72241 +/* AUXV entries are filled via a descendant of search_binary_handler
72242 + after we've already applied the subject for the target
72243 +*/
72244 +int gr_acl_enable_at_secure(void)
72245 +{
72246 + if (unlikely(!(gr_status & GR_READY)))
72247 + return 0;
72248 +
72249 + if (current->acl->mode & GR_ATSECURE)
72250 + return 1;
72251 +
72252 + return 0;
72253 +}
72254 +
72255 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const u64 ino)
72256 +{
72257 + struct task_struct *task = current;
72258 + struct dentry *dentry = file->f_path.dentry;
72259 + struct vfsmount *mnt = file->f_path.mnt;
72260 + struct acl_object_label *obj, *tmp;
72261 + struct acl_subject_label *subj;
72262 + unsigned int bufsize;
72263 + int is_not_root;
72264 + char *path;
72265 + dev_t dev = __get_dev(dentry);
72266 +
72267 + if (unlikely(!(gr_status & GR_READY)))
72268 + return 1;
72269 +
72270 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72271 + return 1;
72272 +
72273 + /* ignore Eric Biederman */
72274 + if (IS_PRIVATE(dentry->d_inode))
72275 + return 1;
72276 +
72277 + subj = task->acl;
72278 + read_lock(&gr_inode_lock);
72279 + do {
72280 + obj = lookup_acl_obj_label(ino, dev, subj);
72281 + if (obj != NULL) {
72282 + read_unlock(&gr_inode_lock);
72283 + return (obj->mode & GR_FIND) ? 1 : 0;
72284 + }
72285 + } while ((subj = subj->parent_subject));
72286 + read_unlock(&gr_inode_lock);
72287 +
72288 + /* this is purely an optimization since we're looking for an object
72289 + for the directory we're doing a readdir on
72290 + if it's possible for any globbed object to match the entry we're
72291 + filling into the directory, then the object we find here will be
72292 + an anchor point with attached globbed objects
72293 + */
72294 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72295 + if (obj->globbed == NULL)
72296 + return (obj->mode & GR_FIND) ? 1 : 0;
72297 +
72298 + is_not_root = ((obj->filename[0] == '/') &&
72299 + (obj->filename[1] == '\0')) ? 0 : 1;
72300 + bufsize = PAGE_SIZE - namelen - is_not_root;
72301 +
72302 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
72303 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72304 + return 1;
72305 +
72306 + preempt_disable();
72307 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72308 + bufsize);
72309 +
72310 + bufsize = strlen(path);
72311 +
72312 + /* if base is "/", don't append an additional slash */
72313 + if (is_not_root)
72314 + *(path + bufsize) = '/';
72315 + memcpy(path + bufsize + is_not_root, name, namelen);
72316 + *(path + bufsize + namelen + is_not_root) = '\0';
72317 +
72318 + tmp = obj->globbed;
72319 + while (tmp) {
72320 + if (!glob_match(tmp->filename, path)) {
72321 + preempt_enable();
72322 + return (tmp->mode & GR_FIND) ? 1 : 0;
72323 + }
72324 + tmp = tmp->next;
72325 + }
72326 + preempt_enable();
72327 + return (obj->mode & GR_FIND) ? 1 : 0;
72328 +}
72329 +
72330 +void gr_put_exec_file(struct task_struct *task)
72331 +{
72332 + struct file *filp;
72333 +
72334 + write_lock(&grsec_exec_file_lock);
72335 + filp = task->exec_file;
72336 + task->exec_file = NULL;
72337 + write_unlock(&grsec_exec_file_lock);
72338 +
72339 + if (filp)
72340 + fput(filp);
72341 +
72342 + return;
72343 +}
72344 +
72345 +
72346 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72347 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72348 +#endif
72349 +#ifdef CONFIG_SECURITY
72350 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72351 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72352 +#endif
72353 +
72354 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72355 new file mode 100644
72356 index 0000000..18ffbbd
72357 --- /dev/null
72358 +++ b/grsecurity/gracl_alloc.c
72359 @@ -0,0 +1,105 @@
72360 +#include <linux/kernel.h>
72361 +#include <linux/mm.h>
72362 +#include <linux/slab.h>
72363 +#include <linux/vmalloc.h>
72364 +#include <linux/gracl.h>
72365 +#include <linux/grsecurity.h>
72366 +
72367 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72368 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72369 +
72370 +static __inline__ int
72371 +alloc_pop(void)
72372 +{
72373 + if (current_alloc_state->alloc_stack_next == 1)
72374 + return 0;
72375 +
72376 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72377 +
72378 + current_alloc_state->alloc_stack_next--;
72379 +
72380 + return 1;
72381 +}
72382 +
72383 +static __inline__ int
72384 +alloc_push(void *buf)
72385 +{
72386 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72387 + return 1;
72388 +
72389 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72390 +
72391 + current_alloc_state->alloc_stack_next++;
72392 +
72393 + return 0;
72394 +}
72395 +
72396 +void *
72397 +acl_alloc(unsigned long len)
72398 +{
72399 + void *ret = NULL;
72400 +
72401 + if (!len || len > PAGE_SIZE)
72402 + goto out;
72403 +
72404 + ret = kmalloc(len, GFP_KERNEL);
72405 +
72406 + if (ret) {
72407 + if (alloc_push(ret)) {
72408 + kfree(ret);
72409 + ret = NULL;
72410 + }
72411 + }
72412 +
72413 +out:
72414 + return ret;
72415 +}
72416 +
72417 +void *
72418 +acl_alloc_num(unsigned long num, unsigned long len)
72419 +{
72420 + if (!len || (num > (PAGE_SIZE / len)))
72421 + return NULL;
72422 +
72423 + return acl_alloc(num * len);
72424 +}
72425 +
72426 +void
72427 +acl_free_all(void)
72428 +{
72429 + if (!current_alloc_state->alloc_stack)
72430 + return;
72431 +
72432 + while (alloc_pop()) ;
72433 +
72434 + if (current_alloc_state->alloc_stack) {
72435 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72436 + kfree(current_alloc_state->alloc_stack);
72437 + else
72438 + vfree(current_alloc_state->alloc_stack);
72439 + }
72440 +
72441 + current_alloc_state->alloc_stack = NULL;
72442 + current_alloc_state->alloc_stack_size = 1;
72443 + current_alloc_state->alloc_stack_next = 1;
72444 +
72445 + return;
72446 +}
72447 +
72448 +int
72449 +acl_alloc_stack_init(unsigned long size)
72450 +{
72451 + if ((size * sizeof (void *)) <= PAGE_SIZE)
72452 + current_alloc_state->alloc_stack =
72453 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72454 + else
72455 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72456 +
72457 + current_alloc_state->alloc_stack_size = size;
72458 + current_alloc_state->alloc_stack_next = 1;
72459 +
72460 + if (!current_alloc_state->alloc_stack)
72461 + return 0;
72462 + else
72463 + return 1;
72464 +}
72465 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72466 new file mode 100644
72467 index 0000000..1a94c11
72468 --- /dev/null
72469 +++ b/grsecurity/gracl_cap.c
72470 @@ -0,0 +1,127 @@
72471 +#include <linux/kernel.h>
72472 +#include <linux/module.h>
72473 +#include <linux/sched.h>
72474 +#include <linux/gracl.h>
72475 +#include <linux/grsecurity.h>
72476 +#include <linux/grinternal.h>
72477 +
72478 +extern const char *captab_log[];
72479 +extern int captab_log_entries;
72480 +
72481 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72482 +{
72483 + struct acl_subject_label *curracl;
72484 +
72485 + if (!gr_acl_is_enabled())
72486 + return 1;
72487 +
72488 + curracl = task->acl;
72489 +
72490 + if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72491 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72492 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
72493 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
72494 + gr_to_filename(task->exec_file->f_path.dentry,
72495 + task->exec_file->f_path.mnt) : curracl->filename,
72496 + curracl->filename, 0UL,
72497 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72498 + return 1;
72499 + }
72500 +
72501 + return 0;
72502 +}
72503 +
72504 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72505 +{
72506 + struct acl_subject_label *curracl;
72507 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72508 + kernel_cap_t cap_audit = __cap_empty_set;
72509 +
72510 + if (!gr_acl_is_enabled())
72511 + return 1;
72512 +
72513 + curracl = task->acl;
72514 +
72515 + cap_drop = curracl->cap_lower;
72516 + cap_mask = curracl->cap_mask;
72517 + cap_audit = curracl->cap_invert_audit;
72518 +
72519 + while ((curracl = curracl->parent_subject)) {
72520 + /* if the cap isn't specified in the current computed mask but is specified in the
72521 + current level subject, and is lowered in the current level subject, then add
72522 + it to the set of dropped capabilities
72523 + otherwise, add the current level subject's mask to the current computed mask
72524 + */
72525 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72526 + cap_raise(cap_mask, cap);
72527 + if (cap_raised(curracl->cap_lower, cap))
72528 + cap_raise(cap_drop, cap);
72529 + if (cap_raised(curracl->cap_invert_audit, cap))
72530 + cap_raise(cap_audit, cap);
72531 + }
72532 + }
72533 +
72534 + if (!cap_raised(cap_drop, cap)) {
72535 + if (cap_raised(cap_audit, cap))
72536 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72537 + return 1;
72538 + }
72539 +
72540 + /* only learn the capability use if the process has the capability in the
72541 + general case, the two uses in sys.c of gr_learn_cap are an exception
72542 + to this rule to ensure any role transition involves what the full-learned
72543 + policy believes in a privileged process
72544 + */
72545 + if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72546 + return 1;
72547 +
72548 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72549 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72550 +
72551 + return 0;
72552 +}
72553 +
72554 +int
72555 +gr_acl_is_capable(const int cap)
72556 +{
72557 + return gr_task_acl_is_capable(current, current_cred(), cap);
72558 +}
72559 +
72560 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72561 +{
72562 + struct acl_subject_label *curracl;
72563 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72564 +
72565 + if (!gr_acl_is_enabled())
72566 + return 1;
72567 +
72568 + curracl = task->acl;
72569 +
72570 + cap_drop = curracl->cap_lower;
72571 + cap_mask = curracl->cap_mask;
72572 +
72573 + while ((curracl = curracl->parent_subject)) {
72574 + /* if the cap isn't specified in the current computed mask but is specified in the
72575 + current level subject, and is lowered in the current level subject, then add
72576 + it to the set of dropped capabilities
72577 + otherwise, add the current level subject's mask to the current computed mask
72578 + */
72579 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72580 + cap_raise(cap_mask, cap);
72581 + if (cap_raised(curracl->cap_lower, cap))
72582 + cap_raise(cap_drop, cap);
72583 + }
72584 + }
72585 +
72586 + if (!cap_raised(cap_drop, cap))
72587 + return 1;
72588 +
72589 + return 0;
72590 +}
72591 +
72592 +int
72593 +gr_acl_is_capable_nolog(const int cap)
72594 +{
72595 + return gr_task_acl_is_capable_nolog(current, cap);
72596 +}
72597 +
72598 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72599 new file mode 100644
72600 index 0000000..a43dd06
72601 --- /dev/null
72602 +++ b/grsecurity/gracl_compat.c
72603 @@ -0,0 +1,269 @@
72604 +#include <linux/kernel.h>
72605 +#include <linux/gracl.h>
72606 +#include <linux/compat.h>
72607 +#include <linux/gracl_compat.h>
72608 +
72609 +#include <asm/uaccess.h>
72610 +
72611 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72612 +{
72613 + struct gr_arg_wrapper_compat uwrapcompat;
72614 +
72615 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72616 + return -EFAULT;
72617 +
72618 + if ((uwrapcompat.version != GRSECURITY_VERSION) ||
72619 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72620 + return -EINVAL;
72621 +
72622 + uwrap->arg = compat_ptr(uwrapcompat.arg);
72623 + uwrap->version = uwrapcompat.version;
72624 + uwrap->size = sizeof(struct gr_arg);
72625 +
72626 + return 0;
72627 +}
72628 +
72629 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72630 +{
72631 + struct gr_arg_compat argcompat;
72632 +
72633 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72634 + return -EFAULT;
72635 +
72636 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72637 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72638 + arg->role_db.num_roles = argcompat.role_db.num_roles;
72639 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72640 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72641 + arg->role_db.num_objects = argcompat.role_db.num_objects;
72642 +
72643 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72644 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72645 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72646 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72647 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72648 + arg->segv_device = argcompat.segv_device;
72649 + arg->segv_inode = argcompat.segv_inode;
72650 + arg->segv_uid = argcompat.segv_uid;
72651 + arg->num_sprole_pws = argcompat.num_sprole_pws;
72652 + arg->mode = argcompat.mode;
72653 +
72654 + return 0;
72655 +}
72656 +
72657 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72658 +{
72659 + struct acl_object_label_compat objcompat;
72660 +
72661 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72662 + return -EFAULT;
72663 +
72664 + obj->filename = compat_ptr(objcompat.filename);
72665 + obj->inode = objcompat.inode;
72666 + obj->device = objcompat.device;
72667 + obj->mode = objcompat.mode;
72668 +
72669 + obj->nested = compat_ptr(objcompat.nested);
72670 + obj->globbed = compat_ptr(objcompat.globbed);
72671 +
72672 + obj->prev = compat_ptr(objcompat.prev);
72673 + obj->next = compat_ptr(objcompat.next);
72674 +
72675 + return 0;
72676 +}
72677 +
72678 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72679 +{
72680 + unsigned int i;
72681 + struct acl_subject_label_compat subjcompat;
72682 +
72683 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72684 + return -EFAULT;
72685 +
72686 + subj->filename = compat_ptr(subjcompat.filename);
72687 + subj->inode = subjcompat.inode;
72688 + subj->device = subjcompat.device;
72689 + subj->mode = subjcompat.mode;
72690 + subj->cap_mask = subjcompat.cap_mask;
72691 + subj->cap_lower = subjcompat.cap_lower;
72692 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
72693 +
72694 + for (i = 0; i < GR_NLIMITS; i++) {
72695 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72696 + subj->res[i].rlim_cur = RLIM_INFINITY;
72697 + else
72698 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72699 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72700 + subj->res[i].rlim_max = RLIM_INFINITY;
72701 + else
72702 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72703 + }
72704 + subj->resmask = subjcompat.resmask;
72705 +
72706 + subj->user_trans_type = subjcompat.user_trans_type;
72707 + subj->group_trans_type = subjcompat.group_trans_type;
72708 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72709 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72710 + subj->user_trans_num = subjcompat.user_trans_num;
72711 + subj->group_trans_num = subjcompat.group_trans_num;
72712 +
72713 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72714 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72715 + subj->ip_type = subjcompat.ip_type;
72716 + subj->ips = compat_ptr(subjcompat.ips);
72717 + subj->ip_num = subjcompat.ip_num;
72718 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
72719 +
72720 + subj->crashes = subjcompat.crashes;
72721 + subj->expires = subjcompat.expires;
72722 +
72723 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72724 + subj->hash = compat_ptr(subjcompat.hash);
72725 + subj->prev = compat_ptr(subjcompat.prev);
72726 + subj->next = compat_ptr(subjcompat.next);
72727 +
72728 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72729 + subj->obj_hash_size = subjcompat.obj_hash_size;
72730 + subj->pax_flags = subjcompat.pax_flags;
72731 +
72732 + return 0;
72733 +}
72734 +
72735 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72736 +{
72737 + struct acl_role_label_compat rolecompat;
72738 +
72739 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72740 + return -EFAULT;
72741 +
72742 + role->rolename = compat_ptr(rolecompat.rolename);
72743 + role->uidgid = rolecompat.uidgid;
72744 + role->roletype = rolecompat.roletype;
72745 +
72746 + role->auth_attempts = rolecompat.auth_attempts;
72747 + role->expires = rolecompat.expires;
72748 +
72749 + role->root_label = compat_ptr(rolecompat.root_label);
72750 + role->hash = compat_ptr(rolecompat.hash);
72751 +
72752 + role->prev = compat_ptr(rolecompat.prev);
72753 + role->next = compat_ptr(rolecompat.next);
72754 +
72755 + role->transitions = compat_ptr(rolecompat.transitions);
72756 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72757 + role->domain_children = compat_ptr(rolecompat.domain_children);
72758 + role->domain_child_num = rolecompat.domain_child_num;
72759 +
72760 + role->umask = rolecompat.umask;
72761 +
72762 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
72763 + role->subj_hash_size = rolecompat.subj_hash_size;
72764 +
72765 + return 0;
72766 +}
72767 +
72768 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72769 +{
72770 + struct role_allowed_ip_compat roleip_compat;
72771 +
72772 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72773 + return -EFAULT;
72774 +
72775 + roleip->addr = roleip_compat.addr;
72776 + roleip->netmask = roleip_compat.netmask;
72777 +
72778 + roleip->prev = compat_ptr(roleip_compat.prev);
72779 + roleip->next = compat_ptr(roleip_compat.next);
72780 +
72781 + return 0;
72782 +}
72783 +
72784 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72785 +{
72786 + struct role_transition_compat trans_compat;
72787 +
72788 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72789 + return -EFAULT;
72790 +
72791 + trans->rolename = compat_ptr(trans_compat.rolename);
72792 +
72793 + trans->prev = compat_ptr(trans_compat.prev);
72794 + trans->next = compat_ptr(trans_compat.next);
72795 +
72796 + return 0;
72797 +
72798 +}
72799 +
72800 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72801 +{
72802 + struct gr_hash_struct_compat hash_compat;
72803 +
72804 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72805 + return -EFAULT;
72806 +
72807 + hash->table = compat_ptr(hash_compat.table);
72808 + hash->nametable = compat_ptr(hash_compat.nametable);
72809 + hash->first = compat_ptr(hash_compat.first);
72810 +
72811 + hash->table_size = hash_compat.table_size;
72812 + hash->used_size = hash_compat.used_size;
72813 +
72814 + hash->type = hash_compat.type;
72815 +
72816 + return 0;
72817 +}
72818 +
72819 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72820 +{
72821 + compat_uptr_t ptrcompat;
72822 +
72823 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72824 + return -EFAULT;
72825 +
72826 + *(void **)ptr = compat_ptr(ptrcompat);
72827 +
72828 + return 0;
72829 +}
72830 +
72831 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72832 +{
72833 + struct acl_ip_label_compat ip_compat;
72834 +
72835 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72836 + return -EFAULT;
72837 +
72838 + ip->iface = compat_ptr(ip_compat.iface);
72839 + ip->addr = ip_compat.addr;
72840 + ip->netmask = ip_compat.netmask;
72841 + ip->low = ip_compat.low;
72842 + ip->high = ip_compat.high;
72843 + ip->mode = ip_compat.mode;
72844 + ip->type = ip_compat.type;
72845 +
72846 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72847 +
72848 + ip->prev = compat_ptr(ip_compat.prev);
72849 + ip->next = compat_ptr(ip_compat.next);
72850 +
72851 + return 0;
72852 +}
72853 +
72854 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72855 +{
72856 + struct sprole_pw_compat pw_compat;
72857 +
72858 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72859 + return -EFAULT;
72860 +
72861 + pw->rolename = compat_ptr(pw_compat.rolename);
72862 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72863 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72864 +
72865 + return 0;
72866 +}
72867 +
72868 +size_t get_gr_arg_wrapper_size_compat(void)
72869 +{
72870 + return sizeof(struct gr_arg_wrapper_compat);
72871 +}
72872 +
72873 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72874 new file mode 100644
72875 index 0000000..8ee8e4f
72876 --- /dev/null
72877 +++ b/grsecurity/gracl_fs.c
72878 @@ -0,0 +1,447 @@
72879 +#include <linux/kernel.h>
72880 +#include <linux/sched.h>
72881 +#include <linux/types.h>
72882 +#include <linux/fs.h>
72883 +#include <linux/file.h>
72884 +#include <linux/stat.h>
72885 +#include <linux/grsecurity.h>
72886 +#include <linux/grinternal.h>
72887 +#include <linux/gracl.h>
72888 +
72889 +umode_t
72890 +gr_acl_umask(void)
72891 +{
72892 + if (unlikely(!gr_acl_is_enabled()))
72893 + return 0;
72894 +
72895 + return current->role->umask;
72896 +}
72897 +
72898 +__u32
72899 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72900 + const struct vfsmount * mnt)
72901 +{
72902 + __u32 mode;
72903 +
72904 + if (unlikely(d_is_negative(dentry)))
72905 + return GR_FIND;
72906 +
72907 + mode =
72908 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72909 +
72910 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72911 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72912 + return mode;
72913 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72914 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72915 + return 0;
72916 + } else if (unlikely(!(mode & GR_FIND)))
72917 + return 0;
72918 +
72919 + return GR_FIND;
72920 +}
72921 +
72922 +__u32
72923 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72924 + int acc_mode)
72925 +{
72926 + __u32 reqmode = GR_FIND;
72927 + __u32 mode;
72928 +
72929 + if (unlikely(d_is_negative(dentry)))
72930 + return reqmode;
72931 +
72932 + if (acc_mode & MAY_APPEND)
72933 + reqmode |= GR_APPEND;
72934 + else if (acc_mode & MAY_WRITE)
72935 + reqmode |= GR_WRITE;
72936 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72937 + reqmode |= GR_READ;
72938 +
72939 + mode =
72940 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72941 + mnt);
72942 +
72943 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72944 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72945 + reqmode & GR_READ ? " reading" : "",
72946 + reqmode & GR_WRITE ? " writing" : reqmode &
72947 + GR_APPEND ? " appending" : "");
72948 + return reqmode;
72949 + } else
72950 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72951 + {
72952 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72953 + reqmode & GR_READ ? " reading" : "",
72954 + reqmode & GR_WRITE ? " writing" : reqmode &
72955 + GR_APPEND ? " appending" : "");
72956 + return 0;
72957 + } else if (unlikely((mode & reqmode) != reqmode))
72958 + return 0;
72959 +
72960 + return reqmode;
72961 +}
72962 +
72963 +__u32
72964 +gr_acl_handle_creat(const struct dentry * dentry,
72965 + const struct dentry * p_dentry,
72966 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72967 + const int imode)
72968 +{
72969 + __u32 reqmode = GR_WRITE | GR_CREATE;
72970 + __u32 mode;
72971 +
72972 + if (acc_mode & MAY_APPEND)
72973 + reqmode |= GR_APPEND;
72974 + // if a directory was required or the directory already exists, then
72975 + // don't count this open as a read
72976 + if ((acc_mode & MAY_READ) &&
72977 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72978 + reqmode |= GR_READ;
72979 + if ((open_flags & O_CREAT) &&
72980 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72981 + reqmode |= GR_SETID;
72982 +
72983 + mode =
72984 + gr_check_create(dentry, p_dentry, p_mnt,
72985 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72986 +
72987 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72988 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72989 + reqmode & GR_READ ? " reading" : "",
72990 + reqmode & GR_WRITE ? " writing" : reqmode &
72991 + GR_APPEND ? " appending" : "");
72992 + return reqmode;
72993 + } else
72994 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72995 + {
72996 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72997 + reqmode & GR_READ ? " reading" : "",
72998 + reqmode & GR_WRITE ? " writing" : reqmode &
72999 + GR_APPEND ? " appending" : "");
73000 + return 0;
73001 + } else if (unlikely((mode & reqmode) != reqmode))
73002 + return 0;
73003 +
73004 + return reqmode;
73005 +}
73006 +
73007 +__u32
73008 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73009 + const int fmode)
73010 +{
73011 + __u32 mode, reqmode = GR_FIND;
73012 +
73013 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73014 + reqmode |= GR_EXEC;
73015 + if (fmode & S_IWOTH)
73016 + reqmode |= GR_WRITE;
73017 + if (fmode & S_IROTH)
73018 + reqmode |= GR_READ;
73019 +
73020 + mode =
73021 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73022 + mnt);
73023 +
73024 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73025 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73026 + reqmode & GR_READ ? " reading" : "",
73027 + reqmode & GR_WRITE ? " writing" : "",
73028 + reqmode & GR_EXEC ? " executing" : "");
73029 + return reqmode;
73030 + } else
73031 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73032 + {
73033 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73034 + reqmode & GR_READ ? " reading" : "",
73035 + reqmode & GR_WRITE ? " writing" : "",
73036 + reqmode & GR_EXEC ? " executing" : "");
73037 + return 0;
73038 + } else if (unlikely((mode & reqmode) != reqmode))
73039 + return 0;
73040 +
73041 + return reqmode;
73042 +}
73043 +
73044 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73045 +{
73046 + __u32 mode;
73047 +
73048 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73049 +
73050 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73051 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73052 + return mode;
73053 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73054 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73055 + return 0;
73056 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73057 + return 0;
73058 +
73059 + return (reqmode);
73060 +}
73061 +
73062 +__u32
73063 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73064 +{
73065 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73066 +}
73067 +
73068 +__u32
73069 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73070 +{
73071 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73072 +}
73073 +
73074 +__u32
73075 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73076 +{
73077 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73078 +}
73079 +
73080 +__u32
73081 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73082 +{
73083 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73084 +}
73085 +
73086 +__u32
73087 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73088 + umode_t *modeptr)
73089 +{
73090 + umode_t mode;
73091 +
73092 + *modeptr &= ~gr_acl_umask();
73093 + mode = *modeptr;
73094 +
73095 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73096 + return 1;
73097 +
73098 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73099 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73100 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73101 + GR_CHMOD_ACL_MSG);
73102 + } else {
73103 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73104 + }
73105 +}
73106 +
73107 +__u32
73108 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73109 +{
73110 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73111 +}
73112 +
73113 +__u32
73114 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73115 +{
73116 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73117 +}
73118 +
73119 +__u32
73120 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73121 +{
73122 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73123 +}
73124 +
73125 +__u32
73126 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73127 +{
73128 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73129 +}
73130 +
73131 +__u32
73132 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73133 +{
73134 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73135 + GR_UNIXCONNECT_ACL_MSG);
73136 +}
73137 +
73138 +/* hardlinks require at minimum create and link permission,
73139 + any additional privilege required is based on the
73140 + privilege of the file being linked to
73141 +*/
73142 +__u32
73143 +gr_acl_handle_link(const struct dentry * new_dentry,
73144 + const struct dentry * parent_dentry,
73145 + const struct vfsmount * parent_mnt,
73146 + const struct dentry * old_dentry,
73147 + const struct vfsmount * old_mnt, const struct filename *to)
73148 +{
73149 + __u32 mode;
73150 + __u32 needmode = GR_CREATE | GR_LINK;
73151 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73152 +
73153 + mode =
73154 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73155 + old_mnt);
73156 +
73157 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73158 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73159 + return mode;
73160 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73161 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73162 + return 0;
73163 + } else if (unlikely((mode & needmode) != needmode))
73164 + return 0;
73165 +
73166 + return 1;
73167 +}
73168 +
73169 +__u32
73170 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73171 + const struct dentry * parent_dentry,
73172 + const struct vfsmount * parent_mnt, const struct filename *from)
73173 +{
73174 + __u32 needmode = GR_WRITE | GR_CREATE;
73175 + __u32 mode;
73176 +
73177 + mode =
73178 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
73179 + GR_CREATE | GR_AUDIT_CREATE |
73180 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73181 +
73182 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73183 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73184 + return mode;
73185 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73186 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73187 + return 0;
73188 + } else if (unlikely((mode & needmode) != needmode))
73189 + return 0;
73190 +
73191 + return (GR_WRITE | GR_CREATE);
73192 +}
73193 +
73194 +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)
73195 +{
73196 + __u32 mode;
73197 +
73198 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73199 +
73200 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73201 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73202 + return mode;
73203 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73204 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73205 + return 0;
73206 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
73207 + return 0;
73208 +
73209 + return (reqmode);
73210 +}
73211 +
73212 +__u32
73213 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73214 + const struct dentry * parent_dentry,
73215 + const struct vfsmount * parent_mnt,
73216 + const int mode)
73217 +{
73218 + __u32 reqmode = GR_WRITE | GR_CREATE;
73219 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73220 + reqmode |= GR_SETID;
73221 +
73222 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73223 + reqmode, GR_MKNOD_ACL_MSG);
73224 +}
73225 +
73226 +__u32
73227 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
73228 + const struct dentry *parent_dentry,
73229 + const struct vfsmount *parent_mnt)
73230 +{
73231 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73232 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73233 +}
73234 +
73235 +#define RENAME_CHECK_SUCCESS(old, new) \
73236 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73237 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73238 +
73239 +int
73240 +gr_acl_handle_rename(struct dentry *new_dentry,
73241 + struct dentry *parent_dentry,
73242 + const struct vfsmount *parent_mnt,
73243 + struct dentry *old_dentry,
73244 + struct inode *old_parent_inode,
73245 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73246 +{
73247 + __u32 comp1, comp2;
73248 + int error = 0;
73249 +
73250 + if (unlikely(!gr_acl_is_enabled()))
73251 + return 0;
73252 +
73253 + if (flags & RENAME_EXCHANGE) {
73254 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73255 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73256 + GR_SUPPRESS, parent_mnt);
73257 + comp2 =
73258 + gr_search_file(old_dentry,
73259 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73260 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73261 + } else if (d_is_negative(new_dentry)) {
73262 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73263 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73264 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73265 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73266 + GR_DELETE | GR_AUDIT_DELETE |
73267 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73268 + GR_SUPPRESS, old_mnt);
73269 + } else {
73270 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73271 + GR_CREATE | GR_DELETE |
73272 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73273 + GR_AUDIT_READ | GR_AUDIT_WRITE |
73274 + GR_SUPPRESS, parent_mnt);
73275 + comp2 =
73276 + gr_search_file(old_dentry,
73277 + GR_READ | GR_WRITE | GR_AUDIT_READ |
73278 + GR_DELETE | GR_AUDIT_DELETE |
73279 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73280 + }
73281 +
73282 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73283 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73284 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73285 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73286 + && !(comp2 & GR_SUPPRESS)) {
73287 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73288 + error = -EACCES;
73289 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73290 + error = -EACCES;
73291 +
73292 + return error;
73293 +}
73294 +
73295 +void
73296 +gr_acl_handle_exit(void)
73297 +{
73298 + u16 id;
73299 + char *rolename;
73300 +
73301 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73302 + !(current->role->roletype & GR_ROLE_PERSIST))) {
73303 + id = current->acl_role_id;
73304 + rolename = current->role->rolename;
73305 + gr_set_acls(1);
73306 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73307 + }
73308 +
73309 + gr_put_exec_file(current);
73310 + return;
73311 +}
73312 +
73313 +int
73314 +gr_acl_handle_procpidmem(const struct task_struct *task)
73315 +{
73316 + if (unlikely(!gr_acl_is_enabled()))
73317 + return 0;
73318 +
73319 + if (task != current && (task->acl->mode & GR_PROTPROCFD) &&
73320 + !(current->acl->mode & GR_POVERRIDE) &&
73321 + !(current->role->roletype & GR_ROLE_GOD))
73322 + return -EACCES;
73323 +
73324 + return 0;
73325 +}
73326 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73327 new file mode 100644
73328 index 0000000..f056b81
73329 --- /dev/null
73330 +++ b/grsecurity/gracl_ip.c
73331 @@ -0,0 +1,386 @@
73332 +#include <linux/kernel.h>
73333 +#include <asm/uaccess.h>
73334 +#include <asm/errno.h>
73335 +#include <net/sock.h>
73336 +#include <linux/file.h>
73337 +#include <linux/fs.h>
73338 +#include <linux/net.h>
73339 +#include <linux/in.h>
73340 +#include <linux/skbuff.h>
73341 +#include <linux/ip.h>
73342 +#include <linux/udp.h>
73343 +#include <linux/types.h>
73344 +#include <linux/sched.h>
73345 +#include <linux/netdevice.h>
73346 +#include <linux/inetdevice.h>
73347 +#include <linux/gracl.h>
73348 +#include <linux/grsecurity.h>
73349 +#include <linux/grinternal.h>
73350 +
73351 +#define GR_BIND 0x01
73352 +#define GR_CONNECT 0x02
73353 +#define GR_INVERT 0x04
73354 +#define GR_BINDOVERRIDE 0x08
73355 +#define GR_CONNECTOVERRIDE 0x10
73356 +#define GR_SOCK_FAMILY 0x20
73357 +
73358 +static const char * gr_protocols[IPPROTO_MAX] = {
73359 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73360 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73361 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73362 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73363 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73364 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73365 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73366 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73367 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73368 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73369 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73370 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73371 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73372 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73373 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73374 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73375 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73376 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73377 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73378 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73379 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73380 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73381 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73382 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73383 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73384 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73385 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73386 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73387 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73388 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73389 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73390 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73391 + };
73392 +
73393 +static const char * gr_socktypes[SOCK_MAX] = {
73394 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73395 + "unknown:7", "unknown:8", "unknown:9", "packet"
73396 + };
73397 +
73398 +static const char * gr_sockfamilies[AF_MAX+1] = {
73399 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73400 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73401 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73402 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73403 + };
73404 +
73405 +const char *
73406 +gr_proto_to_name(unsigned char proto)
73407 +{
73408 + return gr_protocols[proto];
73409 +}
73410 +
73411 +const char *
73412 +gr_socktype_to_name(unsigned char type)
73413 +{
73414 + return gr_socktypes[type];
73415 +}
73416 +
73417 +const char *
73418 +gr_sockfamily_to_name(unsigned char family)
73419 +{
73420 + return gr_sockfamilies[family];
73421 +}
73422 +
73423 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73424 +
73425 +int
73426 +gr_search_socket(const int domain, const int type, const int protocol)
73427 +{
73428 + struct acl_subject_label *curr;
73429 + const struct cred *cred = current_cred();
73430 +
73431 + if (unlikely(!gr_acl_is_enabled()))
73432 + goto exit;
73433 +
73434 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
73435 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73436 + goto exit; // let the kernel handle it
73437 +
73438 + curr = current->acl;
73439 +
73440 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73441 + /* the family is allowed, if this is PF_INET allow it only if
73442 + the extra sock type/protocol checks pass */
73443 + if (domain == PF_INET)
73444 + goto inet_check;
73445 + goto exit;
73446 + } else {
73447 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73448 + __u32 fakeip = 0;
73449 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73450 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73451 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73452 + gr_to_filename(current->exec_file->f_path.dentry,
73453 + current->exec_file->f_path.mnt) :
73454 + curr->filename, curr->filename,
73455 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73456 + &current->signal->saved_ip);
73457 + goto exit;
73458 + }
73459 + goto exit_fail;
73460 + }
73461 +
73462 +inet_check:
73463 + /* the rest of this checking is for IPv4 only */
73464 + if (!curr->ips)
73465 + goto exit;
73466 +
73467 + if ((curr->ip_type & (1U << type)) &&
73468 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73469 + goto exit;
73470 +
73471 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73472 + /* we don't place acls on raw sockets , and sometimes
73473 + dgram/ip sockets are opened for ioctl and not
73474 + bind/connect, so we'll fake a bind learn log */
73475 + if (type == SOCK_RAW || type == SOCK_PACKET) {
73476 + __u32 fakeip = 0;
73477 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73478 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73479 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73480 + gr_to_filename(current->exec_file->f_path.dentry,
73481 + current->exec_file->f_path.mnt) :
73482 + curr->filename, curr->filename,
73483 + &fakeip, 0, type,
73484 + protocol, GR_CONNECT, &current->signal->saved_ip);
73485 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73486 + __u32 fakeip = 0;
73487 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73488 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73489 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73490 + gr_to_filename(current->exec_file->f_path.dentry,
73491 + current->exec_file->f_path.mnt) :
73492 + curr->filename, curr->filename,
73493 + &fakeip, 0, type,
73494 + protocol, GR_BIND, &current->signal->saved_ip);
73495 + }
73496 + /* we'll log when they use connect or bind */
73497 + goto exit;
73498 + }
73499 +
73500 +exit_fail:
73501 + if (domain == PF_INET)
73502 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73503 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
73504 + else if (rcu_access_pointer(net_families[domain]) != NULL)
73505 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73506 + gr_socktype_to_name(type), protocol);
73507 +
73508 + return 0;
73509 +exit:
73510 + return 1;
73511 +}
73512 +
73513 +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)
73514 +{
73515 + if ((ip->mode & mode) &&
73516 + (ip_port >= ip->low) &&
73517 + (ip_port <= ip->high) &&
73518 + ((ntohl(ip_addr) & our_netmask) ==
73519 + (ntohl(our_addr) & our_netmask))
73520 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73521 + && (ip->type & (1U << type))) {
73522 + if (ip->mode & GR_INVERT)
73523 + return 2; // specifically denied
73524 + else
73525 + return 1; // allowed
73526 + }
73527 +
73528 + return 0; // not specifically allowed, may continue parsing
73529 +}
73530 +
73531 +static int
73532 +gr_search_connectbind(const int full_mode, struct sock *sk,
73533 + struct sockaddr_in *addr, const int type)
73534 +{
73535 + char iface[IFNAMSIZ] = {0};
73536 + struct acl_subject_label *curr;
73537 + struct acl_ip_label *ip;
73538 + struct inet_sock *isk;
73539 + struct net_device *dev;
73540 + struct in_device *idev;
73541 + unsigned long i;
73542 + int ret;
73543 + int mode = full_mode & (GR_BIND | GR_CONNECT);
73544 + __u32 ip_addr = 0;
73545 + __u32 our_addr;
73546 + __u32 our_netmask;
73547 + char *p;
73548 + __u16 ip_port = 0;
73549 + const struct cred *cred = current_cred();
73550 +
73551 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73552 + return 0;
73553 +
73554 + curr = current->acl;
73555 + isk = inet_sk(sk);
73556 +
73557 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73558 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73559 + addr->sin_addr.s_addr = curr->inaddr_any_override;
73560 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73561 + struct sockaddr_in saddr;
73562 + int err;
73563 +
73564 + saddr.sin_family = AF_INET;
73565 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
73566 + saddr.sin_port = isk->inet_sport;
73567 +
73568 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73569 + if (err)
73570 + return err;
73571 +
73572 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73573 + if (err)
73574 + return err;
73575 + }
73576 +
73577 + if (!curr->ips)
73578 + return 0;
73579 +
73580 + ip_addr = addr->sin_addr.s_addr;
73581 + ip_port = ntohs(addr->sin_port);
73582 +
73583 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73584 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73585 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
73586 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
73587 + gr_to_filename(current->exec_file->f_path.dentry,
73588 + current->exec_file->f_path.mnt) :
73589 + curr->filename, curr->filename,
73590 + &ip_addr, ip_port, type,
73591 + sk->sk_protocol, mode, &current->signal->saved_ip);
73592 + return 0;
73593 + }
73594 +
73595 + for (i = 0; i < curr->ip_num; i++) {
73596 + ip = *(curr->ips + i);
73597 + if (ip->iface != NULL) {
73598 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
73599 + p = strchr(iface, ':');
73600 + if (p != NULL)
73601 + *p = '\0';
73602 + dev = dev_get_by_name(sock_net(sk), iface);
73603 + if (dev == NULL)
73604 + continue;
73605 + idev = in_dev_get(dev);
73606 + if (idev == NULL) {
73607 + dev_put(dev);
73608 + continue;
73609 + }
73610 + rcu_read_lock();
73611 + for_ifa(idev) {
73612 + if (!strcmp(ip->iface, ifa->ifa_label)) {
73613 + our_addr = ifa->ifa_address;
73614 + our_netmask = 0xffffffff;
73615 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73616 + if (ret == 1) {
73617 + rcu_read_unlock();
73618 + in_dev_put(idev);
73619 + dev_put(dev);
73620 + return 0;
73621 + } else if (ret == 2) {
73622 + rcu_read_unlock();
73623 + in_dev_put(idev);
73624 + dev_put(dev);
73625 + goto denied;
73626 + }
73627 + }
73628 + } endfor_ifa(idev);
73629 + rcu_read_unlock();
73630 + in_dev_put(idev);
73631 + dev_put(dev);
73632 + } else {
73633 + our_addr = ip->addr;
73634 + our_netmask = ip->netmask;
73635 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73636 + if (ret == 1)
73637 + return 0;
73638 + else if (ret == 2)
73639 + goto denied;
73640 + }
73641 + }
73642 +
73643 +denied:
73644 + if (mode == GR_BIND)
73645 + 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));
73646 + else if (mode == GR_CONNECT)
73647 + 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));
73648 +
73649 + return -EACCES;
73650 +}
73651 +
73652 +int
73653 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73654 +{
73655 + /* always allow disconnection of dgram sockets with connect */
73656 + if (addr->sin_family == AF_UNSPEC)
73657 + return 0;
73658 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73659 +}
73660 +
73661 +int
73662 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73663 +{
73664 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73665 +}
73666 +
73667 +int gr_search_listen(struct socket *sock)
73668 +{
73669 + struct sock *sk = sock->sk;
73670 + struct sockaddr_in addr;
73671 +
73672 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73673 + addr.sin_port = inet_sk(sk)->inet_sport;
73674 +
73675 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73676 +}
73677 +
73678 +int gr_search_accept(struct socket *sock)
73679 +{
73680 + struct sock *sk = sock->sk;
73681 + struct sockaddr_in addr;
73682 +
73683 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73684 + addr.sin_port = inet_sk(sk)->inet_sport;
73685 +
73686 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73687 +}
73688 +
73689 +int
73690 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73691 +{
73692 + if (addr)
73693 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73694 + else {
73695 + struct sockaddr_in sin;
73696 + const struct inet_sock *inet = inet_sk(sk);
73697 +
73698 + sin.sin_addr.s_addr = inet->inet_daddr;
73699 + sin.sin_port = inet->inet_dport;
73700 +
73701 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73702 + }
73703 +}
73704 +
73705 +int
73706 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73707 +{
73708 + struct sockaddr_in sin;
73709 +
73710 + if (unlikely(skb->len < sizeof (struct udphdr)))
73711 + return 0; // skip this packet
73712 +
73713 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73714 + sin.sin_port = udp_hdr(skb)->source;
73715 +
73716 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73717 +}
73718 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73719 new file mode 100644
73720 index 0000000..25f54ef
73721 --- /dev/null
73722 +++ b/grsecurity/gracl_learn.c
73723 @@ -0,0 +1,207 @@
73724 +#include <linux/kernel.h>
73725 +#include <linux/mm.h>
73726 +#include <linux/sched.h>
73727 +#include <linux/poll.h>
73728 +#include <linux/string.h>
73729 +#include <linux/file.h>
73730 +#include <linux/types.h>
73731 +#include <linux/vmalloc.h>
73732 +#include <linux/grinternal.h>
73733 +
73734 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73735 + size_t count, loff_t *ppos);
73736 +extern int gr_acl_is_enabled(void);
73737 +
73738 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73739 +static int gr_learn_attached;
73740 +
73741 +/* use a 512k buffer */
73742 +#define LEARN_BUFFER_SIZE (512 * 1024)
73743 +
73744 +static DEFINE_SPINLOCK(gr_learn_lock);
73745 +static DEFINE_MUTEX(gr_learn_user_mutex);
73746 +
73747 +/* we need to maintain two buffers, so that the kernel context of grlearn
73748 + uses a semaphore around the userspace copying, and the other kernel contexts
73749 + use a spinlock when copying into the buffer, since they cannot sleep
73750 +*/
73751 +static char *learn_buffer;
73752 +static char *learn_buffer_user;
73753 +static int learn_buffer_len;
73754 +static int learn_buffer_user_len;
73755 +
73756 +static ssize_t
73757 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73758 +{
73759 + DECLARE_WAITQUEUE(wait, current);
73760 + ssize_t retval = 0;
73761 +
73762 + add_wait_queue(&learn_wait, &wait);
73763 + set_current_state(TASK_INTERRUPTIBLE);
73764 + do {
73765 + mutex_lock(&gr_learn_user_mutex);
73766 + spin_lock(&gr_learn_lock);
73767 + if (learn_buffer_len)
73768 + break;
73769 + spin_unlock(&gr_learn_lock);
73770 + mutex_unlock(&gr_learn_user_mutex);
73771 + if (file->f_flags & O_NONBLOCK) {
73772 + retval = -EAGAIN;
73773 + goto out;
73774 + }
73775 + if (signal_pending(current)) {
73776 + retval = -ERESTARTSYS;
73777 + goto out;
73778 + }
73779 +
73780 + schedule();
73781 + } while (1);
73782 +
73783 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73784 + learn_buffer_user_len = learn_buffer_len;
73785 + retval = learn_buffer_len;
73786 + learn_buffer_len = 0;
73787 +
73788 + spin_unlock(&gr_learn_lock);
73789 +
73790 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73791 + retval = -EFAULT;
73792 +
73793 + mutex_unlock(&gr_learn_user_mutex);
73794 +out:
73795 + set_current_state(TASK_RUNNING);
73796 + remove_wait_queue(&learn_wait, &wait);
73797 + return retval;
73798 +}
73799 +
73800 +static unsigned int
73801 +poll_learn(struct file * file, poll_table * wait)
73802 +{
73803 + poll_wait(file, &learn_wait, wait);
73804 +
73805 + if (learn_buffer_len)
73806 + return (POLLIN | POLLRDNORM);
73807 +
73808 + return 0;
73809 +}
73810 +
73811 +void
73812 +gr_clear_learn_entries(void)
73813 +{
73814 + char *tmp;
73815 +
73816 + mutex_lock(&gr_learn_user_mutex);
73817 + spin_lock(&gr_learn_lock);
73818 + tmp = learn_buffer;
73819 + learn_buffer = NULL;
73820 + spin_unlock(&gr_learn_lock);
73821 + if (tmp)
73822 + vfree(tmp);
73823 + if (learn_buffer_user != NULL) {
73824 + vfree(learn_buffer_user);
73825 + learn_buffer_user = NULL;
73826 + }
73827 + learn_buffer_len = 0;
73828 + mutex_unlock(&gr_learn_user_mutex);
73829 +
73830 + return;
73831 +}
73832 +
73833 +void
73834 +gr_add_learn_entry(const char *fmt, ...)
73835 +{
73836 + va_list args;
73837 + unsigned int len;
73838 +
73839 + if (!gr_learn_attached)
73840 + return;
73841 +
73842 + spin_lock(&gr_learn_lock);
73843 +
73844 + /* leave a gap at the end so we know when it's "full" but don't have to
73845 + compute the exact length of the string we're trying to append
73846 + */
73847 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73848 + spin_unlock(&gr_learn_lock);
73849 + wake_up_interruptible(&learn_wait);
73850 + return;
73851 + }
73852 + if (learn_buffer == NULL) {
73853 + spin_unlock(&gr_learn_lock);
73854 + return;
73855 + }
73856 +
73857 + va_start(args, fmt);
73858 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73859 + va_end(args);
73860 +
73861 + learn_buffer_len += len + 1;
73862 +
73863 + spin_unlock(&gr_learn_lock);
73864 + wake_up_interruptible(&learn_wait);
73865 +
73866 + return;
73867 +}
73868 +
73869 +static int
73870 +open_learn(struct inode *inode, struct file *file)
73871 +{
73872 + if (file->f_mode & FMODE_READ && gr_learn_attached)
73873 + return -EBUSY;
73874 + if (file->f_mode & FMODE_READ) {
73875 + int retval = 0;
73876 + mutex_lock(&gr_learn_user_mutex);
73877 + if (learn_buffer == NULL)
73878 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73879 + if (learn_buffer_user == NULL)
73880 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73881 + if (learn_buffer == NULL) {
73882 + retval = -ENOMEM;
73883 + goto out_error;
73884 + }
73885 + if (learn_buffer_user == NULL) {
73886 + retval = -ENOMEM;
73887 + goto out_error;
73888 + }
73889 + learn_buffer_len = 0;
73890 + learn_buffer_user_len = 0;
73891 + gr_learn_attached = 1;
73892 +out_error:
73893 + mutex_unlock(&gr_learn_user_mutex);
73894 + return retval;
73895 + }
73896 + return 0;
73897 +}
73898 +
73899 +static int
73900 +close_learn(struct inode *inode, struct file *file)
73901 +{
73902 + if (file->f_mode & FMODE_READ) {
73903 + char *tmp = NULL;
73904 + mutex_lock(&gr_learn_user_mutex);
73905 + spin_lock(&gr_learn_lock);
73906 + tmp = learn_buffer;
73907 + learn_buffer = NULL;
73908 + spin_unlock(&gr_learn_lock);
73909 + if (tmp)
73910 + vfree(tmp);
73911 + if (learn_buffer_user != NULL) {
73912 + vfree(learn_buffer_user);
73913 + learn_buffer_user = NULL;
73914 + }
73915 + learn_buffer_len = 0;
73916 + learn_buffer_user_len = 0;
73917 + gr_learn_attached = 0;
73918 + mutex_unlock(&gr_learn_user_mutex);
73919 + }
73920 +
73921 + return 0;
73922 +}
73923 +
73924 +const struct file_operations grsec_fops = {
73925 + .read = read_learn,
73926 + .write = write_grsec_handler,
73927 + .open = open_learn,
73928 + .release = close_learn,
73929 + .poll = poll_learn,
73930 +};
73931 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73932 new file mode 100644
73933 index 0000000..fd26052
73934 --- /dev/null
73935 +++ b/grsecurity/gracl_policy.c
73936 @@ -0,0 +1,1781 @@
73937 +#include <linux/kernel.h>
73938 +#include <linux/module.h>
73939 +#include <linux/sched.h>
73940 +#include <linux/mm.h>
73941 +#include <linux/file.h>
73942 +#include <linux/fs.h>
73943 +#include <linux/namei.h>
73944 +#include <linux/mount.h>
73945 +#include <linux/tty.h>
73946 +#include <linux/proc_fs.h>
73947 +#include <linux/lglock.h>
73948 +#include <linux/slab.h>
73949 +#include <linux/vmalloc.h>
73950 +#include <linux/types.h>
73951 +#include <linux/sysctl.h>
73952 +#include <linux/netdevice.h>
73953 +#include <linux/ptrace.h>
73954 +#include <linux/gracl.h>
73955 +#include <linux/gralloc.h>
73956 +#include <linux/security.h>
73957 +#include <linux/grinternal.h>
73958 +#include <linux/pid_namespace.h>
73959 +#include <linux/stop_machine.h>
73960 +#include <linux/fdtable.h>
73961 +#include <linux/percpu.h>
73962 +#include <linux/lglock.h>
73963 +#include <linux/hugetlb.h>
73964 +#include <linux/posix-timers.h>
73965 +#include "../fs/mount.h"
73966 +
73967 +#include <asm/uaccess.h>
73968 +#include <asm/errno.h>
73969 +#include <asm/mman.h>
73970 +
73971 +extern struct gr_policy_state *polstate;
73972 +
73973 +#define FOR_EACH_ROLE_START(role) \
73974 + role = polstate->role_list; \
73975 + while (role) {
73976 +
73977 +#define FOR_EACH_ROLE_END(role) \
73978 + role = role->prev; \
73979 + }
73980 +
73981 +struct path gr_real_root;
73982 +
73983 +extern struct gr_alloc_state *current_alloc_state;
73984 +
73985 +u16 acl_sp_role_value;
73986 +
73987 +static DEFINE_MUTEX(gr_dev_mutex);
73988 +
73989 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73990 +extern void gr_clear_learn_entries(void);
73991 +
73992 +struct gr_arg *gr_usermode __read_only;
73993 +unsigned char *gr_system_salt __read_only;
73994 +unsigned char *gr_system_sum __read_only;
73995 +
73996 +static unsigned int gr_auth_attempts = 0;
73997 +static unsigned long gr_auth_expires = 0UL;
73998 +
73999 +struct acl_object_label *fakefs_obj_rw;
74000 +struct acl_object_label *fakefs_obj_rwx;
74001 +
74002 +extern int gr_init_uidset(void);
74003 +extern void gr_free_uidset(void);
74004 +extern void gr_remove_uid(uid_t uid);
74005 +extern int gr_find_uid(uid_t uid);
74006 +
74007 +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);
74008 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74009 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74010 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74011 +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);
74012 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74013 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74014 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74015 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74016 +extern struct acl_subject_label *lookup_acl_subj_label(const u64 ino, const dev_t dev, const struct acl_role_label *role);
74017 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const u64 ino, const dev_t dev, const struct acl_role_label *role);
74018 +extern void assign_special_role(const char *rolename);
74019 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74020 +extern int gr_rbac_disable(void *unused);
74021 +extern void gr_enable_rbac_system(void);
74022 +
74023 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74024 +{
74025 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74026 + return -EFAULT;
74027 +
74028 + return 0;
74029 +}
74030 +
74031 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74032 +{
74033 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74034 + return -EFAULT;
74035 +
74036 + return 0;
74037 +}
74038 +
74039 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74040 +{
74041 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74042 + return -EFAULT;
74043 +
74044 + return 0;
74045 +}
74046 +
74047 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74048 +{
74049 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74050 + return -EFAULT;
74051 +
74052 + return 0;
74053 +}
74054 +
74055 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74056 +{
74057 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74058 + return -EFAULT;
74059 +
74060 + return 0;
74061 +}
74062 +
74063 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74064 +{
74065 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74066 + return -EFAULT;
74067 +
74068 + return 0;
74069 +}
74070 +
74071 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74072 +{
74073 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74074 + return -EFAULT;
74075 +
74076 + return 0;
74077 +}
74078 +
74079 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74080 +{
74081 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74082 + return -EFAULT;
74083 +
74084 + return 0;
74085 +}
74086 +
74087 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74088 +{
74089 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74090 + return -EFAULT;
74091 +
74092 + return 0;
74093 +}
74094 +
74095 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74096 +{
74097 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74098 + return -EFAULT;
74099 +
74100 + if ((uwrap->version != GRSECURITY_VERSION) ||
74101 + (uwrap->size != sizeof(struct gr_arg)))
74102 + return -EINVAL;
74103 +
74104 + return 0;
74105 +}
74106 +
74107 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74108 +{
74109 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74110 + return -EFAULT;
74111 +
74112 + return 0;
74113 +}
74114 +
74115 +static size_t get_gr_arg_wrapper_size_normal(void)
74116 +{
74117 + return sizeof(struct gr_arg_wrapper);
74118 +}
74119 +
74120 +#ifdef CONFIG_COMPAT
74121 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74122 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74123 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74124 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74125 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74126 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74127 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74128 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74129 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74130 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74131 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74132 +extern size_t get_gr_arg_wrapper_size_compat(void);
74133 +
74134 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74135 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74136 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74137 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74138 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74139 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74140 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74141 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74142 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74143 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74144 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74145 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74146 +
74147 +#else
74148 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74149 +#define copy_gr_arg copy_gr_arg_normal
74150 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
74151 +#define copy_acl_object_label copy_acl_object_label_normal
74152 +#define copy_acl_subject_label copy_acl_subject_label_normal
74153 +#define copy_acl_role_label copy_acl_role_label_normal
74154 +#define copy_acl_ip_label copy_acl_ip_label_normal
74155 +#define copy_pointer_from_array copy_pointer_from_array_normal
74156 +#define copy_sprole_pw copy_sprole_pw_normal
74157 +#define copy_role_transition copy_role_transition_normal
74158 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
74159 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74160 +#endif
74161 +
74162 +static struct acl_subject_label *
74163 +lookup_subject_map(const struct acl_subject_label *userp)
74164 +{
74165 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74166 + struct subject_map *match;
74167 +
74168 + match = polstate->subj_map_set.s_hash[index];
74169 +
74170 + while (match && match->user != userp)
74171 + match = match->next;
74172 +
74173 + if (match != NULL)
74174 + return match->kernel;
74175 + else
74176 + return NULL;
74177 +}
74178 +
74179 +static void
74180 +insert_subj_map_entry(struct subject_map *subjmap)
74181 +{
74182 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74183 + struct subject_map **curr;
74184 +
74185 + subjmap->prev = NULL;
74186 +
74187 + curr = &polstate->subj_map_set.s_hash[index];
74188 + if (*curr != NULL)
74189 + (*curr)->prev = subjmap;
74190 +
74191 + subjmap->next = *curr;
74192 + *curr = subjmap;
74193 +
74194 + return;
74195 +}
74196 +
74197 +static void
74198 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74199 +{
74200 + unsigned int index =
74201 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74202 + struct acl_role_label **curr;
74203 + struct acl_role_label *tmp, *tmp2;
74204 +
74205 + curr = &polstate->acl_role_set.r_hash[index];
74206 +
74207 + /* simple case, slot is empty, just set it to our role */
74208 + if (*curr == NULL) {
74209 + *curr = role;
74210 + } else {
74211 + /* example:
74212 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
74213 + 2 -> 3
74214 + */
74215 + /* first check to see if we can already be reached via this slot */
74216 + tmp = *curr;
74217 + while (tmp && tmp != role)
74218 + tmp = tmp->next;
74219 + if (tmp == role) {
74220 + /* we don't need to add ourselves to this slot's chain */
74221 + return;
74222 + }
74223 + /* we need to add ourselves to this chain, two cases */
74224 + if (role->next == NULL) {
74225 + /* simple case, append the current chain to our role */
74226 + role->next = *curr;
74227 + *curr = role;
74228 + } else {
74229 + /* 1 -> 2 -> 3 -> 4
74230 + 2 -> 3 -> 4
74231 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74232 + */
74233 + /* trickier case: walk our role's chain until we find
74234 + the role for the start of the current slot's chain */
74235 + tmp = role;
74236 + tmp2 = *curr;
74237 + while (tmp->next && tmp->next != tmp2)
74238 + tmp = tmp->next;
74239 + if (tmp->next == tmp2) {
74240 + /* from example above, we found 3, so just
74241 + replace this slot's chain with ours */
74242 + *curr = role;
74243 + } else {
74244 + /* we didn't find a subset of our role's chain
74245 + in the current slot's chain, so append their
74246 + chain to ours, and set us as the first role in
74247 + the slot's chain
74248 +
74249 + we could fold this case with the case above,
74250 + but making it explicit for clarity
74251 + */
74252 + tmp->next = tmp2;
74253 + *curr = role;
74254 + }
74255 + }
74256 + }
74257 +
74258 + return;
74259 +}
74260 +
74261 +static void
74262 +insert_acl_role_label(struct acl_role_label *role)
74263 +{
74264 + int i;
74265 +
74266 + if (polstate->role_list == NULL) {
74267 + polstate->role_list = role;
74268 + role->prev = NULL;
74269 + } else {
74270 + role->prev = polstate->role_list;
74271 + polstate->role_list = role;
74272 + }
74273 +
74274 + /* used for hash chains */
74275 + role->next = NULL;
74276 +
74277 + if (role->roletype & GR_ROLE_DOMAIN) {
74278 + for (i = 0; i < role->domain_child_num; i++)
74279 + __insert_acl_role_label(role, role->domain_children[i]);
74280 + } else
74281 + __insert_acl_role_label(role, role->uidgid);
74282 +}
74283 +
74284 +static int
74285 +insert_name_entry(char *name, const u64 inode, const dev_t device, __u8 deleted)
74286 +{
74287 + struct name_entry **curr, *nentry;
74288 + struct inodev_entry *ientry;
74289 + unsigned int len = strlen(name);
74290 + unsigned int key = full_name_hash(name, len);
74291 + unsigned int index = key % polstate->name_set.n_size;
74292 +
74293 + curr = &polstate->name_set.n_hash[index];
74294 +
74295 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74296 + curr = &((*curr)->next);
74297 +
74298 + if (*curr != NULL)
74299 + return 1;
74300 +
74301 + nentry = acl_alloc(sizeof (struct name_entry));
74302 + if (nentry == NULL)
74303 + return 0;
74304 + ientry = acl_alloc(sizeof (struct inodev_entry));
74305 + if (ientry == NULL)
74306 + return 0;
74307 + ientry->nentry = nentry;
74308 +
74309 + nentry->key = key;
74310 + nentry->name = name;
74311 + nentry->inode = inode;
74312 + nentry->device = device;
74313 + nentry->len = len;
74314 + nentry->deleted = deleted;
74315 +
74316 + nentry->prev = NULL;
74317 + curr = &polstate->name_set.n_hash[index];
74318 + if (*curr != NULL)
74319 + (*curr)->prev = nentry;
74320 + nentry->next = *curr;
74321 + *curr = nentry;
74322 +
74323 + /* insert us into the table searchable by inode/dev */
74324 + __insert_inodev_entry(polstate, ientry);
74325 +
74326 + return 1;
74327 +}
74328 +
74329 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74330 +
74331 +static void *
74332 +create_table(__u32 * len, int elementsize)
74333 +{
74334 + unsigned int table_sizes[] = {
74335 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74336 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74337 + 4194301, 8388593, 16777213, 33554393, 67108859
74338 + };
74339 + void *newtable = NULL;
74340 + unsigned int pwr = 0;
74341 +
74342 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74343 + table_sizes[pwr] <= *len)
74344 + pwr++;
74345 +
74346 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74347 + return newtable;
74348 +
74349 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74350 + newtable =
74351 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74352 + else
74353 + newtable = vmalloc(table_sizes[pwr] * elementsize);
74354 +
74355 + *len = table_sizes[pwr];
74356 +
74357 + return newtable;
74358 +}
74359 +
74360 +static int
74361 +init_variables(const struct gr_arg *arg, bool reload)
74362 +{
74363 + struct task_struct *reaper = init_pid_ns.child_reaper;
74364 + unsigned int stacksize;
74365 +
74366 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74367 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74368 + polstate->name_set.n_size = arg->role_db.num_objects;
74369 + polstate->inodev_set.i_size = arg->role_db.num_objects;
74370 +
74371 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74372 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74373 + return 1;
74374 +
74375 + if (!reload) {
74376 + if (!gr_init_uidset())
74377 + return 1;
74378 + }
74379 +
74380 + /* set up the stack that holds allocation info */
74381 +
74382 + stacksize = arg->role_db.num_pointers + 5;
74383 +
74384 + if (!acl_alloc_stack_init(stacksize))
74385 + return 1;
74386 +
74387 + if (!reload) {
74388 + /* grab reference for the real root dentry and vfsmount */
74389 + get_fs_root(reaper->fs, &gr_real_root);
74390 +
74391 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74392 + 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);
74393 +#endif
74394 +
74395 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74396 + if (fakefs_obj_rw == NULL)
74397 + return 1;
74398 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74399 +
74400 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74401 + if (fakefs_obj_rwx == NULL)
74402 + return 1;
74403 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74404 + }
74405 +
74406 + polstate->subj_map_set.s_hash =
74407 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74408 + polstate->acl_role_set.r_hash =
74409 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74410 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74411 + polstate->inodev_set.i_hash =
74412 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74413 +
74414 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74415 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74416 + return 1;
74417 +
74418 + memset(polstate->subj_map_set.s_hash, 0,
74419 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74420 + memset(polstate->acl_role_set.r_hash, 0,
74421 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74422 + memset(polstate->name_set.n_hash, 0,
74423 + sizeof (struct name_entry *) * polstate->name_set.n_size);
74424 + memset(polstate->inodev_set.i_hash, 0,
74425 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74426 +
74427 + return 0;
74428 +}
74429 +
74430 +/* free information not needed after startup
74431 + currently contains user->kernel pointer mappings for subjects
74432 +*/
74433 +
74434 +static void
74435 +free_init_variables(void)
74436 +{
74437 + __u32 i;
74438 +
74439 + if (polstate->subj_map_set.s_hash) {
74440 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74441 + if (polstate->subj_map_set.s_hash[i]) {
74442 + kfree(polstate->subj_map_set.s_hash[i]);
74443 + polstate->subj_map_set.s_hash[i] = NULL;
74444 + }
74445 + }
74446 +
74447 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74448 + PAGE_SIZE)
74449 + kfree(polstate->subj_map_set.s_hash);
74450 + else
74451 + vfree(polstate->subj_map_set.s_hash);
74452 + }
74453 +
74454 + return;
74455 +}
74456 +
74457 +static void
74458 +free_variables(bool reload)
74459 +{
74460 + struct acl_subject_label *s;
74461 + struct acl_role_label *r;
74462 + struct task_struct *task, *task2;
74463 + unsigned int x;
74464 +
74465 + if (!reload) {
74466 + gr_clear_learn_entries();
74467 +
74468 + read_lock(&tasklist_lock);
74469 + do_each_thread(task2, task) {
74470 + task->acl_sp_role = 0;
74471 + task->acl_role_id = 0;
74472 + task->inherited = 0;
74473 + task->acl = NULL;
74474 + task->role = NULL;
74475 + } while_each_thread(task2, task);
74476 + read_unlock(&tasklist_lock);
74477 +
74478 + kfree(fakefs_obj_rw);
74479 + fakefs_obj_rw = NULL;
74480 + kfree(fakefs_obj_rwx);
74481 + fakefs_obj_rwx = NULL;
74482 +
74483 + /* release the reference to the real root dentry and vfsmount */
74484 + path_put(&gr_real_root);
74485 + memset(&gr_real_root, 0, sizeof(gr_real_root));
74486 + }
74487 +
74488 + /* free all object hash tables */
74489 +
74490 + FOR_EACH_ROLE_START(r)
74491 + if (r->subj_hash == NULL)
74492 + goto next_role;
74493 + FOR_EACH_SUBJECT_START(r, s, x)
74494 + if (s->obj_hash == NULL)
74495 + break;
74496 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74497 + kfree(s->obj_hash);
74498 + else
74499 + vfree(s->obj_hash);
74500 + FOR_EACH_SUBJECT_END(s, x)
74501 + FOR_EACH_NESTED_SUBJECT_START(r, s)
74502 + if (s->obj_hash == NULL)
74503 + break;
74504 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74505 + kfree(s->obj_hash);
74506 + else
74507 + vfree(s->obj_hash);
74508 + FOR_EACH_NESTED_SUBJECT_END(s)
74509 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74510 + kfree(r->subj_hash);
74511 + else
74512 + vfree(r->subj_hash);
74513 + r->subj_hash = NULL;
74514 +next_role:
74515 + FOR_EACH_ROLE_END(r)
74516 +
74517 + acl_free_all();
74518 +
74519 + if (polstate->acl_role_set.r_hash) {
74520 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74521 + PAGE_SIZE)
74522 + kfree(polstate->acl_role_set.r_hash);
74523 + else
74524 + vfree(polstate->acl_role_set.r_hash);
74525 + }
74526 + if (polstate->name_set.n_hash) {
74527 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74528 + PAGE_SIZE)
74529 + kfree(polstate->name_set.n_hash);
74530 + else
74531 + vfree(polstate->name_set.n_hash);
74532 + }
74533 +
74534 + if (polstate->inodev_set.i_hash) {
74535 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74536 + PAGE_SIZE)
74537 + kfree(polstate->inodev_set.i_hash);
74538 + else
74539 + vfree(polstate->inodev_set.i_hash);
74540 + }
74541 +
74542 + if (!reload)
74543 + gr_free_uidset();
74544 +
74545 + memset(&polstate->name_set, 0, sizeof (struct name_db));
74546 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74547 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74548 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74549 +
74550 + polstate->default_role = NULL;
74551 + polstate->kernel_role = NULL;
74552 + polstate->role_list = NULL;
74553 +
74554 + return;
74555 +}
74556 +
74557 +static struct acl_subject_label *
74558 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74559 +
74560 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
74561 +{
74562 + unsigned int len = strnlen_user(*name, maxlen);
74563 + char *tmp;
74564 +
74565 + if (!len || len >= maxlen)
74566 + return -EINVAL;
74567 +
74568 + if ((tmp = (char *) acl_alloc(len)) == NULL)
74569 + return -ENOMEM;
74570 +
74571 + if (copy_from_user(tmp, *name, len))
74572 + return -EFAULT;
74573 +
74574 + tmp[len-1] = '\0';
74575 + *name = tmp;
74576 +
74577 + return 0;
74578 +}
74579 +
74580 +static int
74581 +copy_user_glob(struct acl_object_label *obj)
74582 +{
74583 + struct acl_object_label *g_tmp, **guser;
74584 + int error;
74585 +
74586 + if (obj->globbed == NULL)
74587 + return 0;
74588 +
74589 + guser = &obj->globbed;
74590 + while (*guser) {
74591 + g_tmp = (struct acl_object_label *)
74592 + acl_alloc(sizeof (struct acl_object_label));
74593 + if (g_tmp == NULL)
74594 + return -ENOMEM;
74595 +
74596 + if (copy_acl_object_label(g_tmp, *guser))
74597 + return -EFAULT;
74598 +
74599 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74600 + if (error)
74601 + return error;
74602 +
74603 + *guser = g_tmp;
74604 + guser = &(g_tmp->next);
74605 + }
74606 +
74607 + return 0;
74608 +}
74609 +
74610 +static int
74611 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74612 + struct acl_role_label *role)
74613 +{
74614 + struct acl_object_label *o_tmp;
74615 + int ret;
74616 +
74617 + while (userp) {
74618 + if ((o_tmp = (struct acl_object_label *)
74619 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
74620 + return -ENOMEM;
74621 +
74622 + if (copy_acl_object_label(o_tmp, userp))
74623 + return -EFAULT;
74624 +
74625 + userp = o_tmp->prev;
74626 +
74627 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74628 + if (ret)
74629 + return ret;
74630 +
74631 + insert_acl_obj_label(o_tmp, subj);
74632 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74633 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74634 + return -ENOMEM;
74635 +
74636 + ret = copy_user_glob(o_tmp);
74637 + if (ret)
74638 + return ret;
74639 +
74640 + if (o_tmp->nested) {
74641 + int already_copied;
74642 +
74643 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74644 + if (IS_ERR(o_tmp->nested))
74645 + return PTR_ERR(o_tmp->nested);
74646 +
74647 + /* insert into nested subject list if we haven't copied this one yet
74648 + to prevent duplicate entries */
74649 + if (!already_copied) {
74650 + o_tmp->nested->next = role->hash->first;
74651 + role->hash->first = o_tmp->nested;
74652 + }
74653 + }
74654 + }
74655 +
74656 + return 0;
74657 +}
74658 +
74659 +static __u32
74660 +count_user_subjs(struct acl_subject_label *userp)
74661 +{
74662 + struct acl_subject_label s_tmp;
74663 + __u32 num = 0;
74664 +
74665 + while (userp) {
74666 + if (copy_acl_subject_label(&s_tmp, userp))
74667 + break;
74668 +
74669 + userp = s_tmp.prev;
74670 + }
74671 +
74672 + return num;
74673 +}
74674 +
74675 +static int
74676 +copy_user_allowedips(struct acl_role_label *rolep)
74677 +{
74678 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74679 +
74680 + ruserip = rolep->allowed_ips;
74681 +
74682 + while (ruserip) {
74683 + rlast = rtmp;
74684 +
74685 + if ((rtmp = (struct role_allowed_ip *)
74686 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74687 + return -ENOMEM;
74688 +
74689 + if (copy_role_allowed_ip(rtmp, ruserip))
74690 + return -EFAULT;
74691 +
74692 + ruserip = rtmp->prev;
74693 +
74694 + if (!rlast) {
74695 + rtmp->prev = NULL;
74696 + rolep->allowed_ips = rtmp;
74697 + } else {
74698 + rlast->next = rtmp;
74699 + rtmp->prev = rlast;
74700 + }
74701 +
74702 + if (!ruserip)
74703 + rtmp->next = NULL;
74704 + }
74705 +
74706 + return 0;
74707 +}
74708 +
74709 +static int
74710 +copy_user_transitions(struct acl_role_label *rolep)
74711 +{
74712 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
74713 + int error;
74714 +
74715 + rusertp = rolep->transitions;
74716 +
74717 + while (rusertp) {
74718 + rlast = rtmp;
74719 +
74720 + if ((rtmp = (struct role_transition *)
74721 + acl_alloc(sizeof (struct role_transition))) == NULL)
74722 + return -ENOMEM;
74723 +
74724 + if (copy_role_transition(rtmp, rusertp))
74725 + return -EFAULT;
74726 +
74727 + rusertp = rtmp->prev;
74728 +
74729 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74730 + if (error)
74731 + return error;
74732 +
74733 + if (!rlast) {
74734 + rtmp->prev = NULL;
74735 + rolep->transitions = rtmp;
74736 + } else {
74737 + rlast->next = rtmp;
74738 + rtmp->prev = rlast;
74739 + }
74740 +
74741 + if (!rusertp)
74742 + rtmp->next = NULL;
74743 + }
74744 +
74745 + return 0;
74746 +}
74747 +
74748 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
74749 +{
74750 + struct acl_object_label o_tmp;
74751 + __u32 num = 0;
74752 +
74753 + while (userp) {
74754 + if (copy_acl_object_label(&o_tmp, userp))
74755 + break;
74756 +
74757 + userp = o_tmp.prev;
74758 + num++;
74759 + }
74760 +
74761 + return num;
74762 +}
74763 +
74764 +static struct acl_subject_label *
74765 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74766 +{
74767 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74768 + __u32 num_objs;
74769 + struct acl_ip_label **i_tmp, *i_utmp2;
74770 + struct gr_hash_struct ghash;
74771 + struct subject_map *subjmap;
74772 + unsigned int i_num;
74773 + int err;
74774 +
74775 + if (already_copied != NULL)
74776 + *already_copied = 0;
74777 +
74778 + s_tmp = lookup_subject_map(userp);
74779 +
74780 + /* we've already copied this subject into the kernel, just return
74781 + the reference to it, and don't copy it over again
74782 + */
74783 + if (s_tmp) {
74784 + if (already_copied != NULL)
74785 + *already_copied = 1;
74786 + return(s_tmp);
74787 + }
74788 +
74789 + if ((s_tmp = (struct acl_subject_label *)
74790 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74791 + return ERR_PTR(-ENOMEM);
74792 +
74793 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74794 + if (subjmap == NULL)
74795 + return ERR_PTR(-ENOMEM);
74796 +
74797 + subjmap->user = userp;
74798 + subjmap->kernel = s_tmp;
74799 + insert_subj_map_entry(subjmap);
74800 +
74801 + if (copy_acl_subject_label(s_tmp, userp))
74802 + return ERR_PTR(-EFAULT);
74803 +
74804 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74805 + if (err)
74806 + return ERR_PTR(err);
74807 +
74808 + if (!strcmp(s_tmp->filename, "/"))
74809 + role->root_label = s_tmp;
74810 +
74811 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74812 + return ERR_PTR(-EFAULT);
74813 +
74814 + /* copy user and group transition tables */
74815 +
74816 + if (s_tmp->user_trans_num) {
74817 + uid_t *uidlist;
74818 +
74819 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74820 + if (uidlist == NULL)
74821 + return ERR_PTR(-ENOMEM);
74822 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74823 + return ERR_PTR(-EFAULT);
74824 +
74825 + s_tmp->user_transitions = uidlist;
74826 + }
74827 +
74828 + if (s_tmp->group_trans_num) {
74829 + gid_t *gidlist;
74830 +
74831 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74832 + if (gidlist == NULL)
74833 + return ERR_PTR(-ENOMEM);
74834 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74835 + return ERR_PTR(-EFAULT);
74836 +
74837 + s_tmp->group_transitions = gidlist;
74838 + }
74839 +
74840 + /* set up object hash table */
74841 + num_objs = count_user_objs(ghash.first);
74842 +
74843 + s_tmp->obj_hash_size = num_objs;
74844 + s_tmp->obj_hash =
74845 + (struct acl_object_label **)
74846 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74847 +
74848 + if (!s_tmp->obj_hash)
74849 + return ERR_PTR(-ENOMEM);
74850 +
74851 + memset(s_tmp->obj_hash, 0,
74852 + s_tmp->obj_hash_size *
74853 + sizeof (struct acl_object_label *));
74854 +
74855 + /* add in objects */
74856 + err = copy_user_objs(ghash.first, s_tmp, role);
74857 +
74858 + if (err)
74859 + return ERR_PTR(err);
74860 +
74861 + /* set pointer for parent subject */
74862 + if (s_tmp->parent_subject) {
74863 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74864 +
74865 + if (IS_ERR(s_tmp2))
74866 + return s_tmp2;
74867 +
74868 + s_tmp->parent_subject = s_tmp2;
74869 + }
74870 +
74871 + /* add in ip acls */
74872 +
74873 + if (!s_tmp->ip_num) {
74874 + s_tmp->ips = NULL;
74875 + goto insert;
74876 + }
74877 +
74878 + i_tmp =
74879 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74880 + sizeof (struct acl_ip_label *));
74881 +
74882 + if (!i_tmp)
74883 + return ERR_PTR(-ENOMEM);
74884 +
74885 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74886 + *(i_tmp + i_num) =
74887 + (struct acl_ip_label *)
74888 + acl_alloc(sizeof (struct acl_ip_label));
74889 + if (!*(i_tmp + i_num))
74890 + return ERR_PTR(-ENOMEM);
74891 +
74892 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74893 + return ERR_PTR(-EFAULT);
74894 +
74895 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74896 + return ERR_PTR(-EFAULT);
74897 +
74898 + if ((*(i_tmp + i_num))->iface == NULL)
74899 + continue;
74900 +
74901 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74902 + if (err)
74903 + return ERR_PTR(err);
74904 + }
74905 +
74906 + s_tmp->ips = i_tmp;
74907 +
74908 +insert:
74909 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74910 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74911 + return ERR_PTR(-ENOMEM);
74912 +
74913 + return s_tmp;
74914 +}
74915 +
74916 +static int
74917 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74918 +{
74919 + struct acl_subject_label s_pre;
74920 + struct acl_subject_label * ret;
74921 + int err;
74922 +
74923 + while (userp) {
74924 + if (copy_acl_subject_label(&s_pre, userp))
74925 + return -EFAULT;
74926 +
74927 + ret = do_copy_user_subj(userp, role, NULL);
74928 +
74929 + err = PTR_ERR(ret);
74930 + if (IS_ERR(ret))
74931 + return err;
74932 +
74933 + insert_acl_subj_label(ret, role);
74934 +
74935 + userp = s_pre.prev;
74936 + }
74937 +
74938 + return 0;
74939 +}
74940 +
74941 +static int
74942 +copy_user_acl(struct gr_arg *arg)
74943 +{
74944 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74945 + struct acl_subject_label *subj_list;
74946 + struct sprole_pw *sptmp;
74947 + struct gr_hash_struct *ghash;
74948 + uid_t *domainlist;
74949 + unsigned int r_num;
74950 + int err = 0;
74951 + __u16 i;
74952 + __u32 num_subjs;
74953 +
74954 + /* we need a default and kernel role */
74955 + if (arg->role_db.num_roles < 2)
74956 + return -EINVAL;
74957 +
74958 + /* copy special role authentication info from userspace */
74959 +
74960 + polstate->num_sprole_pws = arg->num_sprole_pws;
74961 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74962 +
74963 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74964 + return -ENOMEM;
74965 +
74966 + for (i = 0; i < polstate->num_sprole_pws; i++) {
74967 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74968 + if (!sptmp)
74969 + return -ENOMEM;
74970 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74971 + return -EFAULT;
74972 +
74973 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74974 + if (err)
74975 + return err;
74976 +
74977 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74978 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74979 +#endif
74980 +
74981 + polstate->acl_special_roles[i] = sptmp;
74982 + }
74983 +
74984 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74985 +
74986 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74987 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
74988 +
74989 + if (!r_tmp)
74990 + return -ENOMEM;
74991 +
74992 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74993 + return -EFAULT;
74994 +
74995 + if (copy_acl_role_label(r_tmp, r_utmp2))
74996 + return -EFAULT;
74997 +
74998 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74999 + if (err)
75000 + return err;
75001 +
75002 + if (!strcmp(r_tmp->rolename, "default")
75003 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75004 + polstate->default_role = r_tmp;
75005 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75006 + polstate->kernel_role = r_tmp;
75007 + }
75008 +
75009 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75010 + return -ENOMEM;
75011 +
75012 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
75013 + return -EFAULT;
75014 +
75015 + r_tmp->hash = ghash;
75016 +
75017 + num_subjs = count_user_subjs(r_tmp->hash->first);
75018 +
75019 + r_tmp->subj_hash_size = num_subjs;
75020 + r_tmp->subj_hash =
75021 + (struct acl_subject_label **)
75022 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75023 +
75024 + if (!r_tmp->subj_hash)
75025 + return -ENOMEM;
75026 +
75027 + err = copy_user_allowedips(r_tmp);
75028 + if (err)
75029 + return err;
75030 +
75031 + /* copy domain info */
75032 + if (r_tmp->domain_children != NULL) {
75033 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75034 + if (domainlist == NULL)
75035 + return -ENOMEM;
75036 +
75037 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75038 + return -EFAULT;
75039 +
75040 + r_tmp->domain_children = domainlist;
75041 + }
75042 +
75043 + err = copy_user_transitions(r_tmp);
75044 + if (err)
75045 + return err;
75046 +
75047 + memset(r_tmp->subj_hash, 0,
75048 + r_tmp->subj_hash_size *
75049 + sizeof (struct acl_subject_label *));
75050 +
75051 + /* acquire the list of subjects, then NULL out
75052 + the list prior to parsing the subjects for this role,
75053 + as during this parsing the list is replaced with a list
75054 + of *nested* subjects for the role
75055 + */
75056 + subj_list = r_tmp->hash->first;
75057 +
75058 + /* set nested subject list to null */
75059 + r_tmp->hash->first = NULL;
75060 +
75061 + err = copy_user_subjs(subj_list, r_tmp);
75062 +
75063 + if (err)
75064 + return err;
75065 +
75066 + insert_acl_role_label(r_tmp);
75067 + }
75068 +
75069 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75070 + return -EINVAL;
75071 +
75072 + return err;
75073 +}
75074 +
75075 +static int gracl_reload_apply_policies(void *reload)
75076 +{
75077 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75078 + struct task_struct *task, *task2;
75079 + struct acl_role_label *role, *rtmp;
75080 + struct acl_subject_label *subj;
75081 + const struct cred *cred;
75082 + int role_applied;
75083 + int ret = 0;
75084 +
75085 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75086 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75087 +
75088 + /* first make sure we'll be able to apply the new policy cleanly */
75089 + do_each_thread(task2, task) {
75090 + if (task->exec_file == NULL)
75091 + continue;
75092 + role_applied = 0;
75093 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75094 + /* preserve special roles */
75095 + FOR_EACH_ROLE_START(role)
75096 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75097 + rtmp = task->role;
75098 + task->role = role;
75099 + role_applied = 1;
75100 + break;
75101 + }
75102 + FOR_EACH_ROLE_END(role)
75103 + }
75104 + if (!role_applied) {
75105 + cred = __task_cred(task);
75106 + rtmp = task->role;
75107 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75108 + }
75109 + /* this handles non-nested inherited subjects, nested subjects will still
75110 + be dropped currently */
75111 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75112 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL, 1);
75113 + /* change the role back so that we've made no modifications to the policy */
75114 + task->role = rtmp;
75115 +
75116 + if (subj == NULL || task->tmpacl == NULL) {
75117 + ret = -EINVAL;
75118 + goto out;
75119 + }
75120 + } while_each_thread(task2, task);
75121 +
75122 + /* now actually apply the policy */
75123 +
75124 + do_each_thread(task2, task) {
75125 + if (task->exec_file) {
75126 + role_applied = 0;
75127 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75128 + /* preserve special roles */
75129 + FOR_EACH_ROLE_START(role)
75130 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75131 + task->role = role;
75132 + role_applied = 1;
75133 + break;
75134 + }
75135 + FOR_EACH_ROLE_END(role)
75136 + }
75137 + if (!role_applied) {
75138 + cred = __task_cred(task);
75139 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75140 + }
75141 + /* this handles non-nested inherited subjects, nested subjects will still
75142 + be dropped currently */
75143 + if (!reload_state->oldmode && task->inherited)
75144 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename, 1);
75145 + else {
75146 + /* looked up and tagged to the task previously */
75147 + subj = task->tmpacl;
75148 + }
75149 + /* subj will be non-null */
75150 + __gr_apply_subject_to_task(polstate, task, subj);
75151 + if (reload_state->oldmode) {
75152 + task->acl_role_id = 0;
75153 + task->acl_sp_role = 0;
75154 + task->inherited = 0;
75155 + }
75156 + } else {
75157 + // it's a kernel process
75158 + task->role = polstate->kernel_role;
75159 + task->acl = polstate->kernel_role->root_label;
75160 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75161 + task->acl->mode &= ~GR_PROCFIND;
75162 +#endif
75163 + }
75164 + } while_each_thread(task2, task);
75165 +
75166 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75167 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75168 +
75169 +out:
75170 +
75171 + return ret;
75172 +}
75173 +
75174 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75175 +{
75176 + struct gr_reload_state new_reload_state = { };
75177 + int err;
75178 +
75179 + new_reload_state.oldpolicy_ptr = polstate;
75180 + new_reload_state.oldalloc_ptr = current_alloc_state;
75181 + new_reload_state.oldmode = oldmode;
75182 +
75183 + current_alloc_state = &new_reload_state.newalloc;
75184 + polstate = &new_reload_state.newpolicy;
75185 +
75186 + /* everything relevant is now saved off, copy in the new policy */
75187 + if (init_variables(args, true)) {
75188 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75189 + err = -ENOMEM;
75190 + goto error;
75191 + }
75192 +
75193 + err = copy_user_acl(args);
75194 + free_init_variables();
75195 + if (err)
75196 + goto error;
75197 + /* the new policy is copied in, with the old policy available via saved_state
75198 + first go through applying roles, making sure to preserve special roles
75199 + then apply new subjects, making sure to preserve inherited and nested subjects,
75200 + though currently only inherited subjects will be preserved
75201 + */
75202 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75203 + if (err)
75204 + goto error;
75205 +
75206 + /* we've now applied the new policy, so restore the old policy state to free it */
75207 + polstate = &new_reload_state.oldpolicy;
75208 + current_alloc_state = &new_reload_state.oldalloc;
75209 + free_variables(true);
75210 +
75211 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75212 + to running_polstate/current_alloc_state inside stop_machine
75213 + */
75214 + err = 0;
75215 + goto out;
75216 +error:
75217 + /* on error of loading the new policy, we'll just keep the previous
75218 + policy set around
75219 + */
75220 + free_variables(true);
75221 +
75222 + /* doesn't affect runtime, but maintains consistent state */
75223 +out:
75224 + polstate = new_reload_state.oldpolicy_ptr;
75225 + current_alloc_state = new_reload_state.oldalloc_ptr;
75226 +
75227 + return err;
75228 +}
75229 +
75230 +static int
75231 +gracl_init(struct gr_arg *args)
75232 +{
75233 + int error = 0;
75234 +
75235 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75236 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75237 +
75238 + if (init_variables(args, false)) {
75239 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75240 + error = -ENOMEM;
75241 + goto out;
75242 + }
75243 +
75244 + error = copy_user_acl(args);
75245 + free_init_variables();
75246 + if (error)
75247 + goto out;
75248 +
75249 + error = gr_set_acls(0);
75250 + if (error)
75251 + goto out;
75252 +
75253 + gr_enable_rbac_system();
75254 +
75255 + return 0;
75256 +
75257 +out:
75258 + free_variables(false);
75259 + return error;
75260 +}
75261 +
75262 +static int
75263 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75264 + unsigned char **sum)
75265 +{
75266 + struct acl_role_label *r;
75267 + struct role_allowed_ip *ipp;
75268 + struct role_transition *trans;
75269 + unsigned int i;
75270 + int found = 0;
75271 + u32 curr_ip = current->signal->curr_ip;
75272 +
75273 + current->signal->saved_ip = curr_ip;
75274 +
75275 + /* check transition table */
75276 +
75277 + for (trans = current->role->transitions; trans; trans = trans->next) {
75278 + if (!strcmp(rolename, trans->rolename)) {
75279 + found = 1;
75280 + break;
75281 + }
75282 + }
75283 +
75284 + if (!found)
75285 + return 0;
75286 +
75287 + /* handle special roles that do not require authentication
75288 + and check ip */
75289 +
75290 + FOR_EACH_ROLE_START(r)
75291 + if (!strcmp(rolename, r->rolename) &&
75292 + (r->roletype & GR_ROLE_SPECIAL)) {
75293 + found = 0;
75294 + if (r->allowed_ips != NULL) {
75295 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75296 + if ((ntohl(curr_ip) & ipp->netmask) ==
75297 + (ntohl(ipp->addr) & ipp->netmask))
75298 + found = 1;
75299 + }
75300 + } else
75301 + found = 2;
75302 + if (!found)
75303 + return 0;
75304 +
75305 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75306 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75307 + *salt = NULL;
75308 + *sum = NULL;
75309 + return 1;
75310 + }
75311 + }
75312 + FOR_EACH_ROLE_END(r)
75313 +
75314 + for (i = 0; i < polstate->num_sprole_pws; i++) {
75315 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75316 + *salt = polstate->acl_special_roles[i]->salt;
75317 + *sum = polstate->acl_special_roles[i]->sum;
75318 + return 1;
75319 + }
75320 + }
75321 +
75322 + return 0;
75323 +}
75324 +
75325 +int gr_check_secure_terminal(struct task_struct *task)
75326 +{
75327 + struct task_struct *p, *p2, *p3;
75328 + struct files_struct *files;
75329 + struct fdtable *fdt;
75330 + struct file *our_file = NULL, *file;
75331 + int i;
75332 +
75333 + if (task->signal->tty == NULL)
75334 + return 1;
75335 +
75336 + files = get_files_struct(task);
75337 + if (files != NULL) {
75338 + rcu_read_lock();
75339 + fdt = files_fdtable(files);
75340 + for (i=0; i < fdt->max_fds; i++) {
75341 + file = fcheck_files(files, i);
75342 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75343 + get_file(file);
75344 + our_file = file;
75345 + }
75346 + }
75347 + rcu_read_unlock();
75348 + put_files_struct(files);
75349 + }
75350 +
75351 + if (our_file == NULL)
75352 + return 1;
75353 +
75354 + read_lock(&tasklist_lock);
75355 + do_each_thread(p2, p) {
75356 + files = get_files_struct(p);
75357 + if (files == NULL ||
75358 + (p->signal && p->signal->tty == task->signal->tty)) {
75359 + if (files != NULL)
75360 + put_files_struct(files);
75361 + continue;
75362 + }
75363 + rcu_read_lock();
75364 + fdt = files_fdtable(files);
75365 + for (i=0; i < fdt->max_fds; i++) {
75366 + file = fcheck_files(files, i);
75367 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75368 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75369 + p3 = task;
75370 + while (task_pid_nr(p3) > 0) {
75371 + if (p3 == p)
75372 + break;
75373 + p3 = p3->real_parent;
75374 + }
75375 + if (p3 == p)
75376 + break;
75377 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75378 + gr_handle_alertkill(p);
75379 + rcu_read_unlock();
75380 + put_files_struct(files);
75381 + read_unlock(&tasklist_lock);
75382 + fput(our_file);
75383 + return 0;
75384 + }
75385 + }
75386 + rcu_read_unlock();
75387 + put_files_struct(files);
75388 + } while_each_thread(p2, p);
75389 + read_unlock(&tasklist_lock);
75390 +
75391 + fput(our_file);
75392 + return 1;
75393 +}
75394 +
75395 +ssize_t
75396 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75397 +{
75398 + struct gr_arg_wrapper uwrap;
75399 + unsigned char *sprole_salt = NULL;
75400 + unsigned char *sprole_sum = NULL;
75401 + int error = 0;
75402 + int error2 = 0;
75403 + size_t req_count = 0;
75404 + unsigned char oldmode = 0;
75405 +
75406 + mutex_lock(&gr_dev_mutex);
75407 +
75408 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75409 + error = -EPERM;
75410 + goto out;
75411 + }
75412 +
75413 +#ifdef CONFIG_COMPAT
75414 + pax_open_kernel();
75415 + if (is_compat_task()) {
75416 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75417 + copy_gr_arg = &copy_gr_arg_compat;
75418 + copy_acl_object_label = &copy_acl_object_label_compat;
75419 + copy_acl_subject_label = &copy_acl_subject_label_compat;
75420 + copy_acl_role_label = &copy_acl_role_label_compat;
75421 + copy_acl_ip_label = &copy_acl_ip_label_compat;
75422 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75423 + copy_role_transition = &copy_role_transition_compat;
75424 + copy_sprole_pw = &copy_sprole_pw_compat;
75425 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75426 + copy_pointer_from_array = &copy_pointer_from_array_compat;
75427 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75428 + } else {
75429 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75430 + copy_gr_arg = &copy_gr_arg_normal;
75431 + copy_acl_object_label = &copy_acl_object_label_normal;
75432 + copy_acl_subject_label = &copy_acl_subject_label_normal;
75433 + copy_acl_role_label = &copy_acl_role_label_normal;
75434 + copy_acl_ip_label = &copy_acl_ip_label_normal;
75435 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75436 + copy_role_transition = &copy_role_transition_normal;
75437 + copy_sprole_pw = &copy_sprole_pw_normal;
75438 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75439 + copy_pointer_from_array = &copy_pointer_from_array_normal;
75440 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75441 + }
75442 + pax_close_kernel();
75443 +#endif
75444 +
75445 + req_count = get_gr_arg_wrapper_size();
75446 +
75447 + if (count != req_count) {
75448 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75449 + error = -EINVAL;
75450 + goto out;
75451 + }
75452 +
75453 +
75454 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75455 + gr_auth_expires = 0;
75456 + gr_auth_attempts = 0;
75457 + }
75458 +
75459 + error = copy_gr_arg_wrapper(buf, &uwrap);
75460 + if (error)
75461 + goto out;
75462 +
75463 + error = copy_gr_arg(uwrap.arg, gr_usermode);
75464 + if (error)
75465 + goto out;
75466 +
75467 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75468 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75469 + time_after(gr_auth_expires, get_seconds())) {
75470 + error = -EBUSY;
75471 + goto out;
75472 + }
75473 +
75474 + /* if non-root trying to do anything other than use a special role,
75475 + do not attempt authentication, do not count towards authentication
75476 + locking
75477 + */
75478 +
75479 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75480 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75481 + gr_is_global_nonroot(current_uid())) {
75482 + error = -EPERM;
75483 + goto out;
75484 + }
75485 +
75486 + /* ensure pw and special role name are null terminated */
75487 +
75488 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75489 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75490 +
75491 + /* Okay.
75492 + * We have our enough of the argument structure..(we have yet
75493 + * to copy_from_user the tables themselves) . Copy the tables
75494 + * only if we need them, i.e. for loading operations. */
75495 +
75496 + switch (gr_usermode->mode) {
75497 + case GR_STATUS:
75498 + if (gr_acl_is_enabled()) {
75499 + error = 1;
75500 + if (!gr_check_secure_terminal(current))
75501 + error = 3;
75502 + } else
75503 + error = 2;
75504 + goto out;
75505 + case GR_SHUTDOWN:
75506 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75507 + stop_machine(gr_rbac_disable, NULL, NULL);
75508 + free_variables(false);
75509 + memset(gr_usermode, 0, sizeof(struct gr_arg));
75510 + memset(gr_system_salt, 0, GR_SALT_LEN);
75511 + memset(gr_system_sum, 0, GR_SHA_LEN);
75512 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75513 + } else if (gr_acl_is_enabled()) {
75514 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75515 + error = -EPERM;
75516 + } else {
75517 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75518 + error = -EAGAIN;
75519 + }
75520 + break;
75521 + case GR_ENABLE:
75522 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75523 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75524 + else {
75525 + if (gr_acl_is_enabled())
75526 + error = -EAGAIN;
75527 + else
75528 + error = error2;
75529 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75530 + }
75531 + break;
75532 + case GR_OLDRELOAD:
75533 + oldmode = 1;
75534 + case GR_RELOAD:
75535 + if (!gr_acl_is_enabled()) {
75536 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75537 + error = -EAGAIN;
75538 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75539 + error2 = gracl_reload(gr_usermode, oldmode);
75540 + if (!error2)
75541 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75542 + else {
75543 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75544 + error = error2;
75545 + }
75546 + } else {
75547 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75548 + error = -EPERM;
75549 + }
75550 + break;
75551 + case GR_SEGVMOD:
75552 + if (unlikely(!gr_acl_is_enabled())) {
75553 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75554 + error = -EAGAIN;
75555 + break;
75556 + }
75557 +
75558 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75559 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75560 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75561 + struct acl_subject_label *segvacl;
75562 + segvacl =
75563 + lookup_acl_subj_label(gr_usermode->segv_inode,
75564 + gr_usermode->segv_device,
75565 + current->role);
75566 + if (segvacl) {
75567 + segvacl->crashes = 0;
75568 + segvacl->expires = 0;
75569 + }
75570 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75571 + gr_remove_uid(gr_usermode->segv_uid);
75572 + }
75573 + } else {
75574 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75575 + error = -EPERM;
75576 + }
75577 + break;
75578 + case GR_SPROLE:
75579 + case GR_SPROLEPAM:
75580 + if (unlikely(!gr_acl_is_enabled())) {
75581 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75582 + error = -EAGAIN;
75583 + break;
75584 + }
75585 +
75586 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75587 + current->role->expires = 0;
75588 + current->role->auth_attempts = 0;
75589 + }
75590 +
75591 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75592 + time_after(current->role->expires, get_seconds())) {
75593 + error = -EBUSY;
75594 + goto out;
75595 + }
75596 +
75597 + if (lookup_special_role_auth
75598 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75599 + && ((!sprole_salt && !sprole_sum)
75600 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75601 + char *p = "";
75602 + assign_special_role(gr_usermode->sp_role);
75603 + read_lock(&tasklist_lock);
75604 + if (current->real_parent)
75605 + p = current->real_parent->role->rolename;
75606 + read_unlock(&tasklist_lock);
75607 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75608 + p, acl_sp_role_value);
75609 + } else {
75610 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75611 + error = -EPERM;
75612 + if(!(current->role->auth_attempts++))
75613 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75614 +
75615 + goto out;
75616 + }
75617 + break;
75618 + case GR_UNSPROLE:
75619 + if (unlikely(!gr_acl_is_enabled())) {
75620 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75621 + error = -EAGAIN;
75622 + break;
75623 + }
75624 +
75625 + if (current->role->roletype & GR_ROLE_SPECIAL) {
75626 + char *p = "";
75627 + int i = 0;
75628 +
75629 + read_lock(&tasklist_lock);
75630 + if (current->real_parent) {
75631 + p = current->real_parent->role->rolename;
75632 + i = current->real_parent->acl_role_id;
75633 + }
75634 + read_unlock(&tasklist_lock);
75635 +
75636 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75637 + gr_set_acls(1);
75638 + } else {
75639 + error = -EPERM;
75640 + goto out;
75641 + }
75642 + break;
75643 + default:
75644 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75645 + error = -EINVAL;
75646 + break;
75647 + }
75648 +
75649 + if (error != -EPERM)
75650 + goto out;
75651 +
75652 + if(!(gr_auth_attempts++))
75653 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75654 +
75655 + out:
75656 + mutex_unlock(&gr_dev_mutex);
75657 +
75658 + if (!error)
75659 + error = req_count;
75660 +
75661 + return error;
75662 +}
75663 +
75664 +int
75665 +gr_set_acls(const int type)
75666 +{
75667 + struct task_struct *task, *task2;
75668 + struct acl_role_label *role = current->role;
75669 + struct acl_subject_label *subj;
75670 + __u16 acl_role_id = current->acl_role_id;
75671 + const struct cred *cred;
75672 + int ret;
75673 +
75674 + rcu_read_lock();
75675 + read_lock(&tasklist_lock);
75676 + read_lock(&grsec_exec_file_lock);
75677 + do_each_thread(task2, task) {
75678 + /* check to see if we're called from the exit handler,
75679 + if so, only replace ACLs that have inherited the admin
75680 + ACL */
75681 +
75682 + if (type && (task->role != role ||
75683 + task->acl_role_id != acl_role_id))
75684 + continue;
75685 +
75686 + task->acl_role_id = 0;
75687 + task->acl_sp_role = 0;
75688 + task->inherited = 0;
75689 +
75690 + if (task->exec_file) {
75691 + cred = __task_cred(task);
75692 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75693 + subj = __gr_get_subject_for_task(polstate, task, NULL, 1);
75694 + if (subj == NULL) {
75695 + ret = -EINVAL;
75696 + read_unlock(&grsec_exec_file_lock);
75697 + read_unlock(&tasklist_lock);
75698 + rcu_read_unlock();
75699 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75700 + return ret;
75701 + }
75702 + __gr_apply_subject_to_task(polstate, task, subj);
75703 + } else {
75704 + // it's a kernel process
75705 + task->role = polstate->kernel_role;
75706 + task->acl = polstate->kernel_role->root_label;
75707 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75708 + task->acl->mode &= ~GR_PROCFIND;
75709 +#endif
75710 + }
75711 + } while_each_thread(task2, task);
75712 + read_unlock(&grsec_exec_file_lock);
75713 + read_unlock(&tasklist_lock);
75714 + rcu_read_unlock();
75715 +
75716 + return 0;
75717 +}
75718 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75719 new file mode 100644
75720 index 0000000..39645c9
75721 --- /dev/null
75722 +++ b/grsecurity/gracl_res.c
75723 @@ -0,0 +1,68 @@
75724 +#include <linux/kernel.h>
75725 +#include <linux/sched.h>
75726 +#include <linux/gracl.h>
75727 +#include <linux/grinternal.h>
75728 +
75729 +static const char *restab_log[] = {
75730 + [RLIMIT_CPU] = "RLIMIT_CPU",
75731 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75732 + [RLIMIT_DATA] = "RLIMIT_DATA",
75733 + [RLIMIT_STACK] = "RLIMIT_STACK",
75734 + [RLIMIT_CORE] = "RLIMIT_CORE",
75735 + [RLIMIT_RSS] = "RLIMIT_RSS",
75736 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
75737 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75738 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75739 + [RLIMIT_AS] = "RLIMIT_AS",
75740 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75741 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75742 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75743 + [RLIMIT_NICE] = "RLIMIT_NICE",
75744 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75745 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75746 + [GR_CRASH_RES] = "RLIMIT_CRASH"
75747 +};
75748 +
75749 +void
75750 +gr_log_resource(const struct task_struct *task,
75751 + const int res, const unsigned long wanted, const int gt)
75752 +{
75753 + const struct cred *cred;
75754 + unsigned long rlim;
75755 +
75756 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
75757 + return;
75758 +
75759 + // not yet supported resource
75760 + if (unlikely(!restab_log[res]))
75761 + return;
75762 +
75763 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75764 + rlim = task_rlimit_max(task, res);
75765 + else
75766 + rlim = task_rlimit(task, res);
75767 +
75768 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75769 + return;
75770 +
75771 + rcu_read_lock();
75772 + cred = __task_cred(task);
75773 +
75774 + if (res == RLIMIT_NPROC &&
75775 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75776 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75777 + goto out_rcu_unlock;
75778 + else if (res == RLIMIT_MEMLOCK &&
75779 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75780 + goto out_rcu_unlock;
75781 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75782 + goto out_rcu_unlock;
75783 + rcu_read_unlock();
75784 +
75785 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75786 +
75787 + return;
75788 +out_rcu_unlock:
75789 + rcu_read_unlock();
75790 + return;
75791 +}
75792 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75793 new file mode 100644
75794 index 0000000..218b66b
75795 --- /dev/null
75796 +++ b/grsecurity/gracl_segv.c
75797 @@ -0,0 +1,324 @@
75798 +#include <linux/kernel.h>
75799 +#include <linux/mm.h>
75800 +#include <asm/uaccess.h>
75801 +#include <asm/errno.h>
75802 +#include <asm/mman.h>
75803 +#include <net/sock.h>
75804 +#include <linux/file.h>
75805 +#include <linux/fs.h>
75806 +#include <linux/net.h>
75807 +#include <linux/in.h>
75808 +#include <linux/slab.h>
75809 +#include <linux/types.h>
75810 +#include <linux/sched.h>
75811 +#include <linux/timer.h>
75812 +#include <linux/gracl.h>
75813 +#include <linux/grsecurity.h>
75814 +#include <linux/grinternal.h>
75815 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75816 +#include <linux/magic.h>
75817 +#include <linux/pagemap.h>
75818 +#include "../fs/btrfs/async-thread.h"
75819 +#include "../fs/btrfs/ctree.h"
75820 +#include "../fs/btrfs/btrfs_inode.h"
75821 +#endif
75822 +
75823 +static struct crash_uid *uid_set;
75824 +static unsigned short uid_used;
75825 +static DEFINE_SPINLOCK(gr_uid_lock);
75826 +extern rwlock_t gr_inode_lock;
75827 +extern struct acl_subject_label *
75828 + lookup_acl_subj_label(const u64 inode, const dev_t dev,
75829 + struct acl_role_label *role);
75830 +
75831 +static inline dev_t __get_dev(const struct dentry *dentry)
75832 +{
75833 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75834 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75835 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
75836 + else
75837 +#endif
75838 + return dentry->d_sb->s_dev;
75839 +}
75840 +
75841 +static inline u64 __get_ino(const struct dentry *dentry)
75842 +{
75843 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75844 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75845 + return btrfs_ino(dentry->d_inode);
75846 + else
75847 +#endif
75848 + return dentry->d_inode->i_ino;
75849 +}
75850 +
75851 +int
75852 +gr_init_uidset(void)
75853 +{
75854 + uid_set =
75855 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75856 + uid_used = 0;
75857 +
75858 + return uid_set ? 1 : 0;
75859 +}
75860 +
75861 +void
75862 +gr_free_uidset(void)
75863 +{
75864 + if (uid_set) {
75865 + struct crash_uid *tmpset;
75866 + spin_lock(&gr_uid_lock);
75867 + tmpset = uid_set;
75868 + uid_set = NULL;
75869 + uid_used = 0;
75870 + spin_unlock(&gr_uid_lock);
75871 + if (tmpset)
75872 + kfree(tmpset);
75873 + }
75874 +
75875 + return;
75876 +}
75877 +
75878 +int
75879 +gr_find_uid(const uid_t uid)
75880 +{
75881 + struct crash_uid *tmp = uid_set;
75882 + uid_t buid;
75883 + int low = 0, high = uid_used - 1, mid;
75884 +
75885 + while (high >= low) {
75886 + mid = (low + high) >> 1;
75887 + buid = tmp[mid].uid;
75888 + if (buid == uid)
75889 + return mid;
75890 + if (buid > uid)
75891 + high = mid - 1;
75892 + if (buid < uid)
75893 + low = mid + 1;
75894 + }
75895 +
75896 + return -1;
75897 +}
75898 +
75899 +static __inline__ void
75900 +gr_insertsort(void)
75901 +{
75902 + unsigned short i, j;
75903 + struct crash_uid index;
75904 +
75905 + for (i = 1; i < uid_used; i++) {
75906 + index = uid_set[i];
75907 + j = i;
75908 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75909 + uid_set[j] = uid_set[j - 1];
75910 + j--;
75911 + }
75912 + uid_set[j] = index;
75913 + }
75914 +
75915 + return;
75916 +}
75917 +
75918 +static __inline__ void
75919 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75920 +{
75921 + int loc;
75922 + uid_t uid = GR_GLOBAL_UID(kuid);
75923 +
75924 + if (uid_used == GR_UIDTABLE_MAX)
75925 + return;
75926 +
75927 + loc = gr_find_uid(uid);
75928 +
75929 + if (loc >= 0) {
75930 + uid_set[loc].expires = expires;
75931 + return;
75932 + }
75933 +
75934 + uid_set[uid_used].uid = uid;
75935 + uid_set[uid_used].expires = expires;
75936 + uid_used++;
75937 +
75938 + gr_insertsort();
75939 +
75940 + return;
75941 +}
75942 +
75943 +void
75944 +gr_remove_uid(const unsigned short loc)
75945 +{
75946 + unsigned short i;
75947 +
75948 + for (i = loc + 1; i < uid_used; i++)
75949 + uid_set[i - 1] = uid_set[i];
75950 +
75951 + uid_used--;
75952 +
75953 + return;
75954 +}
75955 +
75956 +int
75957 +gr_check_crash_uid(const kuid_t kuid)
75958 +{
75959 + int loc;
75960 + int ret = 0;
75961 + uid_t uid;
75962 +
75963 + if (unlikely(!gr_acl_is_enabled()))
75964 + return 0;
75965 +
75966 + uid = GR_GLOBAL_UID(kuid);
75967 +
75968 + spin_lock(&gr_uid_lock);
75969 + loc = gr_find_uid(uid);
75970 +
75971 + if (loc < 0)
75972 + goto out_unlock;
75973 +
75974 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
75975 + gr_remove_uid(loc);
75976 + else
75977 + ret = 1;
75978 +
75979 +out_unlock:
75980 + spin_unlock(&gr_uid_lock);
75981 + return ret;
75982 +}
75983 +
75984 +static __inline__ int
75985 +proc_is_setxid(const struct cred *cred)
75986 +{
75987 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75988 + !uid_eq(cred->uid, cred->fsuid))
75989 + return 1;
75990 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75991 + !gid_eq(cred->gid, cred->fsgid))
75992 + return 1;
75993 +
75994 + return 0;
75995 +}
75996 +
75997 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
75998 +
75999 +void
76000 +gr_handle_crash(struct task_struct *task, const int sig)
76001 +{
76002 + struct acl_subject_label *curr;
76003 + struct task_struct *tsk, *tsk2;
76004 + const struct cred *cred;
76005 + const struct cred *cred2;
76006 +
76007 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76008 + return;
76009 +
76010 + if (unlikely(!gr_acl_is_enabled()))
76011 + return;
76012 +
76013 + curr = task->acl;
76014 +
76015 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
76016 + return;
76017 +
76018 + if (time_before_eq(curr->expires, get_seconds())) {
76019 + curr->expires = 0;
76020 + curr->crashes = 0;
76021 + }
76022 +
76023 + curr->crashes++;
76024 +
76025 + if (!curr->expires)
76026 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76027 +
76028 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76029 + time_after(curr->expires, get_seconds())) {
76030 + rcu_read_lock();
76031 + cred = __task_cred(task);
76032 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76033 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76034 + spin_lock(&gr_uid_lock);
76035 + gr_insert_uid(cred->uid, curr->expires);
76036 + spin_unlock(&gr_uid_lock);
76037 + curr->expires = 0;
76038 + curr->crashes = 0;
76039 + read_lock(&tasklist_lock);
76040 + do_each_thread(tsk2, tsk) {
76041 + cred2 = __task_cred(tsk);
76042 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
76043 + gr_fake_force_sig(SIGKILL, tsk);
76044 + } while_each_thread(tsk2, tsk);
76045 + read_unlock(&tasklist_lock);
76046 + } else {
76047 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76048 + read_lock(&tasklist_lock);
76049 + read_lock(&grsec_exec_file_lock);
76050 + do_each_thread(tsk2, tsk) {
76051 + if (likely(tsk != task)) {
76052 + // if this thread has the same subject as the one that triggered
76053 + // RES_CRASH and it's the same binary, kill it
76054 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76055 + gr_fake_force_sig(SIGKILL, tsk);
76056 + }
76057 + } while_each_thread(tsk2, tsk);
76058 + read_unlock(&grsec_exec_file_lock);
76059 + read_unlock(&tasklist_lock);
76060 + }
76061 + rcu_read_unlock();
76062 + }
76063 +
76064 + return;
76065 +}
76066 +
76067 +int
76068 +gr_check_crash_exec(const struct file *filp)
76069 +{
76070 + struct acl_subject_label *curr;
76071 + struct dentry *dentry;
76072 +
76073 + if (unlikely(!gr_acl_is_enabled()))
76074 + return 0;
76075 +
76076 + read_lock(&gr_inode_lock);
76077 + dentry = filp->f_path.dentry;
76078 + curr = lookup_acl_subj_label(__get_ino(dentry), __get_dev(dentry),
76079 + current->role);
76080 + read_unlock(&gr_inode_lock);
76081 +
76082 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76083 + (!curr->crashes && !curr->expires))
76084 + return 0;
76085 +
76086 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76087 + time_after(curr->expires, get_seconds()))
76088 + return 1;
76089 + else if (time_before_eq(curr->expires, get_seconds())) {
76090 + curr->crashes = 0;
76091 + curr->expires = 0;
76092 + }
76093 +
76094 + return 0;
76095 +}
76096 +
76097 +void
76098 +gr_handle_alertkill(struct task_struct *task)
76099 +{
76100 + struct acl_subject_label *curracl;
76101 + __u32 curr_ip;
76102 + struct task_struct *p, *p2;
76103 +
76104 + if (unlikely(!gr_acl_is_enabled()))
76105 + return;
76106 +
76107 + curracl = task->acl;
76108 + curr_ip = task->signal->curr_ip;
76109 +
76110 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76111 + read_lock(&tasklist_lock);
76112 + do_each_thread(p2, p) {
76113 + if (p->signal->curr_ip == curr_ip)
76114 + gr_fake_force_sig(SIGKILL, p);
76115 + } while_each_thread(p2, p);
76116 + read_unlock(&tasklist_lock);
76117 + } else if (curracl->mode & GR_KILLPROC)
76118 + gr_fake_force_sig(SIGKILL, task);
76119 +
76120 + return;
76121 +}
76122 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76123 new file mode 100644
76124 index 0000000..6b0c9cc
76125 --- /dev/null
76126 +++ b/grsecurity/gracl_shm.c
76127 @@ -0,0 +1,40 @@
76128 +#include <linux/kernel.h>
76129 +#include <linux/mm.h>
76130 +#include <linux/sched.h>
76131 +#include <linux/file.h>
76132 +#include <linux/ipc.h>
76133 +#include <linux/gracl.h>
76134 +#include <linux/grsecurity.h>
76135 +#include <linux/grinternal.h>
76136 +
76137 +int
76138 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76139 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
76140 +{
76141 + struct task_struct *task;
76142 +
76143 + if (!gr_acl_is_enabled())
76144 + return 1;
76145 +
76146 + rcu_read_lock();
76147 + read_lock(&tasklist_lock);
76148 +
76149 + task = find_task_by_vpid(shm_cprid);
76150 +
76151 + if (unlikely(!task))
76152 + task = find_task_by_vpid(shm_lapid);
76153 +
76154 + if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76155 + (task_pid_nr(task) == shm_lapid)) &&
76156 + (task->acl->mode & GR_PROTSHM) &&
76157 + (task->acl != current->acl))) {
76158 + read_unlock(&tasklist_lock);
76159 + rcu_read_unlock();
76160 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76161 + return 0;
76162 + }
76163 + read_unlock(&tasklist_lock);
76164 + rcu_read_unlock();
76165 +
76166 + return 1;
76167 +}
76168 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76169 new file mode 100644
76170 index 0000000..bc0be01
76171 --- /dev/null
76172 +++ b/grsecurity/grsec_chdir.c
76173 @@ -0,0 +1,19 @@
76174 +#include <linux/kernel.h>
76175 +#include <linux/sched.h>
76176 +#include <linux/fs.h>
76177 +#include <linux/file.h>
76178 +#include <linux/grsecurity.h>
76179 +#include <linux/grinternal.h>
76180 +
76181 +void
76182 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76183 +{
76184 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76185 + if ((grsec_enable_chdir && grsec_enable_group &&
76186 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76187 + !grsec_enable_group)) {
76188 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76189 + }
76190 +#endif
76191 + return;
76192 +}
76193 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76194 new file mode 100644
76195 index 0000000..114ea4f
76196 --- /dev/null
76197 +++ b/grsecurity/grsec_chroot.c
76198 @@ -0,0 +1,467 @@
76199 +#include <linux/kernel.h>
76200 +#include <linux/module.h>
76201 +#include <linux/sched.h>
76202 +#include <linux/file.h>
76203 +#include <linux/fs.h>
76204 +#include <linux/mount.h>
76205 +#include <linux/types.h>
76206 +#include "../fs/mount.h"
76207 +#include <linux/grsecurity.h>
76208 +#include <linux/grinternal.h>
76209 +
76210 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76211 +int gr_init_ran;
76212 +#endif
76213 +
76214 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76215 +{
76216 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76217 + struct dentry *tmpd = dentry;
76218 +
76219 + read_seqlock_excl(&mount_lock);
76220 + write_seqlock(&rename_lock);
76221 +
76222 + while (tmpd != mnt->mnt_root) {
76223 + atomic_inc(&tmpd->chroot_refcnt);
76224 + tmpd = tmpd->d_parent;
76225 + }
76226 + atomic_inc(&tmpd->chroot_refcnt);
76227 +
76228 + write_sequnlock(&rename_lock);
76229 + read_sequnlock_excl(&mount_lock);
76230 +#endif
76231 +}
76232 +
76233 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt)
76234 +{
76235 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76236 + struct dentry *tmpd = dentry;
76237 +
76238 + read_seqlock_excl(&mount_lock);
76239 + write_seqlock(&rename_lock);
76240 +
76241 + while (tmpd != mnt->mnt_root) {
76242 + atomic_dec(&tmpd->chroot_refcnt);
76243 + tmpd = tmpd->d_parent;
76244 + }
76245 + atomic_dec(&tmpd->chroot_refcnt);
76246 +
76247 + write_sequnlock(&rename_lock);
76248 + read_sequnlock_excl(&mount_lock);
76249 +#endif
76250 +}
76251 +
76252 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76253 +static struct dentry *get_closest_chroot(struct dentry *dentry)
76254 +{
76255 + write_seqlock(&rename_lock);
76256 + do {
76257 + if (atomic_read(&dentry->chroot_refcnt)) {
76258 + write_sequnlock(&rename_lock);
76259 + return dentry;
76260 + }
76261 + dentry = dentry->d_parent;
76262 + } while (!IS_ROOT(dentry));
76263 + write_sequnlock(&rename_lock);
76264 + return NULL;
76265 +}
76266 +#endif
76267 +
76268 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
76269 + struct dentry *newdentry, struct vfsmount *newmnt)
76270 +{
76271 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
76272 + struct dentry *chroot;
76273 +
76274 + if (unlikely(!grsec_enable_chroot_rename))
76275 + return 0;
76276 +
76277 + if (likely(!proc_is_chrooted(current) && gr_is_global_root(current_uid())))
76278 + return 0;
76279 +
76280 + chroot = get_closest_chroot(olddentry);
76281 +
76282 + if (chroot == NULL)
76283 + return 0;
76284 +
76285 + if (is_subdir(newdentry, chroot))
76286 + return 0;
76287 +
76288 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_RENAME_MSG, olddentry, oldmnt);
76289 +
76290 + return 1;
76291 +#else
76292 + return 0;
76293 +#endif
76294 +}
76295 +
76296 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76297 +{
76298 +#ifdef CONFIG_GRKERNSEC
76299 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76300 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76301 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76302 + && gr_init_ran
76303 +#endif
76304 + )
76305 + task->gr_is_chrooted = 1;
76306 + else {
76307 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76308 + if (task_pid_nr(task) == 1 && !gr_init_ran)
76309 + gr_init_ran = 1;
76310 +#endif
76311 + task->gr_is_chrooted = 0;
76312 + }
76313 +
76314 + task->gr_chroot_dentry = path->dentry;
76315 +#endif
76316 + return;
76317 +}
76318 +
76319 +void gr_clear_chroot_entries(struct task_struct *task)
76320 +{
76321 +#ifdef CONFIG_GRKERNSEC
76322 + task->gr_is_chrooted = 0;
76323 + task->gr_chroot_dentry = NULL;
76324 +#endif
76325 + return;
76326 +}
76327 +
76328 +int
76329 +gr_handle_chroot_unix(const pid_t pid)
76330 +{
76331 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76332 + struct task_struct *p;
76333 +
76334 + if (unlikely(!grsec_enable_chroot_unix))
76335 + return 1;
76336 +
76337 + if (likely(!proc_is_chrooted(current)))
76338 + return 1;
76339 +
76340 + rcu_read_lock();
76341 + read_lock(&tasklist_lock);
76342 + p = find_task_by_vpid_unrestricted(pid);
76343 + if (unlikely(p && !have_same_root(current, p))) {
76344 + read_unlock(&tasklist_lock);
76345 + rcu_read_unlock();
76346 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76347 + return 0;
76348 + }
76349 + read_unlock(&tasklist_lock);
76350 + rcu_read_unlock();
76351 +#endif
76352 + return 1;
76353 +}
76354 +
76355 +int
76356 +gr_handle_chroot_nice(void)
76357 +{
76358 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76359 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76360 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76361 + return -EPERM;
76362 + }
76363 +#endif
76364 + return 0;
76365 +}
76366 +
76367 +int
76368 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76369 +{
76370 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76371 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76372 + && proc_is_chrooted(current)) {
76373 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76374 + return -EACCES;
76375 + }
76376 +#endif
76377 + return 0;
76378 +}
76379 +
76380 +int
76381 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76382 +{
76383 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76384 + struct task_struct *p;
76385 + int ret = 0;
76386 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76387 + return ret;
76388 +
76389 + read_lock(&tasklist_lock);
76390 + do_each_pid_task(pid, type, p) {
76391 + if (!have_same_root(current, p)) {
76392 + ret = 1;
76393 + goto out;
76394 + }
76395 + } while_each_pid_task(pid, type, p);
76396 +out:
76397 + read_unlock(&tasklist_lock);
76398 + return ret;
76399 +#endif
76400 + return 0;
76401 +}
76402 +
76403 +int
76404 +gr_pid_is_chrooted(struct task_struct *p)
76405 +{
76406 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76407 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76408 + return 0;
76409 +
76410 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76411 + !have_same_root(current, p)) {
76412 + return 1;
76413 + }
76414 +#endif
76415 + return 0;
76416 +}
76417 +
76418 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76419 +
76420 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76421 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76422 +{
76423 + struct path path, currentroot;
76424 + int ret = 0;
76425 +
76426 + path.dentry = (struct dentry *)u_dentry;
76427 + path.mnt = (struct vfsmount *)u_mnt;
76428 + get_fs_root(current->fs, &currentroot);
76429 + if (path_is_under(&path, &currentroot))
76430 + ret = 1;
76431 + path_put(&currentroot);
76432 +
76433 + return ret;
76434 +}
76435 +#endif
76436 +
76437 +int
76438 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76439 +{
76440 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76441 + if (!grsec_enable_chroot_fchdir)
76442 + return 1;
76443 +
76444 + if (!proc_is_chrooted(current))
76445 + return 1;
76446 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76447 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76448 + return 0;
76449 + }
76450 +#endif
76451 + return 1;
76452 +}
76453 +
76454 +int
76455 +gr_chroot_fhandle(void)
76456 +{
76457 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76458 + if (!grsec_enable_chroot_fchdir)
76459 + return 1;
76460 +
76461 + if (!proc_is_chrooted(current))
76462 + return 1;
76463 + else {
76464 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76465 + return 0;
76466 + }
76467 +#endif
76468 + return 1;
76469 +}
76470 +
76471 +int
76472 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76473 + const u64 shm_createtime)
76474 +{
76475 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76476 + struct task_struct *p;
76477 +
76478 + if (unlikely(!grsec_enable_chroot_shmat))
76479 + return 1;
76480 +
76481 + if (likely(!proc_is_chrooted(current)))
76482 + return 1;
76483 +
76484 + rcu_read_lock();
76485 + read_lock(&tasklist_lock);
76486 +
76487 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76488 + if (time_before_eq64(p->start_time, shm_createtime)) {
76489 + if (have_same_root(current, p)) {
76490 + goto allow;
76491 + } else {
76492 + read_unlock(&tasklist_lock);
76493 + rcu_read_unlock();
76494 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76495 + return 0;
76496 + }
76497 + }
76498 + /* creator exited, pid reuse, fall through to next check */
76499 + }
76500 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76501 + if (unlikely(!have_same_root(current, p))) {
76502 + read_unlock(&tasklist_lock);
76503 + rcu_read_unlock();
76504 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76505 + return 0;
76506 + }
76507 + }
76508 +
76509 +allow:
76510 + read_unlock(&tasklist_lock);
76511 + rcu_read_unlock();
76512 +#endif
76513 + return 1;
76514 +}
76515 +
76516 +void
76517 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76518 +{
76519 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76520 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76521 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76522 +#endif
76523 + return;
76524 +}
76525 +
76526 +int
76527 +gr_handle_chroot_mknod(const struct dentry *dentry,
76528 + const struct vfsmount *mnt, const int mode)
76529 +{
76530 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76531 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76532 + proc_is_chrooted(current)) {
76533 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76534 + return -EPERM;
76535 + }
76536 +#endif
76537 + return 0;
76538 +}
76539 +
76540 +int
76541 +gr_handle_chroot_mount(const struct dentry *dentry,
76542 + const struct vfsmount *mnt, const char *dev_name)
76543 +{
76544 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76545 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76546 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76547 + return -EPERM;
76548 + }
76549 +#endif
76550 + return 0;
76551 +}
76552 +
76553 +int
76554 +gr_handle_chroot_pivot(void)
76555 +{
76556 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76557 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76558 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76559 + return -EPERM;
76560 + }
76561 +#endif
76562 + return 0;
76563 +}
76564 +
76565 +int
76566 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76567 +{
76568 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76569 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76570 + !gr_is_outside_chroot(dentry, mnt)) {
76571 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76572 + return -EPERM;
76573 + }
76574 +#endif
76575 + return 0;
76576 +}
76577 +
76578 +extern const char *captab_log[];
76579 +extern int captab_log_entries;
76580 +
76581 +int
76582 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76583 +{
76584 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76585 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76586 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76587 + if (cap_raised(chroot_caps, cap)) {
76588 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76589 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76590 + }
76591 + return 0;
76592 + }
76593 + }
76594 +#endif
76595 + return 1;
76596 +}
76597 +
76598 +int
76599 +gr_chroot_is_capable(const int cap)
76600 +{
76601 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76602 + return gr_task_chroot_is_capable(current, current_cred(), cap);
76603 +#endif
76604 + return 1;
76605 +}
76606 +
76607 +int
76608 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76609 +{
76610 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76611 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76612 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76613 + if (cap_raised(chroot_caps, cap)) {
76614 + return 0;
76615 + }
76616 + }
76617 +#endif
76618 + return 1;
76619 +}
76620 +
76621 +int
76622 +gr_chroot_is_capable_nolog(const int cap)
76623 +{
76624 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76625 + return gr_task_chroot_is_capable_nolog(current, cap);
76626 +#endif
76627 + return 1;
76628 +}
76629 +
76630 +int
76631 +gr_handle_chroot_sysctl(const int op)
76632 +{
76633 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76634 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76635 + proc_is_chrooted(current))
76636 + return -EACCES;
76637 +#endif
76638 + return 0;
76639 +}
76640 +
76641 +void
76642 +gr_handle_chroot_chdir(const struct path *path)
76643 +{
76644 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76645 + if (grsec_enable_chroot_chdir)
76646 + set_fs_pwd(current->fs, path);
76647 +#endif
76648 + return;
76649 +}
76650 +
76651 +int
76652 +gr_handle_chroot_chmod(const struct dentry *dentry,
76653 + const struct vfsmount *mnt, const int mode)
76654 +{
76655 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76656 + /* allow chmod +s on directories, but not files */
76657 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76658 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76659 + proc_is_chrooted(current)) {
76660 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76661 + return -EPERM;
76662 + }
76663 +#endif
76664 + return 0;
76665 +}
76666 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76667 new file mode 100644
76668 index 0000000..946f750
76669 --- /dev/null
76670 +++ b/grsecurity/grsec_disabled.c
76671 @@ -0,0 +1,445 @@
76672 +#include <linux/kernel.h>
76673 +#include <linux/module.h>
76674 +#include <linux/sched.h>
76675 +#include <linux/file.h>
76676 +#include <linux/fs.h>
76677 +#include <linux/kdev_t.h>
76678 +#include <linux/net.h>
76679 +#include <linux/in.h>
76680 +#include <linux/ip.h>
76681 +#include <linux/skbuff.h>
76682 +#include <linux/sysctl.h>
76683 +
76684 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76685 +void
76686 +pax_set_initial_flags(struct linux_binprm *bprm)
76687 +{
76688 + return;
76689 +}
76690 +#endif
76691 +
76692 +#ifdef CONFIG_SYSCTL
76693 +__u32
76694 +gr_handle_sysctl(const struct ctl_table * table, const int op)
76695 +{
76696 + return 0;
76697 +}
76698 +#endif
76699 +
76700 +#ifdef CONFIG_TASKSTATS
76701 +int gr_is_taskstats_denied(int pid)
76702 +{
76703 + return 0;
76704 +}
76705 +#endif
76706 +
76707 +int
76708 +gr_acl_is_enabled(void)
76709 +{
76710 + return 0;
76711 +}
76712 +
76713 +int
76714 +gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76715 +{
76716 + return 0;
76717 +}
76718 +
76719 +void
76720 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76721 +{
76722 + return;
76723 +}
76724 +
76725 +int
76726 +gr_handle_rawio(const struct inode *inode)
76727 +{
76728 + return 0;
76729 +}
76730 +
76731 +void
76732 +gr_acl_handle_psacct(struct task_struct *task, const long code)
76733 +{
76734 + return;
76735 +}
76736 +
76737 +int
76738 +gr_handle_ptrace(struct task_struct *task, const long request)
76739 +{
76740 + return 0;
76741 +}
76742 +
76743 +int
76744 +gr_handle_proc_ptrace(struct task_struct *task)
76745 +{
76746 + return 0;
76747 +}
76748 +
76749 +int
76750 +gr_set_acls(const int type)
76751 +{
76752 + return 0;
76753 +}
76754 +
76755 +int
76756 +gr_check_hidden_task(const struct task_struct *tsk)
76757 +{
76758 + return 0;
76759 +}
76760 +
76761 +int
76762 +gr_check_protected_task(const struct task_struct *task)
76763 +{
76764 + return 0;
76765 +}
76766 +
76767 +int
76768 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76769 +{
76770 + return 0;
76771 +}
76772 +
76773 +void
76774 +gr_copy_label(struct task_struct *tsk)
76775 +{
76776 + return;
76777 +}
76778 +
76779 +void
76780 +gr_set_pax_flags(struct task_struct *task)
76781 +{
76782 + return;
76783 +}
76784 +
76785 +int
76786 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76787 + const int unsafe_share)
76788 +{
76789 + return 0;
76790 +}
76791 +
76792 +void
76793 +gr_handle_delete(const u64 ino, const dev_t dev)
76794 +{
76795 + return;
76796 +}
76797 +
76798 +void
76799 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76800 +{
76801 + return;
76802 +}
76803 +
76804 +void
76805 +gr_handle_crash(struct task_struct *task, const int sig)
76806 +{
76807 + return;
76808 +}
76809 +
76810 +int
76811 +gr_check_crash_exec(const struct file *filp)
76812 +{
76813 + return 0;
76814 +}
76815 +
76816 +int
76817 +gr_check_crash_uid(const kuid_t uid)
76818 +{
76819 + return 0;
76820 +}
76821 +
76822 +void
76823 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76824 + struct dentry *old_dentry,
76825 + struct dentry *new_dentry,
76826 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76827 +{
76828 + return;
76829 +}
76830 +
76831 +int
76832 +gr_search_socket(const int family, const int type, const int protocol)
76833 +{
76834 + return 1;
76835 +}
76836 +
76837 +int
76838 +gr_search_connectbind(const int mode, const struct socket *sock,
76839 + const struct sockaddr_in *addr)
76840 +{
76841 + return 0;
76842 +}
76843 +
76844 +void
76845 +gr_handle_alertkill(struct task_struct *task)
76846 +{
76847 + return;
76848 +}
76849 +
76850 +__u32
76851 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76852 +{
76853 + return 1;
76854 +}
76855 +
76856 +__u32
76857 +gr_acl_handle_hidden_file(const struct dentry * dentry,
76858 + const struct vfsmount * mnt)
76859 +{
76860 + return 1;
76861 +}
76862 +
76863 +__u32
76864 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76865 + int acc_mode)
76866 +{
76867 + return 1;
76868 +}
76869 +
76870 +__u32
76871 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76872 +{
76873 + return 1;
76874 +}
76875 +
76876 +__u32
76877 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76878 +{
76879 + return 1;
76880 +}
76881 +
76882 +int
76883 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76884 + unsigned int *vm_flags)
76885 +{
76886 + return 1;
76887 +}
76888 +
76889 +__u32
76890 +gr_acl_handle_truncate(const struct dentry * dentry,
76891 + const struct vfsmount * mnt)
76892 +{
76893 + return 1;
76894 +}
76895 +
76896 +__u32
76897 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76898 +{
76899 + return 1;
76900 +}
76901 +
76902 +__u32
76903 +gr_acl_handle_access(const struct dentry * dentry,
76904 + const struct vfsmount * mnt, const int fmode)
76905 +{
76906 + return 1;
76907 +}
76908 +
76909 +__u32
76910 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76911 + umode_t *mode)
76912 +{
76913 + return 1;
76914 +}
76915 +
76916 +__u32
76917 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76918 +{
76919 + return 1;
76920 +}
76921 +
76922 +__u32
76923 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76924 +{
76925 + return 1;
76926 +}
76927 +
76928 +__u32
76929 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76930 +{
76931 + return 1;
76932 +}
76933 +
76934 +void
76935 +grsecurity_init(void)
76936 +{
76937 + return;
76938 +}
76939 +
76940 +umode_t gr_acl_umask(void)
76941 +{
76942 + return 0;
76943 +}
76944 +
76945 +__u32
76946 +gr_acl_handle_mknod(const struct dentry * new_dentry,
76947 + const struct dentry * parent_dentry,
76948 + const struct vfsmount * parent_mnt,
76949 + const int mode)
76950 +{
76951 + return 1;
76952 +}
76953 +
76954 +__u32
76955 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
76956 + const struct dentry * parent_dentry,
76957 + const struct vfsmount * parent_mnt)
76958 +{
76959 + return 1;
76960 +}
76961 +
76962 +__u32
76963 +gr_acl_handle_symlink(const struct dentry * new_dentry,
76964 + const struct dentry * parent_dentry,
76965 + const struct vfsmount * parent_mnt, const struct filename *from)
76966 +{
76967 + return 1;
76968 +}
76969 +
76970 +__u32
76971 +gr_acl_handle_link(const struct dentry * new_dentry,
76972 + const struct dentry * parent_dentry,
76973 + const struct vfsmount * parent_mnt,
76974 + const struct dentry * old_dentry,
76975 + const struct vfsmount * old_mnt, const struct filename *to)
76976 +{
76977 + return 1;
76978 +}
76979 +
76980 +int
76981 +gr_acl_handle_rename(const struct dentry *new_dentry,
76982 + const struct dentry *parent_dentry,
76983 + const struct vfsmount *parent_mnt,
76984 + const struct dentry *old_dentry,
76985 + const struct inode *old_parent_inode,
76986 + const struct vfsmount *old_mnt, const struct filename *newname,
76987 + unsigned int flags)
76988 +{
76989 + return 0;
76990 +}
76991 +
76992 +int
76993 +gr_acl_handle_filldir(const struct file *file, const char *name,
76994 + const int namelen, const u64 ino)
76995 +{
76996 + return 1;
76997 +}
76998 +
76999 +int
77000 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77001 + const u64 shm_createtime, const kuid_t cuid, const int shmid)
77002 +{
77003 + return 1;
77004 +}
77005 +
77006 +int
77007 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77008 +{
77009 + return 0;
77010 +}
77011 +
77012 +int
77013 +gr_search_accept(const struct socket *sock)
77014 +{
77015 + return 0;
77016 +}
77017 +
77018 +int
77019 +gr_search_listen(const struct socket *sock)
77020 +{
77021 + return 0;
77022 +}
77023 +
77024 +int
77025 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77026 +{
77027 + return 0;
77028 +}
77029 +
77030 +__u32
77031 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77032 +{
77033 + return 1;
77034 +}
77035 +
77036 +__u32
77037 +gr_acl_handle_creat(const struct dentry * dentry,
77038 + const struct dentry * p_dentry,
77039 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77040 + const int imode)
77041 +{
77042 + return 1;
77043 +}
77044 +
77045 +void
77046 +gr_acl_handle_exit(void)
77047 +{
77048 + return;
77049 +}
77050 +
77051 +int
77052 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77053 +{
77054 + return 1;
77055 +}
77056 +
77057 +void
77058 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
77059 +{
77060 + return;
77061 +}
77062 +
77063 +int
77064 +gr_acl_handle_procpidmem(const struct task_struct *task)
77065 +{
77066 + return 0;
77067 +}
77068 +
77069 +int
77070 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77071 +{
77072 + return 0;
77073 +}
77074 +
77075 +int
77076 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77077 +{
77078 + return 0;
77079 +}
77080 +
77081 +int
77082 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77083 +{
77084 + return 0;
77085 +}
77086 +
77087 +int
77088 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77089 +{
77090 + return 0;
77091 +}
77092 +
77093 +int gr_acl_enable_at_secure(void)
77094 +{
77095 + return 0;
77096 +}
77097 +
77098 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77099 +{
77100 + return dentry->d_sb->s_dev;
77101 +}
77102 +
77103 +u64 gr_get_ino_from_dentry(struct dentry *dentry)
77104 +{
77105 + return dentry->d_inode->i_ino;
77106 +}
77107 +
77108 +void gr_put_exec_file(struct task_struct *task)
77109 +{
77110 + return;
77111 +}
77112 +
77113 +#ifdef CONFIG_SECURITY
77114 +EXPORT_SYMBOL_GPL(gr_check_user_change);
77115 +EXPORT_SYMBOL_GPL(gr_check_group_change);
77116 +#endif
77117 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77118 new file mode 100644
77119 index 0000000..14638ff
77120 --- /dev/null
77121 +++ b/grsecurity/grsec_exec.c
77122 @@ -0,0 +1,188 @@
77123 +#include <linux/kernel.h>
77124 +#include <linux/sched.h>
77125 +#include <linux/file.h>
77126 +#include <linux/binfmts.h>
77127 +#include <linux/fs.h>
77128 +#include <linux/types.h>
77129 +#include <linux/grdefs.h>
77130 +#include <linux/grsecurity.h>
77131 +#include <linux/grinternal.h>
77132 +#include <linux/capability.h>
77133 +#include <linux/module.h>
77134 +#include <linux/compat.h>
77135 +
77136 +#include <asm/uaccess.h>
77137 +
77138 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77139 +static char gr_exec_arg_buf[132];
77140 +static DEFINE_MUTEX(gr_exec_arg_mutex);
77141 +#endif
77142 +
77143 +struct user_arg_ptr {
77144 +#ifdef CONFIG_COMPAT
77145 + bool is_compat;
77146 +#endif
77147 + union {
77148 + const char __user *const __user *native;
77149 +#ifdef CONFIG_COMPAT
77150 + const compat_uptr_t __user *compat;
77151 +#endif
77152 + } ptr;
77153 +};
77154 +
77155 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77156 +
77157 +void
77158 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77159 +{
77160 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77161 + char *grarg = gr_exec_arg_buf;
77162 + unsigned int i, x, execlen = 0;
77163 + char c;
77164 +
77165 + if (!((grsec_enable_execlog && grsec_enable_group &&
77166 + in_group_p(grsec_audit_gid))
77167 + || (grsec_enable_execlog && !grsec_enable_group)))
77168 + return;
77169 +
77170 + mutex_lock(&gr_exec_arg_mutex);
77171 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
77172 +
77173 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
77174 + const char __user *p;
77175 + unsigned int len;
77176 +
77177 + p = get_user_arg_ptr(argv, i);
77178 + if (IS_ERR(p))
77179 + goto log;
77180 +
77181 + len = strnlen_user(p, 128 - execlen);
77182 + if (len > 128 - execlen)
77183 + len = 128 - execlen;
77184 + else if (len > 0)
77185 + len--;
77186 + if (copy_from_user(grarg + execlen, p, len))
77187 + goto log;
77188 +
77189 + /* rewrite unprintable characters */
77190 + for (x = 0; x < len; x++) {
77191 + c = *(grarg + execlen + x);
77192 + if (c < 32 || c > 126)
77193 + *(grarg + execlen + x) = ' ';
77194 + }
77195 +
77196 + execlen += len;
77197 + *(grarg + execlen) = ' ';
77198 + *(grarg + execlen + 1) = '\0';
77199 + execlen++;
77200 + }
77201 +
77202 + log:
77203 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77204 + bprm->file->f_path.mnt, grarg);
77205 + mutex_unlock(&gr_exec_arg_mutex);
77206 +#endif
77207 + return;
77208 +}
77209 +
77210 +#ifdef CONFIG_GRKERNSEC
77211 +extern int gr_acl_is_capable(const int cap);
77212 +extern int gr_acl_is_capable_nolog(const int cap);
77213 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77214 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77215 +extern int gr_chroot_is_capable(const int cap);
77216 +extern int gr_chroot_is_capable_nolog(const int cap);
77217 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77218 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77219 +#endif
77220 +
77221 +const char *captab_log[] = {
77222 + "CAP_CHOWN",
77223 + "CAP_DAC_OVERRIDE",
77224 + "CAP_DAC_READ_SEARCH",
77225 + "CAP_FOWNER",
77226 + "CAP_FSETID",
77227 + "CAP_KILL",
77228 + "CAP_SETGID",
77229 + "CAP_SETUID",
77230 + "CAP_SETPCAP",
77231 + "CAP_LINUX_IMMUTABLE",
77232 + "CAP_NET_BIND_SERVICE",
77233 + "CAP_NET_BROADCAST",
77234 + "CAP_NET_ADMIN",
77235 + "CAP_NET_RAW",
77236 + "CAP_IPC_LOCK",
77237 + "CAP_IPC_OWNER",
77238 + "CAP_SYS_MODULE",
77239 + "CAP_SYS_RAWIO",
77240 + "CAP_SYS_CHROOT",
77241 + "CAP_SYS_PTRACE",
77242 + "CAP_SYS_PACCT",
77243 + "CAP_SYS_ADMIN",
77244 + "CAP_SYS_BOOT",
77245 + "CAP_SYS_NICE",
77246 + "CAP_SYS_RESOURCE",
77247 + "CAP_SYS_TIME",
77248 + "CAP_SYS_TTY_CONFIG",
77249 + "CAP_MKNOD",
77250 + "CAP_LEASE",
77251 + "CAP_AUDIT_WRITE",
77252 + "CAP_AUDIT_CONTROL",
77253 + "CAP_SETFCAP",
77254 + "CAP_MAC_OVERRIDE",
77255 + "CAP_MAC_ADMIN",
77256 + "CAP_SYSLOG",
77257 + "CAP_WAKE_ALARM",
77258 + "CAP_BLOCK_SUSPEND"
77259 +};
77260 +
77261 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77262 +
77263 +int gr_is_capable(const int cap)
77264 +{
77265 +#ifdef CONFIG_GRKERNSEC
77266 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77267 + return 1;
77268 + return 0;
77269 +#else
77270 + return 1;
77271 +#endif
77272 +}
77273 +
77274 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77275 +{
77276 +#ifdef CONFIG_GRKERNSEC
77277 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77278 + return 1;
77279 + return 0;
77280 +#else
77281 + return 1;
77282 +#endif
77283 +}
77284 +
77285 +int gr_is_capable_nolog(const int cap)
77286 +{
77287 +#ifdef CONFIG_GRKERNSEC
77288 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77289 + return 1;
77290 + return 0;
77291 +#else
77292 + return 1;
77293 +#endif
77294 +}
77295 +
77296 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77297 +{
77298 +#ifdef CONFIG_GRKERNSEC
77299 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77300 + return 1;
77301 + return 0;
77302 +#else
77303 + return 1;
77304 +#endif
77305 +}
77306 +
77307 +EXPORT_SYMBOL_GPL(gr_is_capable);
77308 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77309 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
77310 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77311 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77312 new file mode 100644
77313 index 0000000..06cc6ea
77314 --- /dev/null
77315 +++ b/grsecurity/grsec_fifo.c
77316 @@ -0,0 +1,24 @@
77317 +#include <linux/kernel.h>
77318 +#include <linux/sched.h>
77319 +#include <linux/fs.h>
77320 +#include <linux/file.h>
77321 +#include <linux/grinternal.h>
77322 +
77323 +int
77324 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77325 + const struct dentry *dir, const int flag, const int acc_mode)
77326 +{
77327 +#ifdef CONFIG_GRKERNSEC_FIFO
77328 + const struct cred *cred = current_cred();
77329 +
77330 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77331 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77332 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77333 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77334 + if (!inode_permission(dentry->d_inode, acc_mode))
77335 + 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));
77336 + return -EACCES;
77337 + }
77338 +#endif
77339 + return 0;
77340 +}
77341 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77342 new file mode 100644
77343 index 0000000..8ca18bf
77344 --- /dev/null
77345 +++ b/grsecurity/grsec_fork.c
77346 @@ -0,0 +1,23 @@
77347 +#include <linux/kernel.h>
77348 +#include <linux/sched.h>
77349 +#include <linux/grsecurity.h>
77350 +#include <linux/grinternal.h>
77351 +#include <linux/errno.h>
77352 +
77353 +void
77354 +gr_log_forkfail(const int retval)
77355 +{
77356 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77357 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77358 + switch (retval) {
77359 + case -EAGAIN:
77360 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77361 + break;
77362 + case -ENOMEM:
77363 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77364 + break;
77365 + }
77366 + }
77367 +#endif
77368 + return;
77369 +}
77370 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77371 new file mode 100644
77372 index 0000000..4ed9e7d
77373 --- /dev/null
77374 +++ b/grsecurity/grsec_init.c
77375 @@ -0,0 +1,290 @@
77376 +#include <linux/kernel.h>
77377 +#include <linux/sched.h>
77378 +#include <linux/mm.h>
77379 +#include <linux/gracl.h>
77380 +#include <linux/slab.h>
77381 +#include <linux/vmalloc.h>
77382 +#include <linux/percpu.h>
77383 +#include <linux/module.h>
77384 +
77385 +int grsec_enable_ptrace_readexec;
77386 +int grsec_enable_setxid;
77387 +int grsec_enable_symlinkown;
77388 +kgid_t grsec_symlinkown_gid;
77389 +int grsec_enable_brute;
77390 +int grsec_enable_link;
77391 +int grsec_enable_dmesg;
77392 +int grsec_enable_harden_ptrace;
77393 +int grsec_enable_harden_ipc;
77394 +int grsec_enable_fifo;
77395 +int grsec_enable_execlog;
77396 +int grsec_enable_signal;
77397 +int grsec_enable_forkfail;
77398 +int grsec_enable_audit_ptrace;
77399 +int grsec_enable_time;
77400 +int grsec_enable_group;
77401 +kgid_t grsec_audit_gid;
77402 +int grsec_enable_chdir;
77403 +int grsec_enable_mount;
77404 +int grsec_enable_rofs;
77405 +int grsec_deny_new_usb;
77406 +int grsec_enable_chroot_findtask;
77407 +int grsec_enable_chroot_mount;
77408 +int grsec_enable_chroot_shmat;
77409 +int grsec_enable_chroot_fchdir;
77410 +int grsec_enable_chroot_double;
77411 +int grsec_enable_chroot_pivot;
77412 +int grsec_enable_chroot_chdir;
77413 +int grsec_enable_chroot_chmod;
77414 +int grsec_enable_chroot_mknod;
77415 +int grsec_enable_chroot_nice;
77416 +int grsec_enable_chroot_execlog;
77417 +int grsec_enable_chroot_caps;
77418 +int grsec_enable_chroot_rename;
77419 +int grsec_enable_chroot_sysctl;
77420 +int grsec_enable_chroot_unix;
77421 +int grsec_enable_tpe;
77422 +kgid_t grsec_tpe_gid;
77423 +int grsec_enable_blackhole;
77424 +#ifdef CONFIG_IPV6_MODULE
77425 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77426 +#endif
77427 +int grsec_lastack_retries;
77428 +int grsec_enable_tpe_all;
77429 +int grsec_enable_tpe_invert;
77430 +int grsec_enable_socket_all;
77431 +kgid_t grsec_socket_all_gid;
77432 +int grsec_enable_socket_client;
77433 +kgid_t grsec_socket_client_gid;
77434 +int grsec_enable_socket_server;
77435 +kgid_t grsec_socket_server_gid;
77436 +int grsec_resource_logging;
77437 +int grsec_disable_privio;
77438 +int grsec_enable_log_rwxmaps;
77439 +int grsec_lock;
77440 +
77441 +DEFINE_SPINLOCK(grsec_alert_lock);
77442 +unsigned long grsec_alert_wtime = 0;
77443 +unsigned long grsec_alert_fyet = 0;
77444 +
77445 +DEFINE_SPINLOCK(grsec_audit_lock);
77446 +
77447 +DEFINE_RWLOCK(grsec_exec_file_lock);
77448 +
77449 +char *gr_shared_page[4];
77450 +
77451 +char *gr_alert_log_fmt;
77452 +char *gr_audit_log_fmt;
77453 +char *gr_alert_log_buf;
77454 +char *gr_audit_log_buf;
77455 +
77456 +extern struct gr_arg *gr_usermode;
77457 +extern unsigned char *gr_system_salt;
77458 +extern unsigned char *gr_system_sum;
77459 +
77460 +void __init
77461 +grsecurity_init(void)
77462 +{
77463 + int j;
77464 + /* create the per-cpu shared pages */
77465 +
77466 +#ifdef CONFIG_X86
77467 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77468 +#endif
77469 +
77470 + for (j = 0; j < 4; j++) {
77471 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77472 + if (gr_shared_page[j] == NULL) {
77473 + panic("Unable to allocate grsecurity shared page");
77474 + return;
77475 + }
77476 + }
77477 +
77478 + /* allocate log buffers */
77479 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77480 + if (!gr_alert_log_fmt) {
77481 + panic("Unable to allocate grsecurity alert log format buffer");
77482 + return;
77483 + }
77484 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77485 + if (!gr_audit_log_fmt) {
77486 + panic("Unable to allocate grsecurity audit log format buffer");
77487 + return;
77488 + }
77489 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77490 + if (!gr_alert_log_buf) {
77491 + panic("Unable to allocate grsecurity alert log buffer");
77492 + return;
77493 + }
77494 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77495 + if (!gr_audit_log_buf) {
77496 + panic("Unable to allocate grsecurity audit log buffer");
77497 + return;
77498 + }
77499 +
77500 + /* allocate memory for authentication structure */
77501 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77502 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77503 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77504 +
77505 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77506 + panic("Unable to allocate grsecurity authentication structure");
77507 + return;
77508 + }
77509 +
77510 +#ifdef CONFIG_GRKERNSEC_IO
77511 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77512 + grsec_disable_privio = 1;
77513 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77514 + grsec_disable_privio = 1;
77515 +#else
77516 + grsec_disable_privio = 0;
77517 +#endif
77518 +#endif
77519 +
77520 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77521 + /* for backward compatibility, tpe_invert always defaults to on if
77522 + enabled in the kernel
77523 + */
77524 + grsec_enable_tpe_invert = 1;
77525 +#endif
77526 +
77527 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77528 +#ifndef CONFIG_GRKERNSEC_SYSCTL
77529 + grsec_lock = 1;
77530 +#endif
77531 +
77532 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77533 + grsec_enable_log_rwxmaps = 1;
77534 +#endif
77535 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77536 + grsec_enable_group = 1;
77537 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77538 +#endif
77539 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77540 + grsec_enable_ptrace_readexec = 1;
77541 +#endif
77542 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77543 + grsec_enable_chdir = 1;
77544 +#endif
77545 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77546 + grsec_enable_harden_ptrace = 1;
77547 +#endif
77548 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77549 + grsec_enable_harden_ipc = 1;
77550 +#endif
77551 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77552 + grsec_enable_mount = 1;
77553 +#endif
77554 +#ifdef CONFIG_GRKERNSEC_LINK
77555 + grsec_enable_link = 1;
77556 +#endif
77557 +#ifdef CONFIG_GRKERNSEC_BRUTE
77558 + grsec_enable_brute = 1;
77559 +#endif
77560 +#ifdef CONFIG_GRKERNSEC_DMESG
77561 + grsec_enable_dmesg = 1;
77562 +#endif
77563 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77564 + grsec_enable_blackhole = 1;
77565 + grsec_lastack_retries = 4;
77566 +#endif
77567 +#ifdef CONFIG_GRKERNSEC_FIFO
77568 + grsec_enable_fifo = 1;
77569 +#endif
77570 +#ifdef CONFIG_GRKERNSEC_EXECLOG
77571 + grsec_enable_execlog = 1;
77572 +#endif
77573 +#ifdef CONFIG_GRKERNSEC_SETXID
77574 + grsec_enable_setxid = 1;
77575 +#endif
77576 +#ifdef CONFIG_GRKERNSEC_SIGNAL
77577 + grsec_enable_signal = 1;
77578 +#endif
77579 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
77580 + grsec_enable_forkfail = 1;
77581 +#endif
77582 +#ifdef CONFIG_GRKERNSEC_TIME
77583 + grsec_enable_time = 1;
77584 +#endif
77585 +#ifdef CONFIG_GRKERNSEC_RESLOG
77586 + grsec_resource_logging = 1;
77587 +#endif
77588 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77589 + grsec_enable_chroot_findtask = 1;
77590 +#endif
77591 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77592 + grsec_enable_chroot_unix = 1;
77593 +#endif
77594 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77595 + grsec_enable_chroot_mount = 1;
77596 +#endif
77597 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77598 + grsec_enable_chroot_fchdir = 1;
77599 +#endif
77600 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77601 + grsec_enable_chroot_shmat = 1;
77602 +#endif
77603 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77604 + grsec_enable_audit_ptrace = 1;
77605 +#endif
77606 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77607 + grsec_enable_chroot_double = 1;
77608 +#endif
77609 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77610 + grsec_enable_chroot_pivot = 1;
77611 +#endif
77612 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77613 + grsec_enable_chroot_chdir = 1;
77614 +#endif
77615 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77616 + grsec_enable_chroot_chmod = 1;
77617 +#endif
77618 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77619 + grsec_enable_chroot_mknod = 1;
77620 +#endif
77621 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77622 + grsec_enable_chroot_nice = 1;
77623 +#endif
77624 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77625 + grsec_enable_chroot_execlog = 1;
77626 +#endif
77627 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77628 + grsec_enable_chroot_caps = 1;
77629 +#endif
77630 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
77631 + grsec_enable_chroot_rename = 1;
77632 +#endif
77633 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77634 + grsec_enable_chroot_sysctl = 1;
77635 +#endif
77636 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77637 + grsec_enable_symlinkown = 1;
77638 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77639 +#endif
77640 +#ifdef CONFIG_GRKERNSEC_TPE
77641 + grsec_enable_tpe = 1;
77642 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77643 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
77644 + grsec_enable_tpe_all = 1;
77645 +#endif
77646 +#endif
77647 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77648 + grsec_enable_socket_all = 1;
77649 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77650 +#endif
77651 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77652 + grsec_enable_socket_client = 1;
77653 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77654 +#endif
77655 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77656 + grsec_enable_socket_server = 1;
77657 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77658 +#endif
77659 +#endif
77660 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77661 + grsec_deny_new_usb = 1;
77662 +#endif
77663 +
77664 + return;
77665 +}
77666 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77667 new file mode 100644
77668 index 0000000..1773300
77669 --- /dev/null
77670 +++ b/grsecurity/grsec_ipc.c
77671 @@ -0,0 +1,48 @@
77672 +#include <linux/kernel.h>
77673 +#include <linux/mm.h>
77674 +#include <linux/sched.h>
77675 +#include <linux/file.h>
77676 +#include <linux/ipc.h>
77677 +#include <linux/ipc_namespace.h>
77678 +#include <linux/grsecurity.h>
77679 +#include <linux/grinternal.h>
77680 +
77681 +int
77682 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77683 +{
77684 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77685 + int write;
77686 + int orig_granted_mode;
77687 + kuid_t euid;
77688 + kgid_t egid;
77689 +
77690 + if (!grsec_enable_harden_ipc)
77691 + return 1;
77692 +
77693 + euid = current_euid();
77694 + egid = current_egid();
77695 +
77696 + write = requested_mode & 00002;
77697 + orig_granted_mode = ipcp->mode;
77698 +
77699 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77700 + orig_granted_mode >>= 6;
77701 + else {
77702 + /* if likely wrong permissions, lock to user */
77703 + if (orig_granted_mode & 0007)
77704 + orig_granted_mode = 0;
77705 + /* otherwise do a egid-only check */
77706 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77707 + orig_granted_mode >>= 3;
77708 + /* otherwise, no access */
77709 + else
77710 + orig_granted_mode = 0;
77711 + }
77712 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77713 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77714 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77715 + return 0;
77716 + }
77717 +#endif
77718 + return 1;
77719 +}
77720 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77721 new file mode 100644
77722 index 0000000..5e05e20
77723 --- /dev/null
77724 +++ b/grsecurity/grsec_link.c
77725 @@ -0,0 +1,58 @@
77726 +#include <linux/kernel.h>
77727 +#include <linux/sched.h>
77728 +#include <linux/fs.h>
77729 +#include <linux/file.h>
77730 +#include <linux/grinternal.h>
77731 +
77732 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77733 +{
77734 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77735 + const struct inode *link_inode = link->dentry->d_inode;
77736 +
77737 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77738 + /* ignore root-owned links, e.g. /proc/self */
77739 + gr_is_global_nonroot(link_inode->i_uid) && target &&
77740 + !uid_eq(link_inode->i_uid, target->i_uid)) {
77741 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77742 + return 1;
77743 + }
77744 +#endif
77745 + return 0;
77746 +}
77747 +
77748 +int
77749 +gr_handle_follow_link(const struct inode *parent,
77750 + const struct inode *inode,
77751 + const struct dentry *dentry, const struct vfsmount *mnt)
77752 +{
77753 +#ifdef CONFIG_GRKERNSEC_LINK
77754 + const struct cred *cred = current_cred();
77755 +
77756 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77757 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77758 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77759 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77760 + return -EACCES;
77761 + }
77762 +#endif
77763 + return 0;
77764 +}
77765 +
77766 +int
77767 +gr_handle_hardlink(const struct dentry *dentry,
77768 + const struct vfsmount *mnt,
77769 + struct inode *inode, const int mode, const struct filename *to)
77770 +{
77771 +#ifdef CONFIG_GRKERNSEC_LINK
77772 + const struct cred *cred = current_cred();
77773 +
77774 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77775 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77776 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77777 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77778 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77779 + return -EPERM;
77780 + }
77781 +#endif
77782 + return 0;
77783 +}
77784 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77785 new file mode 100644
77786 index 0000000..dbe0a6b
77787 --- /dev/null
77788 +++ b/grsecurity/grsec_log.c
77789 @@ -0,0 +1,341 @@
77790 +#include <linux/kernel.h>
77791 +#include <linux/sched.h>
77792 +#include <linux/file.h>
77793 +#include <linux/tty.h>
77794 +#include <linux/fs.h>
77795 +#include <linux/mm.h>
77796 +#include <linux/grinternal.h>
77797 +
77798 +#ifdef CONFIG_TREE_PREEMPT_RCU
77799 +#define DISABLE_PREEMPT() preempt_disable()
77800 +#define ENABLE_PREEMPT() preempt_enable()
77801 +#else
77802 +#define DISABLE_PREEMPT()
77803 +#define ENABLE_PREEMPT()
77804 +#endif
77805 +
77806 +#define BEGIN_LOCKS(x) \
77807 + DISABLE_PREEMPT(); \
77808 + rcu_read_lock(); \
77809 + read_lock(&tasklist_lock); \
77810 + read_lock(&grsec_exec_file_lock); \
77811 + if (x != GR_DO_AUDIT) \
77812 + spin_lock(&grsec_alert_lock); \
77813 + else \
77814 + spin_lock(&grsec_audit_lock)
77815 +
77816 +#define END_LOCKS(x) \
77817 + if (x != GR_DO_AUDIT) \
77818 + spin_unlock(&grsec_alert_lock); \
77819 + else \
77820 + spin_unlock(&grsec_audit_lock); \
77821 + read_unlock(&grsec_exec_file_lock); \
77822 + read_unlock(&tasklist_lock); \
77823 + rcu_read_unlock(); \
77824 + ENABLE_PREEMPT(); \
77825 + if (x == GR_DONT_AUDIT) \
77826 + gr_handle_alertkill(current)
77827 +
77828 +enum {
77829 + FLOODING,
77830 + NO_FLOODING
77831 +};
77832 +
77833 +extern char *gr_alert_log_fmt;
77834 +extern char *gr_audit_log_fmt;
77835 +extern char *gr_alert_log_buf;
77836 +extern char *gr_audit_log_buf;
77837 +
77838 +static int gr_log_start(int audit)
77839 +{
77840 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77841 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77842 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77843 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77844 + unsigned long curr_secs = get_seconds();
77845 +
77846 + if (audit == GR_DO_AUDIT)
77847 + goto set_fmt;
77848 +
77849 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77850 + grsec_alert_wtime = curr_secs;
77851 + grsec_alert_fyet = 0;
77852 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77853 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77854 + grsec_alert_fyet++;
77855 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77856 + grsec_alert_wtime = curr_secs;
77857 + grsec_alert_fyet++;
77858 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77859 + return FLOODING;
77860 + }
77861 + else return FLOODING;
77862 +
77863 +set_fmt:
77864 +#endif
77865 + memset(buf, 0, PAGE_SIZE);
77866 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
77867 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77868 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77869 + } else if (current->signal->curr_ip) {
77870 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77871 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77872 + } else if (gr_acl_is_enabled()) {
77873 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77874 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77875 + } else {
77876 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
77877 + strcpy(buf, fmt);
77878 + }
77879 +
77880 + return NO_FLOODING;
77881 +}
77882 +
77883 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77884 + __attribute__ ((format (printf, 2, 0)));
77885 +
77886 +static void gr_log_middle(int audit, const char *msg, va_list ap)
77887 +{
77888 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77889 + unsigned int len = strlen(buf);
77890 +
77891 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77892 +
77893 + return;
77894 +}
77895 +
77896 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77897 + __attribute__ ((format (printf, 2, 3)));
77898 +
77899 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
77900 +{
77901 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77902 + unsigned int len = strlen(buf);
77903 + va_list ap;
77904 +
77905 + va_start(ap, msg);
77906 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77907 + va_end(ap);
77908 +
77909 + return;
77910 +}
77911 +
77912 +static void gr_log_end(int audit, int append_default)
77913 +{
77914 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77915 + if (append_default) {
77916 + struct task_struct *task = current;
77917 + struct task_struct *parent = task->real_parent;
77918 + const struct cred *cred = __task_cred(task);
77919 + const struct cred *pcred = __task_cred(parent);
77920 + unsigned int len = strlen(buf);
77921 +
77922 + 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));
77923 + }
77924 +
77925 + printk("%s\n", buf);
77926 +
77927 + return;
77928 +}
77929 +
77930 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77931 +{
77932 + int logtype;
77933 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77934 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77935 + void *voidptr = NULL;
77936 + int num1 = 0, num2 = 0;
77937 + unsigned long ulong1 = 0, ulong2 = 0;
77938 + struct dentry *dentry = NULL;
77939 + struct vfsmount *mnt = NULL;
77940 + struct file *file = NULL;
77941 + struct task_struct *task = NULL;
77942 + struct vm_area_struct *vma = NULL;
77943 + const struct cred *cred, *pcred;
77944 + va_list ap;
77945 +
77946 + BEGIN_LOCKS(audit);
77947 + logtype = gr_log_start(audit);
77948 + if (logtype == FLOODING) {
77949 + END_LOCKS(audit);
77950 + return;
77951 + }
77952 + va_start(ap, argtypes);
77953 + switch (argtypes) {
77954 + case GR_TTYSNIFF:
77955 + task = va_arg(ap, struct task_struct *);
77956 + 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));
77957 + break;
77958 + case GR_SYSCTL_HIDDEN:
77959 + str1 = va_arg(ap, char *);
77960 + gr_log_middle_varargs(audit, msg, result, str1);
77961 + break;
77962 + case GR_RBAC:
77963 + dentry = va_arg(ap, struct dentry *);
77964 + mnt = va_arg(ap, struct vfsmount *);
77965 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77966 + break;
77967 + case GR_RBAC_STR:
77968 + dentry = va_arg(ap, struct dentry *);
77969 + mnt = va_arg(ap, struct vfsmount *);
77970 + str1 = va_arg(ap, char *);
77971 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77972 + break;
77973 + case GR_STR_RBAC:
77974 + str1 = va_arg(ap, char *);
77975 + dentry = va_arg(ap, struct dentry *);
77976 + mnt = va_arg(ap, struct vfsmount *);
77977 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77978 + break;
77979 + case GR_RBAC_MODE2:
77980 + dentry = va_arg(ap, struct dentry *);
77981 + mnt = va_arg(ap, struct vfsmount *);
77982 + str1 = va_arg(ap, char *);
77983 + str2 = va_arg(ap, char *);
77984 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77985 + break;
77986 + case GR_RBAC_MODE3:
77987 + dentry = va_arg(ap, struct dentry *);
77988 + mnt = va_arg(ap, struct vfsmount *);
77989 + str1 = va_arg(ap, char *);
77990 + str2 = va_arg(ap, char *);
77991 + str3 = va_arg(ap, char *);
77992 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77993 + break;
77994 + case GR_FILENAME:
77995 + dentry = va_arg(ap, struct dentry *);
77996 + mnt = va_arg(ap, struct vfsmount *);
77997 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77998 + break;
77999 + case GR_STR_FILENAME:
78000 + str1 = va_arg(ap, char *);
78001 + dentry = va_arg(ap, struct dentry *);
78002 + mnt = va_arg(ap, struct vfsmount *);
78003 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78004 + break;
78005 + case GR_FILENAME_STR:
78006 + dentry = va_arg(ap, struct dentry *);
78007 + mnt = va_arg(ap, struct vfsmount *);
78008 + str1 = va_arg(ap, char *);
78009 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78010 + break;
78011 + case GR_FILENAME_TWO_INT:
78012 + dentry = va_arg(ap, struct dentry *);
78013 + mnt = va_arg(ap, struct vfsmount *);
78014 + num1 = va_arg(ap, int);
78015 + num2 = va_arg(ap, int);
78016 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78017 + break;
78018 + case GR_FILENAME_TWO_INT_STR:
78019 + dentry = va_arg(ap, struct dentry *);
78020 + mnt = va_arg(ap, struct vfsmount *);
78021 + num1 = va_arg(ap, int);
78022 + num2 = va_arg(ap, int);
78023 + str1 = va_arg(ap, char *);
78024 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78025 + break;
78026 + case GR_TEXTREL:
78027 + file = va_arg(ap, struct file *);
78028 + ulong1 = va_arg(ap, unsigned long);
78029 + ulong2 = va_arg(ap, unsigned long);
78030 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78031 + break;
78032 + case GR_PTRACE:
78033 + task = va_arg(ap, struct task_struct *);
78034 + 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));
78035 + break;
78036 + case GR_RESOURCE:
78037 + task = va_arg(ap, struct task_struct *);
78038 + cred = __task_cred(task);
78039 + pcred = __task_cred(task->real_parent);
78040 + ulong1 = va_arg(ap, unsigned long);
78041 + str1 = va_arg(ap, char *);
78042 + ulong2 = va_arg(ap, unsigned long);
78043 + 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));
78044 + break;
78045 + case GR_CAP:
78046 + task = va_arg(ap, struct task_struct *);
78047 + cred = __task_cred(task);
78048 + pcred = __task_cred(task->real_parent);
78049 + str1 = va_arg(ap, char *);
78050 + 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));
78051 + break;
78052 + case GR_SIG:
78053 + str1 = va_arg(ap, char *);
78054 + voidptr = va_arg(ap, void *);
78055 + gr_log_middle_varargs(audit, msg, str1, voidptr);
78056 + break;
78057 + case GR_SIG2:
78058 + task = va_arg(ap, struct task_struct *);
78059 + cred = __task_cred(task);
78060 + pcred = __task_cred(task->real_parent);
78061 + num1 = va_arg(ap, int);
78062 + 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));
78063 + break;
78064 + case GR_CRASH1:
78065 + task = va_arg(ap, struct task_struct *);
78066 + cred = __task_cred(task);
78067 + pcred = __task_cred(task->real_parent);
78068 + ulong1 = va_arg(ap, unsigned long);
78069 + 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);
78070 + break;
78071 + case GR_CRASH2:
78072 + task = va_arg(ap, struct task_struct *);
78073 + cred = __task_cred(task);
78074 + pcred = __task_cred(task->real_parent);
78075 + ulong1 = va_arg(ap, unsigned long);
78076 + 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);
78077 + break;
78078 + case GR_RWXMAP:
78079 + file = va_arg(ap, struct file *);
78080 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78081 + break;
78082 + case GR_RWXMAPVMA:
78083 + vma = va_arg(ap, struct vm_area_struct *);
78084 + if (vma->vm_file)
78085 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78086 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78087 + str1 = "<stack>";
78088 + else if (vma->vm_start <= current->mm->brk &&
78089 + vma->vm_end >= current->mm->start_brk)
78090 + str1 = "<heap>";
78091 + else
78092 + str1 = "<anonymous mapping>";
78093 + gr_log_middle_varargs(audit, msg, str1);
78094 + break;
78095 + case GR_PSACCT:
78096 + {
78097 + unsigned int wday, cday;
78098 + __u8 whr, chr;
78099 + __u8 wmin, cmin;
78100 + __u8 wsec, csec;
78101 + char cur_tty[64] = { 0 };
78102 + char parent_tty[64] = { 0 };
78103 +
78104 + task = va_arg(ap, struct task_struct *);
78105 + wday = va_arg(ap, unsigned int);
78106 + cday = va_arg(ap, unsigned int);
78107 + whr = va_arg(ap, int);
78108 + chr = va_arg(ap, int);
78109 + wmin = va_arg(ap, int);
78110 + cmin = va_arg(ap, int);
78111 + wsec = va_arg(ap, int);
78112 + csec = va_arg(ap, int);
78113 + ulong1 = va_arg(ap, unsigned long);
78114 + cred = __task_cred(task);
78115 + pcred = __task_cred(task->real_parent);
78116 +
78117 + 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));
78118 + }
78119 + break;
78120 + default:
78121 + gr_log_middle(audit, msg, ap);
78122 + }
78123 + va_end(ap);
78124 + // these don't need DEFAULTSECARGS printed on the end
78125 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78126 + gr_log_end(audit, 0);
78127 + else
78128 + gr_log_end(audit, 1);
78129 + END_LOCKS(audit);
78130 +}
78131 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78132 new file mode 100644
78133 index 0000000..0e39d8c
78134 --- /dev/null
78135 +++ b/grsecurity/grsec_mem.c
78136 @@ -0,0 +1,48 @@
78137 +#include <linux/kernel.h>
78138 +#include <linux/sched.h>
78139 +#include <linux/mm.h>
78140 +#include <linux/mman.h>
78141 +#include <linux/module.h>
78142 +#include <linux/grinternal.h>
78143 +
78144 +void gr_handle_msr_write(void)
78145 +{
78146 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78147 + return;
78148 +}
78149 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78150 +
78151 +void
78152 +gr_handle_ioperm(void)
78153 +{
78154 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78155 + return;
78156 +}
78157 +
78158 +void
78159 +gr_handle_iopl(void)
78160 +{
78161 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78162 + return;
78163 +}
78164 +
78165 +void
78166 +gr_handle_mem_readwrite(u64 from, u64 to)
78167 +{
78168 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78169 + return;
78170 +}
78171 +
78172 +void
78173 +gr_handle_vm86(void)
78174 +{
78175 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78176 + return;
78177 +}
78178 +
78179 +void
78180 +gr_log_badprocpid(const char *entry)
78181 +{
78182 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78183 + return;
78184 +}
78185 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78186 new file mode 100644
78187 index 0000000..6f9eb73
78188 --- /dev/null
78189 +++ b/grsecurity/grsec_mount.c
78190 @@ -0,0 +1,65 @@
78191 +#include <linux/kernel.h>
78192 +#include <linux/sched.h>
78193 +#include <linux/mount.h>
78194 +#include <linux/major.h>
78195 +#include <linux/grsecurity.h>
78196 +#include <linux/grinternal.h>
78197 +
78198 +void
78199 +gr_log_remount(const char *devname, const int retval)
78200 +{
78201 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78202 + if (grsec_enable_mount && (retval >= 0))
78203 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78204 +#endif
78205 + return;
78206 +}
78207 +
78208 +void
78209 +gr_log_unmount(const char *devname, const int retval)
78210 +{
78211 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78212 + if (grsec_enable_mount && (retval >= 0))
78213 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78214 +#endif
78215 + return;
78216 +}
78217 +
78218 +void
78219 +gr_log_mount(const char *from, struct path *to, const int retval)
78220 +{
78221 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78222 + if (grsec_enable_mount && (retval >= 0))
78223 + gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
78224 +#endif
78225 + return;
78226 +}
78227 +
78228 +int
78229 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78230 +{
78231 +#ifdef CONFIG_GRKERNSEC_ROFS
78232 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78233 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78234 + return -EPERM;
78235 + } else
78236 + return 0;
78237 +#endif
78238 + return 0;
78239 +}
78240 +
78241 +int
78242 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78243 +{
78244 +#ifdef CONFIG_GRKERNSEC_ROFS
78245 + struct inode *inode = dentry->d_inode;
78246 +
78247 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78248 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78249 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78250 + return -EPERM;
78251 + } else
78252 + return 0;
78253 +#endif
78254 + return 0;
78255 +}
78256 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78257 new file mode 100644
78258 index 0000000..6ee9d50
78259 --- /dev/null
78260 +++ b/grsecurity/grsec_pax.c
78261 @@ -0,0 +1,45 @@
78262 +#include <linux/kernel.h>
78263 +#include <linux/sched.h>
78264 +#include <linux/mm.h>
78265 +#include <linux/file.h>
78266 +#include <linux/grinternal.h>
78267 +#include <linux/grsecurity.h>
78268 +
78269 +void
78270 +gr_log_textrel(struct vm_area_struct * vma)
78271 +{
78272 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78273 + if (grsec_enable_log_rwxmaps)
78274 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78275 +#endif
78276 + return;
78277 +}
78278 +
78279 +void gr_log_ptgnustack(struct file *file)
78280 +{
78281 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78282 + if (grsec_enable_log_rwxmaps)
78283 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78284 +#endif
78285 + return;
78286 +}
78287 +
78288 +void
78289 +gr_log_rwxmmap(struct file *file)
78290 +{
78291 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78292 + if (grsec_enable_log_rwxmaps)
78293 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78294 +#endif
78295 + return;
78296 +}
78297 +
78298 +void
78299 +gr_log_rwxmprotect(struct vm_area_struct *vma)
78300 +{
78301 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78302 + if (grsec_enable_log_rwxmaps)
78303 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78304 +#endif
78305 + return;
78306 +}
78307 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78308 new file mode 100644
78309 index 0000000..2005a3a
78310 --- /dev/null
78311 +++ b/grsecurity/grsec_proc.c
78312 @@ -0,0 +1,20 @@
78313 +#include <linux/kernel.h>
78314 +#include <linux/sched.h>
78315 +#include <linux/grsecurity.h>
78316 +#include <linux/grinternal.h>
78317 +
78318 +int gr_proc_is_restricted(void)
78319 +{
78320 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78321 + const struct cred *cred = current_cred();
78322 +#endif
78323 +
78324 +#ifdef CONFIG_GRKERNSEC_PROC_USER
78325 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78326 + return -EACCES;
78327 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78328 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78329 + return -EACCES;
78330 +#endif
78331 + return 0;
78332 +}
78333 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78334 new file mode 100644
78335 index 0000000..f7f29aa
78336 --- /dev/null
78337 +++ b/grsecurity/grsec_ptrace.c
78338 @@ -0,0 +1,30 @@
78339 +#include <linux/kernel.h>
78340 +#include <linux/sched.h>
78341 +#include <linux/grinternal.h>
78342 +#include <linux/security.h>
78343 +
78344 +void
78345 +gr_audit_ptrace(struct task_struct *task)
78346 +{
78347 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78348 + if (grsec_enable_audit_ptrace)
78349 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78350 +#endif
78351 + return;
78352 +}
78353 +
78354 +int
78355 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
78356 +{
78357 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78358 + const struct dentry *dentry = file->f_path.dentry;
78359 + const struct vfsmount *mnt = file->f_path.mnt;
78360 +
78361 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78362 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78363 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78364 + return -EACCES;
78365 + }
78366 +#endif
78367 + return 0;
78368 +}
78369 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78370 new file mode 100644
78371 index 0000000..3860c7e
78372 --- /dev/null
78373 +++ b/grsecurity/grsec_sig.c
78374 @@ -0,0 +1,236 @@
78375 +#include <linux/kernel.h>
78376 +#include <linux/sched.h>
78377 +#include <linux/fs.h>
78378 +#include <linux/delay.h>
78379 +#include <linux/grsecurity.h>
78380 +#include <linux/grinternal.h>
78381 +#include <linux/hardirq.h>
78382 +
78383 +char *signames[] = {
78384 + [SIGSEGV] = "Segmentation fault",
78385 + [SIGILL] = "Illegal instruction",
78386 + [SIGABRT] = "Abort",
78387 + [SIGBUS] = "Invalid alignment/Bus error"
78388 +};
78389 +
78390 +void
78391 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78392 +{
78393 +#ifdef CONFIG_GRKERNSEC_SIGNAL
78394 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78395 + (sig == SIGABRT) || (sig == SIGBUS))) {
78396 + if (task_pid_nr(t) == task_pid_nr(current)) {
78397 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78398 + } else {
78399 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78400 + }
78401 + }
78402 +#endif
78403 + return;
78404 +}
78405 +
78406 +int
78407 +gr_handle_signal(const struct task_struct *p, const int sig)
78408 +{
78409 +#ifdef CONFIG_GRKERNSEC
78410 + /* ignore the 0 signal for protected task checks */
78411 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78412 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78413 + return -EPERM;
78414 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78415 + return -EPERM;
78416 + }
78417 +#endif
78418 + return 0;
78419 +}
78420 +
78421 +#ifdef CONFIG_GRKERNSEC
78422 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78423 +
78424 +int gr_fake_force_sig(int sig, struct task_struct *t)
78425 +{
78426 + unsigned long int flags;
78427 + int ret, blocked, ignored;
78428 + struct k_sigaction *action;
78429 +
78430 + spin_lock_irqsave(&t->sighand->siglock, flags);
78431 + action = &t->sighand->action[sig-1];
78432 + ignored = action->sa.sa_handler == SIG_IGN;
78433 + blocked = sigismember(&t->blocked, sig);
78434 + if (blocked || ignored) {
78435 + action->sa.sa_handler = SIG_DFL;
78436 + if (blocked) {
78437 + sigdelset(&t->blocked, sig);
78438 + recalc_sigpending_and_wake(t);
78439 + }
78440 + }
78441 + if (action->sa.sa_handler == SIG_DFL)
78442 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
78443 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78444 +
78445 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
78446 +
78447 + return ret;
78448 +}
78449 +#endif
78450 +
78451 +#define GR_USER_BAN_TIME (15 * 60)
78452 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
78453 +
78454 +void gr_handle_brute_attach(int dumpable)
78455 +{
78456 +#ifdef CONFIG_GRKERNSEC_BRUTE
78457 + struct task_struct *p = current;
78458 + kuid_t uid = GLOBAL_ROOT_UID;
78459 + int daemon = 0;
78460 +
78461 + if (!grsec_enable_brute)
78462 + return;
78463 +
78464 + rcu_read_lock();
78465 + read_lock(&tasklist_lock);
78466 + read_lock(&grsec_exec_file_lock);
78467 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78468 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78469 + p->real_parent->brute = 1;
78470 + daemon = 1;
78471 + } else {
78472 + const struct cred *cred = __task_cred(p), *cred2;
78473 + struct task_struct *tsk, *tsk2;
78474 +
78475 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78476 + struct user_struct *user;
78477 +
78478 + uid = cred->uid;
78479 +
78480 + /* this is put upon execution past expiration */
78481 + user = find_user(uid);
78482 + if (user == NULL)
78483 + goto unlock;
78484 + user->suid_banned = 1;
78485 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78486 + if (user->suid_ban_expires == ~0UL)
78487 + user->suid_ban_expires--;
78488 +
78489 + /* only kill other threads of the same binary, from the same user */
78490 + do_each_thread(tsk2, tsk) {
78491 + cred2 = __task_cred(tsk);
78492 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78493 + gr_fake_force_sig(SIGKILL, tsk);
78494 + } while_each_thread(tsk2, tsk);
78495 + }
78496 + }
78497 +unlock:
78498 + read_unlock(&grsec_exec_file_lock);
78499 + read_unlock(&tasklist_lock);
78500 + rcu_read_unlock();
78501 +
78502 + if (gr_is_global_nonroot(uid))
78503 + 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);
78504 + else if (daemon)
78505 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78506 +
78507 +#endif
78508 + return;
78509 +}
78510 +
78511 +void gr_handle_brute_check(void)
78512 +{
78513 +#ifdef CONFIG_GRKERNSEC_BRUTE
78514 + struct task_struct *p = current;
78515 +
78516 + if (unlikely(p->brute)) {
78517 + if (!grsec_enable_brute)
78518 + p->brute = 0;
78519 + else if (time_before(get_seconds(), p->brute_expires))
78520 + msleep(30 * 1000);
78521 + }
78522 +#endif
78523 + return;
78524 +}
78525 +
78526 +void gr_handle_kernel_exploit(void)
78527 +{
78528 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78529 + const struct cred *cred;
78530 + struct task_struct *tsk, *tsk2;
78531 + struct user_struct *user;
78532 + kuid_t uid;
78533 +
78534 + if (in_irq() || in_serving_softirq() || in_nmi())
78535 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78536 +
78537 + uid = current_uid();
78538 +
78539 + if (gr_is_global_root(uid))
78540 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
78541 + else {
78542 + /* kill all the processes of this user, hold a reference
78543 + to their creds struct, and prevent them from creating
78544 + another process until system reset
78545 + */
78546 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78547 + GR_GLOBAL_UID(uid));
78548 + /* we intentionally leak this ref */
78549 + user = get_uid(current->cred->user);
78550 + if (user)
78551 + user->kernel_banned = 1;
78552 +
78553 + /* kill all processes of this user */
78554 + read_lock(&tasklist_lock);
78555 + do_each_thread(tsk2, tsk) {
78556 + cred = __task_cred(tsk);
78557 + if (uid_eq(cred->uid, uid))
78558 + gr_fake_force_sig(SIGKILL, tsk);
78559 + } while_each_thread(tsk2, tsk);
78560 + read_unlock(&tasklist_lock);
78561 + }
78562 +#endif
78563 +}
78564 +
78565 +#ifdef CONFIG_GRKERNSEC_BRUTE
78566 +static bool suid_ban_expired(struct user_struct *user)
78567 +{
78568 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78569 + user->suid_banned = 0;
78570 + user->suid_ban_expires = 0;
78571 + free_uid(user);
78572 + return true;
78573 + }
78574 +
78575 + return false;
78576 +}
78577 +#endif
78578 +
78579 +int gr_process_kernel_exec_ban(void)
78580 +{
78581 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78582 + if (unlikely(current->cred->user->kernel_banned))
78583 + return -EPERM;
78584 +#endif
78585 + return 0;
78586 +}
78587 +
78588 +int gr_process_kernel_setuid_ban(struct user_struct *user)
78589 +{
78590 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78591 + if (unlikely(user->kernel_banned))
78592 + gr_fake_force_sig(SIGKILL, current);
78593 +#endif
78594 + return 0;
78595 +}
78596 +
78597 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78598 +{
78599 +#ifdef CONFIG_GRKERNSEC_BRUTE
78600 + struct user_struct *user = current->cred->user;
78601 + if (unlikely(user->suid_banned)) {
78602 + if (suid_ban_expired(user))
78603 + return 0;
78604 + /* disallow execution of suid binaries only */
78605 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78606 + return -EPERM;
78607 + }
78608 +#endif
78609 + return 0;
78610 +}
78611 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78612 new file mode 100644
78613 index 0000000..e3650b6
78614 --- /dev/null
78615 +++ b/grsecurity/grsec_sock.c
78616 @@ -0,0 +1,244 @@
78617 +#include <linux/kernel.h>
78618 +#include <linux/module.h>
78619 +#include <linux/sched.h>
78620 +#include <linux/file.h>
78621 +#include <linux/net.h>
78622 +#include <linux/in.h>
78623 +#include <linux/ip.h>
78624 +#include <net/sock.h>
78625 +#include <net/inet_sock.h>
78626 +#include <linux/grsecurity.h>
78627 +#include <linux/grinternal.h>
78628 +#include <linux/gracl.h>
78629 +
78630 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78631 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78632 +
78633 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78634 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78635 +
78636 +#ifdef CONFIG_UNIX_MODULE
78637 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78638 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78639 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78640 +EXPORT_SYMBOL_GPL(gr_handle_create);
78641 +#endif
78642 +
78643 +#ifdef CONFIG_GRKERNSEC
78644 +#define gr_conn_table_size 32749
78645 +struct conn_table_entry {
78646 + struct conn_table_entry *next;
78647 + struct signal_struct *sig;
78648 +};
78649 +
78650 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78651 +DEFINE_SPINLOCK(gr_conn_table_lock);
78652 +
78653 +extern const char * gr_socktype_to_name(unsigned char type);
78654 +extern const char * gr_proto_to_name(unsigned char proto);
78655 +extern const char * gr_sockfamily_to_name(unsigned char family);
78656 +
78657 +static __inline__ int
78658 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78659 +{
78660 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78661 +}
78662 +
78663 +static __inline__ int
78664 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78665 + __u16 sport, __u16 dport)
78666 +{
78667 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78668 + sig->gr_sport == sport && sig->gr_dport == dport))
78669 + return 1;
78670 + else
78671 + return 0;
78672 +}
78673 +
78674 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78675 +{
78676 + struct conn_table_entry **match;
78677 + unsigned int index;
78678 +
78679 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78680 + sig->gr_sport, sig->gr_dport,
78681 + gr_conn_table_size);
78682 +
78683 + newent->sig = sig;
78684 +
78685 + match = &gr_conn_table[index];
78686 + newent->next = *match;
78687 + *match = newent;
78688 +
78689 + return;
78690 +}
78691 +
78692 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78693 +{
78694 + struct conn_table_entry *match, *last = NULL;
78695 + unsigned int index;
78696 +
78697 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78698 + sig->gr_sport, sig->gr_dport,
78699 + gr_conn_table_size);
78700 +
78701 + match = gr_conn_table[index];
78702 + while (match && !conn_match(match->sig,
78703 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78704 + sig->gr_dport)) {
78705 + last = match;
78706 + match = match->next;
78707 + }
78708 +
78709 + if (match) {
78710 + if (last)
78711 + last->next = match->next;
78712 + else
78713 + gr_conn_table[index] = NULL;
78714 + kfree(match);
78715 + }
78716 +
78717 + return;
78718 +}
78719 +
78720 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78721 + __u16 sport, __u16 dport)
78722 +{
78723 + struct conn_table_entry *match;
78724 + unsigned int index;
78725 +
78726 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78727 +
78728 + match = gr_conn_table[index];
78729 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78730 + match = match->next;
78731 +
78732 + if (match)
78733 + return match->sig;
78734 + else
78735 + return NULL;
78736 +}
78737 +
78738 +#endif
78739 +
78740 +void gr_update_task_in_ip_table(const struct inet_sock *inet)
78741 +{
78742 +#ifdef CONFIG_GRKERNSEC
78743 + struct signal_struct *sig = current->signal;
78744 + struct conn_table_entry *newent;
78745 +
78746 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78747 + if (newent == NULL)
78748 + return;
78749 + /* no bh lock needed since we are called with bh disabled */
78750 + spin_lock(&gr_conn_table_lock);
78751 + gr_del_task_from_ip_table_nolock(sig);
78752 + sig->gr_saddr = inet->inet_rcv_saddr;
78753 + sig->gr_daddr = inet->inet_daddr;
78754 + sig->gr_sport = inet->inet_sport;
78755 + sig->gr_dport = inet->inet_dport;
78756 + gr_add_to_task_ip_table_nolock(sig, newent);
78757 + spin_unlock(&gr_conn_table_lock);
78758 +#endif
78759 + return;
78760 +}
78761 +
78762 +void gr_del_task_from_ip_table(struct task_struct *task)
78763 +{
78764 +#ifdef CONFIG_GRKERNSEC
78765 + spin_lock_bh(&gr_conn_table_lock);
78766 + gr_del_task_from_ip_table_nolock(task->signal);
78767 + spin_unlock_bh(&gr_conn_table_lock);
78768 +#endif
78769 + return;
78770 +}
78771 +
78772 +void
78773 +gr_attach_curr_ip(const struct sock *sk)
78774 +{
78775 +#ifdef CONFIG_GRKERNSEC
78776 + struct signal_struct *p, *set;
78777 + const struct inet_sock *inet = inet_sk(sk);
78778 +
78779 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78780 + return;
78781 +
78782 + set = current->signal;
78783 +
78784 + spin_lock_bh(&gr_conn_table_lock);
78785 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78786 + inet->inet_dport, inet->inet_sport);
78787 + if (unlikely(p != NULL)) {
78788 + set->curr_ip = p->curr_ip;
78789 + set->used_accept = 1;
78790 + gr_del_task_from_ip_table_nolock(p);
78791 + spin_unlock_bh(&gr_conn_table_lock);
78792 + return;
78793 + }
78794 + spin_unlock_bh(&gr_conn_table_lock);
78795 +
78796 + set->curr_ip = inet->inet_daddr;
78797 + set->used_accept = 1;
78798 +#endif
78799 + return;
78800 +}
78801 +
78802 +int
78803 +gr_handle_sock_all(const int family, const int type, const int protocol)
78804 +{
78805 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78806 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78807 + (family != AF_UNIX)) {
78808 + if (family == AF_INET)
78809 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78810 + else
78811 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78812 + return -EACCES;
78813 + }
78814 +#endif
78815 + return 0;
78816 +}
78817 +
78818 +int
78819 +gr_handle_sock_server(const struct sockaddr *sck)
78820 +{
78821 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78822 + if (grsec_enable_socket_server &&
78823 + in_group_p(grsec_socket_server_gid) &&
78824 + sck && (sck->sa_family != AF_UNIX) &&
78825 + (sck->sa_family != AF_LOCAL)) {
78826 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78827 + return -EACCES;
78828 + }
78829 +#endif
78830 + return 0;
78831 +}
78832 +
78833 +int
78834 +gr_handle_sock_server_other(const struct sock *sck)
78835 +{
78836 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78837 + if (grsec_enable_socket_server &&
78838 + in_group_p(grsec_socket_server_gid) &&
78839 + sck && (sck->sk_family != AF_UNIX) &&
78840 + (sck->sk_family != AF_LOCAL)) {
78841 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78842 + return -EACCES;
78843 + }
78844 +#endif
78845 + return 0;
78846 +}
78847 +
78848 +int
78849 +gr_handle_sock_client(const struct sockaddr *sck)
78850 +{
78851 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78852 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78853 + sck && (sck->sa_family != AF_UNIX) &&
78854 + (sck->sa_family != AF_LOCAL)) {
78855 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78856 + return -EACCES;
78857 + }
78858 +#endif
78859 + return 0;
78860 +}
78861 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78862 new file mode 100644
78863 index 0000000..cce889e
78864 --- /dev/null
78865 +++ b/grsecurity/grsec_sysctl.c
78866 @@ -0,0 +1,488 @@
78867 +#include <linux/kernel.h>
78868 +#include <linux/sched.h>
78869 +#include <linux/sysctl.h>
78870 +#include <linux/grsecurity.h>
78871 +#include <linux/grinternal.h>
78872 +
78873 +int
78874 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78875 +{
78876 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78877 + if (dirname == NULL || name == NULL)
78878 + return 0;
78879 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78880 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78881 + return -EACCES;
78882 + }
78883 +#endif
78884 + return 0;
78885 +}
78886 +
78887 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78888 +static int __maybe_unused __read_only one = 1;
78889 +#endif
78890 +
78891 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78892 + defined(CONFIG_GRKERNSEC_DENYUSB)
78893 +struct ctl_table grsecurity_table[] = {
78894 +#ifdef CONFIG_GRKERNSEC_SYSCTL
78895 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78896 +#ifdef CONFIG_GRKERNSEC_IO
78897 + {
78898 + .procname = "disable_priv_io",
78899 + .data = &grsec_disable_privio,
78900 + .maxlen = sizeof(int),
78901 + .mode = 0600,
78902 + .proc_handler = &proc_dointvec,
78903 + },
78904 +#endif
78905 +#endif
78906 +#ifdef CONFIG_GRKERNSEC_LINK
78907 + {
78908 + .procname = "linking_restrictions",
78909 + .data = &grsec_enable_link,
78910 + .maxlen = sizeof(int),
78911 + .mode = 0600,
78912 + .proc_handler = &proc_dointvec,
78913 + },
78914 +#endif
78915 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78916 + {
78917 + .procname = "enforce_symlinksifowner",
78918 + .data = &grsec_enable_symlinkown,
78919 + .maxlen = sizeof(int),
78920 + .mode = 0600,
78921 + .proc_handler = &proc_dointvec,
78922 + },
78923 + {
78924 + .procname = "symlinkown_gid",
78925 + .data = &grsec_symlinkown_gid,
78926 + .maxlen = sizeof(int),
78927 + .mode = 0600,
78928 + .proc_handler = &proc_dointvec,
78929 + },
78930 +#endif
78931 +#ifdef CONFIG_GRKERNSEC_BRUTE
78932 + {
78933 + .procname = "deter_bruteforce",
78934 + .data = &grsec_enable_brute,
78935 + .maxlen = sizeof(int),
78936 + .mode = 0600,
78937 + .proc_handler = &proc_dointvec,
78938 + },
78939 +#endif
78940 +#ifdef CONFIG_GRKERNSEC_FIFO
78941 + {
78942 + .procname = "fifo_restrictions",
78943 + .data = &grsec_enable_fifo,
78944 + .maxlen = sizeof(int),
78945 + .mode = 0600,
78946 + .proc_handler = &proc_dointvec,
78947 + },
78948 +#endif
78949 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78950 + {
78951 + .procname = "ptrace_readexec",
78952 + .data = &grsec_enable_ptrace_readexec,
78953 + .maxlen = sizeof(int),
78954 + .mode = 0600,
78955 + .proc_handler = &proc_dointvec,
78956 + },
78957 +#endif
78958 +#ifdef CONFIG_GRKERNSEC_SETXID
78959 + {
78960 + .procname = "consistent_setxid",
78961 + .data = &grsec_enable_setxid,
78962 + .maxlen = sizeof(int),
78963 + .mode = 0600,
78964 + .proc_handler = &proc_dointvec,
78965 + },
78966 +#endif
78967 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78968 + {
78969 + .procname = "ip_blackhole",
78970 + .data = &grsec_enable_blackhole,
78971 + .maxlen = sizeof(int),
78972 + .mode = 0600,
78973 + .proc_handler = &proc_dointvec,
78974 + },
78975 + {
78976 + .procname = "lastack_retries",
78977 + .data = &grsec_lastack_retries,
78978 + .maxlen = sizeof(int),
78979 + .mode = 0600,
78980 + .proc_handler = &proc_dointvec,
78981 + },
78982 +#endif
78983 +#ifdef CONFIG_GRKERNSEC_EXECLOG
78984 + {
78985 + .procname = "exec_logging",
78986 + .data = &grsec_enable_execlog,
78987 + .maxlen = sizeof(int),
78988 + .mode = 0600,
78989 + .proc_handler = &proc_dointvec,
78990 + },
78991 +#endif
78992 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78993 + {
78994 + .procname = "rwxmap_logging",
78995 + .data = &grsec_enable_log_rwxmaps,
78996 + .maxlen = sizeof(int),
78997 + .mode = 0600,
78998 + .proc_handler = &proc_dointvec,
78999 + },
79000 +#endif
79001 +#ifdef CONFIG_GRKERNSEC_SIGNAL
79002 + {
79003 + .procname = "signal_logging",
79004 + .data = &grsec_enable_signal,
79005 + .maxlen = sizeof(int),
79006 + .mode = 0600,
79007 + .proc_handler = &proc_dointvec,
79008 + },
79009 +#endif
79010 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
79011 + {
79012 + .procname = "forkfail_logging",
79013 + .data = &grsec_enable_forkfail,
79014 + .maxlen = sizeof(int),
79015 + .mode = 0600,
79016 + .proc_handler = &proc_dointvec,
79017 + },
79018 +#endif
79019 +#ifdef CONFIG_GRKERNSEC_TIME
79020 + {
79021 + .procname = "timechange_logging",
79022 + .data = &grsec_enable_time,
79023 + .maxlen = sizeof(int),
79024 + .mode = 0600,
79025 + .proc_handler = &proc_dointvec,
79026 + },
79027 +#endif
79028 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79029 + {
79030 + .procname = "chroot_deny_shmat",
79031 + .data = &grsec_enable_chroot_shmat,
79032 + .maxlen = sizeof(int),
79033 + .mode = 0600,
79034 + .proc_handler = &proc_dointvec,
79035 + },
79036 +#endif
79037 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79038 + {
79039 + .procname = "chroot_deny_unix",
79040 + .data = &grsec_enable_chroot_unix,
79041 + .maxlen = sizeof(int),
79042 + .mode = 0600,
79043 + .proc_handler = &proc_dointvec,
79044 + },
79045 +#endif
79046 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79047 + {
79048 + .procname = "chroot_deny_mount",
79049 + .data = &grsec_enable_chroot_mount,
79050 + .maxlen = sizeof(int),
79051 + .mode = 0600,
79052 + .proc_handler = &proc_dointvec,
79053 + },
79054 +#endif
79055 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79056 + {
79057 + .procname = "chroot_deny_fchdir",
79058 + .data = &grsec_enable_chroot_fchdir,
79059 + .maxlen = sizeof(int),
79060 + .mode = 0600,
79061 + .proc_handler = &proc_dointvec,
79062 + },
79063 +#endif
79064 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79065 + {
79066 + .procname = "chroot_deny_chroot",
79067 + .data = &grsec_enable_chroot_double,
79068 + .maxlen = sizeof(int),
79069 + .mode = 0600,
79070 + .proc_handler = &proc_dointvec,
79071 + },
79072 +#endif
79073 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79074 + {
79075 + .procname = "chroot_deny_pivot",
79076 + .data = &grsec_enable_chroot_pivot,
79077 + .maxlen = sizeof(int),
79078 + .mode = 0600,
79079 + .proc_handler = &proc_dointvec,
79080 + },
79081 +#endif
79082 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79083 + {
79084 + .procname = "chroot_enforce_chdir",
79085 + .data = &grsec_enable_chroot_chdir,
79086 + .maxlen = sizeof(int),
79087 + .mode = 0600,
79088 + .proc_handler = &proc_dointvec,
79089 + },
79090 +#endif
79091 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79092 + {
79093 + .procname = "chroot_deny_chmod",
79094 + .data = &grsec_enable_chroot_chmod,
79095 + .maxlen = sizeof(int),
79096 + .mode = 0600,
79097 + .proc_handler = &proc_dointvec,
79098 + },
79099 +#endif
79100 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79101 + {
79102 + .procname = "chroot_deny_mknod",
79103 + .data = &grsec_enable_chroot_mknod,
79104 + .maxlen = sizeof(int),
79105 + .mode = 0600,
79106 + .proc_handler = &proc_dointvec,
79107 + },
79108 +#endif
79109 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79110 + {
79111 + .procname = "chroot_restrict_nice",
79112 + .data = &grsec_enable_chroot_nice,
79113 + .maxlen = sizeof(int),
79114 + .mode = 0600,
79115 + .proc_handler = &proc_dointvec,
79116 + },
79117 +#endif
79118 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79119 + {
79120 + .procname = "chroot_execlog",
79121 + .data = &grsec_enable_chroot_execlog,
79122 + .maxlen = sizeof(int),
79123 + .mode = 0600,
79124 + .proc_handler = &proc_dointvec,
79125 + },
79126 +#endif
79127 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79128 + {
79129 + .procname = "chroot_caps",
79130 + .data = &grsec_enable_chroot_caps,
79131 + .maxlen = sizeof(int),
79132 + .mode = 0600,
79133 + .proc_handler = &proc_dointvec,
79134 + },
79135 +#endif
79136 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
79137 + {
79138 + .procname = "chroot_deny_bad_rename",
79139 + .data = &grsec_enable_chroot_rename,
79140 + .maxlen = sizeof(int),
79141 + .mode = 0600,
79142 + .proc_handler = &proc_dointvec,
79143 + },
79144 +#endif
79145 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79146 + {
79147 + .procname = "chroot_deny_sysctl",
79148 + .data = &grsec_enable_chroot_sysctl,
79149 + .maxlen = sizeof(int),
79150 + .mode = 0600,
79151 + .proc_handler = &proc_dointvec,
79152 + },
79153 +#endif
79154 +#ifdef CONFIG_GRKERNSEC_TPE
79155 + {
79156 + .procname = "tpe",
79157 + .data = &grsec_enable_tpe,
79158 + .maxlen = sizeof(int),
79159 + .mode = 0600,
79160 + .proc_handler = &proc_dointvec,
79161 + },
79162 + {
79163 + .procname = "tpe_gid",
79164 + .data = &grsec_tpe_gid,
79165 + .maxlen = sizeof(int),
79166 + .mode = 0600,
79167 + .proc_handler = &proc_dointvec,
79168 + },
79169 +#endif
79170 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79171 + {
79172 + .procname = "tpe_invert",
79173 + .data = &grsec_enable_tpe_invert,
79174 + .maxlen = sizeof(int),
79175 + .mode = 0600,
79176 + .proc_handler = &proc_dointvec,
79177 + },
79178 +#endif
79179 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79180 + {
79181 + .procname = "tpe_restrict_all",
79182 + .data = &grsec_enable_tpe_all,
79183 + .maxlen = sizeof(int),
79184 + .mode = 0600,
79185 + .proc_handler = &proc_dointvec,
79186 + },
79187 +#endif
79188 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79189 + {
79190 + .procname = "socket_all",
79191 + .data = &grsec_enable_socket_all,
79192 + .maxlen = sizeof(int),
79193 + .mode = 0600,
79194 + .proc_handler = &proc_dointvec,
79195 + },
79196 + {
79197 + .procname = "socket_all_gid",
79198 + .data = &grsec_socket_all_gid,
79199 + .maxlen = sizeof(int),
79200 + .mode = 0600,
79201 + .proc_handler = &proc_dointvec,
79202 + },
79203 +#endif
79204 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79205 + {
79206 + .procname = "socket_client",
79207 + .data = &grsec_enable_socket_client,
79208 + .maxlen = sizeof(int),
79209 + .mode = 0600,
79210 + .proc_handler = &proc_dointvec,
79211 + },
79212 + {
79213 + .procname = "socket_client_gid",
79214 + .data = &grsec_socket_client_gid,
79215 + .maxlen = sizeof(int),
79216 + .mode = 0600,
79217 + .proc_handler = &proc_dointvec,
79218 + },
79219 +#endif
79220 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79221 + {
79222 + .procname = "socket_server",
79223 + .data = &grsec_enable_socket_server,
79224 + .maxlen = sizeof(int),
79225 + .mode = 0600,
79226 + .proc_handler = &proc_dointvec,
79227 + },
79228 + {
79229 + .procname = "socket_server_gid",
79230 + .data = &grsec_socket_server_gid,
79231 + .maxlen = sizeof(int),
79232 + .mode = 0600,
79233 + .proc_handler = &proc_dointvec,
79234 + },
79235 +#endif
79236 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79237 + {
79238 + .procname = "audit_group",
79239 + .data = &grsec_enable_group,
79240 + .maxlen = sizeof(int),
79241 + .mode = 0600,
79242 + .proc_handler = &proc_dointvec,
79243 + },
79244 + {
79245 + .procname = "audit_gid",
79246 + .data = &grsec_audit_gid,
79247 + .maxlen = sizeof(int),
79248 + .mode = 0600,
79249 + .proc_handler = &proc_dointvec,
79250 + },
79251 +#endif
79252 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79253 + {
79254 + .procname = "audit_chdir",
79255 + .data = &grsec_enable_chdir,
79256 + .maxlen = sizeof(int),
79257 + .mode = 0600,
79258 + .proc_handler = &proc_dointvec,
79259 + },
79260 +#endif
79261 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79262 + {
79263 + .procname = "audit_mount",
79264 + .data = &grsec_enable_mount,
79265 + .maxlen = sizeof(int),
79266 + .mode = 0600,
79267 + .proc_handler = &proc_dointvec,
79268 + },
79269 +#endif
79270 +#ifdef CONFIG_GRKERNSEC_DMESG
79271 + {
79272 + .procname = "dmesg",
79273 + .data = &grsec_enable_dmesg,
79274 + .maxlen = sizeof(int),
79275 + .mode = 0600,
79276 + .proc_handler = &proc_dointvec,
79277 + },
79278 +#endif
79279 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79280 + {
79281 + .procname = "chroot_findtask",
79282 + .data = &grsec_enable_chroot_findtask,
79283 + .maxlen = sizeof(int),
79284 + .mode = 0600,
79285 + .proc_handler = &proc_dointvec,
79286 + },
79287 +#endif
79288 +#ifdef CONFIG_GRKERNSEC_RESLOG
79289 + {
79290 + .procname = "resource_logging",
79291 + .data = &grsec_resource_logging,
79292 + .maxlen = sizeof(int),
79293 + .mode = 0600,
79294 + .proc_handler = &proc_dointvec,
79295 + },
79296 +#endif
79297 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79298 + {
79299 + .procname = "audit_ptrace",
79300 + .data = &grsec_enable_audit_ptrace,
79301 + .maxlen = sizeof(int),
79302 + .mode = 0600,
79303 + .proc_handler = &proc_dointvec,
79304 + },
79305 +#endif
79306 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79307 + {
79308 + .procname = "harden_ptrace",
79309 + .data = &grsec_enable_harden_ptrace,
79310 + .maxlen = sizeof(int),
79311 + .mode = 0600,
79312 + .proc_handler = &proc_dointvec,
79313 + },
79314 +#endif
79315 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79316 + {
79317 + .procname = "harden_ipc",
79318 + .data = &grsec_enable_harden_ipc,
79319 + .maxlen = sizeof(int),
79320 + .mode = 0600,
79321 + .proc_handler = &proc_dointvec,
79322 + },
79323 +#endif
79324 + {
79325 + .procname = "grsec_lock",
79326 + .data = &grsec_lock,
79327 + .maxlen = sizeof(int),
79328 + .mode = 0600,
79329 + .proc_handler = &proc_dointvec,
79330 + },
79331 +#endif
79332 +#ifdef CONFIG_GRKERNSEC_ROFS
79333 + {
79334 + .procname = "romount_protect",
79335 + .data = &grsec_enable_rofs,
79336 + .maxlen = sizeof(int),
79337 + .mode = 0600,
79338 + .proc_handler = &proc_dointvec_minmax,
79339 + .extra1 = &one,
79340 + .extra2 = &one,
79341 + },
79342 +#endif
79343 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79344 + {
79345 + .procname = "deny_new_usb",
79346 + .data = &grsec_deny_new_usb,
79347 + .maxlen = sizeof(int),
79348 + .mode = 0600,
79349 + .proc_handler = &proc_dointvec,
79350 + },
79351 +#endif
79352 + { }
79353 +};
79354 +#endif
79355 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79356 new file mode 100644
79357 index 0000000..61b514e
79358 --- /dev/null
79359 +++ b/grsecurity/grsec_time.c
79360 @@ -0,0 +1,16 @@
79361 +#include <linux/kernel.h>
79362 +#include <linux/sched.h>
79363 +#include <linux/grinternal.h>
79364 +#include <linux/module.h>
79365 +
79366 +void
79367 +gr_log_timechange(void)
79368 +{
79369 +#ifdef CONFIG_GRKERNSEC_TIME
79370 + if (grsec_enable_time)
79371 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79372 +#endif
79373 + return;
79374 +}
79375 +
79376 +EXPORT_SYMBOL_GPL(gr_log_timechange);
79377 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79378 new file mode 100644
79379 index 0000000..d1953de
79380 --- /dev/null
79381 +++ b/grsecurity/grsec_tpe.c
79382 @@ -0,0 +1,78 @@
79383 +#include <linux/kernel.h>
79384 +#include <linux/sched.h>
79385 +#include <linux/file.h>
79386 +#include <linux/fs.h>
79387 +#include <linux/grinternal.h>
79388 +
79389 +extern int gr_acl_tpe_check(void);
79390 +
79391 +int
79392 +gr_tpe_allow(const struct file *file)
79393 +{
79394 +#ifdef CONFIG_GRKERNSEC
79395 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79396 + struct inode *file_inode = file->f_path.dentry->d_inode;
79397 + const struct cred *cred = current_cred();
79398 + char *msg = NULL;
79399 + char *msg2 = NULL;
79400 +
79401 + // never restrict root
79402 + if (gr_is_global_root(cred->uid))
79403 + return 1;
79404 +
79405 + if (grsec_enable_tpe) {
79406 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79407 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79408 + msg = "not being in trusted group";
79409 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79410 + msg = "being in untrusted group";
79411 +#else
79412 + if (in_group_p(grsec_tpe_gid))
79413 + msg = "being in untrusted group";
79414 +#endif
79415 + }
79416 + if (!msg && gr_acl_tpe_check())
79417 + msg = "being in untrusted role";
79418 +
79419 + // not in any affected group/role
79420 + if (!msg)
79421 + goto next_check;
79422 +
79423 + if (gr_is_global_nonroot(inode->i_uid))
79424 + msg2 = "file in non-root-owned directory";
79425 + else if (inode->i_mode & S_IWOTH)
79426 + msg2 = "file in world-writable directory";
79427 + else if (inode->i_mode & S_IWGRP)
79428 + msg2 = "file in group-writable directory";
79429 + else if (file_inode->i_mode & S_IWOTH)
79430 + msg2 = "file is world-writable";
79431 +
79432 + if (msg && msg2) {
79433 + char fullmsg[70] = {0};
79434 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79435 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79436 + return 0;
79437 + }
79438 + msg = NULL;
79439 +next_check:
79440 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
79441 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79442 + return 1;
79443 +
79444 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79445 + msg = "directory not owned by user";
79446 + else if (inode->i_mode & S_IWOTH)
79447 + msg = "file in world-writable directory";
79448 + else if (inode->i_mode & S_IWGRP)
79449 + msg = "file in group-writable directory";
79450 + else if (file_inode->i_mode & S_IWOTH)
79451 + msg = "file is world-writable";
79452 +
79453 + if (msg) {
79454 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79455 + return 0;
79456 + }
79457 +#endif
79458 +#endif
79459 + return 1;
79460 +}
79461 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79462 new file mode 100644
79463 index 0000000..ae02d8e
79464 --- /dev/null
79465 +++ b/grsecurity/grsec_usb.c
79466 @@ -0,0 +1,15 @@
79467 +#include <linux/kernel.h>
79468 +#include <linux/grinternal.h>
79469 +#include <linux/module.h>
79470 +
79471 +int gr_handle_new_usb(void)
79472 +{
79473 +#ifdef CONFIG_GRKERNSEC_DENYUSB
79474 + if (grsec_deny_new_usb) {
79475 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79476 + return 1;
79477 + }
79478 +#endif
79479 + return 0;
79480 +}
79481 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79482 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79483 new file mode 100644
79484 index 0000000..158b330
79485 --- /dev/null
79486 +++ b/grsecurity/grsum.c
79487 @@ -0,0 +1,64 @@
79488 +#include <linux/err.h>
79489 +#include <linux/kernel.h>
79490 +#include <linux/sched.h>
79491 +#include <linux/mm.h>
79492 +#include <linux/scatterlist.h>
79493 +#include <linux/crypto.h>
79494 +#include <linux/gracl.h>
79495 +
79496 +
79497 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79498 +#error "crypto and sha256 must be built into the kernel"
79499 +#endif
79500 +
79501 +int
79502 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79503 +{
79504 + struct crypto_hash *tfm;
79505 + struct hash_desc desc;
79506 + struct scatterlist sg[2];
79507 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79508 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79509 + unsigned long *sumptr = (unsigned long *)sum;
79510 + int cryptres;
79511 + int retval = 1;
79512 + volatile int mismatched = 0;
79513 + volatile int dummy = 0;
79514 + unsigned int i;
79515 +
79516 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79517 + if (IS_ERR(tfm)) {
79518 + /* should never happen, since sha256 should be built in */
79519 + memset(entry->pw, 0, GR_PW_LEN);
79520 + return 1;
79521 + }
79522 +
79523 + sg_init_table(sg, 2);
79524 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79525 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79526 +
79527 + desc.tfm = tfm;
79528 + desc.flags = 0;
79529 +
79530 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79531 + temp_sum);
79532 +
79533 + memset(entry->pw, 0, GR_PW_LEN);
79534 +
79535 + if (cryptres)
79536 + goto out;
79537 +
79538 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79539 + if (sumptr[i] != tmpsumptr[i])
79540 + mismatched = 1;
79541 + else
79542 + dummy = 1; // waste a cycle
79543 +
79544 + if (!mismatched)
79545 + retval = dummy - 1;
79546 +
79547 +out:
79548 + crypto_free_hash(tfm);
79549 +
79550 + return retval;
79551 +}
79552 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79553 index 77ff547..181834f 100644
79554 --- a/include/asm-generic/4level-fixup.h
79555 +++ b/include/asm-generic/4level-fixup.h
79556 @@ -13,8 +13,10 @@
79557 #define pmd_alloc(mm, pud, address) \
79558 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79559 NULL: pmd_offset(pud, address))
79560 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79561
79562 #define pud_alloc(mm, pgd, address) (pgd)
79563 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79564 #define pud_offset(pgd, start) (pgd)
79565 #define pud_none(pud) 0
79566 #define pud_bad(pud) 0
79567 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79568 index b7babf0..1e4b4f1 100644
79569 --- a/include/asm-generic/atomic-long.h
79570 +++ b/include/asm-generic/atomic-long.h
79571 @@ -22,6 +22,12 @@
79572
79573 typedef atomic64_t atomic_long_t;
79574
79575 +#ifdef CONFIG_PAX_REFCOUNT
79576 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
79577 +#else
79578 +typedef atomic64_t atomic_long_unchecked_t;
79579 +#endif
79580 +
79581 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79582
79583 static inline long atomic_long_read(atomic_long_t *l)
79584 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79585 return (long)atomic64_read(v);
79586 }
79587
79588 +#ifdef CONFIG_PAX_REFCOUNT
79589 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79590 +{
79591 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79592 +
79593 + return (long)atomic64_read_unchecked(v);
79594 +}
79595 +#endif
79596 +
79597 static inline void atomic_long_set(atomic_long_t *l, long i)
79598 {
79599 atomic64_t *v = (atomic64_t *)l;
79600 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79601 atomic64_set(v, i);
79602 }
79603
79604 +#ifdef CONFIG_PAX_REFCOUNT
79605 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79606 +{
79607 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79608 +
79609 + atomic64_set_unchecked(v, i);
79610 +}
79611 +#endif
79612 +
79613 static inline void atomic_long_inc(atomic_long_t *l)
79614 {
79615 atomic64_t *v = (atomic64_t *)l;
79616 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79617 atomic64_inc(v);
79618 }
79619
79620 +#ifdef CONFIG_PAX_REFCOUNT
79621 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79622 +{
79623 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79624 +
79625 + atomic64_inc_unchecked(v);
79626 +}
79627 +#endif
79628 +
79629 static inline void atomic_long_dec(atomic_long_t *l)
79630 {
79631 atomic64_t *v = (atomic64_t *)l;
79632 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79633 atomic64_dec(v);
79634 }
79635
79636 +#ifdef CONFIG_PAX_REFCOUNT
79637 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79638 +{
79639 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79640 +
79641 + atomic64_dec_unchecked(v);
79642 +}
79643 +#endif
79644 +
79645 static inline void atomic_long_add(long i, atomic_long_t *l)
79646 {
79647 atomic64_t *v = (atomic64_t *)l;
79648 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79649 atomic64_add(i, v);
79650 }
79651
79652 +#ifdef CONFIG_PAX_REFCOUNT
79653 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79654 +{
79655 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79656 +
79657 + atomic64_add_unchecked(i, v);
79658 +}
79659 +#endif
79660 +
79661 static inline void atomic_long_sub(long i, atomic_long_t *l)
79662 {
79663 atomic64_t *v = (atomic64_t *)l;
79664 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79665 atomic64_sub(i, v);
79666 }
79667
79668 +#ifdef CONFIG_PAX_REFCOUNT
79669 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79670 +{
79671 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79672 +
79673 + atomic64_sub_unchecked(i, v);
79674 +}
79675 +#endif
79676 +
79677 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79678 {
79679 atomic64_t *v = (atomic64_t *)l;
79680 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79681 return atomic64_add_negative(i, v);
79682 }
79683
79684 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79685 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79686 {
79687 atomic64_t *v = (atomic64_t *)l;
79688
79689 return (long)atomic64_add_return(i, v);
79690 }
79691
79692 +#ifdef CONFIG_PAX_REFCOUNT
79693 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79694 +{
79695 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79696 +
79697 + return (long)atomic64_add_return_unchecked(i, v);
79698 +}
79699 +#endif
79700 +
79701 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79702 {
79703 atomic64_t *v = (atomic64_t *)l;
79704 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79705 return (long)atomic64_inc_return(v);
79706 }
79707
79708 +#ifdef CONFIG_PAX_REFCOUNT
79709 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79710 +{
79711 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79712 +
79713 + return (long)atomic64_inc_return_unchecked(v);
79714 +}
79715 +#endif
79716 +
79717 static inline long atomic_long_dec_return(atomic_long_t *l)
79718 {
79719 atomic64_t *v = (atomic64_t *)l;
79720 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79721
79722 typedef atomic_t atomic_long_t;
79723
79724 +#ifdef CONFIG_PAX_REFCOUNT
79725 +typedef atomic_unchecked_t atomic_long_unchecked_t;
79726 +#else
79727 +typedef atomic_t atomic_long_unchecked_t;
79728 +#endif
79729 +
79730 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79731 static inline long atomic_long_read(atomic_long_t *l)
79732 {
79733 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79734 return (long)atomic_read(v);
79735 }
79736
79737 +#ifdef CONFIG_PAX_REFCOUNT
79738 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79739 +{
79740 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79741 +
79742 + return (long)atomic_read_unchecked(v);
79743 +}
79744 +#endif
79745 +
79746 static inline void atomic_long_set(atomic_long_t *l, long i)
79747 {
79748 atomic_t *v = (atomic_t *)l;
79749 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79750 atomic_set(v, i);
79751 }
79752
79753 +#ifdef CONFIG_PAX_REFCOUNT
79754 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79755 +{
79756 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79757 +
79758 + atomic_set_unchecked(v, i);
79759 +}
79760 +#endif
79761 +
79762 static inline void atomic_long_inc(atomic_long_t *l)
79763 {
79764 atomic_t *v = (atomic_t *)l;
79765 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79766 atomic_inc(v);
79767 }
79768
79769 +#ifdef CONFIG_PAX_REFCOUNT
79770 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79771 +{
79772 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79773 +
79774 + atomic_inc_unchecked(v);
79775 +}
79776 +#endif
79777 +
79778 static inline void atomic_long_dec(atomic_long_t *l)
79779 {
79780 atomic_t *v = (atomic_t *)l;
79781 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79782 atomic_dec(v);
79783 }
79784
79785 +#ifdef CONFIG_PAX_REFCOUNT
79786 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79787 +{
79788 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79789 +
79790 + atomic_dec_unchecked(v);
79791 +}
79792 +#endif
79793 +
79794 static inline void atomic_long_add(long i, atomic_long_t *l)
79795 {
79796 atomic_t *v = (atomic_t *)l;
79797 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79798 atomic_add(i, v);
79799 }
79800
79801 +#ifdef CONFIG_PAX_REFCOUNT
79802 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79803 +{
79804 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79805 +
79806 + atomic_add_unchecked(i, v);
79807 +}
79808 +#endif
79809 +
79810 static inline void atomic_long_sub(long i, atomic_long_t *l)
79811 {
79812 atomic_t *v = (atomic_t *)l;
79813 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79814 atomic_sub(i, v);
79815 }
79816
79817 +#ifdef CONFIG_PAX_REFCOUNT
79818 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79819 +{
79820 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79821 +
79822 + atomic_sub_unchecked(i, v);
79823 +}
79824 +#endif
79825 +
79826 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79827 {
79828 atomic_t *v = (atomic_t *)l;
79829 @@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79830 return atomic_add_negative(i, v);
79831 }
79832
79833 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
79834 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79835 {
79836 atomic_t *v = (atomic_t *)l;
79837
79838 return (long)atomic_add_return(i, v);
79839 }
79840
79841 +#ifdef CONFIG_PAX_REFCOUNT
79842 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79843 +{
79844 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79845 +
79846 + return (long)atomic_add_return_unchecked(i, v);
79847 +}
79848 +
79849 +#endif
79850 +
79851 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79852 {
79853 atomic_t *v = (atomic_t *)l;
79854 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79855 return (long)atomic_inc_return(v);
79856 }
79857
79858 +#ifdef CONFIG_PAX_REFCOUNT
79859 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79860 +{
79861 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79862 +
79863 + return (long)atomic_inc_return_unchecked(v);
79864 +}
79865 +#endif
79866 +
79867 static inline long atomic_long_dec_return(atomic_long_t *l)
79868 {
79869 atomic_t *v = (atomic_t *)l;
79870 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79871
79872 #endif /* BITS_PER_LONG == 64 */
79873
79874 +#ifdef CONFIG_PAX_REFCOUNT
79875 +static inline void pax_refcount_needs_these_functions(void)
79876 +{
79877 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
79878 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79879 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79880 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79881 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79882 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79883 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79884 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79885 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79886 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79887 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79888 +#ifdef CONFIG_X86
79889 + atomic_clear_mask_unchecked(0, NULL);
79890 + atomic_set_mask_unchecked(0, NULL);
79891 +#endif
79892 +
79893 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79894 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79895 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79896 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79897 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79898 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79899 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79900 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79901 +}
79902 +#else
79903 +#define atomic_read_unchecked(v) atomic_read(v)
79904 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79905 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79906 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79907 +#define atomic_inc_unchecked(v) atomic_inc(v)
79908 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79909 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79910 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79911 +#define atomic_dec_unchecked(v) atomic_dec(v)
79912 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79913 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79914 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79915 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79916 +
79917 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
79918 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79919 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79920 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79921 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79922 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79923 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79924 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79925 +#endif
79926 +
79927 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79928 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79929 index 30ad9c8..c70c170 100644
79930 --- a/include/asm-generic/atomic64.h
79931 +++ b/include/asm-generic/atomic64.h
79932 @@ -16,6 +16,8 @@ typedef struct {
79933 long long counter;
79934 } atomic64_t;
79935
79936 +typedef atomic64_t atomic64_unchecked_t;
79937 +
79938 #define ATOMIC64_INIT(i) { (i) }
79939
79940 extern long long atomic64_read(const atomic64_t *v);
79941 @@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79942 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79943 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79944
79945 +#define atomic64_read_unchecked(v) atomic64_read(v)
79946 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79947 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79948 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79949 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79950 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
79951 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79952 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
79953 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79954 +
79955 #endif /* _ASM_GENERIC_ATOMIC64_H */
79956 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79957 index 1402fa8..025a736 100644
79958 --- a/include/asm-generic/barrier.h
79959 +++ b/include/asm-generic/barrier.h
79960 @@ -74,7 +74,7 @@
79961 do { \
79962 compiletime_assert_atomic_type(*p); \
79963 smp_mb(); \
79964 - ACCESS_ONCE(*p) = (v); \
79965 + ACCESS_ONCE_RW(*p) = (v); \
79966 } while (0)
79967
79968 #define smp_load_acquire(p) \
79969 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79970 index a60a7cc..0fe12f2 100644
79971 --- a/include/asm-generic/bitops/__fls.h
79972 +++ b/include/asm-generic/bitops/__fls.h
79973 @@ -9,7 +9,7 @@
79974 *
79975 * Undefined if no set bit exists, so code should check against 0 first.
79976 */
79977 -static __always_inline unsigned long __fls(unsigned long word)
79978 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79979 {
79980 int num = BITS_PER_LONG - 1;
79981
79982 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79983 index 0576d1f..dad6c71 100644
79984 --- a/include/asm-generic/bitops/fls.h
79985 +++ b/include/asm-generic/bitops/fls.h
79986 @@ -9,7 +9,7 @@
79987 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79988 */
79989
79990 -static __always_inline int fls(int x)
79991 +static __always_inline int __intentional_overflow(-1) fls(int x)
79992 {
79993 int r = 32;
79994
79995 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79996 index b097cf8..3d40e14 100644
79997 --- a/include/asm-generic/bitops/fls64.h
79998 +++ b/include/asm-generic/bitops/fls64.h
79999 @@ -15,7 +15,7 @@
80000 * at position 64.
80001 */
80002 #if BITS_PER_LONG == 32
80003 -static __always_inline int fls64(__u64 x)
80004 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80005 {
80006 __u32 h = x >> 32;
80007 if (h)
80008 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80009 return fls(x);
80010 }
80011 #elif BITS_PER_LONG == 64
80012 -static __always_inline int fls64(__u64 x)
80013 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80014 {
80015 if (x == 0)
80016 return 0;
80017 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80018 index 1bfcfe5..e04c5c9 100644
80019 --- a/include/asm-generic/cache.h
80020 +++ b/include/asm-generic/cache.h
80021 @@ -6,7 +6,7 @@
80022 * cache lines need to provide their own cache.h.
80023 */
80024
80025 -#define L1_CACHE_SHIFT 5
80026 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80027 +#define L1_CACHE_SHIFT 5UL
80028 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80029
80030 #endif /* __ASM_GENERIC_CACHE_H */
80031 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80032 index 0d68a1e..b74a761 100644
80033 --- a/include/asm-generic/emergency-restart.h
80034 +++ b/include/asm-generic/emergency-restart.h
80035 @@ -1,7 +1,7 @@
80036 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80037 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80038
80039 -static inline void machine_emergency_restart(void)
80040 +static inline __noreturn void machine_emergency_restart(void)
80041 {
80042 machine_restart(NULL);
80043 }
80044 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80045 index b8fdc57..c6d5a5c 100644
80046 --- a/include/asm-generic/io.h
80047 +++ b/include/asm-generic/io.h
80048 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80049 * These are pretty trivial
80050 */
80051 #ifndef virt_to_phys
80052 -static inline unsigned long virt_to_phys(volatile void *address)
80053 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80054 {
80055 return __pa((unsigned long)address);
80056 }
80057 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80058 index 90f99c7..00ce236 100644
80059 --- a/include/asm-generic/kmap_types.h
80060 +++ b/include/asm-generic/kmap_types.h
80061 @@ -2,9 +2,9 @@
80062 #define _ASM_GENERIC_KMAP_TYPES_H
80063
80064 #ifdef __WITH_KM_FENCE
80065 -# define KM_TYPE_NR 41
80066 +# define KM_TYPE_NR 42
80067 #else
80068 -# define KM_TYPE_NR 20
80069 +# define KM_TYPE_NR 21
80070 #endif
80071
80072 #endif
80073 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80074 index 9ceb03b..62b0b8f 100644
80075 --- a/include/asm-generic/local.h
80076 +++ b/include/asm-generic/local.h
80077 @@ -23,24 +23,37 @@ typedef struct
80078 atomic_long_t a;
80079 } local_t;
80080
80081 +typedef struct {
80082 + atomic_long_unchecked_t a;
80083 +} local_unchecked_t;
80084 +
80085 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80086
80087 #define local_read(l) atomic_long_read(&(l)->a)
80088 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80089 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80090 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80091 #define local_inc(l) atomic_long_inc(&(l)->a)
80092 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80093 #define local_dec(l) atomic_long_dec(&(l)->a)
80094 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80095 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80096 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80097 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80098 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80099
80100 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80101 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80102 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80103 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80104 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80105 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80106 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80107 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80108 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80109
80110 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80111 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80112 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80113 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80114 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80115 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80116 index 725612b..9cc513a 100644
80117 --- a/include/asm-generic/pgtable-nopmd.h
80118 +++ b/include/asm-generic/pgtable-nopmd.h
80119 @@ -1,14 +1,19 @@
80120 #ifndef _PGTABLE_NOPMD_H
80121 #define _PGTABLE_NOPMD_H
80122
80123 -#ifndef __ASSEMBLY__
80124 -
80125 #include <asm-generic/pgtable-nopud.h>
80126
80127 -struct mm_struct;
80128 -
80129 #define __PAGETABLE_PMD_FOLDED
80130
80131 +#define PMD_SHIFT PUD_SHIFT
80132 +#define PTRS_PER_PMD 1
80133 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80134 +#define PMD_MASK (~(PMD_SIZE-1))
80135 +
80136 +#ifndef __ASSEMBLY__
80137 +
80138 +struct mm_struct;
80139 +
80140 /*
80141 * Having the pmd type consist of a pud gets the size right, and allows
80142 * us to conceptually access the pud entry that this pmd is folded into
80143 @@ -16,11 +21,6 @@ struct mm_struct;
80144 */
80145 typedef struct { pud_t pud; } pmd_t;
80146
80147 -#define PMD_SHIFT PUD_SHIFT
80148 -#define PTRS_PER_PMD 1
80149 -#define PMD_SIZE (1UL << PMD_SHIFT)
80150 -#define PMD_MASK (~(PMD_SIZE-1))
80151 -
80152 /*
80153 * The "pud_xxx()" functions here are trivial for a folded two-level
80154 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80155 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80156 index 810431d..0ec4804f 100644
80157 --- a/include/asm-generic/pgtable-nopud.h
80158 +++ b/include/asm-generic/pgtable-nopud.h
80159 @@ -1,10 +1,15 @@
80160 #ifndef _PGTABLE_NOPUD_H
80161 #define _PGTABLE_NOPUD_H
80162
80163 -#ifndef __ASSEMBLY__
80164 -
80165 #define __PAGETABLE_PUD_FOLDED
80166
80167 +#define PUD_SHIFT PGDIR_SHIFT
80168 +#define PTRS_PER_PUD 1
80169 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80170 +#define PUD_MASK (~(PUD_SIZE-1))
80171 +
80172 +#ifndef __ASSEMBLY__
80173 +
80174 /*
80175 * Having the pud type consist of a pgd gets the size right, and allows
80176 * us to conceptually access the pgd entry that this pud is folded into
80177 @@ -12,11 +17,6 @@
80178 */
80179 typedef struct { pgd_t pgd; } pud_t;
80180
80181 -#define PUD_SHIFT PGDIR_SHIFT
80182 -#define PTRS_PER_PUD 1
80183 -#define PUD_SIZE (1UL << PUD_SHIFT)
80184 -#define PUD_MASK (~(PUD_SIZE-1))
80185 -
80186 /*
80187 * The "pgd_xxx()" functions here are trivial for a folded two-level
80188 * setup: the pud is never bad, and a pud always exists (as it's folded
80189 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80190 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80191
80192 #define pgd_populate(mm, pgd, pud) do { } while (0)
80193 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80194 /*
80195 * (puds are folded into pgds so this doesn't get actually called,
80196 * but the define is needed for a generic inline function.)
80197 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80198 index 752e30d..87f172d 100644
80199 --- a/include/asm-generic/pgtable.h
80200 +++ b/include/asm-generic/pgtable.h
80201 @@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80202 }
80203 #endif /* CONFIG_NUMA_BALANCING */
80204
80205 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80206 +#ifdef CONFIG_PAX_KERNEXEC
80207 +#error KERNEXEC requires pax_open_kernel
80208 +#else
80209 +static inline unsigned long pax_open_kernel(void) { return 0; }
80210 +#endif
80211 +#endif
80212 +
80213 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80214 +#ifdef CONFIG_PAX_KERNEXEC
80215 +#error KERNEXEC requires pax_close_kernel
80216 +#else
80217 +static inline unsigned long pax_close_kernel(void) { return 0; }
80218 +#endif
80219 +#endif
80220 +
80221 #endif /* CONFIG_MMU */
80222
80223 #endif /* !__ASSEMBLY__ */
80224 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80225 index 72d8803..cb9749c 100644
80226 --- a/include/asm-generic/uaccess.h
80227 +++ b/include/asm-generic/uaccess.h
80228 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80229 return __clear_user(to, n);
80230 }
80231
80232 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80233 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80234 +#error UDEREF requires pax_open_userland
80235 +#else
80236 +static inline unsigned long pax_open_userland(void) { return 0; }
80237 +#endif
80238 +#endif
80239 +
80240 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80241 +#ifdef CONFIG_PAX_MEMORY_UDEREF
80242 +#error UDEREF requires pax_close_userland
80243 +#else
80244 +static inline unsigned long pax_close_userland(void) { return 0; }
80245 +#endif
80246 +#endif
80247 +
80248 #endif /* __ASM_GENERIC_UACCESS_H */
80249 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80250 index aa70cbd..fd72c7a 100644
80251 --- a/include/asm-generic/vmlinux.lds.h
80252 +++ b/include/asm-generic/vmlinux.lds.h
80253 @@ -233,6 +233,7 @@
80254 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80255 VMLINUX_SYMBOL(__start_rodata) = .; \
80256 *(.rodata) *(.rodata.*) \
80257 + *(.data..read_only) \
80258 *(__vermagic) /* Kernel version magic */ \
80259 . = ALIGN(8); \
80260 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80261 @@ -724,17 +725,18 @@
80262 * section in the linker script will go there too. @phdr should have
80263 * a leading colon.
80264 *
80265 - * Note that this macros defines __per_cpu_load as an absolute symbol.
80266 + * Note that this macros defines per_cpu_load as an absolute symbol.
80267 * If there is no need to put the percpu section at a predetermined
80268 * address, use PERCPU_SECTION.
80269 */
80270 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80271 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
80272 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80273 + per_cpu_load = .; \
80274 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80275 - LOAD_OFFSET) { \
80276 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80277 PERCPU_INPUT(cacheline) \
80278 } phdr \
80279 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80280 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80281
80282 /**
80283 * PERCPU_SECTION - define output section for percpu area, simple version
80284 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80285 index 623a59c..1e79ab9 100644
80286 --- a/include/crypto/algapi.h
80287 +++ b/include/crypto/algapi.h
80288 @@ -34,7 +34,7 @@ struct crypto_type {
80289 unsigned int maskclear;
80290 unsigned int maskset;
80291 unsigned int tfmsize;
80292 -};
80293 +} __do_const;
80294
80295 struct crypto_instance {
80296 struct crypto_alg alg;
80297 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80298 index 53ed876..5bb09be 100644
80299 --- a/include/drm/drmP.h
80300 +++ b/include/drm/drmP.h
80301 @@ -59,6 +59,7 @@
80302
80303 #include <asm/mman.h>
80304 #include <asm/pgalloc.h>
80305 +#include <asm/local.h>
80306 #include <asm/uaccess.h>
80307
80308 #include <uapi/drm/drm.h>
80309 @@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80310 * \param cmd command.
80311 * \param arg argument.
80312 */
80313 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80314 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80315 + struct drm_file *file_priv);
80316 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80317 struct drm_file *file_priv);
80318
80319 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80320 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80321 unsigned long arg);
80322
80323 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80324 @@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80325 struct drm_ioctl_desc {
80326 unsigned int cmd;
80327 int flags;
80328 - drm_ioctl_t *func;
80329 + drm_ioctl_t func;
80330 unsigned int cmd_drv;
80331 const char *name;
80332 -};
80333 +} __do_const;
80334
80335 /**
80336 * Creates a driver or general drm_ioctl_desc array entry for the given
80337 @@ -629,7 +632,8 @@ struct drm_info_list {
80338 int (*show)(struct seq_file*, void*); /** show callback */
80339 u32 driver_features; /**< Required driver features for this entry */
80340 void *data;
80341 -};
80342 +} __do_const;
80343 +typedef struct drm_info_list __no_const drm_info_list_no_const;
80344
80345 /**
80346 * debugfs node structure. This structure represents a debugfs file.
80347 @@ -713,7 +717,7 @@ struct drm_device {
80348
80349 /** \name Usage Counters */
80350 /*@{ */
80351 - int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80352 + local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80353 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80354 int buf_use; /**< Buffers in use -- cannot alloc */
80355 atomic_t buf_alloc; /**< Buffer allocation in progress */
80356 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80357 index a3d75fe..6802f9c 100644
80358 --- a/include/drm/drm_crtc_helper.h
80359 +++ b/include/drm/drm_crtc_helper.h
80360 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80361 struct drm_connector *connector);
80362 /* disable encoder when not in use - more explicit than dpms off */
80363 void (*disable)(struct drm_encoder *encoder);
80364 -};
80365 +} __no_const;
80366
80367 /**
80368 * drm_connector_helper_funcs - helper operations for connectors
80369 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80370 index a70d456..6ea07cd 100644
80371 --- a/include/drm/i915_pciids.h
80372 +++ b/include/drm/i915_pciids.h
80373 @@ -37,7 +37,7 @@
80374 */
80375 #define INTEL_VGA_DEVICE(id, info) { \
80376 0x8086, id, \
80377 - ~0, ~0, \
80378 + PCI_ANY_ID, PCI_ANY_ID, \
80379 0x030000, 0xff0000, \
80380 (unsigned long) info }
80381
80382 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80383 index 72dcbe8..8db58d7 100644
80384 --- a/include/drm/ttm/ttm_memory.h
80385 +++ b/include/drm/ttm/ttm_memory.h
80386 @@ -48,7 +48,7 @@
80387
80388 struct ttm_mem_shrink {
80389 int (*do_shrink) (struct ttm_mem_shrink *);
80390 -};
80391 +} __no_const;
80392
80393 /**
80394 * struct ttm_mem_global - Global memory accounting structure.
80395 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80396 index 49a8284..9643967 100644
80397 --- a/include/drm/ttm/ttm_page_alloc.h
80398 +++ b/include/drm/ttm/ttm_page_alloc.h
80399 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80400 */
80401 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80402
80403 +struct device;
80404 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80405 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80406
80407 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80408 index 4b840e8..155d235 100644
80409 --- a/include/keys/asymmetric-subtype.h
80410 +++ b/include/keys/asymmetric-subtype.h
80411 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80412 /* Verify the signature on a key of this subtype (optional) */
80413 int (*verify_signature)(const struct key *key,
80414 const struct public_key_signature *sig);
80415 -};
80416 +} __do_const;
80417
80418 /**
80419 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80420 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80421 index c1da539..1dcec55 100644
80422 --- a/include/linux/atmdev.h
80423 +++ b/include/linux/atmdev.h
80424 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80425 #endif
80426
80427 struct k_atm_aal_stats {
80428 -#define __HANDLE_ITEM(i) atomic_t i
80429 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80430 __AAL_STAT_ITEMS
80431 #undef __HANDLE_ITEM
80432 };
80433 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80434 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80435 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80436 struct module *owner;
80437 -};
80438 +} __do_const ;
80439
80440 struct atmphy_ops {
80441 int (*start)(struct atm_dev *dev);
80442 diff --git a/include/linux/audit.h b/include/linux/audit.h
80443 index 10f155b..6c73ffe 100644
80444 --- a/include/linux/audit.h
80445 +++ b/include/linux/audit.h
80446 @@ -219,7 +219,7 @@ static inline void audit_ptrace(struct task_struct *t)
80447 extern unsigned int audit_serial(void);
80448 extern int auditsc_get_stamp(struct audit_context *ctx,
80449 struct timespec *t, unsigned int *serial);
80450 -extern int audit_set_loginuid(kuid_t loginuid);
80451 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80452
80453 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80454 {
80455 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80456 index 61f29e5..e67c658 100644
80457 --- a/include/linux/binfmts.h
80458 +++ b/include/linux/binfmts.h
80459 @@ -44,7 +44,7 @@ struct linux_binprm {
80460 unsigned interp_flags;
80461 unsigned interp_data;
80462 unsigned long loader, exec;
80463 -};
80464 +} __randomize_layout;
80465
80466 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80467 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80468 @@ -73,8 +73,10 @@ struct linux_binfmt {
80469 int (*load_binary)(struct linux_binprm *);
80470 int (*load_shlib)(struct file *);
80471 int (*core_dump)(struct coredump_params *cprm);
80472 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80473 + void (*handle_mmap)(struct file *);
80474 unsigned long min_coredump; /* minimal dump size */
80475 -};
80476 +} __do_const __randomize_layout;
80477
80478 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80479
80480 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80481 index 5d858e0..336c1d9 100644
80482 --- a/include/linux/bitops.h
80483 +++ b/include/linux/bitops.h
80484 @@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80485 * @word: value to rotate
80486 * @shift: bits to roll
80487 */
80488 -static inline __u32 rol32(__u32 word, unsigned int shift)
80489 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80490 {
80491 return (word << shift) | (word >> (32 - shift));
80492 }
80493 @@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80494 * @word: value to rotate
80495 * @shift: bits to roll
80496 */
80497 -static inline __u32 ror32(__u32 word, unsigned int shift)
80498 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80499 {
80500 return (word >> shift) | (word << (32 - shift));
80501 }
80502 @@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80503 return (__s32)(value << shift) >> shift;
80504 }
80505
80506 -static inline unsigned fls_long(unsigned long l)
80507 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80508 {
80509 if (sizeof(l) == 4)
80510 return fls(l);
80511 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80512 index aac0f9e..73c9869 100644
80513 --- a/include/linux/blkdev.h
80514 +++ b/include/linux/blkdev.h
80515 @@ -1615,7 +1615,7 @@ struct block_device_operations {
80516 /* this callback is with swap_lock and sometimes page table lock held */
80517 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80518 struct module *owner;
80519 -};
80520 +} __do_const;
80521
80522 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80523 unsigned long);
80524 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80525 index afc1343..9735539 100644
80526 --- a/include/linux/blktrace_api.h
80527 +++ b/include/linux/blktrace_api.h
80528 @@ -25,7 +25,7 @@ struct blk_trace {
80529 struct dentry *dropped_file;
80530 struct dentry *msg_file;
80531 struct list_head running_list;
80532 - atomic_t dropped;
80533 + atomic_unchecked_t dropped;
80534 };
80535
80536 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80537 diff --git a/include/linux/cache.h b/include/linux/cache.h
80538 index 17e7e82..1d7da26 100644
80539 --- a/include/linux/cache.h
80540 +++ b/include/linux/cache.h
80541 @@ -16,6 +16,14 @@
80542 #define __read_mostly
80543 #endif
80544
80545 +#ifndef __read_only
80546 +#ifdef CONFIG_PAX_KERNEXEC
80547 +#error KERNEXEC requires __read_only
80548 +#else
80549 +#define __read_only __read_mostly
80550 +#endif
80551 +#endif
80552 +
80553 #ifndef ____cacheline_aligned
80554 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80555 #endif
80556 diff --git a/include/linux/capability.h b/include/linux/capability.h
80557 index aa93e5e..985a1b0 100644
80558 --- a/include/linux/capability.h
80559 +++ b/include/linux/capability.h
80560 @@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80561 extern bool capable(int cap);
80562 extern bool ns_capable(struct user_namespace *ns, int cap);
80563 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80564 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80565 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80566 +extern bool capable_nolog(int cap);
80567 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80568
80569 /* audit system wants to get cap info from files as well */
80570 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80571
80572 +extern int is_privileged_binary(const struct dentry *dentry);
80573 +
80574 #endif /* !_LINUX_CAPABILITY_H */
80575 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80576 index 8609d57..86e4d79 100644
80577 --- a/include/linux/cdrom.h
80578 +++ b/include/linux/cdrom.h
80579 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
80580
80581 /* driver specifications */
80582 const int capability; /* capability flags */
80583 - int n_minors; /* number of active minor devices */
80584 /* handle uniform packets for scsi type devices (scsi,atapi) */
80585 int (*generic_packet) (struct cdrom_device_info *,
80586 struct packet_command *);
80587 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80588 index 4ce9056..86caac6 100644
80589 --- a/include/linux/cleancache.h
80590 +++ b/include/linux/cleancache.h
80591 @@ -31,7 +31,7 @@ struct cleancache_ops {
80592 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80593 void (*invalidate_inode)(int, struct cleancache_filekey);
80594 void (*invalidate_fs)(int);
80595 -};
80596 +} __no_const;
80597
80598 extern struct cleancache_ops *
80599 cleancache_register_ops(struct cleancache_ops *ops);
80600 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80601 index 2839c63..5b06b6b 100644
80602 --- a/include/linux/clk-provider.h
80603 +++ b/include/linux/clk-provider.h
80604 @@ -191,6 +191,7 @@ struct clk_ops {
80605 void (*init)(struct clk_hw *hw);
80606 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80607 };
80608 +typedef struct clk_ops __no_const clk_ops_no_const;
80609
80610 /**
80611 * struct clk_init_data - holds init data that's common to all clocks and is
80612 diff --git a/include/linux/compat.h b/include/linux/compat.h
80613 index e649426..a74047b 100644
80614 --- a/include/linux/compat.h
80615 +++ b/include/linux/compat.h
80616 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80617 compat_size_t __user *len_ptr);
80618
80619 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80620 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80621 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80622 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80623 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80624 compat_ssize_t msgsz, int msgflg);
80625 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80626 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80627 compat_ulong_t addr, compat_ulong_t data);
80628 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80629 - compat_long_t addr, compat_long_t data);
80630 + compat_ulong_t addr, compat_ulong_t data);
80631
80632 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80633 /*
80634 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80635 index d1a5582..4424efa 100644
80636 --- a/include/linux/compiler-gcc4.h
80637 +++ b/include/linux/compiler-gcc4.h
80638 @@ -39,9 +39,34 @@
80639 # define __compiletime_warning(message) __attribute__((warning(message)))
80640 # define __compiletime_error(message) __attribute__((error(message)))
80641 #endif /* __CHECKER__ */
80642 +
80643 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80644 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80645 +#define __bos0(ptr) __bos((ptr), 0)
80646 +#define __bos1(ptr) __bos((ptr), 1)
80647 #endif /* GCC_VERSION >= 40300 */
80648
80649 #if GCC_VERSION >= 40500
80650 +
80651 +#ifdef RANDSTRUCT_PLUGIN
80652 +#define __randomize_layout __attribute__((randomize_layout))
80653 +#define __no_randomize_layout __attribute__((no_randomize_layout))
80654 +#endif
80655 +
80656 +#ifdef CONSTIFY_PLUGIN
80657 +#define __no_const __attribute__((no_const))
80658 +#define __do_const __attribute__((do_const))
80659 +#endif
80660 +
80661 +#ifdef SIZE_OVERFLOW_PLUGIN
80662 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80663 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80664 +#endif
80665 +
80666 +#ifdef LATENT_ENTROPY_PLUGIN
80667 +#define __latent_entropy __attribute__((latent_entropy))
80668 +#endif
80669 +
80670 /*
80671 * Mark a position in code as unreachable. This can be used to
80672 * suppress control flow warnings after asm blocks that transfer
80673 diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h
80674 index c8c5659..d09f2ad 100644
80675 --- a/include/linux/compiler-gcc5.h
80676 +++ b/include/linux/compiler-gcc5.h
80677 @@ -28,6 +28,28 @@
80678 # define __compiletime_error(message) __attribute__((error(message)))
80679 #endif /* __CHECKER__ */
80680
80681 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80682 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80683 +#define __bos0(ptr) __bos((ptr), 0)
80684 +#define __bos1(ptr) __bos((ptr), 1)
80685 +
80686 +#ifdef CONSTIFY_PLUGIN
80687 +#error not yet
80688 +#define __no_const __attribute__((no_const))
80689 +#define __do_const __attribute__((do_const))
80690 +#endif
80691 +
80692 +#ifdef SIZE_OVERFLOW_PLUGIN
80693 +#error not yet
80694 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80695 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80696 +#endif
80697 +
80698 +#ifdef LATENT_ENTROPY_PLUGIN
80699 +#error not yet
80700 +#define __latent_entropy __attribute__((latent_entropy))
80701 +#endif
80702 +
80703 /*
80704 * Mark a position in code as unreachable. This can be used to
80705 * suppress control flow warnings after asm blocks that transfer
80706 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80707 index d5ad7b1..3b74638 100644
80708 --- a/include/linux/compiler.h
80709 +++ b/include/linux/compiler.h
80710 @@ -5,11 +5,14 @@
80711
80712 #ifdef __CHECKER__
80713 # define __user __attribute__((noderef, address_space(1)))
80714 +# define __force_user __force __user
80715 # define __kernel __attribute__((address_space(0)))
80716 +# define __force_kernel __force __kernel
80717 # define __safe __attribute__((safe))
80718 # define __force __attribute__((force))
80719 # define __nocast __attribute__((nocast))
80720 # define __iomem __attribute__((noderef, address_space(2)))
80721 +# define __force_iomem __force __iomem
80722 # define __must_hold(x) __attribute__((context(x,1,1)))
80723 # define __acquires(x) __attribute__((context(x,0,1)))
80724 # define __releases(x) __attribute__((context(x,1,0)))
80725 @@ -17,20 +20,37 @@
80726 # define __release(x) __context__(x,-1)
80727 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80728 # define __percpu __attribute__((noderef, address_space(3)))
80729 +# define __force_percpu __force __percpu
80730 #ifdef CONFIG_SPARSE_RCU_POINTER
80731 # define __rcu __attribute__((noderef, address_space(4)))
80732 +# define __force_rcu __force __rcu
80733 #else
80734 # define __rcu
80735 +# define __force_rcu
80736 #endif
80737 extern void __chk_user_ptr(const volatile void __user *);
80738 extern void __chk_io_ptr(const volatile void __iomem *);
80739 #else
80740 -# define __user
80741 -# define __kernel
80742 +# ifdef CHECKER_PLUGIN
80743 +//# define __user
80744 +//# define __force_user
80745 +//# define __kernel
80746 +//# define __force_kernel
80747 +# else
80748 +# ifdef STRUCTLEAK_PLUGIN
80749 +# define __user __attribute__((user))
80750 +# else
80751 +# define __user
80752 +# endif
80753 +# define __force_user
80754 +# define __kernel
80755 +# define __force_kernel
80756 +# endif
80757 # define __safe
80758 # define __force
80759 # define __nocast
80760 # define __iomem
80761 +# define __force_iomem
80762 # define __chk_user_ptr(x) (void)0
80763 # define __chk_io_ptr(x) (void)0
80764 # define __builtin_warning(x, y...) (1)
80765 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80766 # define __release(x) (void)0
80767 # define __cond_lock(x,c) (c)
80768 # define __percpu
80769 +# define __force_percpu
80770 # define __rcu
80771 +# define __force_rcu
80772 #endif
80773
80774 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80775 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80776 # define __attribute_const__ /* unimplemented */
80777 #endif
80778
80779 +#ifndef __randomize_layout
80780 +# define __randomize_layout
80781 +#endif
80782 +
80783 +#ifndef __no_randomize_layout
80784 +# define __no_randomize_layout
80785 +#endif
80786 +
80787 +#ifndef __no_const
80788 +# define __no_const
80789 +#endif
80790 +
80791 +#ifndef __do_const
80792 +# define __do_const
80793 +#endif
80794 +
80795 +#ifndef __size_overflow
80796 +# define __size_overflow(...)
80797 +#endif
80798 +
80799 +#ifndef __intentional_overflow
80800 +# define __intentional_overflow(...)
80801 +#endif
80802 +
80803 +#ifndef __latent_entropy
80804 +# define __latent_entropy
80805 +#endif
80806 +
80807 /*
80808 * Tell gcc if a function is cold. The compiler will assume any path
80809 * directly leading to the call is unlikely.
80810 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80811 #define __cold
80812 #endif
80813
80814 +#ifndef __alloc_size
80815 +#define __alloc_size(...)
80816 +#endif
80817 +
80818 +#ifndef __bos
80819 +#define __bos(ptr, arg)
80820 +#endif
80821 +
80822 +#ifndef __bos0
80823 +#define __bos0(ptr)
80824 +#endif
80825 +
80826 +#ifndef __bos1
80827 +#define __bos1(ptr)
80828 +#endif
80829 +
80830 /* Simple shorthand for a section definition */
80831 #ifndef __section
80832 # define __section(S) __attribute__ ((__section__(#S)))
80833 @@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80834 * use is to mediate communication between process-level code and irq/NMI
80835 * handlers, all running on the same CPU.
80836 */
80837 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80838 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80839 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80840
80841 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80842 #ifdef CONFIG_KPROBES
80843 diff --git a/include/linux/completion.h b/include/linux/completion.h
80844 index 5d5aaae..0ea9b84 100644
80845 --- a/include/linux/completion.h
80846 +++ b/include/linux/completion.h
80847 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80848
80849 extern void wait_for_completion(struct completion *);
80850 extern void wait_for_completion_io(struct completion *);
80851 -extern int wait_for_completion_interruptible(struct completion *x);
80852 -extern int wait_for_completion_killable(struct completion *x);
80853 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80854 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80855 extern unsigned long wait_for_completion_timeout(struct completion *x,
80856 - unsigned long timeout);
80857 + unsigned long timeout) __intentional_overflow(-1);
80858 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80859 - unsigned long timeout);
80860 + unsigned long timeout) __intentional_overflow(-1);
80861 extern long wait_for_completion_interruptible_timeout(
80862 - struct completion *x, unsigned long timeout);
80863 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80864 extern long wait_for_completion_killable_timeout(
80865 - struct completion *x, unsigned long timeout);
80866 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80867 extern bool try_wait_for_completion(struct completion *x);
80868 extern bool completion_done(struct completion *x);
80869
80870 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80871 index 34025df..d94bbbc 100644
80872 --- a/include/linux/configfs.h
80873 +++ b/include/linux/configfs.h
80874 @@ -125,7 +125,7 @@ struct configfs_attribute {
80875 const char *ca_name;
80876 struct module *ca_owner;
80877 umode_t ca_mode;
80878 -};
80879 +} __do_const;
80880
80881 /*
80882 * Users often need to create attribute structures for their configurable
80883 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80884 index 503b085b..1638c9e 100644
80885 --- a/include/linux/cpufreq.h
80886 +++ b/include/linux/cpufreq.h
80887 @@ -206,6 +206,7 @@ struct global_attr {
80888 ssize_t (*store)(struct kobject *a, struct attribute *b,
80889 const char *c, size_t count);
80890 };
80891 +typedef struct global_attr __no_const global_attr_no_const;
80892
80893 #define define_one_global_ro(_name) \
80894 static struct global_attr _name = \
80895 @@ -273,7 +274,7 @@ struct cpufreq_driver {
80896 bool boost_supported;
80897 bool boost_enabled;
80898 int (*set_boost) (int state);
80899 -};
80900 +} __do_const;
80901
80902 /* flags */
80903 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80904 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80905 index 25e0df6..952dffd 100644
80906 --- a/include/linux/cpuidle.h
80907 +++ b/include/linux/cpuidle.h
80908 @@ -50,7 +50,8 @@ struct cpuidle_state {
80909 int index);
80910
80911 int (*enter_dead) (struct cpuidle_device *dev, int index);
80912 -};
80913 +} __do_const;
80914 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80915
80916 /* Idle State Flags */
80917 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80918 @@ -209,7 +210,7 @@ struct cpuidle_governor {
80919 void (*reflect) (struct cpuidle_device *dev, int index);
80920
80921 struct module *owner;
80922 -};
80923 +} __do_const;
80924
80925 #ifdef CONFIG_CPU_IDLE
80926 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80927 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80928 index 0a9a6da..ea597ca 100644
80929 --- a/include/linux/cpumask.h
80930 +++ b/include/linux/cpumask.h
80931 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80932 }
80933
80934 /* Valid inputs for n are -1 and 0. */
80935 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80936 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80937 {
80938 return n+1;
80939 }
80940
80941 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80942 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80943 {
80944 return n+1;
80945 }
80946
80947 -static inline unsigned int cpumask_next_and(int n,
80948 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80949 const struct cpumask *srcp,
80950 const struct cpumask *andp)
80951 {
80952 @@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80953 *
80954 * Returns >= nr_cpu_ids if no further cpus set.
80955 */
80956 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80957 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80958 {
80959 /* -1 is a legal arg here. */
80960 if (n != -1)
80961 @@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80962 *
80963 * Returns >= nr_cpu_ids if no further cpus unset.
80964 */
80965 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80966 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80967 {
80968 /* -1 is a legal arg here. */
80969 if (n != -1)
80970 @@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80971 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80972 }
80973
80974 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80975 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80976 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80977 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80978
80979 diff --git a/include/linux/cred.h b/include/linux/cred.h
80980 index 2fb2ca2..d6a3340 100644
80981 --- a/include/linux/cred.h
80982 +++ b/include/linux/cred.h
80983 @@ -35,7 +35,7 @@ struct group_info {
80984 int nblocks;
80985 kgid_t small_block[NGROUPS_SMALL];
80986 kgid_t *blocks[0];
80987 -};
80988 +} __randomize_layout;
80989
80990 /**
80991 * get_group_info - Get a reference to a group info structure
80992 @@ -137,7 +137,7 @@ struct cred {
80993 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80994 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80995 struct rcu_head rcu; /* RCU deletion hook */
80996 -};
80997 +} __randomize_layout;
80998
80999 extern void __put_cred(struct cred *);
81000 extern void exit_creds(struct task_struct *);
81001 @@ -195,6 +195,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81002 static inline void validate_process_creds(void)
81003 {
81004 }
81005 +static inline void validate_task_creds(struct task_struct *task)
81006 +{
81007 +}
81008 #endif
81009
81010 /**
81011 @@ -332,6 +335,7 @@ static inline void put_cred(const struct cred *_cred)
81012
81013 #define task_uid(task) (task_cred_xxx((task), uid))
81014 #define task_euid(task) (task_cred_xxx((task), euid))
81015 +#define task_securebits(task) (task_cred_xxx((task), securebits))
81016
81017 #define current_cred_xxx(xxx) \
81018 ({ \
81019 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81020 index dc34dfc..bdf9b5d 100644
81021 --- a/include/linux/crypto.h
81022 +++ b/include/linux/crypto.h
81023 @@ -386,7 +386,7 @@ struct cipher_tfm {
81024 const u8 *key, unsigned int keylen);
81025 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81026 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81027 -};
81028 +} __no_const;
81029
81030 struct hash_tfm {
81031 int (*init)(struct hash_desc *desc);
81032 @@ -407,13 +407,13 @@ struct compress_tfm {
81033 int (*cot_decompress)(struct crypto_tfm *tfm,
81034 const u8 *src, unsigned int slen,
81035 u8 *dst, unsigned int *dlen);
81036 -};
81037 +} __no_const;
81038
81039 struct rng_tfm {
81040 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81041 unsigned int dlen);
81042 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81043 -};
81044 +} __no_const;
81045
81046 #define crt_ablkcipher crt_u.ablkcipher
81047 #define crt_aead crt_u.aead
81048 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81049 index 653589e..4ef254a 100644
81050 --- a/include/linux/ctype.h
81051 +++ b/include/linux/ctype.h
81052 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81053 * Fast implementation of tolower() for internal usage. Do not use in your
81054 * code.
81055 */
81056 -static inline char _tolower(const char c)
81057 +static inline unsigned char _tolower(const unsigned char c)
81058 {
81059 return c | 0x20;
81060 }
81061 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81062 index 1c2f1b8..7b9f50c 100644
81063 --- a/include/linux/dcache.h
81064 +++ b/include/linux/dcache.h
81065 @@ -123,6 +123,9 @@ struct dentry {
81066 unsigned long d_time; /* used by d_revalidate */
81067 void *d_fsdata; /* fs-specific data */
81068
81069 +#ifdef CONFIG_GRKERNSEC_CHROOT_RENAME
81070 + atomic_t chroot_refcnt; /* tracks use of directory in chroot */
81071 +#endif
81072 struct list_head d_lru; /* LRU list */
81073 struct list_head d_child; /* child of parent list */
81074 struct list_head d_subdirs; /* our children */
81075 @@ -133,7 +136,7 @@ struct dentry {
81076 struct hlist_node d_alias; /* inode alias list */
81077 struct rcu_head d_rcu;
81078 } d_u;
81079 -};
81080 +} __randomize_layout;
81081
81082 /*
81083 * dentry->d_lock spinlock nesting subclasses:
81084 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81085 index 7925bf0..d5143d2 100644
81086 --- a/include/linux/decompress/mm.h
81087 +++ b/include/linux/decompress/mm.h
81088 @@ -77,7 +77,7 @@ static void free(void *where)
81089 * warnings when not needed (indeed large_malloc / large_free are not
81090 * needed by inflate */
81091
81092 -#define malloc(a) kmalloc(a, GFP_KERNEL)
81093 +#define malloc(a) kmalloc((a), GFP_KERNEL)
81094 #define free(a) kfree(a)
81095
81096 #define large_malloc(a) vmalloc(a)
81097 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81098 index f1863dc..5c26074 100644
81099 --- a/include/linux/devfreq.h
81100 +++ b/include/linux/devfreq.h
81101 @@ -114,7 +114,7 @@ struct devfreq_governor {
81102 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81103 int (*event_handler)(struct devfreq *devfreq,
81104 unsigned int event, void *data);
81105 -};
81106 +} __do_const;
81107
81108 /**
81109 * struct devfreq - Device devfreq structure
81110 diff --git a/include/linux/device.h b/include/linux/device.h
81111 index ce1f2160..189bc33 100644
81112 --- a/include/linux/device.h
81113 +++ b/include/linux/device.h
81114 @@ -311,7 +311,7 @@ struct subsys_interface {
81115 struct list_head node;
81116 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81117 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81118 -};
81119 +} __do_const;
81120
81121 int subsys_interface_register(struct subsys_interface *sif);
81122 void subsys_interface_unregister(struct subsys_interface *sif);
81123 @@ -507,7 +507,7 @@ struct device_type {
81124 void (*release)(struct device *dev);
81125
81126 const struct dev_pm_ops *pm;
81127 -};
81128 +} __do_const;
81129
81130 /* interface for exporting device attributes */
81131 struct device_attribute {
81132 @@ -517,11 +517,12 @@ struct device_attribute {
81133 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81134 const char *buf, size_t count);
81135 };
81136 +typedef struct device_attribute __no_const device_attribute_no_const;
81137
81138 struct dev_ext_attribute {
81139 struct device_attribute attr;
81140 void *var;
81141 -};
81142 +} __do_const;
81143
81144 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81145 char *buf);
81146 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81147 index d5d3881..7ed54af 100644
81148 --- a/include/linux/dma-mapping.h
81149 +++ b/include/linux/dma-mapping.h
81150 @@ -60,7 +60,7 @@ struct dma_map_ops {
81151 u64 (*get_required_mask)(struct device *dev);
81152 #endif
81153 int is_phys;
81154 -};
81155 +} __do_const;
81156
81157 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81158
81159 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81160 index 653a1fd..9133cd1 100644
81161 --- a/include/linux/dmaengine.h
81162 +++ b/include/linux/dmaengine.h
81163 @@ -1136,9 +1136,9 @@ struct dma_pinned_list {
81164 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81165 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81166
81167 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81168 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81169 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81170 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81171 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81172 struct dma_pinned_list *pinned_list, struct page *page,
81173 unsigned int offset, size_t len);
81174
81175 diff --git a/include/linux/efi.h b/include/linux/efi.h
81176 index 0949f9c..04cb9a5 100644
81177 --- a/include/linux/efi.h
81178 +++ b/include/linux/efi.h
81179 @@ -1050,6 +1050,7 @@ struct efivar_operations {
81180 efi_set_variable_nonblocking_t *set_variable_nonblocking;
81181 efi_query_variable_store_t *query_variable_store;
81182 };
81183 +typedef struct efivar_operations __no_const efivar_operations_no_const;
81184
81185 struct efivars {
81186 /*
81187 diff --git a/include/linux/elf.h b/include/linux/elf.h
81188 index 67a5fa7..b817372 100644
81189 --- a/include/linux/elf.h
81190 +++ b/include/linux/elf.h
81191 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81192 #define elf_note elf32_note
81193 #define elf_addr_t Elf32_Off
81194 #define Elf_Half Elf32_Half
81195 +#define elf_dyn Elf32_Dyn
81196
81197 #else
81198
81199 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81200 #define elf_note elf64_note
81201 #define elf_addr_t Elf64_Off
81202 #define Elf_Half Elf64_Half
81203 +#define elf_dyn Elf64_Dyn
81204
81205 #endif
81206
81207 diff --git a/include/linux/err.h b/include/linux/err.h
81208 index a729120..6ede2c9 100644
81209 --- a/include/linux/err.h
81210 +++ b/include/linux/err.h
81211 @@ -20,12 +20,12 @@
81212
81213 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81214
81215 -static inline void * __must_check ERR_PTR(long error)
81216 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81217 {
81218 return (void *) error;
81219 }
81220
81221 -static inline long __must_check PTR_ERR(__force const void *ptr)
81222 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81223 {
81224 return (long) ptr;
81225 }
81226 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81227 index 36f49c4..a2a1f4c 100644
81228 --- a/include/linux/extcon.h
81229 +++ b/include/linux/extcon.h
81230 @@ -135,7 +135,7 @@ struct extcon_dev {
81231 /* /sys/class/extcon/.../mutually_exclusive/... */
81232 struct attribute_group attr_g_muex;
81233 struct attribute **attrs_muex;
81234 - struct device_attribute *d_attrs_muex;
81235 + device_attribute_no_const *d_attrs_muex;
81236 };
81237
81238 /**
81239 diff --git a/include/linux/fb.h b/include/linux/fb.h
81240 index 09bb7a1..d98870a 100644
81241 --- a/include/linux/fb.h
81242 +++ b/include/linux/fb.h
81243 @@ -305,7 +305,7 @@ struct fb_ops {
81244 /* called at KDB enter and leave time to prepare the console */
81245 int (*fb_debug_enter)(struct fb_info *info);
81246 int (*fb_debug_leave)(struct fb_info *info);
81247 -};
81248 +} __do_const;
81249
81250 #ifdef CONFIG_FB_TILEBLITTING
81251 #define FB_TILE_CURSOR_NONE 0
81252 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81253 index 230f87b..1fd0485 100644
81254 --- a/include/linux/fdtable.h
81255 +++ b/include/linux/fdtable.h
81256 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81257 void put_files_struct(struct files_struct *fs);
81258 void reset_files_struct(struct files_struct *);
81259 int unshare_files(struct files_struct **);
81260 -struct files_struct *dup_fd(struct files_struct *, int *);
81261 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81262 void do_close_on_exec(struct files_struct *);
81263 int iterate_fd(struct files_struct *, unsigned,
81264 int (*)(const void *, struct file *, unsigned),
81265 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81266 index 8293262..2b3b8bd 100644
81267 --- a/include/linux/frontswap.h
81268 +++ b/include/linux/frontswap.h
81269 @@ -11,7 +11,7 @@ struct frontswap_ops {
81270 int (*load)(unsigned, pgoff_t, struct page *);
81271 void (*invalidate_page)(unsigned, pgoff_t);
81272 void (*invalidate_area)(unsigned);
81273 -};
81274 +} __no_const;
81275
81276 extern bool frontswap_enabled;
81277 extern struct frontswap_ops *
81278 diff --git a/include/linux/fs.h b/include/linux/fs.h
81279 index 9ab779e..0c636f2 100644
81280 --- a/include/linux/fs.h
81281 +++ b/include/linux/fs.h
81282 @@ -412,7 +412,7 @@ struct address_space {
81283 spinlock_t private_lock; /* for use by the address_space */
81284 struct list_head private_list; /* ditto */
81285 void *private_data; /* ditto */
81286 -} __attribute__((aligned(sizeof(long))));
81287 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81288 /*
81289 * On most architectures that alignment is already the case; but
81290 * must be enforced here for CRIS, to let the least significant bit
81291 @@ -455,7 +455,7 @@ struct block_device {
81292 int bd_fsfreeze_count;
81293 /* Mutex for freeze */
81294 struct mutex bd_fsfreeze_mutex;
81295 -};
81296 +} __randomize_layout;
81297
81298 /*
81299 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81300 @@ -624,7 +624,7 @@ struct inode {
81301 #endif
81302
81303 void *i_private; /* fs or device private pointer */
81304 -};
81305 +} __randomize_layout;
81306
81307 static inline int inode_unhashed(struct inode *inode)
81308 {
81309 @@ -820,7 +820,7 @@ struct file {
81310 struct list_head f_tfile_llink;
81311 #endif /* #ifdef CONFIG_EPOLL */
81312 struct address_space *f_mapping;
81313 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81314 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81315
81316 struct file_handle {
81317 __u32 handle_bytes;
81318 @@ -945,7 +945,7 @@ struct file_lock {
81319 int state; /* state of grant or error if -ve */
81320 } afs;
81321 } fl_u;
81322 -};
81323 +} __randomize_layout;
81324
81325 /* The following constant reflects the upper bound of the file/locking space */
81326 #ifndef OFFSET_MAX
81327 @@ -1287,7 +1287,7 @@ struct super_block {
81328 * Indicates how deep in a filesystem stack this SB is
81329 */
81330 int s_stack_depth;
81331 -};
81332 +} __randomize_layout;
81333
81334 extern struct timespec current_fs_time(struct super_block *sb);
81335
81336 @@ -1514,7 +1514,8 @@ struct file_operations {
81337 long (*fallocate)(struct file *file, int mode, loff_t offset,
81338 loff_t len);
81339 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81340 -};
81341 +} __do_const __randomize_layout;
81342 +typedef struct file_operations __no_const file_operations_no_const;
81343
81344 struct inode_operations {
81345 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81346 @@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81347 return !IS_DEADDIR(inode);
81348 }
81349
81350 +static inline bool is_sidechannel_device(const struct inode *inode)
81351 +{
81352 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81353 + umode_t mode = inode->i_mode;
81354 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81355 +#else
81356 + return false;
81357 +#endif
81358 +}
81359 +
81360 #endif /* _LINUX_FS_H */
81361 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81362 index 0efc3e6..fd23610 100644
81363 --- a/include/linux/fs_struct.h
81364 +++ b/include/linux/fs_struct.h
81365 @@ -6,13 +6,13 @@
81366 #include <linux/seqlock.h>
81367
81368 struct fs_struct {
81369 - int users;
81370 + atomic_t users;
81371 spinlock_t lock;
81372 seqcount_t seq;
81373 int umask;
81374 int in_exec;
81375 struct path root, pwd;
81376 -};
81377 +} __randomize_layout;
81378
81379 extern struct kmem_cache *fs_cachep;
81380
81381 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81382 index 7714849..a4a5c7a 100644
81383 --- a/include/linux/fscache-cache.h
81384 +++ b/include/linux/fscache-cache.h
81385 @@ -113,7 +113,7 @@ struct fscache_operation {
81386 fscache_operation_release_t release;
81387 };
81388
81389 -extern atomic_t fscache_op_debug_id;
81390 +extern atomic_unchecked_t fscache_op_debug_id;
81391 extern void fscache_op_work_func(struct work_struct *work);
81392
81393 extern void fscache_enqueue_operation(struct fscache_operation *);
81394 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81395 INIT_WORK(&op->work, fscache_op_work_func);
81396 atomic_set(&op->usage, 1);
81397 op->state = FSCACHE_OP_ST_INITIALISED;
81398 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81399 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81400 op->processor = processor;
81401 op->release = release;
81402 INIT_LIST_HEAD(&op->pend_link);
81403 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81404 index 115bb81..e7b812b 100644
81405 --- a/include/linux/fscache.h
81406 +++ b/include/linux/fscache.h
81407 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
81408 * - this is mandatory for any object that may have data
81409 */
81410 void (*now_uncached)(void *cookie_netfs_data);
81411 -};
81412 +} __do_const;
81413
81414 /*
81415 * fscache cached network filesystem type
81416 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81417 index 7ee1774..72505b8 100644
81418 --- a/include/linux/fsnotify.h
81419 +++ b/include/linux/fsnotify.h
81420 @@ -197,6 +197,9 @@ static inline void fsnotify_access(struct file *file)
81421 struct inode *inode = file_inode(file);
81422 __u32 mask = FS_ACCESS;
81423
81424 + if (is_sidechannel_device(inode))
81425 + return;
81426 +
81427 if (S_ISDIR(inode->i_mode))
81428 mask |= FS_ISDIR;
81429
81430 @@ -215,6 +218,9 @@ static inline void fsnotify_modify(struct file *file)
81431 struct inode *inode = file_inode(file);
81432 __u32 mask = FS_MODIFY;
81433
81434 + if (is_sidechannel_device(inode))
81435 + return;
81436 +
81437 if (S_ISDIR(inode->i_mode))
81438 mask |= FS_ISDIR;
81439
81440 @@ -317,7 +323,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81441 */
81442 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81443 {
81444 - return kstrdup(name, GFP_KERNEL);
81445 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81446 }
81447
81448 /*
81449 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81450 index ec274e0..e678159 100644
81451 --- a/include/linux/genhd.h
81452 +++ b/include/linux/genhd.h
81453 @@ -194,7 +194,7 @@ struct gendisk {
81454 struct kobject *slave_dir;
81455
81456 struct timer_rand_state *random;
81457 - atomic_t sync_io; /* RAID */
81458 + atomic_unchecked_t sync_io; /* RAID */
81459 struct disk_events *ev;
81460 #ifdef CONFIG_BLK_DEV_INTEGRITY
81461 struct blk_integrity *integrity;
81462 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81463 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81464
81465 /* drivers/char/random.c */
81466 -extern void add_disk_randomness(struct gendisk *disk);
81467 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81468 extern void rand_initialize_disk(struct gendisk *disk);
81469
81470 static inline sector_t get_start_sect(struct block_device *bdev)
81471 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81472 index 667c311..abac2a7 100644
81473 --- a/include/linux/genl_magic_func.h
81474 +++ b/include/linux/genl_magic_func.h
81475 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81476 },
81477
81478 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81479 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81480 +static struct genl_ops ZZZ_genl_ops[] = {
81481 #include GENL_MAGIC_INCLUDE_FILE
81482 };
81483
81484 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81485 index 41b30fd..a3718cf 100644
81486 --- a/include/linux/gfp.h
81487 +++ b/include/linux/gfp.h
81488 @@ -34,6 +34,13 @@ struct vm_area_struct;
81489 #define ___GFP_NO_KSWAPD 0x400000u
81490 #define ___GFP_OTHER_NODE 0x800000u
81491 #define ___GFP_WRITE 0x1000000u
81492 +
81493 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81494 +#define ___GFP_USERCOPY 0x2000000u
81495 +#else
81496 +#define ___GFP_USERCOPY 0
81497 +#endif
81498 +
81499 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81500
81501 /*
81502 @@ -90,6 +97,7 @@ struct vm_area_struct;
81503 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81504 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81505 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81506 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81507
81508 /*
81509 * This may seem redundant, but it's a way of annotating false positives vs.
81510 @@ -97,7 +105,7 @@ struct vm_area_struct;
81511 */
81512 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81513
81514 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81515 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81516 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81517
81518 /* This equals 0, but use constants in case they ever change */
81519 @@ -155,6 +163,8 @@ struct vm_area_struct;
81520 /* 4GB DMA on some platforms */
81521 #define GFP_DMA32 __GFP_DMA32
81522
81523 +#define GFP_USERCOPY __GFP_USERCOPY
81524 +
81525 /* Convert GFP flags to their corresponding migrate type */
81526 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81527 {
81528 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81529 new file mode 100644
81530 index 0000000..91858e4
81531 --- /dev/null
81532 +++ b/include/linux/gracl.h
81533 @@ -0,0 +1,342 @@
81534 +#ifndef GR_ACL_H
81535 +#define GR_ACL_H
81536 +
81537 +#include <linux/grdefs.h>
81538 +#include <linux/resource.h>
81539 +#include <linux/capability.h>
81540 +#include <linux/dcache.h>
81541 +#include <asm/resource.h>
81542 +
81543 +/* Major status information */
81544 +
81545 +#define GR_VERSION "grsecurity 3.1"
81546 +#define GRSECURITY_VERSION 0x3100
81547 +
81548 +enum {
81549 + GR_SHUTDOWN = 0,
81550 + GR_ENABLE = 1,
81551 + GR_SPROLE = 2,
81552 + GR_OLDRELOAD = 3,
81553 + GR_SEGVMOD = 4,
81554 + GR_STATUS = 5,
81555 + GR_UNSPROLE = 6,
81556 + GR_PASSSET = 7,
81557 + GR_SPROLEPAM = 8,
81558 + GR_RELOAD = 9,
81559 +};
81560 +
81561 +/* Password setup definitions
81562 + * kernel/grhash.c */
81563 +enum {
81564 + GR_PW_LEN = 128,
81565 + GR_SALT_LEN = 16,
81566 + GR_SHA_LEN = 32,
81567 +};
81568 +
81569 +enum {
81570 + GR_SPROLE_LEN = 64,
81571 +};
81572 +
81573 +enum {
81574 + GR_NO_GLOB = 0,
81575 + GR_REG_GLOB,
81576 + GR_CREATE_GLOB
81577 +};
81578 +
81579 +#define GR_NLIMITS 32
81580 +
81581 +/* Begin Data Structures */
81582 +
81583 +struct sprole_pw {
81584 + unsigned char *rolename;
81585 + unsigned char salt[GR_SALT_LEN];
81586 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81587 +};
81588 +
81589 +struct name_entry {
81590 + __u32 key;
81591 + u64 inode;
81592 + dev_t device;
81593 + char *name;
81594 + __u16 len;
81595 + __u8 deleted;
81596 + struct name_entry *prev;
81597 + struct name_entry *next;
81598 +};
81599 +
81600 +struct inodev_entry {
81601 + struct name_entry *nentry;
81602 + struct inodev_entry *prev;
81603 + struct inodev_entry *next;
81604 +};
81605 +
81606 +struct acl_role_db {
81607 + struct acl_role_label **r_hash;
81608 + __u32 r_size;
81609 +};
81610 +
81611 +struct inodev_db {
81612 + struct inodev_entry **i_hash;
81613 + __u32 i_size;
81614 +};
81615 +
81616 +struct name_db {
81617 + struct name_entry **n_hash;
81618 + __u32 n_size;
81619 +};
81620 +
81621 +struct crash_uid {
81622 + uid_t uid;
81623 + unsigned long expires;
81624 +};
81625 +
81626 +struct gr_hash_struct {
81627 + void **table;
81628 + void **nametable;
81629 + void *first;
81630 + __u32 table_size;
81631 + __u32 used_size;
81632 + int type;
81633 +};
81634 +
81635 +/* Userspace Grsecurity ACL data structures */
81636 +
81637 +struct acl_subject_label {
81638 + char *filename;
81639 + u64 inode;
81640 + dev_t device;
81641 + __u32 mode;
81642 + kernel_cap_t cap_mask;
81643 + kernel_cap_t cap_lower;
81644 + kernel_cap_t cap_invert_audit;
81645 +
81646 + struct rlimit res[GR_NLIMITS];
81647 + __u32 resmask;
81648 +
81649 + __u8 user_trans_type;
81650 + __u8 group_trans_type;
81651 + uid_t *user_transitions;
81652 + gid_t *group_transitions;
81653 + __u16 user_trans_num;
81654 + __u16 group_trans_num;
81655 +
81656 + __u32 sock_families[2];
81657 + __u32 ip_proto[8];
81658 + __u32 ip_type;
81659 + struct acl_ip_label **ips;
81660 + __u32 ip_num;
81661 + __u32 inaddr_any_override;
81662 +
81663 + __u32 crashes;
81664 + unsigned long expires;
81665 +
81666 + struct acl_subject_label *parent_subject;
81667 + struct gr_hash_struct *hash;
81668 + struct acl_subject_label *prev;
81669 + struct acl_subject_label *next;
81670 +
81671 + struct acl_object_label **obj_hash;
81672 + __u32 obj_hash_size;
81673 + __u16 pax_flags;
81674 +};
81675 +
81676 +struct role_allowed_ip {
81677 + __u32 addr;
81678 + __u32 netmask;
81679 +
81680 + struct role_allowed_ip *prev;
81681 + struct role_allowed_ip *next;
81682 +};
81683 +
81684 +struct role_transition {
81685 + char *rolename;
81686 +
81687 + struct role_transition *prev;
81688 + struct role_transition *next;
81689 +};
81690 +
81691 +struct acl_role_label {
81692 + char *rolename;
81693 + uid_t uidgid;
81694 + __u16 roletype;
81695 +
81696 + __u16 auth_attempts;
81697 + unsigned long expires;
81698 +
81699 + struct acl_subject_label *root_label;
81700 + struct gr_hash_struct *hash;
81701 +
81702 + struct acl_role_label *prev;
81703 + struct acl_role_label *next;
81704 +
81705 + struct role_transition *transitions;
81706 + struct role_allowed_ip *allowed_ips;
81707 + uid_t *domain_children;
81708 + __u16 domain_child_num;
81709 +
81710 + umode_t umask;
81711 +
81712 + struct acl_subject_label **subj_hash;
81713 + __u32 subj_hash_size;
81714 +};
81715 +
81716 +struct user_acl_role_db {
81717 + struct acl_role_label **r_table;
81718 + __u32 num_pointers; /* Number of allocations to track */
81719 + __u32 num_roles; /* Number of roles */
81720 + __u32 num_domain_children; /* Number of domain children */
81721 + __u32 num_subjects; /* Number of subjects */
81722 + __u32 num_objects; /* Number of objects */
81723 +};
81724 +
81725 +struct acl_object_label {
81726 + char *filename;
81727 + u64 inode;
81728 + dev_t device;
81729 + __u32 mode;
81730 +
81731 + struct acl_subject_label *nested;
81732 + struct acl_object_label *globbed;
81733 +
81734 + /* next two structures not used */
81735 +
81736 + struct acl_object_label *prev;
81737 + struct acl_object_label *next;
81738 +};
81739 +
81740 +struct acl_ip_label {
81741 + char *iface;
81742 + __u32 addr;
81743 + __u32 netmask;
81744 + __u16 low, high;
81745 + __u8 mode;
81746 + __u32 type;
81747 + __u32 proto[8];
81748 +
81749 + /* next two structures not used */
81750 +
81751 + struct acl_ip_label *prev;
81752 + struct acl_ip_label *next;
81753 +};
81754 +
81755 +struct gr_arg {
81756 + struct user_acl_role_db role_db;
81757 + unsigned char pw[GR_PW_LEN];
81758 + unsigned char salt[GR_SALT_LEN];
81759 + unsigned char sum[GR_SHA_LEN];
81760 + unsigned char sp_role[GR_SPROLE_LEN];
81761 + struct sprole_pw *sprole_pws;
81762 + dev_t segv_device;
81763 + u64 segv_inode;
81764 + uid_t segv_uid;
81765 + __u16 num_sprole_pws;
81766 + __u16 mode;
81767 +};
81768 +
81769 +struct gr_arg_wrapper {
81770 + struct gr_arg *arg;
81771 + __u32 version;
81772 + __u32 size;
81773 +};
81774 +
81775 +struct subject_map {
81776 + struct acl_subject_label *user;
81777 + struct acl_subject_label *kernel;
81778 + struct subject_map *prev;
81779 + struct subject_map *next;
81780 +};
81781 +
81782 +struct acl_subj_map_db {
81783 + struct subject_map **s_hash;
81784 + __u32 s_size;
81785 +};
81786 +
81787 +struct gr_policy_state {
81788 + struct sprole_pw **acl_special_roles;
81789 + __u16 num_sprole_pws;
81790 + struct acl_role_label *kernel_role;
81791 + struct acl_role_label *role_list;
81792 + struct acl_role_label *default_role;
81793 + struct acl_role_db acl_role_set;
81794 + struct acl_subj_map_db subj_map_set;
81795 + struct name_db name_set;
81796 + struct inodev_db inodev_set;
81797 +};
81798 +
81799 +struct gr_alloc_state {
81800 + unsigned long alloc_stack_next;
81801 + unsigned long alloc_stack_size;
81802 + void **alloc_stack;
81803 +};
81804 +
81805 +struct gr_reload_state {
81806 + struct gr_policy_state oldpolicy;
81807 + struct gr_alloc_state oldalloc;
81808 + struct gr_policy_state newpolicy;
81809 + struct gr_alloc_state newalloc;
81810 + struct gr_policy_state *oldpolicy_ptr;
81811 + struct gr_alloc_state *oldalloc_ptr;
81812 + unsigned char oldmode;
81813 +};
81814 +
81815 +/* End Data Structures Section */
81816 +
81817 +/* Hash functions generated by empirical testing by Brad Spengler
81818 + Makes good use of the low bits of the inode. Generally 0-1 times
81819 + in loop for successful match. 0-3 for unsuccessful match.
81820 + Shift/add algorithm with modulus of table size and an XOR*/
81821 +
81822 +static __inline__ unsigned int
81823 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81824 +{
81825 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
81826 +}
81827 +
81828 + static __inline__ unsigned int
81829 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81830 +{
81831 + return ((const unsigned long)userp % sz);
81832 +}
81833 +
81834 +static __inline__ unsigned int
81835 +gr_fhash(const u64 ino, const dev_t dev, const unsigned int sz)
81836 +{
81837 + unsigned int rem;
81838 + div_u64_rem((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9)), sz, &rem);
81839 + return rem;
81840 +}
81841 +
81842 +static __inline__ unsigned int
81843 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81844 +{
81845 + return full_name_hash((const unsigned char *)name, len) % sz;
81846 +}
81847 +
81848 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81849 + subj = NULL; \
81850 + iter = 0; \
81851 + while (iter < role->subj_hash_size) { \
81852 + if (subj == NULL) \
81853 + subj = role->subj_hash[iter]; \
81854 + if (subj == NULL) { \
81855 + iter++; \
81856 + continue; \
81857 + }
81858 +
81859 +#define FOR_EACH_SUBJECT_END(subj,iter) \
81860 + subj = subj->next; \
81861 + if (subj == NULL) \
81862 + iter++; \
81863 + }
81864 +
81865 +
81866 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81867 + subj = role->hash->first; \
81868 + while (subj != NULL) {
81869 +
81870 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81871 + subj = subj->next; \
81872 + }
81873 +
81874 +#endif
81875 +
81876 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81877 new file mode 100644
81878 index 0000000..af64092
81879 --- /dev/null
81880 +++ b/include/linux/gracl_compat.h
81881 @@ -0,0 +1,156 @@
81882 +#ifndef GR_ACL_COMPAT_H
81883 +#define GR_ACL_COMPAT_H
81884 +
81885 +#include <linux/resource.h>
81886 +#include <asm/resource.h>
81887 +
81888 +struct sprole_pw_compat {
81889 + compat_uptr_t rolename;
81890 + unsigned char salt[GR_SALT_LEN];
81891 + unsigned char sum[GR_SHA_LEN];
81892 +};
81893 +
81894 +struct gr_hash_struct_compat {
81895 + compat_uptr_t table;
81896 + compat_uptr_t nametable;
81897 + compat_uptr_t first;
81898 + __u32 table_size;
81899 + __u32 used_size;
81900 + int type;
81901 +};
81902 +
81903 +struct acl_subject_label_compat {
81904 + compat_uptr_t filename;
81905 + compat_u64 inode;
81906 + __u32 device;
81907 + __u32 mode;
81908 + kernel_cap_t cap_mask;
81909 + kernel_cap_t cap_lower;
81910 + kernel_cap_t cap_invert_audit;
81911 +
81912 + struct compat_rlimit res[GR_NLIMITS];
81913 + __u32 resmask;
81914 +
81915 + __u8 user_trans_type;
81916 + __u8 group_trans_type;
81917 + compat_uptr_t user_transitions;
81918 + compat_uptr_t group_transitions;
81919 + __u16 user_trans_num;
81920 + __u16 group_trans_num;
81921 +
81922 + __u32 sock_families[2];
81923 + __u32 ip_proto[8];
81924 + __u32 ip_type;
81925 + compat_uptr_t ips;
81926 + __u32 ip_num;
81927 + __u32 inaddr_any_override;
81928 +
81929 + __u32 crashes;
81930 + compat_ulong_t expires;
81931 +
81932 + compat_uptr_t parent_subject;
81933 + compat_uptr_t hash;
81934 + compat_uptr_t prev;
81935 + compat_uptr_t next;
81936 +
81937 + compat_uptr_t obj_hash;
81938 + __u32 obj_hash_size;
81939 + __u16 pax_flags;
81940 +};
81941 +
81942 +struct role_allowed_ip_compat {
81943 + __u32 addr;
81944 + __u32 netmask;
81945 +
81946 + compat_uptr_t prev;
81947 + compat_uptr_t next;
81948 +};
81949 +
81950 +struct role_transition_compat {
81951 + compat_uptr_t rolename;
81952 +
81953 + compat_uptr_t prev;
81954 + compat_uptr_t next;
81955 +};
81956 +
81957 +struct acl_role_label_compat {
81958 + compat_uptr_t rolename;
81959 + uid_t uidgid;
81960 + __u16 roletype;
81961 +
81962 + __u16 auth_attempts;
81963 + compat_ulong_t expires;
81964 +
81965 + compat_uptr_t root_label;
81966 + compat_uptr_t hash;
81967 +
81968 + compat_uptr_t prev;
81969 + compat_uptr_t next;
81970 +
81971 + compat_uptr_t transitions;
81972 + compat_uptr_t allowed_ips;
81973 + compat_uptr_t domain_children;
81974 + __u16 domain_child_num;
81975 +
81976 + umode_t umask;
81977 +
81978 + compat_uptr_t subj_hash;
81979 + __u32 subj_hash_size;
81980 +};
81981 +
81982 +struct user_acl_role_db_compat {
81983 + compat_uptr_t r_table;
81984 + __u32 num_pointers;
81985 + __u32 num_roles;
81986 + __u32 num_domain_children;
81987 + __u32 num_subjects;
81988 + __u32 num_objects;
81989 +};
81990 +
81991 +struct acl_object_label_compat {
81992 + compat_uptr_t filename;
81993 + compat_u64 inode;
81994 + __u32 device;
81995 + __u32 mode;
81996 +
81997 + compat_uptr_t nested;
81998 + compat_uptr_t globbed;
81999 +
82000 + compat_uptr_t prev;
82001 + compat_uptr_t next;
82002 +};
82003 +
82004 +struct acl_ip_label_compat {
82005 + compat_uptr_t iface;
82006 + __u32 addr;
82007 + __u32 netmask;
82008 + __u16 low, high;
82009 + __u8 mode;
82010 + __u32 type;
82011 + __u32 proto[8];
82012 +
82013 + compat_uptr_t prev;
82014 + compat_uptr_t next;
82015 +};
82016 +
82017 +struct gr_arg_compat {
82018 + struct user_acl_role_db_compat role_db;
82019 + unsigned char pw[GR_PW_LEN];
82020 + unsigned char salt[GR_SALT_LEN];
82021 + unsigned char sum[GR_SHA_LEN];
82022 + unsigned char sp_role[GR_SPROLE_LEN];
82023 + compat_uptr_t sprole_pws;
82024 + __u32 segv_device;
82025 + compat_u64 segv_inode;
82026 + uid_t segv_uid;
82027 + __u16 num_sprole_pws;
82028 + __u16 mode;
82029 +};
82030 +
82031 +struct gr_arg_wrapper_compat {
82032 + compat_uptr_t arg;
82033 + __u32 version;
82034 + __u32 size;
82035 +};
82036 +
82037 +#endif
82038 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82039 new file mode 100644
82040 index 0000000..323ecf2
82041 --- /dev/null
82042 +++ b/include/linux/gralloc.h
82043 @@ -0,0 +1,9 @@
82044 +#ifndef __GRALLOC_H
82045 +#define __GRALLOC_H
82046 +
82047 +void acl_free_all(void);
82048 +int acl_alloc_stack_init(unsigned long size);
82049 +void *acl_alloc(unsigned long len);
82050 +void *acl_alloc_num(unsigned long num, unsigned long len);
82051 +
82052 +#endif
82053 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82054 new file mode 100644
82055 index 0000000..be66033
82056 --- /dev/null
82057 +++ b/include/linux/grdefs.h
82058 @@ -0,0 +1,140 @@
82059 +#ifndef GRDEFS_H
82060 +#define GRDEFS_H
82061 +
82062 +/* Begin grsecurity status declarations */
82063 +
82064 +enum {
82065 + GR_READY = 0x01,
82066 + GR_STATUS_INIT = 0x00 // disabled state
82067 +};
82068 +
82069 +/* Begin ACL declarations */
82070 +
82071 +/* Role flags */
82072 +
82073 +enum {
82074 + GR_ROLE_USER = 0x0001,
82075 + GR_ROLE_GROUP = 0x0002,
82076 + GR_ROLE_DEFAULT = 0x0004,
82077 + GR_ROLE_SPECIAL = 0x0008,
82078 + GR_ROLE_AUTH = 0x0010,
82079 + GR_ROLE_NOPW = 0x0020,
82080 + GR_ROLE_GOD = 0x0040,
82081 + GR_ROLE_LEARN = 0x0080,
82082 + GR_ROLE_TPE = 0x0100,
82083 + GR_ROLE_DOMAIN = 0x0200,
82084 + GR_ROLE_PAM = 0x0400,
82085 + GR_ROLE_PERSIST = 0x0800
82086 +};
82087 +
82088 +/* ACL Subject and Object mode flags */
82089 +enum {
82090 + GR_DELETED = 0x80000000
82091 +};
82092 +
82093 +/* ACL Object-only mode flags */
82094 +enum {
82095 + GR_READ = 0x00000001,
82096 + GR_APPEND = 0x00000002,
82097 + GR_WRITE = 0x00000004,
82098 + GR_EXEC = 0x00000008,
82099 + GR_FIND = 0x00000010,
82100 + GR_INHERIT = 0x00000020,
82101 + GR_SETID = 0x00000040,
82102 + GR_CREATE = 0x00000080,
82103 + GR_DELETE = 0x00000100,
82104 + GR_LINK = 0x00000200,
82105 + GR_AUDIT_READ = 0x00000400,
82106 + GR_AUDIT_APPEND = 0x00000800,
82107 + GR_AUDIT_WRITE = 0x00001000,
82108 + GR_AUDIT_EXEC = 0x00002000,
82109 + GR_AUDIT_FIND = 0x00004000,
82110 + GR_AUDIT_INHERIT= 0x00008000,
82111 + GR_AUDIT_SETID = 0x00010000,
82112 + GR_AUDIT_CREATE = 0x00020000,
82113 + GR_AUDIT_DELETE = 0x00040000,
82114 + GR_AUDIT_LINK = 0x00080000,
82115 + GR_PTRACERD = 0x00100000,
82116 + GR_NOPTRACE = 0x00200000,
82117 + GR_SUPPRESS = 0x00400000,
82118 + GR_NOLEARN = 0x00800000,
82119 + GR_INIT_TRANSFER= 0x01000000
82120 +};
82121 +
82122 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82123 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82124 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82125 +
82126 +/* ACL subject-only mode flags */
82127 +enum {
82128 + GR_KILL = 0x00000001,
82129 + GR_VIEW = 0x00000002,
82130 + GR_PROTECTED = 0x00000004,
82131 + GR_LEARN = 0x00000008,
82132 + GR_OVERRIDE = 0x00000010,
82133 + /* just a placeholder, this mode is only used in userspace */
82134 + GR_DUMMY = 0x00000020,
82135 + GR_PROTSHM = 0x00000040,
82136 + GR_KILLPROC = 0x00000080,
82137 + GR_KILLIPPROC = 0x00000100,
82138 + /* just a placeholder, this mode is only used in userspace */
82139 + GR_NOTROJAN = 0x00000200,
82140 + GR_PROTPROCFD = 0x00000400,
82141 + GR_PROCACCT = 0x00000800,
82142 + GR_RELAXPTRACE = 0x00001000,
82143 + //GR_NESTED = 0x00002000,
82144 + GR_INHERITLEARN = 0x00004000,
82145 + GR_PROCFIND = 0x00008000,
82146 + GR_POVERRIDE = 0x00010000,
82147 + GR_KERNELAUTH = 0x00020000,
82148 + GR_ATSECURE = 0x00040000,
82149 + GR_SHMEXEC = 0x00080000
82150 +};
82151 +
82152 +enum {
82153 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82154 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82155 + GR_PAX_ENABLE_MPROTECT = 0x0004,
82156 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
82157 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82158 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82159 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82160 + GR_PAX_DISABLE_MPROTECT = 0x0400,
82161 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
82162 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82163 +};
82164 +
82165 +enum {
82166 + GR_ID_USER = 0x01,
82167 + GR_ID_GROUP = 0x02,
82168 +};
82169 +
82170 +enum {
82171 + GR_ID_ALLOW = 0x01,
82172 + GR_ID_DENY = 0x02,
82173 +};
82174 +
82175 +#define GR_CRASH_RES 31
82176 +#define GR_UIDTABLE_MAX 500
82177 +
82178 +/* begin resource learning section */
82179 +enum {
82180 + GR_RLIM_CPU_BUMP = 60,
82181 + GR_RLIM_FSIZE_BUMP = 50000,
82182 + GR_RLIM_DATA_BUMP = 10000,
82183 + GR_RLIM_STACK_BUMP = 1000,
82184 + GR_RLIM_CORE_BUMP = 10000,
82185 + GR_RLIM_RSS_BUMP = 500000,
82186 + GR_RLIM_NPROC_BUMP = 1,
82187 + GR_RLIM_NOFILE_BUMP = 5,
82188 + GR_RLIM_MEMLOCK_BUMP = 50000,
82189 + GR_RLIM_AS_BUMP = 500000,
82190 + GR_RLIM_LOCKS_BUMP = 2,
82191 + GR_RLIM_SIGPENDING_BUMP = 5,
82192 + GR_RLIM_MSGQUEUE_BUMP = 10000,
82193 + GR_RLIM_NICE_BUMP = 1,
82194 + GR_RLIM_RTPRIO_BUMP = 1,
82195 + GR_RLIM_RTTIME_BUMP = 1000000
82196 +};
82197 +
82198 +#endif
82199 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82200 new file mode 100644
82201 index 0000000..fb1de5d
82202 --- /dev/null
82203 +++ b/include/linux/grinternal.h
82204 @@ -0,0 +1,230 @@
82205 +#ifndef __GRINTERNAL_H
82206 +#define __GRINTERNAL_H
82207 +
82208 +#ifdef CONFIG_GRKERNSEC
82209 +
82210 +#include <linux/fs.h>
82211 +#include <linux/mnt_namespace.h>
82212 +#include <linux/nsproxy.h>
82213 +#include <linux/gracl.h>
82214 +#include <linux/grdefs.h>
82215 +#include <linux/grmsg.h>
82216 +
82217 +void gr_add_learn_entry(const char *fmt, ...)
82218 + __attribute__ ((format (printf, 1, 2)));
82219 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82220 + const struct vfsmount *mnt);
82221 +__u32 gr_check_create(const struct dentry *new_dentry,
82222 + const struct dentry *parent,
82223 + const struct vfsmount *mnt, const __u32 mode);
82224 +int gr_check_protected_task(const struct task_struct *task);
82225 +__u32 to_gr_audit(const __u32 reqmode);
82226 +int gr_set_acls(const int type);
82227 +int gr_acl_is_enabled(void);
82228 +char gr_roletype_to_char(void);
82229 +
82230 +void gr_handle_alertkill(struct task_struct *task);
82231 +char *gr_to_filename(const struct dentry *dentry,
82232 + const struct vfsmount *mnt);
82233 +char *gr_to_filename1(const struct dentry *dentry,
82234 + const struct vfsmount *mnt);
82235 +char *gr_to_filename2(const struct dentry *dentry,
82236 + const struct vfsmount *mnt);
82237 +char *gr_to_filename3(const struct dentry *dentry,
82238 + const struct vfsmount *mnt);
82239 +
82240 +extern int grsec_enable_ptrace_readexec;
82241 +extern int grsec_enable_harden_ptrace;
82242 +extern int grsec_enable_link;
82243 +extern int grsec_enable_fifo;
82244 +extern int grsec_enable_execve;
82245 +extern int grsec_enable_shm;
82246 +extern int grsec_enable_execlog;
82247 +extern int grsec_enable_signal;
82248 +extern int grsec_enable_audit_ptrace;
82249 +extern int grsec_enable_forkfail;
82250 +extern int grsec_enable_time;
82251 +extern int grsec_enable_rofs;
82252 +extern int grsec_deny_new_usb;
82253 +extern int grsec_enable_chroot_shmat;
82254 +extern int grsec_enable_chroot_mount;
82255 +extern int grsec_enable_chroot_double;
82256 +extern int grsec_enable_chroot_pivot;
82257 +extern int grsec_enable_chroot_chdir;
82258 +extern int grsec_enable_chroot_chmod;
82259 +extern int grsec_enable_chroot_mknod;
82260 +extern int grsec_enable_chroot_fchdir;
82261 +extern int grsec_enable_chroot_nice;
82262 +extern int grsec_enable_chroot_execlog;
82263 +extern int grsec_enable_chroot_caps;
82264 +extern int grsec_enable_chroot_rename;
82265 +extern int grsec_enable_chroot_sysctl;
82266 +extern int grsec_enable_chroot_unix;
82267 +extern int grsec_enable_symlinkown;
82268 +extern kgid_t grsec_symlinkown_gid;
82269 +extern int grsec_enable_tpe;
82270 +extern kgid_t grsec_tpe_gid;
82271 +extern int grsec_enable_tpe_all;
82272 +extern int grsec_enable_tpe_invert;
82273 +extern int grsec_enable_socket_all;
82274 +extern kgid_t grsec_socket_all_gid;
82275 +extern int grsec_enable_socket_client;
82276 +extern kgid_t grsec_socket_client_gid;
82277 +extern int grsec_enable_socket_server;
82278 +extern kgid_t grsec_socket_server_gid;
82279 +extern kgid_t grsec_audit_gid;
82280 +extern int grsec_enable_group;
82281 +extern int grsec_enable_log_rwxmaps;
82282 +extern int grsec_enable_mount;
82283 +extern int grsec_enable_chdir;
82284 +extern int grsec_resource_logging;
82285 +extern int grsec_enable_blackhole;
82286 +extern int grsec_lastack_retries;
82287 +extern int grsec_enable_brute;
82288 +extern int grsec_enable_harden_ipc;
82289 +extern int grsec_lock;
82290 +
82291 +extern spinlock_t grsec_alert_lock;
82292 +extern unsigned long grsec_alert_wtime;
82293 +extern unsigned long grsec_alert_fyet;
82294 +
82295 +extern spinlock_t grsec_audit_lock;
82296 +
82297 +extern rwlock_t grsec_exec_file_lock;
82298 +
82299 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82300 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82301 + (tsk)->exec_file->f_path.mnt) : "/")
82302 +
82303 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82304 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82305 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82306 +
82307 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82308 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
82309 + (tsk)->exec_file->f_path.mnt) : "/")
82310 +
82311 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82312 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82313 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82314 +
82315 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82316 +
82317 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82318 +
82319 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82320 +{
82321 + if (file1 && file2) {
82322 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
82323 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
82324 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82325 + return true;
82326 + }
82327 +
82328 + return false;
82329 +}
82330 +
82331 +#define GR_CHROOT_CAPS {{ \
82332 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82333 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82334 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82335 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82336 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82337 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82338 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82339 +
82340 +#define security_learn(normal_msg,args...) \
82341 +({ \
82342 + read_lock(&grsec_exec_file_lock); \
82343 + gr_add_learn_entry(normal_msg "\n", ## args); \
82344 + read_unlock(&grsec_exec_file_lock); \
82345 +})
82346 +
82347 +enum {
82348 + GR_DO_AUDIT,
82349 + GR_DONT_AUDIT,
82350 + /* used for non-audit messages that we shouldn't kill the task on */
82351 + GR_DONT_AUDIT_GOOD
82352 +};
82353 +
82354 +enum {
82355 + GR_TTYSNIFF,
82356 + GR_RBAC,
82357 + GR_RBAC_STR,
82358 + GR_STR_RBAC,
82359 + GR_RBAC_MODE2,
82360 + GR_RBAC_MODE3,
82361 + GR_FILENAME,
82362 + GR_SYSCTL_HIDDEN,
82363 + GR_NOARGS,
82364 + GR_ONE_INT,
82365 + GR_ONE_INT_TWO_STR,
82366 + GR_ONE_STR,
82367 + GR_STR_INT,
82368 + GR_TWO_STR_INT,
82369 + GR_TWO_INT,
82370 + GR_TWO_U64,
82371 + GR_THREE_INT,
82372 + GR_FIVE_INT_TWO_STR,
82373 + GR_TWO_STR,
82374 + GR_THREE_STR,
82375 + GR_FOUR_STR,
82376 + GR_STR_FILENAME,
82377 + GR_FILENAME_STR,
82378 + GR_FILENAME_TWO_INT,
82379 + GR_FILENAME_TWO_INT_STR,
82380 + GR_TEXTREL,
82381 + GR_PTRACE,
82382 + GR_RESOURCE,
82383 + GR_CAP,
82384 + GR_SIG,
82385 + GR_SIG2,
82386 + GR_CRASH1,
82387 + GR_CRASH2,
82388 + GR_PSACCT,
82389 + GR_RWXMAP,
82390 + GR_RWXMAPVMA
82391 +};
82392 +
82393 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82394 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82395 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82396 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82397 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82398 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82399 +#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)
82400 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82401 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82402 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82403 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82404 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82405 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82406 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82407 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82408 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82409 +#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)
82410 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82411 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82412 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82413 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82414 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82415 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82416 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82417 +#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)
82418 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82419 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82420 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82421 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82422 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82423 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82424 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82425 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82426 +#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)
82427 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82428 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82429 +
82430 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82431 +
82432 +#endif
82433 +
82434 +#endif
82435 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82436 new file mode 100644
82437 index 0000000..26ef560
82438 --- /dev/null
82439 +++ b/include/linux/grmsg.h
82440 @@ -0,0 +1,118 @@
82441 +#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"
82442 +#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"
82443 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82444 +#define GR_STOPMOD_MSG "denied modification of module state by "
82445 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82446 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82447 +#define GR_IOPERM_MSG "denied use of ioperm() by "
82448 +#define GR_IOPL_MSG "denied use of iopl() by "
82449 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82450 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82451 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82452 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82453 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82454 +#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"
82455 +#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"
82456 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82457 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82458 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82459 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82460 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82461 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82462 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82463 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82464 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82465 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82466 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82467 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82468 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82469 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82470 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82471 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82472 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82473 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82474 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82475 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82476 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82477 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82478 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82479 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82480 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82481 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82482 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82483 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82484 +#define GR_CHROOT_RENAME_MSG "denied bad rename of %.950s out of a chroot by "
82485 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82486 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82487 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82488 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82489 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82490 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82491 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82492 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82493 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82494 +#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"
82495 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82496 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82497 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82498 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82499 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82500 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82501 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82502 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82503 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82504 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82505 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82506 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82507 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82508 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82509 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82510 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82511 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82512 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82513 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82514 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82515 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
82516 +#define GR_NICE_CHROOT_MSG "denied priority change by "
82517 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82518 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82519 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82520 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82521 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82522 +#define GR_TIME_MSG "time set by "
82523 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82524 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82525 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82526 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82527 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82528 +#define GR_BIND_MSG "denied bind() by "
82529 +#define GR_CONNECT_MSG "denied connect() by "
82530 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82531 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82532 +#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"
82533 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82534 +#define GR_CAP_ACL_MSG "use of %s denied for "
82535 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82536 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82537 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82538 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82539 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82540 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82541 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82542 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82543 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82544 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82545 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82546 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82547 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82548 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82549 +#define GR_VM86_MSG "denied use of vm86 by "
82550 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82551 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82552 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82553 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82554 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82555 +#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 "
82556 +#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 "
82557 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82558 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82559 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82560 new file mode 100644
82561 index 0000000..63c1850
82562 --- /dev/null
82563 +++ b/include/linux/grsecurity.h
82564 @@ -0,0 +1,250 @@
82565 +#ifndef GR_SECURITY_H
82566 +#define GR_SECURITY_H
82567 +#include <linux/fs.h>
82568 +#include <linux/fs_struct.h>
82569 +#include <linux/binfmts.h>
82570 +#include <linux/gracl.h>
82571 +
82572 +/* notify of brain-dead configs */
82573 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82574 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82575 +#endif
82576 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82577 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82578 +#endif
82579 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82580 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82581 +#endif
82582 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82583 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82584 +#endif
82585 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82586 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
82587 +#endif
82588 +
82589 +int gr_handle_new_usb(void);
82590 +
82591 +void gr_handle_brute_attach(int dumpable);
82592 +void gr_handle_brute_check(void);
82593 +void gr_handle_kernel_exploit(void);
82594 +
82595 +char gr_roletype_to_char(void);
82596 +
82597 +int gr_proc_is_restricted(void);
82598 +
82599 +int gr_acl_enable_at_secure(void);
82600 +
82601 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82602 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82603 +
82604 +int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82605 +
82606 +void gr_del_task_from_ip_table(struct task_struct *p);
82607 +
82608 +int gr_pid_is_chrooted(struct task_struct *p);
82609 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82610 +int gr_handle_chroot_nice(void);
82611 +int gr_handle_chroot_sysctl(const int op);
82612 +int gr_handle_chroot_setpriority(struct task_struct *p,
82613 + const int niceval);
82614 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82615 +int gr_chroot_fhandle(void);
82616 +int gr_handle_chroot_chroot(const struct dentry *dentry,
82617 + const struct vfsmount *mnt);
82618 +void gr_handle_chroot_chdir(const struct path *path);
82619 +int gr_handle_chroot_chmod(const struct dentry *dentry,
82620 + const struct vfsmount *mnt, const int mode);
82621 +int gr_handle_chroot_mknod(const struct dentry *dentry,
82622 + const struct vfsmount *mnt, const int mode);
82623 +int gr_handle_chroot_mount(const struct dentry *dentry,
82624 + const struct vfsmount *mnt,
82625 + const char *dev_name);
82626 +int gr_handle_chroot_pivot(void);
82627 +int gr_handle_chroot_unix(const pid_t pid);
82628 +
82629 +int gr_handle_rawio(const struct inode *inode);
82630 +
82631 +void gr_handle_ioperm(void);
82632 +void gr_handle_iopl(void);
82633 +void gr_handle_msr_write(void);
82634 +
82635 +umode_t gr_acl_umask(void);
82636 +
82637 +int gr_tpe_allow(const struct file *file);
82638 +
82639 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82640 +void gr_clear_chroot_entries(struct task_struct *task);
82641 +
82642 +void gr_log_forkfail(const int retval);
82643 +void gr_log_timechange(void);
82644 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82645 +void gr_log_chdir(const struct dentry *dentry,
82646 + const struct vfsmount *mnt);
82647 +void gr_log_chroot_exec(const struct dentry *dentry,
82648 + const struct vfsmount *mnt);
82649 +void gr_log_remount(const char *devname, const int retval);
82650 +void gr_log_unmount(const char *devname, const int retval);
82651 +void gr_log_mount(const char *from, struct path *to, const int retval);
82652 +void gr_log_textrel(struct vm_area_struct *vma);
82653 +void gr_log_ptgnustack(struct file *file);
82654 +void gr_log_rwxmmap(struct file *file);
82655 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
82656 +
82657 +int gr_handle_follow_link(const struct inode *parent,
82658 + const struct inode *inode,
82659 + const struct dentry *dentry,
82660 + const struct vfsmount *mnt);
82661 +int gr_handle_fifo(const struct dentry *dentry,
82662 + const struct vfsmount *mnt,
82663 + const struct dentry *dir, const int flag,
82664 + const int acc_mode);
82665 +int gr_handle_hardlink(const struct dentry *dentry,
82666 + const struct vfsmount *mnt,
82667 + struct inode *inode,
82668 + const int mode, const struct filename *to);
82669 +
82670 +int gr_is_capable(const int cap);
82671 +int gr_is_capable_nolog(const int cap);
82672 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82673 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82674 +
82675 +void gr_copy_label(struct task_struct *tsk);
82676 +void gr_handle_crash(struct task_struct *task, const int sig);
82677 +int gr_handle_signal(const struct task_struct *p, const int sig);
82678 +int gr_check_crash_uid(const kuid_t uid);
82679 +int gr_check_protected_task(const struct task_struct *task);
82680 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82681 +int gr_acl_handle_mmap(const struct file *file,
82682 + const unsigned long prot);
82683 +int gr_acl_handle_mprotect(const struct file *file,
82684 + const unsigned long prot);
82685 +int gr_check_hidden_task(const struct task_struct *tsk);
82686 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82687 + const struct vfsmount *mnt);
82688 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
82689 + const struct vfsmount *mnt);
82690 +__u32 gr_acl_handle_access(const struct dentry *dentry,
82691 + const struct vfsmount *mnt, const int fmode);
82692 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82693 + const struct vfsmount *mnt, umode_t *mode);
82694 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
82695 + const struct vfsmount *mnt);
82696 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82697 + const struct vfsmount *mnt);
82698 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82699 + const struct vfsmount *mnt);
82700 +int gr_handle_ptrace(struct task_struct *task, const long request);
82701 +int gr_handle_proc_ptrace(struct task_struct *task);
82702 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
82703 + const struct vfsmount *mnt);
82704 +int gr_check_crash_exec(const struct file *filp);
82705 +int gr_acl_is_enabled(void);
82706 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82707 + const kgid_t gid);
82708 +int gr_set_proc_label(const struct dentry *dentry,
82709 + const struct vfsmount *mnt,
82710 + const int unsafe_flags);
82711 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82712 + const struct vfsmount *mnt);
82713 +__u32 gr_acl_handle_open(const struct dentry *dentry,
82714 + const struct vfsmount *mnt, int acc_mode);
82715 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
82716 + const struct dentry *p_dentry,
82717 + const struct vfsmount *p_mnt,
82718 + int open_flags, int acc_mode, const int imode);
82719 +void gr_handle_create(const struct dentry *dentry,
82720 + const struct vfsmount *mnt);
82721 +void gr_handle_proc_create(const struct dentry *dentry,
82722 + const struct inode *inode);
82723 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82724 + const struct dentry *parent_dentry,
82725 + const struct vfsmount *parent_mnt,
82726 + const int mode);
82727 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82728 + const struct dentry *parent_dentry,
82729 + const struct vfsmount *parent_mnt);
82730 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82731 + const struct vfsmount *mnt);
82732 +void gr_handle_delete(const u64 ino, const dev_t dev);
82733 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82734 + const struct vfsmount *mnt);
82735 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82736 + const struct dentry *parent_dentry,
82737 + const struct vfsmount *parent_mnt,
82738 + const struct filename *from);
82739 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82740 + const struct dentry *parent_dentry,
82741 + const struct vfsmount *parent_mnt,
82742 + const struct dentry *old_dentry,
82743 + const struct vfsmount *old_mnt, const struct filename *to);
82744 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82745 +int gr_acl_handle_rename(struct dentry *new_dentry,
82746 + struct dentry *parent_dentry,
82747 + const struct vfsmount *parent_mnt,
82748 + struct dentry *old_dentry,
82749 + struct inode *old_parent_inode,
82750 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82751 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82752 + struct dentry *old_dentry,
82753 + struct dentry *new_dentry,
82754 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82755 +__u32 gr_check_link(const struct dentry *new_dentry,
82756 + const struct dentry *parent_dentry,
82757 + const struct vfsmount *parent_mnt,
82758 + const struct dentry *old_dentry,
82759 + const struct vfsmount *old_mnt);
82760 +int gr_acl_handle_filldir(const struct file *file, const char *name,
82761 + const unsigned int namelen, const u64 ino);
82762 +
82763 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
82764 + const struct vfsmount *mnt);
82765 +void gr_acl_handle_exit(void);
82766 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
82767 +int gr_acl_handle_procpidmem(const struct task_struct *task);
82768 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82769 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82770 +void gr_audit_ptrace(struct task_struct *task);
82771 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82772 +u64 gr_get_ino_from_dentry(struct dentry *dentry);
82773 +void gr_put_exec_file(struct task_struct *task);
82774 +
82775 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82776 +
82777 +void gr_inc_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82778 +void gr_dec_chroot_refcnts(struct dentry *dentry, struct vfsmount *mnt);
82779 +int gr_bad_chroot_rename(struct dentry *olddentry, struct vfsmount *oldmnt,
82780 + struct dentry *newdentry, struct vfsmount *newmnt);
82781 +
82782 +#ifdef CONFIG_GRKERNSEC_RESLOG
82783 +extern void gr_log_resource(const struct task_struct *task, const int res,
82784 + const unsigned long wanted, const int gt);
82785 +#else
82786 +static inline void gr_log_resource(const struct task_struct *task, const int res,
82787 + const unsigned long wanted, const int gt)
82788 +{
82789 +}
82790 +#endif
82791 +
82792 +#ifdef CONFIG_GRKERNSEC
82793 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82794 +void gr_handle_vm86(void);
82795 +void gr_handle_mem_readwrite(u64 from, u64 to);
82796 +
82797 +void gr_log_badprocpid(const char *entry);
82798 +
82799 +extern int grsec_enable_dmesg;
82800 +extern int grsec_disable_privio;
82801 +
82802 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82803 +extern kgid_t grsec_proc_gid;
82804 +#endif
82805 +
82806 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82807 +extern int grsec_enable_chroot_findtask;
82808 +#endif
82809 +#ifdef CONFIG_GRKERNSEC_SETXID
82810 +extern int grsec_enable_setxid;
82811 +#endif
82812 +#endif
82813 +
82814 +#endif
82815 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82816 new file mode 100644
82817 index 0000000..e7ffaaf
82818 --- /dev/null
82819 +++ b/include/linux/grsock.h
82820 @@ -0,0 +1,19 @@
82821 +#ifndef __GRSOCK_H
82822 +#define __GRSOCK_H
82823 +
82824 +extern void gr_attach_curr_ip(const struct sock *sk);
82825 +extern int gr_handle_sock_all(const int family, const int type,
82826 + const int protocol);
82827 +extern int gr_handle_sock_server(const struct sockaddr *sck);
82828 +extern int gr_handle_sock_server_other(const struct sock *sck);
82829 +extern int gr_handle_sock_client(const struct sockaddr *sck);
82830 +extern int gr_search_connect(struct socket * sock,
82831 + struct sockaddr_in * addr);
82832 +extern int gr_search_bind(struct socket * sock,
82833 + struct sockaddr_in * addr);
82834 +extern int gr_search_listen(struct socket * sock);
82835 +extern int gr_search_accept(struct socket * sock);
82836 +extern int gr_search_socket(const int domain, const int type,
82837 + const int protocol);
82838 +
82839 +#endif
82840 diff --git a/include/linux/hash.h b/include/linux/hash.h
82841 index d0494c3..69b7715 100644
82842 --- a/include/linux/hash.h
82843 +++ b/include/linux/hash.h
82844 @@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82845 struct fast_hash_ops {
82846 u32 (*hash)(const void *data, u32 len, u32 seed);
82847 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82848 -};
82849 +} __no_const;
82850
82851 /**
82852 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82853 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82854 index 9286a46..373f27f 100644
82855 --- a/include/linux/highmem.h
82856 +++ b/include/linux/highmem.h
82857 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82858 kunmap_atomic(kaddr);
82859 }
82860
82861 +static inline void sanitize_highpage(struct page *page)
82862 +{
82863 + void *kaddr;
82864 + unsigned long flags;
82865 +
82866 + local_irq_save(flags);
82867 + kaddr = kmap_atomic(page);
82868 + clear_page(kaddr);
82869 + kunmap_atomic(kaddr);
82870 + local_irq_restore(flags);
82871 +}
82872 +
82873 static inline void zero_user_segments(struct page *page,
82874 unsigned start1, unsigned end1,
82875 unsigned start2, unsigned end2)
82876 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82877 index 1c7b89a..7dda400 100644
82878 --- a/include/linux/hwmon-sysfs.h
82879 +++ b/include/linux/hwmon-sysfs.h
82880 @@ -25,7 +25,8 @@
82881 struct sensor_device_attribute{
82882 struct device_attribute dev_attr;
82883 int index;
82884 -};
82885 +} __do_const;
82886 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82887 #define to_sensor_dev_attr(_dev_attr) \
82888 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82889
82890 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82891 struct device_attribute dev_attr;
82892 u8 index;
82893 u8 nr;
82894 -};
82895 +} __do_const;
82896 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82897 #define to_sensor_dev_attr_2(_dev_attr) \
82898 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82899
82900 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82901 index b556e0a..c10a515 100644
82902 --- a/include/linux/i2c.h
82903 +++ b/include/linux/i2c.h
82904 @@ -378,6 +378,7 @@ struct i2c_algorithm {
82905 /* To determine what the adapter supports */
82906 u32 (*functionality) (struct i2c_adapter *);
82907 };
82908 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82909
82910 /**
82911 * struct i2c_bus_recovery_info - I2C bus recovery information
82912 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82913 index d23c3c2..eb63c81 100644
82914 --- a/include/linux/i2o.h
82915 +++ b/include/linux/i2o.h
82916 @@ -565,7 +565,7 @@ struct i2o_controller {
82917 struct i2o_device *exec; /* Executive */
82918 #if BITS_PER_LONG == 64
82919 spinlock_t context_list_lock; /* lock for context_list */
82920 - atomic_t context_list_counter; /* needed for unique contexts */
82921 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82922 struct list_head context_list; /* list of context id's
82923 and pointers */
82924 #endif
82925 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82926 index aff7ad8..3942bbd 100644
82927 --- a/include/linux/if_pppox.h
82928 +++ b/include/linux/if_pppox.h
82929 @@ -76,7 +76,7 @@ struct pppox_proto {
82930 int (*ioctl)(struct socket *sock, unsigned int cmd,
82931 unsigned long arg);
82932 struct module *owner;
82933 -};
82934 +} __do_const;
82935
82936 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82937 extern void unregister_pppox_proto(int proto_num);
82938 diff --git a/include/linux/init.h b/include/linux/init.h
82939 index 2df8e8d..3e1280d 100644
82940 --- a/include/linux/init.h
82941 +++ b/include/linux/init.h
82942 @@ -37,9 +37,17 @@
82943 * section.
82944 */
82945
82946 +#define add_init_latent_entropy __latent_entropy
82947 +
82948 +#ifdef CONFIG_MEMORY_HOTPLUG
82949 +#define add_meminit_latent_entropy
82950 +#else
82951 +#define add_meminit_latent_entropy __latent_entropy
82952 +#endif
82953 +
82954 /* These are for everybody (although not all archs will actually
82955 discard it in modules) */
82956 -#define __init __section(.init.text) __cold notrace
82957 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82958 #define __initdata __section(.init.data)
82959 #define __initconst __constsection(.init.rodata)
82960 #define __exitdata __section(.exit.data)
82961 @@ -100,7 +108,7 @@
82962 #define __cpuexitconst
82963
82964 /* Used for MEMORY_HOTPLUG */
82965 -#define __meminit __section(.meminit.text) __cold notrace
82966 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82967 #define __meminitdata __section(.meminit.data)
82968 #define __meminitconst __constsection(.meminit.rodata)
82969 #define __memexit __section(.memexit.text) __exitused __cold notrace
82970 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82971 index 77fc43f..73caf92 100644
82972 --- a/include/linux/init_task.h
82973 +++ b/include/linux/init_task.h
82974 @@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82975
82976 #define INIT_TASK_COMM "swapper"
82977
82978 +#ifdef CONFIG_X86
82979 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82980 +#else
82981 +#define INIT_TASK_THREAD_INFO
82982 +#endif
82983 +
82984 #ifdef CONFIG_RT_MUTEXES
82985 # define INIT_RT_MUTEXES(tsk) \
82986 .pi_waiters = RB_ROOT, \
82987 @@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82988 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82989 .comm = INIT_TASK_COMM, \
82990 .thread = INIT_THREAD, \
82991 + INIT_TASK_THREAD_INFO \
82992 .fs = &init_fs, \
82993 .files = &init_files, \
82994 .signal = &init_signals, \
82995 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82996 index 69517a2..6b12d37 100644
82997 --- a/include/linux/interrupt.h
82998 +++ b/include/linux/interrupt.h
82999 @@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83000
83001 struct softirq_action
83002 {
83003 - void (*action)(struct softirq_action *);
83004 -};
83005 + void (*action)(void);
83006 +} __no_const;
83007
83008 asmlinkage void do_softirq(void);
83009 asmlinkage void __do_softirq(void);
83010 @@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
83011 }
83012 #endif
83013
83014 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83015 +extern void open_softirq(int nr, void (*action)(void));
83016 extern void softirq_init(void);
83017 extern void __raise_softirq_irqoff(unsigned int nr);
83018
83019 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83020 index e6a7c9f..5804745 100644
83021 --- a/include/linux/iommu.h
83022 +++ b/include/linux/iommu.h
83023 @@ -133,7 +133,7 @@ struct iommu_ops {
83024 u32 (*domain_get_windows)(struct iommu_domain *domain);
83025
83026 unsigned long pgsize_bitmap;
83027 -};
83028 +} __do_const;
83029
83030 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83031 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83032 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83033 index 2c525022..345b106 100644
83034 --- a/include/linux/ioport.h
83035 +++ b/include/linux/ioport.h
83036 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83037 int adjust_resource(struct resource *res, resource_size_t start,
83038 resource_size_t size);
83039 resource_size_t resource_alignment(struct resource *res);
83040 -static inline resource_size_t resource_size(const struct resource *res)
83041 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83042 {
83043 return res->end - res->start + 1;
83044 }
83045 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83046 index 35e7eca..6afb7ad 100644
83047 --- a/include/linux/ipc_namespace.h
83048 +++ b/include/linux/ipc_namespace.h
83049 @@ -69,7 +69,7 @@ struct ipc_namespace {
83050 struct user_namespace *user_ns;
83051
83052 unsigned int proc_inum;
83053 -};
83054 +} __randomize_layout;
83055
83056 extern struct ipc_namespace init_ipc_ns;
83057 extern atomic_t nr_ipc_ns;
83058 diff --git a/include/linux/irq.h b/include/linux/irq.h
83059 index 03f48d9..e86af0c 100644
83060 --- a/include/linux/irq.h
83061 +++ b/include/linux/irq.h
83062 @@ -352,7 +352,8 @@ struct irq_chip {
83063 void (*irq_release_resources)(struct irq_data *data);
83064
83065 unsigned long flags;
83066 -};
83067 +} __do_const;
83068 +typedef struct irq_chip __no_const irq_chip_no_const;
83069
83070 /*
83071 * irq_chip specific flags
83072 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83073 index 13eed92..3261c86 100644
83074 --- a/include/linux/irqchip/arm-gic.h
83075 +++ b/include/linux/irqchip/arm-gic.h
83076 @@ -91,9 +91,11 @@
83077
83078 #ifndef __ASSEMBLY__
83079
83080 +#include <linux/irq.h>
83081 +
83082 struct device_node;
83083
83084 -extern struct irq_chip gic_arch_extn;
83085 +extern irq_chip_no_const gic_arch_extn;
83086
83087 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83088 u32 offset, struct device_node *);
83089 diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
83090 index faf433a..7dcb186 100644
83091 --- a/include/linux/irqdesc.h
83092 +++ b/include/linux/irqdesc.h
83093 @@ -61,7 +61,7 @@ struct irq_desc {
83094 unsigned int irq_count; /* For detecting broken IRQs */
83095 unsigned long last_unhandled; /* Aging timer for unhandled count */
83096 unsigned int irqs_unhandled;
83097 - atomic_t threads_handled;
83098 + atomic_unchecked_t threads_handled;
83099 int threads_handled_last;
83100 raw_spinlock_t lock;
83101 struct cpumask *percpu_enabled;
83102 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83103 index c367cbd..c9b79e6 100644
83104 --- a/include/linux/jiffies.h
83105 +++ b/include/linux/jiffies.h
83106 @@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83107 /*
83108 * Convert various time units to each other:
83109 */
83110 -extern unsigned int jiffies_to_msecs(const unsigned long j);
83111 -extern unsigned int jiffies_to_usecs(const unsigned long j);
83112 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83113 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83114
83115 -static inline u64 jiffies_to_nsecs(const unsigned long j)
83116 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83117 {
83118 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83119 }
83120
83121 -extern unsigned long msecs_to_jiffies(const unsigned int m);
83122 -extern unsigned long usecs_to_jiffies(const unsigned int u);
83123 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83124 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83125 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83126 extern void jiffies_to_timespec(const unsigned long jiffies,
83127 - struct timespec *value);
83128 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
83129 + struct timespec *value) __intentional_overflow(-1);
83130 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83131 extern void jiffies_to_timeval(const unsigned long jiffies,
83132 struct timeval *value);
83133
83134 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83135 index 6883e19..e854fcb 100644
83136 --- a/include/linux/kallsyms.h
83137 +++ b/include/linux/kallsyms.h
83138 @@ -15,7 +15,8 @@
83139
83140 struct module;
83141
83142 -#ifdef CONFIG_KALLSYMS
83143 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83144 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83145 /* Lookup the address for a symbol. Returns 0 if not found. */
83146 unsigned long kallsyms_lookup_name(const char *name);
83147
83148 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83149 /* Stupid that this does nothing, but I didn't create this mess. */
83150 #define __print_symbol(fmt, addr)
83151 #endif /*CONFIG_KALLSYMS*/
83152 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83153 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83154 +extern unsigned long kallsyms_lookup_name(const char *name);
83155 +extern void __print_symbol(const char *fmt, unsigned long address);
83156 +extern int sprint_backtrace(char *buffer, unsigned long address);
83157 +extern int sprint_symbol(char *buffer, unsigned long address);
83158 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83159 +const char *kallsyms_lookup(unsigned long addr,
83160 + unsigned long *symbolsize,
83161 + unsigned long *offset,
83162 + char **modname, char *namebuf);
83163 +extern int kallsyms_lookup_size_offset(unsigned long addr,
83164 + unsigned long *symbolsize,
83165 + unsigned long *offset);
83166 +#endif
83167
83168 /* This macro allows us to keep printk typechecking */
83169 static __printf(1, 2)
83170 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83171 index ff9f1d3..6712be5 100644
83172 --- a/include/linux/key-type.h
83173 +++ b/include/linux/key-type.h
83174 @@ -152,7 +152,7 @@ struct key_type {
83175 /* internal fields */
83176 struct list_head link; /* link in types list */
83177 struct lock_class_key lock_class; /* key->sem lock class */
83178 -};
83179 +} __do_const;
83180
83181 extern struct key_type key_type_keyring;
83182
83183 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83184 index e465bb1..19f605fd 100644
83185 --- a/include/linux/kgdb.h
83186 +++ b/include/linux/kgdb.h
83187 @@ -52,7 +52,7 @@ extern int kgdb_connected;
83188 extern int kgdb_io_module_registered;
83189
83190 extern atomic_t kgdb_setting_breakpoint;
83191 -extern atomic_t kgdb_cpu_doing_single_step;
83192 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83193
83194 extern struct task_struct *kgdb_usethread;
83195 extern struct task_struct *kgdb_contthread;
83196 @@ -254,7 +254,7 @@ struct kgdb_arch {
83197 void (*correct_hw_break)(void);
83198
83199 void (*enable_nmi)(bool on);
83200 -};
83201 +} __do_const;
83202
83203 /**
83204 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83205 @@ -279,7 +279,7 @@ struct kgdb_io {
83206 void (*pre_exception) (void);
83207 void (*post_exception) (void);
83208 int is_console;
83209 -};
83210 +} __do_const;
83211
83212 extern struct kgdb_arch arch_kgdb_ops;
83213
83214 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83215 index 0555cc6..40116ce 100644
83216 --- a/include/linux/kmod.h
83217 +++ b/include/linux/kmod.h
83218 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83219 * usually useless though. */
83220 extern __printf(2, 3)
83221 int __request_module(bool wait, const char *name, ...);
83222 +extern __printf(3, 4)
83223 +int ___request_module(bool wait, char *param_name, const char *name, ...);
83224 #define request_module(mod...) __request_module(true, mod)
83225 #define request_module_nowait(mod...) __request_module(false, mod)
83226 #define try_then_request_module(x, mod...) \
83227 @@ -57,6 +59,9 @@ struct subprocess_info {
83228 struct work_struct work;
83229 struct completion *complete;
83230 char *path;
83231 +#ifdef CONFIG_GRKERNSEC
83232 + char *origpath;
83233 +#endif
83234 char **argv;
83235 char **envp;
83236 int wait;
83237 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83238 index 2d61b90..a1d0a13 100644
83239 --- a/include/linux/kobject.h
83240 +++ b/include/linux/kobject.h
83241 @@ -118,7 +118,7 @@ struct kobj_type {
83242 struct attribute **default_attrs;
83243 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83244 const void *(*namespace)(struct kobject *kobj);
83245 -};
83246 +} __do_const;
83247
83248 struct kobj_uevent_env {
83249 char *argv[3];
83250 @@ -142,6 +142,7 @@ struct kobj_attribute {
83251 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83252 const char *buf, size_t count);
83253 };
83254 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83255
83256 extern const struct sysfs_ops kobj_sysfs_ops;
83257
83258 @@ -169,7 +170,7 @@ struct kset {
83259 spinlock_t list_lock;
83260 struct kobject kobj;
83261 const struct kset_uevent_ops *uevent_ops;
83262 -};
83263 +} __randomize_layout;
83264
83265 extern void kset_init(struct kset *kset);
83266 extern int __must_check kset_register(struct kset *kset);
83267 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83268 index df32d25..fb52e27 100644
83269 --- a/include/linux/kobject_ns.h
83270 +++ b/include/linux/kobject_ns.h
83271 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83272 const void *(*netlink_ns)(struct sock *sk);
83273 const void *(*initial_ns)(void);
83274 void (*drop_ns)(void *);
83275 -};
83276 +} __do_const;
83277
83278 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83279 int kobj_ns_type_registered(enum kobj_ns_type type);
83280 diff --git a/include/linux/kref.h b/include/linux/kref.h
83281 index 484604d..0f6c5b6 100644
83282 --- a/include/linux/kref.h
83283 +++ b/include/linux/kref.h
83284 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83285 static inline int kref_sub(struct kref *kref, unsigned int count,
83286 void (*release)(struct kref *kref))
83287 {
83288 - WARN_ON(release == NULL);
83289 + BUG_ON(release == NULL);
83290
83291 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83292 release(kref);
83293 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83294 index a6059bd..8126d5c 100644
83295 --- a/include/linux/kvm_host.h
83296 +++ b/include/linux/kvm_host.h
83297 @@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
83298 {
83299 }
83300 #endif
83301 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83302 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83303 struct module *module);
83304 void kvm_exit(void);
83305
83306 @@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83307 struct kvm_guest_debug *dbg);
83308 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83309
83310 -int kvm_arch_init(void *opaque);
83311 +int kvm_arch_init(const void *opaque);
83312 void kvm_arch_exit(void);
83313
83314 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83315 diff --git a/include/linux/libata.h b/include/linux/libata.h
83316 index fe0bf8d..c511ca6 100644
83317 --- a/include/linux/libata.h
83318 +++ b/include/linux/libata.h
83319 @@ -977,7 +977,7 @@ struct ata_port_operations {
83320 * fields must be pointers.
83321 */
83322 const struct ata_port_operations *inherits;
83323 -};
83324 +} __do_const;
83325
83326 struct ata_port_info {
83327 unsigned long flags;
83328 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83329 index a6a42dd..6c5ebce 100644
83330 --- a/include/linux/linkage.h
83331 +++ b/include/linux/linkage.h
83332 @@ -36,6 +36,7 @@
83333 #endif
83334
83335 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83336 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83337 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83338
83339 /*
83340 diff --git a/include/linux/list.h b/include/linux/list.h
83341 index f33f831..1ffe5e2 100644
83342 --- a/include/linux/list.h
83343 +++ b/include/linux/list.h
83344 @@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83345 extern void list_del(struct list_head *entry);
83346 #endif
83347
83348 +extern void __pax_list_add(struct list_head *new,
83349 + struct list_head *prev,
83350 + struct list_head *next);
83351 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
83352 +{
83353 + __pax_list_add(new, head, head->next);
83354 +}
83355 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83356 +{
83357 + __pax_list_add(new, head->prev, head);
83358 +}
83359 +extern void pax_list_del(struct list_head *entry);
83360 +
83361 /**
83362 * list_replace - replace old entry by new one
83363 * @old : the element to be replaced
83364 @@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83365 INIT_LIST_HEAD(entry);
83366 }
83367
83368 +extern void pax_list_del_init(struct list_head *entry);
83369 +
83370 /**
83371 * list_move - delete from one list and add as another's head
83372 * @list: the entry to move
83373 diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83374 index 4bfde0e..d6e2e09 100644
83375 --- a/include/linux/lockref.h
83376 +++ b/include/linux/lockref.h
83377 @@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83378 return ((int)l->count < 0);
83379 }
83380
83381 +static inline unsigned int __lockref_read(struct lockref *lockref)
83382 +{
83383 + return lockref->count;
83384 +}
83385 +
83386 +static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83387 +{
83388 + lockref->count = count;
83389 +}
83390 +
83391 +static inline void __lockref_inc(struct lockref *lockref)
83392 +{
83393 +
83394 +#ifdef CONFIG_PAX_REFCOUNT
83395 + atomic_inc((atomic_t *)&lockref->count);
83396 +#else
83397 + lockref->count++;
83398 +#endif
83399 +
83400 +}
83401 +
83402 +static inline void __lockref_dec(struct lockref *lockref)
83403 +{
83404 +
83405 +#ifdef CONFIG_PAX_REFCOUNT
83406 + atomic_dec((atomic_t *)&lockref->count);
83407 +#else
83408 + lockref->count--;
83409 +#endif
83410 +
83411 +}
83412 +
83413 #endif /* __LINUX_LOCKREF_H */
83414 diff --git a/include/linux/math64.h b/include/linux/math64.h
83415 index c45c089..298841c 100644
83416 --- a/include/linux/math64.h
83417 +++ b/include/linux/math64.h
83418 @@ -15,7 +15,7 @@
83419 * This is commonly provided by 32bit archs to provide an optimized 64bit
83420 * divide.
83421 */
83422 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83423 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83424 {
83425 *remainder = dividend % divisor;
83426 return dividend / divisor;
83427 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83428 /**
83429 * div64_u64 - unsigned 64bit divide with 64bit divisor
83430 */
83431 -static inline u64 div64_u64(u64 dividend, u64 divisor)
83432 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83433 {
83434 return dividend / divisor;
83435 }
83436 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83437 #define div64_ul(x, y) div_u64((x), (y))
83438
83439 #ifndef div_u64_rem
83440 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83441 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83442 {
83443 *remainder = do_div(dividend, divisor);
83444 return dividend;
83445 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83446 #endif
83447
83448 #ifndef div64_u64
83449 -extern u64 div64_u64(u64 dividend, u64 divisor);
83450 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83451 #endif
83452
83453 #ifndef div64_s64
83454 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83455 * divide.
83456 */
83457 #ifndef div_u64
83458 -static inline u64 div_u64(u64 dividend, u32 divisor)
83459 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83460 {
83461 u32 remainder;
83462 return div_u64_rem(dividend, divisor, &remainder);
83463 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83464 index 3d385c8..deacb6a 100644
83465 --- a/include/linux/mempolicy.h
83466 +++ b/include/linux/mempolicy.h
83467 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83468 }
83469
83470 #define vma_policy(vma) ((vma)->vm_policy)
83471 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83472 +{
83473 + vma->vm_policy = pol;
83474 +}
83475
83476 static inline void mpol_get(struct mempolicy *pol)
83477 {
83478 @@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83479 }
83480
83481 #define vma_policy(vma) NULL
83482 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83483 +{
83484 +}
83485
83486 static inline int
83487 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83488 diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
83489 index 37e4404..26ebbd0 100644
83490 --- a/include/linux/mlx4/device.h
83491 +++ b/include/linux/mlx4/device.h
83492 @@ -97,7 +97,7 @@ enum {
83493 MLX4_MAX_NUM_PF = 16,
83494 MLX4_MAX_NUM_VF = 64,
83495 MLX4_MAX_NUM_VF_P_PORT = 64,
83496 - MLX4_MFUNC_MAX = 80,
83497 + MLX4_MFUNC_MAX = 128,
83498 MLX4_MAX_EQ_NUM = 1024,
83499 MLX4_MFUNC_EQ_NUM = 4,
83500 MLX4_MFUNC_MAX_EQES = 8,
83501 diff --git a/include/linux/mm.h b/include/linux/mm.h
83502 index 86a977b..8122960 100644
83503 --- a/include/linux/mm.h
83504 +++ b/include/linux/mm.h
83505 @@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83506 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83507 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83508 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83509 +
83510 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83511 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83512 +#endif
83513 +
83514 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83515
83516 #ifdef CONFIG_MEM_SOFT_DIRTY
83517 @@ -238,8 +243,8 @@ struct vm_operations_struct {
83518 /* called by access_process_vm when get_user_pages() fails, typically
83519 * for use by special VMAs that can switch between memory and hardware
83520 */
83521 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
83522 - void *buf, int len, int write);
83523 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83524 + void *buf, size_t len, int write);
83525
83526 /* Called by the /proc/PID/maps code to ask the vma whether it
83527 * has a special name. Returning non-NULL will also cause this
83528 @@ -275,6 +280,7 @@ struct vm_operations_struct {
83529 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83530 unsigned long size, pgoff_t pgoff);
83531 };
83532 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83533
83534 struct mmu_gather;
83535 struct inode;
83536 @@ -1167,8 +1173,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83537 unsigned long *pfn);
83538 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83539 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83540 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83541 - void *buf, int len, int write);
83542 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83543 + void *buf, size_t len, int write);
83544
83545 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83546 loff_t const holebegin, loff_t const holelen)
83547 @@ -1208,9 +1214,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83548 }
83549 #endif
83550
83551 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83552 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83553 - void *buf, int len, int write);
83554 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83555 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83556 + void *buf, size_t len, int write);
83557
83558 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83559 unsigned long start, unsigned long nr_pages,
83560 @@ -1242,34 +1248,6 @@ int set_page_dirty_lock(struct page *page);
83561 int clear_page_dirty_for_io(struct page *page);
83562 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83563
83564 -/* Is the vma a continuation of the stack vma above it? */
83565 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83566 -{
83567 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83568 -}
83569 -
83570 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
83571 - unsigned long addr)
83572 -{
83573 - return (vma->vm_flags & VM_GROWSDOWN) &&
83574 - (vma->vm_start == addr) &&
83575 - !vma_growsdown(vma->vm_prev, addr);
83576 -}
83577 -
83578 -/* Is the vma a continuation of the stack vma below it? */
83579 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83580 -{
83581 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83582 -}
83583 -
83584 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
83585 - unsigned long addr)
83586 -{
83587 - return (vma->vm_flags & VM_GROWSUP) &&
83588 - (vma->vm_end == addr) &&
83589 - !vma_growsup(vma->vm_next, addr);
83590 -}
83591 -
83592 extern struct task_struct *task_of_stack(struct task_struct *task,
83593 struct vm_area_struct *vma, bool in_group);
83594
83595 @@ -1387,8 +1365,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83596 {
83597 return 0;
83598 }
83599 +
83600 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83601 + unsigned long address)
83602 +{
83603 + return 0;
83604 +}
83605 #else
83606 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83607 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83608 #endif
83609
83610 #ifdef __PAGETABLE_PMD_FOLDED
83611 @@ -1397,8 +1382,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83612 {
83613 return 0;
83614 }
83615 +
83616 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83617 + unsigned long address)
83618 +{
83619 + return 0;
83620 +}
83621 #else
83622 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83623 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83624 #endif
83625
83626 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83627 @@ -1416,11 +1408,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83628 NULL: pud_offset(pgd, address);
83629 }
83630
83631 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83632 +{
83633 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83634 + NULL: pud_offset(pgd, address);
83635 +}
83636 +
83637 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83638 {
83639 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83640 NULL: pmd_offset(pud, address);
83641 }
83642 +
83643 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83644 +{
83645 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83646 + NULL: pmd_offset(pud, address);
83647 +}
83648 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83649
83650 #if USE_SPLIT_PTE_PTLOCKS
83651 @@ -1803,12 +1807,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83652 bool *need_rmap_locks);
83653 extern void exit_mmap(struct mm_struct *);
83654
83655 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83656 +extern void gr_learn_resource(const struct task_struct *task, const int res,
83657 + const unsigned long wanted, const int gt);
83658 +#else
83659 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
83660 + const unsigned long wanted, const int gt)
83661 +{
83662 +}
83663 +#endif
83664 +
83665 static inline int check_data_rlimit(unsigned long rlim,
83666 unsigned long new,
83667 unsigned long start,
83668 unsigned long end_data,
83669 unsigned long start_data)
83670 {
83671 + gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83672 if (rlim < RLIM_INFINITY) {
83673 if (((new - start) + (end_data - start_data)) > rlim)
83674 return -ENOSPC;
83675 @@ -1833,7 +1848,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83676 unsigned long addr, unsigned long len,
83677 unsigned long flags, struct page **pages);
83678
83679 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83680 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83681
83682 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83683 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83684 @@ -1841,6 +1856,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83685 unsigned long len, unsigned long prot, unsigned long flags,
83686 unsigned long pgoff, unsigned long *populate);
83687 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83688 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83689
83690 #ifdef CONFIG_MMU
83691 extern int __mm_populate(unsigned long addr, unsigned long len,
83692 @@ -1869,10 +1885,11 @@ struct vm_unmapped_area_info {
83693 unsigned long high_limit;
83694 unsigned long align_mask;
83695 unsigned long align_offset;
83696 + unsigned long threadstack_offset;
83697 };
83698
83699 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83700 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83701 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83702 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83703
83704 /*
83705 * Search for an unmapped address range.
83706 @@ -1884,7 +1901,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83707 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83708 */
83709 static inline unsigned long
83710 -vm_unmapped_area(struct vm_unmapped_area_info *info)
83711 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
83712 {
83713 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83714 return unmapped_area(info);
83715 @@ -1946,6 +1963,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83716 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83717 struct vm_area_struct **pprev);
83718
83719 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83720 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83721 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83722 +
83723 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83724 NULL if none. Assume start_addr < end_addr. */
83725 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83726 @@ -1975,10 +1996,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83727 }
83728
83729 #ifdef CONFIG_MMU
83730 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
83731 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83732 void vma_set_page_prot(struct vm_area_struct *vma);
83733 #else
83734 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83735 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83736 {
83737 return __pgprot(0);
83738 }
83739 @@ -2040,6 +2061,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83740 static inline void vm_stat_account(struct mm_struct *mm,
83741 unsigned long flags, struct file *file, long pages)
83742 {
83743 +
83744 +#ifdef CONFIG_PAX_RANDMMAP
83745 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83746 +#endif
83747 +
83748 mm->total_vm += pages;
83749 }
83750 #endif /* CONFIG_PROC_FS */
83751 @@ -2128,7 +2154,7 @@ extern int unpoison_memory(unsigned long pfn);
83752 extern int sysctl_memory_failure_early_kill;
83753 extern int sysctl_memory_failure_recovery;
83754 extern void shake_page(struct page *p, int access);
83755 -extern atomic_long_t num_poisoned_pages;
83756 +extern atomic_long_unchecked_t num_poisoned_pages;
83757 extern int soft_offline_page(struct page *page, int flags);
83758
83759 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83760 @@ -2163,5 +2189,11 @@ void __init setup_nr_node_ids(void);
83761 static inline void setup_nr_node_ids(void) {}
83762 #endif
83763
83764 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83765 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83766 +#else
83767 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83768 +#endif
83769 +
83770 #endif /* __KERNEL__ */
83771 #endif /* _LINUX_MM_H */
83772 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83773 index 6e0b286..90d9c0d 100644
83774 --- a/include/linux/mm_types.h
83775 +++ b/include/linux/mm_types.h
83776 @@ -308,7 +308,9 @@ struct vm_area_struct {
83777 #ifdef CONFIG_NUMA
83778 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83779 #endif
83780 -};
83781 +
83782 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83783 +} __randomize_layout;
83784
83785 struct core_thread {
83786 struct task_struct *task;
83787 @@ -454,7 +456,25 @@ struct mm_struct {
83788 bool tlb_flush_pending;
83789 #endif
83790 struct uprobes_state uprobes_state;
83791 -};
83792 +
83793 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83794 + unsigned long pax_flags;
83795 +#endif
83796 +
83797 +#ifdef CONFIG_PAX_DLRESOLVE
83798 + unsigned long call_dl_resolve;
83799 +#endif
83800 +
83801 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83802 + unsigned long call_syscall;
83803 +#endif
83804 +
83805 +#ifdef CONFIG_PAX_ASLR
83806 + unsigned long delta_mmap; /* randomized offset */
83807 + unsigned long delta_stack; /* randomized offset */
83808 +#endif
83809 +
83810 +} __randomize_layout;
83811
83812 static inline void mm_init_cpumask(struct mm_struct *mm)
83813 {
83814 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83815 index c5d5278..f0b68c8 100644
83816 --- a/include/linux/mmiotrace.h
83817 +++ b/include/linux/mmiotrace.h
83818 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83819 /* Called from ioremap.c */
83820 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83821 void __iomem *addr);
83822 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
83823 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83824
83825 /* For anyone to insert markers. Remember trailing newline. */
83826 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83827 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83828 {
83829 }
83830
83831 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83832 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83833 {
83834 }
83835
83836 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83837 index ffe66e3..b310722 100644
83838 --- a/include/linux/mmzone.h
83839 +++ b/include/linux/mmzone.h
83840 @@ -527,7 +527,7 @@ struct zone {
83841
83842 ZONE_PADDING(_pad3_)
83843 /* Zone statistics */
83844 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83845 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83846 } ____cacheline_internodealigned_in_smp;
83847
83848 enum zone_flags {
83849 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83850 index 44eeef0..a92d3f9 100644
83851 --- a/include/linux/mod_devicetable.h
83852 +++ b/include/linux/mod_devicetable.h
83853 @@ -139,7 +139,7 @@ struct usb_device_id {
83854 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83855 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83856
83857 -#define HID_ANY_ID (~0)
83858 +#define HID_ANY_ID (~0U)
83859 #define HID_BUS_ANY 0xffff
83860 #define HID_GROUP_ANY 0x0000
83861
83862 @@ -475,7 +475,7 @@ struct dmi_system_id {
83863 const char *ident;
83864 struct dmi_strmatch matches[4];
83865 void *driver_data;
83866 -};
83867 +} __do_const;
83868 /*
83869 * struct dmi_device_id appears during expansion of
83870 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83871 diff --git a/include/linux/module.h b/include/linux/module.h
83872 index 71f282a..b2387e2 100644
83873 --- a/include/linux/module.h
83874 +++ b/include/linux/module.h
83875 @@ -17,9 +17,11 @@
83876 #include <linux/moduleparam.h>
83877 #include <linux/jump_label.h>
83878 #include <linux/export.h>
83879 +#include <linux/fs.h>
83880
83881 #include <linux/percpu.h>
83882 #include <asm/module.h>
83883 +#include <asm/pgtable.h>
83884
83885 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83886 #define MODULE_SIG_STRING "~Module signature appended~\n"
83887 @@ -42,7 +44,7 @@ struct module_kobject {
83888 struct kobject *drivers_dir;
83889 struct module_param_attrs *mp;
83890 struct completion *kobj_completion;
83891 -};
83892 +} __randomize_layout;
83893
83894 struct module_attribute {
83895 struct attribute attr;
83896 @@ -54,12 +56,13 @@ struct module_attribute {
83897 int (*test)(struct module *);
83898 void (*free)(struct module *);
83899 };
83900 +typedef struct module_attribute __no_const module_attribute_no_const;
83901
83902 struct module_version_attribute {
83903 struct module_attribute mattr;
83904 const char *module_name;
83905 const char *version;
83906 -} __attribute__ ((__aligned__(sizeof(void *))));
83907 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83908
83909 extern ssize_t __modver_version_show(struct module_attribute *,
83910 struct module_kobject *, char *);
83911 @@ -235,7 +238,7 @@ struct module {
83912
83913 /* Sysfs stuff. */
83914 struct module_kobject mkobj;
83915 - struct module_attribute *modinfo_attrs;
83916 + module_attribute_no_const *modinfo_attrs;
83917 const char *version;
83918 const char *srcversion;
83919 struct kobject *holders_dir;
83920 @@ -284,19 +287,16 @@ struct module {
83921 int (*init)(void);
83922
83923 /* If this is non-NULL, vfree after init() returns */
83924 - void *module_init;
83925 + void *module_init_rx, *module_init_rw;
83926
83927 /* Here is the actual code + data, vfree'd on unload. */
83928 - void *module_core;
83929 + void *module_core_rx, *module_core_rw;
83930
83931 /* Here are the sizes of the init and core sections */
83932 - unsigned int init_size, core_size;
83933 + unsigned int init_size_rw, core_size_rw;
83934
83935 /* The size of the executable code in each section. */
83936 - unsigned int init_text_size, core_text_size;
83937 -
83938 - /* Size of RO sections of the module (text+rodata) */
83939 - unsigned int init_ro_size, core_ro_size;
83940 + unsigned int init_size_rx, core_size_rx;
83941
83942 /* Arch-specific module values */
83943 struct mod_arch_specific arch;
83944 @@ -352,6 +352,10 @@ struct module {
83945 #ifdef CONFIG_EVENT_TRACING
83946 struct ftrace_event_call **trace_events;
83947 unsigned int num_trace_events;
83948 + struct file_operations trace_id;
83949 + struct file_operations trace_enable;
83950 + struct file_operations trace_format;
83951 + struct file_operations trace_filter;
83952 #endif
83953 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83954 unsigned int num_ftrace_callsites;
83955 @@ -375,7 +379,7 @@ struct module {
83956 ctor_fn_t *ctors;
83957 unsigned int num_ctors;
83958 #endif
83959 -};
83960 +} __randomize_layout;
83961 #ifndef MODULE_ARCH_INIT
83962 #define MODULE_ARCH_INIT {}
83963 #endif
83964 @@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83965 bool is_module_percpu_address(unsigned long addr);
83966 bool is_module_text_address(unsigned long addr);
83967
83968 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83969 +{
83970 +
83971 +#ifdef CONFIG_PAX_KERNEXEC
83972 + if (ktla_ktva(addr) >= (unsigned long)start &&
83973 + ktla_ktva(addr) < (unsigned long)start + size)
83974 + return 1;
83975 +#endif
83976 +
83977 + return ((void *)addr >= start && (void *)addr < start + size);
83978 +}
83979 +
83980 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83981 +{
83982 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83983 +}
83984 +
83985 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83986 +{
83987 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83988 +}
83989 +
83990 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83991 +{
83992 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83993 +}
83994 +
83995 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83996 +{
83997 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83998 +}
83999 +
84000 static inline bool within_module_core(unsigned long addr,
84001 const struct module *mod)
84002 {
84003 - return (unsigned long)mod->module_core <= addr &&
84004 - addr < (unsigned long)mod->module_core + mod->core_size;
84005 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84006 }
84007
84008 static inline bool within_module_init(unsigned long addr,
84009 const struct module *mod)
84010 {
84011 - return (unsigned long)mod->module_init <= addr &&
84012 - addr < (unsigned long)mod->module_init + mod->init_size;
84013 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84014 }
84015
84016 static inline bool within_module(unsigned long addr, const struct module *mod)
84017 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84018 index 7eeb9bb..68f37e0 100644
84019 --- a/include/linux/moduleloader.h
84020 +++ b/include/linux/moduleloader.h
84021 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84022 sections. Returns NULL on failure. */
84023 void *module_alloc(unsigned long size);
84024
84025 +#ifdef CONFIG_PAX_KERNEXEC
84026 +void *module_alloc_exec(unsigned long size);
84027 +#else
84028 +#define module_alloc_exec(x) module_alloc(x)
84029 +#endif
84030 +
84031 /* Free memory returned from module_alloc. */
84032 void module_free(struct module *mod, void *module_region);
84033
84034 +#ifdef CONFIG_PAX_KERNEXEC
84035 +void module_free_exec(struct module *mod, void *module_region);
84036 +#else
84037 +#define module_free_exec(x, y) module_free((x), (y))
84038 +#endif
84039 +
84040 /*
84041 * Apply the given relocation to the (simplified) ELF. Return -error
84042 * or 0.
84043 @@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84044 unsigned int relsec,
84045 struct module *me)
84046 {
84047 +#ifdef CONFIG_MODULES
84048 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84049 module_name(me));
84050 +#endif
84051 return -ENOEXEC;
84052 }
84053 #endif
84054 @@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84055 unsigned int relsec,
84056 struct module *me)
84057 {
84058 +#ifdef CONFIG_MODULES
84059 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84060 module_name(me));
84061 +#endif
84062 return -ENOEXEC;
84063 }
84064 #endif
84065 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84066 index 1c9effa..1160bdd 100644
84067 --- a/include/linux/moduleparam.h
84068 +++ b/include/linux/moduleparam.h
84069 @@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
84070 * @len is usually just sizeof(string).
84071 */
84072 #define module_param_string(name, string, len, perm) \
84073 - static const struct kparam_string __param_string_##name \
84074 + static const struct kparam_string __param_string_##name __used \
84075 = { len, string }; \
84076 __module_param_call(MODULE_PARAM_PREFIX, name, \
84077 &param_ops_string, \
84078 @@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84079 */
84080 #define module_param_array_named(name, array, type, nump, perm) \
84081 param_check_##type(name, &(array)[0]); \
84082 - static const struct kparam_array __param_arr_##name \
84083 + static const struct kparam_array __param_arr_##name __used \
84084 = { .max = ARRAY_SIZE(array), .num = nump, \
84085 .ops = &param_ops_##type, \
84086 .elemsize = sizeof(array[0]), .elem = array }; \
84087 diff --git a/include/linux/mount.h b/include/linux/mount.h
84088 index c2c561d..a5f2a8c 100644
84089 --- a/include/linux/mount.h
84090 +++ b/include/linux/mount.h
84091 @@ -66,7 +66,7 @@ struct vfsmount {
84092 struct dentry *mnt_root; /* root of the mounted tree */
84093 struct super_block *mnt_sb; /* pointer to superblock */
84094 int mnt_flags;
84095 -};
84096 +} __randomize_layout;
84097
84098 struct file; /* forward dec */
84099 struct path;
84100 diff --git a/include/linux/namei.h b/include/linux/namei.h
84101 index 492de72..1bddcd4 100644
84102 --- a/include/linux/namei.h
84103 +++ b/include/linux/namei.h
84104 @@ -19,7 +19,7 @@ struct nameidata {
84105 unsigned seq, m_seq;
84106 int last_type;
84107 unsigned depth;
84108 - char *saved_names[MAX_NESTED_LINKS + 1];
84109 + const char *saved_names[MAX_NESTED_LINKS + 1];
84110 };
84111
84112 /*
84113 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84114
84115 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84116
84117 -static inline void nd_set_link(struct nameidata *nd, char *path)
84118 +static inline void nd_set_link(struct nameidata *nd, const char *path)
84119 {
84120 nd->saved_names[nd->depth] = path;
84121 }
84122
84123 -static inline char *nd_get_link(struct nameidata *nd)
84124 +static inline const char *nd_get_link(const struct nameidata *nd)
84125 {
84126 return nd->saved_names[nd->depth];
84127 }
84128 diff --git a/include/linux/net.h b/include/linux/net.h
84129 index 17d8339..81656c0 100644
84130 --- a/include/linux/net.h
84131 +++ b/include/linux/net.h
84132 @@ -192,7 +192,7 @@ struct net_proto_family {
84133 int (*create)(struct net *net, struct socket *sock,
84134 int protocol, int kern);
84135 struct module *owner;
84136 -};
84137 +} __do_const;
84138
84139 struct iovec;
84140 struct kvec;
84141 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84142 index 22339b4..4b4d5b3 100644
84143 --- a/include/linux/netdevice.h
84144 +++ b/include/linux/netdevice.h
84145 @@ -1160,6 +1160,7 @@ struct net_device_ops {
84146 struct net_device *dev,
84147 netdev_features_t features);
84148 };
84149 +typedef struct net_device_ops __no_const net_device_ops_no_const;
84150
84151 /**
84152 * enum net_device_priv_flags - &struct net_device priv_flags
84153 @@ -1502,10 +1503,10 @@ struct net_device {
84154
84155 struct net_device_stats stats;
84156
84157 - atomic_long_t rx_dropped;
84158 - atomic_long_t tx_dropped;
84159 + atomic_long_unchecked_t rx_dropped;
84160 + atomic_long_unchecked_t tx_dropped;
84161
84162 - atomic_t carrier_changes;
84163 + atomic_unchecked_t carrier_changes;
84164
84165 #ifdef CONFIG_WIRELESS_EXT
84166 const struct iw_handler_def * wireless_handlers;
84167 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84168 index 2517ece..0bbfcfb 100644
84169 --- a/include/linux/netfilter.h
84170 +++ b/include/linux/netfilter.h
84171 @@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84172 #endif
84173 /* Use the module struct to lock set/get code in place */
84174 struct module *owner;
84175 -};
84176 +} __do_const;
84177
84178 /* Function to register/unregister hook points. */
84179 int nf_register_hook(struct nf_hook_ops *reg);
84180 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84181 index e955d47..04a5338 100644
84182 --- a/include/linux/netfilter/nfnetlink.h
84183 +++ b/include/linux/netfilter/nfnetlink.h
84184 @@ -19,7 +19,7 @@ struct nfnl_callback {
84185 const struct nlattr * const cda[]);
84186 const struct nla_policy *policy; /* netlink attribute policy */
84187 const u_int16_t attr_count; /* number of nlattr's */
84188 -};
84189 +} __do_const;
84190
84191 struct nfnetlink_subsystem {
84192 const char *name;
84193 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84194 new file mode 100644
84195 index 0000000..33f4af8
84196 --- /dev/null
84197 +++ b/include/linux/netfilter/xt_gradm.h
84198 @@ -0,0 +1,9 @@
84199 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
84200 +#define _LINUX_NETFILTER_XT_GRADM_H 1
84201 +
84202 +struct xt_gradm_mtinfo {
84203 + __u16 flags;
84204 + __u16 invflags;
84205 +};
84206 +
84207 +#endif
84208 diff --git a/include/linux/nls.h b/include/linux/nls.h
84209 index 520681b..2b7fabb 100644
84210 --- a/include/linux/nls.h
84211 +++ b/include/linux/nls.h
84212 @@ -31,7 +31,7 @@ struct nls_table {
84213 const unsigned char *charset2upper;
84214 struct module *owner;
84215 struct nls_table *next;
84216 -};
84217 +} __do_const;
84218
84219 /* this value hold the maximum octet of charset */
84220 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84221 @@ -46,7 +46,7 @@ enum utf16_endian {
84222 /* nls_base.c */
84223 extern int __register_nls(struct nls_table *, struct module *);
84224 extern int unregister_nls(struct nls_table *);
84225 -extern struct nls_table *load_nls(char *);
84226 +extern struct nls_table *load_nls(const char *);
84227 extern void unload_nls(struct nls_table *);
84228 extern struct nls_table *load_nls_default(void);
84229 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84230 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84231 index d14a4c3..a078786 100644
84232 --- a/include/linux/notifier.h
84233 +++ b/include/linux/notifier.h
84234 @@ -54,7 +54,8 @@ struct notifier_block {
84235 notifier_fn_t notifier_call;
84236 struct notifier_block __rcu *next;
84237 int priority;
84238 -};
84239 +} __do_const;
84240 +typedef struct notifier_block __no_const notifier_block_no_const;
84241
84242 struct atomic_notifier_head {
84243 spinlock_t lock;
84244 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84245 index b2a0f15..4d7da32 100644
84246 --- a/include/linux/oprofile.h
84247 +++ b/include/linux/oprofile.h
84248 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84249 int oprofilefs_create_ro_ulong(struct dentry * root,
84250 char const * name, ulong * val);
84251
84252 -/** Create a file for read-only access to an atomic_t. */
84253 +/** Create a file for read-only access to an atomic_unchecked_t. */
84254 int oprofilefs_create_ro_atomic(struct dentry * root,
84255 - char const * name, atomic_t * val);
84256 + char const * name, atomic_unchecked_t * val);
84257
84258 /** create a directory */
84259 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84260 diff --git a/include/linux/padata.h b/include/linux/padata.h
84261 index 4386946..f50c615 100644
84262 --- a/include/linux/padata.h
84263 +++ b/include/linux/padata.h
84264 @@ -129,7 +129,7 @@ struct parallel_data {
84265 struct padata_serial_queue __percpu *squeue;
84266 atomic_t reorder_objects;
84267 atomic_t refcnt;
84268 - atomic_t seq_nr;
84269 + atomic_unchecked_t seq_nr;
84270 struct padata_cpumask cpumask;
84271 spinlock_t lock ____cacheline_aligned;
84272 unsigned int processed;
84273 diff --git a/include/linux/path.h b/include/linux/path.h
84274 index d137218..be0c176 100644
84275 --- a/include/linux/path.h
84276 +++ b/include/linux/path.h
84277 @@ -1,13 +1,15 @@
84278 #ifndef _LINUX_PATH_H
84279 #define _LINUX_PATH_H
84280
84281 +#include <linux/compiler.h>
84282 +
84283 struct dentry;
84284 struct vfsmount;
84285
84286 struct path {
84287 struct vfsmount *mnt;
84288 struct dentry *dentry;
84289 -};
84290 +} __randomize_layout;
84291
84292 extern void path_get(const struct path *);
84293 extern void path_put(const struct path *);
84294 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84295 index 2706ee9..e691f7c 100644
84296 --- a/include/linux/pci_hotplug.h
84297 +++ b/include/linux/pci_hotplug.h
84298 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84299 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84300 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84301 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84302 -};
84303 +} __do_const;
84304 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84305
84306 /**
84307 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84308 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84309 index 893a0d0..d5f996e 100644
84310 --- a/include/linux/perf_event.h
84311 +++ b/include/linux/perf_event.h
84312 @@ -341,8 +341,8 @@ struct perf_event {
84313
84314 enum perf_event_active_state state;
84315 unsigned int attach_state;
84316 - local64_t count;
84317 - atomic64_t child_count;
84318 + local64_t count; /* PaX: fix it one day */
84319 + atomic64_unchecked_t child_count;
84320
84321 /*
84322 * These are the total time in nanoseconds that the event
84323 @@ -393,8 +393,8 @@ struct perf_event {
84324 * These accumulate total time (in nanoseconds) that children
84325 * events have been enabled and running, respectively.
84326 */
84327 - atomic64_t child_total_time_enabled;
84328 - atomic64_t child_total_time_running;
84329 + atomic64_unchecked_t child_total_time_enabled;
84330 + atomic64_unchecked_t child_total_time_running;
84331
84332 /*
84333 * Protect attach/detach and child_list:
84334 @@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84335 entry->ip[entry->nr++] = ip;
84336 }
84337
84338 -extern int sysctl_perf_event_paranoid;
84339 +extern int sysctl_perf_event_legitimately_concerned;
84340 extern int sysctl_perf_event_mlock;
84341 extern int sysctl_perf_event_sample_rate;
84342 extern int sysctl_perf_cpu_time_max_percent;
84343 @@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84344 loff_t *ppos);
84345
84346
84347 +static inline bool perf_paranoid_any(void)
84348 +{
84349 + return sysctl_perf_event_legitimately_concerned > 2;
84350 +}
84351 +
84352 static inline bool perf_paranoid_tracepoint_raw(void)
84353 {
84354 - return sysctl_perf_event_paranoid > -1;
84355 + return sysctl_perf_event_legitimately_concerned > -1;
84356 }
84357
84358 static inline bool perf_paranoid_cpu(void)
84359 {
84360 - return sysctl_perf_event_paranoid > 0;
84361 + return sysctl_perf_event_legitimately_concerned > 0;
84362 }
84363
84364 static inline bool perf_paranoid_kernel(void)
84365 {
84366 - return sysctl_perf_event_paranoid > 1;
84367 + return sysctl_perf_event_legitimately_concerned > 1;
84368 }
84369
84370 extern void perf_event_init(void);
84371 @@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84372 struct device_attribute attr;
84373 u64 id;
84374 const char *event_str;
84375 -};
84376 +} __do_const;
84377
84378 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84379 static struct perf_pmu_events_attr _var = { \
84380 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84381 index 1997ffc..4f1f44d 100644
84382 --- a/include/linux/pid_namespace.h
84383 +++ b/include/linux/pid_namespace.h
84384 @@ -44,7 +44,7 @@ struct pid_namespace {
84385 int hide_pid;
84386 int reboot; /* group exit code if this pidns was rebooted */
84387 unsigned int proc_inum;
84388 -};
84389 +} __randomize_layout;
84390
84391 extern struct pid_namespace init_pid_ns;
84392
84393 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84394 index eb8b8ac..62649e1 100644
84395 --- a/include/linux/pipe_fs_i.h
84396 +++ b/include/linux/pipe_fs_i.h
84397 @@ -47,10 +47,10 @@ struct pipe_inode_info {
84398 struct mutex mutex;
84399 wait_queue_head_t wait;
84400 unsigned int nrbufs, curbuf, buffers;
84401 - unsigned int readers;
84402 - unsigned int writers;
84403 - unsigned int files;
84404 - unsigned int waiting_writers;
84405 + atomic_t readers;
84406 + atomic_t writers;
84407 + atomic_t files;
84408 + atomic_t waiting_writers;
84409 unsigned int r_counter;
84410 unsigned int w_counter;
84411 struct page *tmp_page;
84412 diff --git a/include/linux/pm.h b/include/linux/pm.h
84413 index 383fd68..7a11504 100644
84414 --- a/include/linux/pm.h
84415 +++ b/include/linux/pm.h
84416 @@ -621,6 +621,7 @@ struct dev_pm_domain {
84417 struct dev_pm_ops ops;
84418 void (*detach)(struct device *dev, bool power_off);
84419 };
84420 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84421
84422 /*
84423 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84424 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84425 index 2e0e06d..824cc9b 100644
84426 --- a/include/linux/pm_domain.h
84427 +++ b/include/linux/pm_domain.h
84428 @@ -36,11 +36,11 @@ struct gpd_dev_ops {
84429 int (*save_state)(struct device *dev);
84430 int (*restore_state)(struct device *dev);
84431 bool (*active_wakeup)(struct device *dev);
84432 -};
84433 +} __no_const;
84434
84435 struct gpd_cpuidle_data {
84436 unsigned int saved_exit_latency;
84437 - struct cpuidle_state *idle_state;
84438 + cpuidle_state_no_const *idle_state;
84439 };
84440
84441 struct generic_pm_domain {
84442 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84443 index 367f49b..d2f5a14 100644
84444 --- a/include/linux/pm_runtime.h
84445 +++ b/include/linux/pm_runtime.h
84446 @@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84447
84448 static inline void pm_runtime_mark_last_busy(struct device *dev)
84449 {
84450 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
84451 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84452 }
84453
84454 #else /* !CONFIG_PM_RUNTIME */
84455 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84456 index 195aafc..49a7bc2 100644
84457 --- a/include/linux/pnp.h
84458 +++ b/include/linux/pnp.h
84459 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84460 struct pnp_fixup {
84461 char id[7];
84462 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84463 -};
84464 +} __do_const;
84465
84466 /* config parameters */
84467 #define PNP_CONFIG_NORMAL 0x0001
84468 diff --git a/include/linux/poison.h b/include/linux/poison.h
84469 index 2110a81..13a11bb 100644
84470 --- a/include/linux/poison.h
84471 +++ b/include/linux/poison.h
84472 @@ -19,8 +19,8 @@
84473 * under normal circumstances, used to verify that nobody uses
84474 * non-initialized list entries.
84475 */
84476 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84477 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84478 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84479 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84480
84481 /********** include/linux/timer.h **********/
84482 /*
84483 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84484 index d8b187c3..9a9257a 100644
84485 --- a/include/linux/power/smartreflex.h
84486 +++ b/include/linux/power/smartreflex.h
84487 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
84488 int (*notify)(struct omap_sr *sr, u32 status);
84489 u8 notify_flags;
84490 u8 class_type;
84491 -};
84492 +} __do_const;
84493
84494 /**
84495 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84496 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84497 index 4ea1d37..80f4b33 100644
84498 --- a/include/linux/ppp-comp.h
84499 +++ b/include/linux/ppp-comp.h
84500 @@ -84,7 +84,7 @@ struct compressor {
84501 struct module *owner;
84502 /* Extra skb space needed by the compressor algorithm */
84503 unsigned int comp_extra;
84504 -};
84505 +} __do_const;
84506
84507 /*
84508 * The return value from decompress routine is the length of the
84509 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84510 index de83b4e..c4b997d 100644
84511 --- a/include/linux/preempt.h
84512 +++ b/include/linux/preempt.h
84513 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84514 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84515 #endif
84516
84517 +#define raw_preempt_count_add(val) __preempt_count_add(val)
84518 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84519 +
84520 #define __preempt_count_inc() __preempt_count_add(1)
84521 #define __preempt_count_dec() __preempt_count_sub(1)
84522
84523 #define preempt_count_inc() preempt_count_add(1)
84524 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
84525 #define preempt_count_dec() preempt_count_sub(1)
84526 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84527
84528 #ifdef CONFIG_PREEMPT_COUNT
84529
84530 @@ -41,6 +46,12 @@ do { \
84531 barrier(); \
84532 } while (0)
84533
84534 +#define raw_preempt_disable() \
84535 +do { \
84536 + raw_preempt_count_inc(); \
84537 + barrier(); \
84538 +} while (0)
84539 +
84540 #define sched_preempt_enable_no_resched() \
84541 do { \
84542 barrier(); \
84543 @@ -49,6 +60,12 @@ do { \
84544
84545 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84546
84547 +#define raw_preempt_enable_no_resched() \
84548 +do { \
84549 + barrier(); \
84550 + raw_preempt_count_dec(); \
84551 +} while (0)
84552 +
84553 #ifdef CONFIG_PREEMPT
84554 #define preempt_enable() \
84555 do { \
84556 @@ -113,8 +130,10 @@ do { \
84557 * region.
84558 */
84559 #define preempt_disable() barrier()
84560 +#define raw_preempt_disable() barrier()
84561 #define sched_preempt_enable_no_resched() barrier()
84562 #define preempt_enable_no_resched() barrier()
84563 +#define raw_preempt_enable_no_resched() barrier()
84564 #define preempt_enable() barrier()
84565 #define preempt_check_resched() do { } while (0)
84566
84567 @@ -128,11 +147,13 @@ do { \
84568 /*
84569 * Modules have no business playing preemption tricks.
84570 */
84571 +#ifndef CONFIG_PAX_KERNEXEC
84572 #undef sched_preempt_enable_no_resched
84573 #undef preempt_enable_no_resched
84574 #undef preempt_enable_no_resched_notrace
84575 #undef preempt_check_resched
84576 #endif
84577 +#endif
84578
84579 #define preempt_set_need_resched() \
84580 do { \
84581 diff --git a/include/linux/printk.h b/include/linux/printk.h
84582 index d78125f..7f36596 100644
84583 --- a/include/linux/printk.h
84584 +++ b/include/linux/printk.h
84585 @@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84586 void early_printk(const char *s, ...) { }
84587 #endif
84588
84589 +extern int kptr_restrict;
84590 +
84591 #ifdef CONFIG_PRINTK
84592 asmlinkage __printf(5, 0)
84593 int vprintk_emit(int facility, int level,
84594 @@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84595
84596 extern int printk_delay_msec;
84597 extern int dmesg_restrict;
84598 -extern int kptr_restrict;
84599
84600 extern void wake_up_klogd(void);
84601
84602 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84603 index b97bf2e..f14c92d4 100644
84604 --- a/include/linux/proc_fs.h
84605 +++ b/include/linux/proc_fs.h
84606 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84607 extern struct proc_dir_entry *proc_symlink(const char *,
84608 struct proc_dir_entry *, const char *);
84609 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84610 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84611 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84612 struct proc_dir_entry *, void *);
84613 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84614 + struct proc_dir_entry *, void *);
84615 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84616 struct proc_dir_entry *);
84617
84618 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84619 return proc_create_data(name, mode, parent, proc_fops, NULL);
84620 }
84621
84622 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84623 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84624 +{
84625 +#ifdef CONFIG_GRKERNSEC_PROC_USER
84626 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84627 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84628 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84629 +#else
84630 + return proc_create_data(name, mode, parent, proc_fops, NULL);
84631 +#endif
84632 +}
84633 +
84634 +
84635 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84636 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84637 extern void *PDE_DATA(const struct inode *);
84638 @@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84639 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84640 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84641 struct proc_dir_entry *parent) {return NULL;}
84642 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84643 + struct proc_dir_entry *parent) { return NULL; }
84644 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84645 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84646 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84647 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84648 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84649 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84650 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84651 @@ -79,7 +99,7 @@ struct net;
84652 static inline struct proc_dir_entry *proc_net_mkdir(
84653 struct net *net, const char *name, struct proc_dir_entry *parent)
84654 {
84655 - return proc_mkdir_data(name, 0, parent, net);
84656 + return proc_mkdir_data_restrict(name, 0, parent, net);
84657 }
84658
84659 #endif /* _LINUX_PROC_FS_H */
84660 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84661 index 34a1e10..70f6bde 100644
84662 --- a/include/linux/proc_ns.h
84663 +++ b/include/linux/proc_ns.h
84664 @@ -14,7 +14,7 @@ struct proc_ns_operations {
84665 void (*put)(void *ns);
84666 int (*install)(struct nsproxy *nsproxy, void *ns);
84667 unsigned int (*inum)(void *ns);
84668 -};
84669 +} __do_const __randomize_layout;
84670
84671 struct proc_ns {
84672 void *ns;
84673 diff --git a/include/linux/quota.h b/include/linux/quota.h
84674 index 8b0877f..b1071c5 100644
84675 --- a/include/linux/quota.h
84676 +++ b/include/linux/quota.h
84677 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84678
84679 extern bool qid_eq(struct kqid left, struct kqid right);
84680 extern bool qid_lt(struct kqid left, struct kqid right);
84681 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84682 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84683 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84684 extern bool qid_valid(struct kqid qid);
84685
84686 diff --git a/include/linux/random.h b/include/linux/random.h
84687 index b05856e..0a9f14e 100644
84688 --- a/include/linux/random.h
84689 +++ b/include/linux/random.h
84690 @@ -9,9 +9,19 @@
84691 #include <uapi/linux/random.h>
84692
84693 extern void add_device_randomness(const void *, unsigned int);
84694 +
84695 +static inline void add_latent_entropy(void)
84696 +{
84697 +
84698 +#ifdef LATENT_ENTROPY_PLUGIN
84699 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84700 +#endif
84701 +
84702 +}
84703 +
84704 extern void add_input_randomness(unsigned int type, unsigned int code,
84705 - unsigned int value);
84706 -extern void add_interrupt_randomness(int irq, int irq_flags);
84707 + unsigned int value) __latent_entropy;
84708 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84709
84710 extern void get_random_bytes(void *buf, int nbytes);
84711 extern void get_random_bytes_arch(void *buf, int nbytes);
84712 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84713 extern const struct file_operations random_fops, urandom_fops;
84714 #endif
84715
84716 -unsigned int get_random_int(void);
84717 +unsigned int __intentional_overflow(-1) get_random_int(void);
84718 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84719
84720 -u32 prandom_u32(void);
84721 +u32 prandom_u32(void) __intentional_overflow(-1);
84722 void prandom_bytes(void *buf, size_t nbytes);
84723 void prandom_seed(u32 seed);
84724 void prandom_reseed_late(void);
84725 @@ -37,6 +47,11 @@ struct rnd_state {
84726 u32 prandom_u32_state(struct rnd_state *state);
84727 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84728
84729 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84730 +{
84731 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84732 +}
84733 +
84734 /**
84735 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84736 * @ep_ro: right open interval endpoint
84737 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84738 *
84739 * Returns: pseudo-random number in interval [0, ep_ro)
84740 */
84741 -static inline u32 prandom_u32_max(u32 ep_ro)
84742 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84743 {
84744 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84745 }
84746 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84747 index 378c5ee..aa84a47 100644
84748 --- a/include/linux/rbtree_augmented.h
84749 +++ b/include/linux/rbtree_augmented.h
84750 @@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84751 old->rbaugmented = rbcompute(old); \
84752 } \
84753 rbstatic const struct rb_augment_callbacks rbname = { \
84754 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84755 + .propagate = rbname ## _propagate, \
84756 + .copy = rbname ## _copy, \
84757 + .rotate = rbname ## _rotate \
84758 };
84759
84760
84761 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84762 index 372ad5e..d4373f8 100644
84763 --- a/include/linux/rculist.h
84764 +++ b/include/linux/rculist.h
84765 @@ -29,8 +29,8 @@
84766 */
84767 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84768 {
84769 - ACCESS_ONCE(list->next) = list;
84770 - ACCESS_ONCE(list->prev) = list;
84771 + ACCESS_ONCE_RW(list->next) = list;
84772 + ACCESS_ONCE_RW(list->prev) = list;
84773 }
84774
84775 /*
84776 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84777 struct list_head *prev, struct list_head *next);
84778 #endif
84779
84780 +void __pax_list_add_rcu(struct list_head *new,
84781 + struct list_head *prev, struct list_head *next);
84782 +
84783 /**
84784 * list_add_rcu - add a new entry to rcu-protected list
84785 * @new: new entry to be added
84786 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84787 __list_add_rcu(new, head, head->next);
84788 }
84789
84790 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84791 +{
84792 + __pax_list_add_rcu(new, head, head->next);
84793 +}
84794 +
84795 /**
84796 * list_add_tail_rcu - add a new entry to rcu-protected list
84797 * @new: new entry to be added
84798 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84799 __list_add_rcu(new, head->prev, head);
84800 }
84801
84802 +static inline void pax_list_add_tail_rcu(struct list_head *new,
84803 + struct list_head *head)
84804 +{
84805 + __pax_list_add_rcu(new, head->prev, head);
84806 +}
84807 +
84808 /**
84809 * list_del_rcu - deletes entry from list without re-initialization
84810 * @entry: the element to delete from the list.
84811 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84812 entry->prev = LIST_POISON2;
84813 }
84814
84815 +extern void pax_list_del_rcu(struct list_head *entry);
84816 +
84817 /**
84818 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84819 * @n: the element to delete from the hash list.
84820 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84821 index 53ff1a7..c40f0ab 100644
84822 --- a/include/linux/rcupdate.h
84823 +++ b/include/linux/rcupdate.h
84824 @@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84825 #define rcu_note_voluntary_context_switch(t) \
84826 do { \
84827 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84828 - ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84829 + ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84830 } while (0)
84831 #else /* #ifdef CONFIG_TASKS_RCU */
84832 #define TASKS_RCU(x) do { } while (0)
84833 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84834 index 67fc8fc..a90f7d8 100644
84835 --- a/include/linux/reboot.h
84836 +++ b/include/linux/reboot.h
84837 @@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84838 */
84839
84840 extern void migrate_to_reboot_cpu(void);
84841 -extern void machine_restart(char *cmd);
84842 -extern void machine_halt(void);
84843 -extern void machine_power_off(void);
84844 +extern void machine_restart(char *cmd) __noreturn;
84845 +extern void machine_halt(void) __noreturn;
84846 +extern void machine_power_off(void) __noreturn;
84847
84848 extern void machine_shutdown(void);
84849 struct pt_regs;
84850 @@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84851 */
84852
84853 extern void kernel_restart_prepare(char *cmd);
84854 -extern void kernel_restart(char *cmd);
84855 -extern void kernel_halt(void);
84856 -extern void kernel_power_off(void);
84857 +extern void kernel_restart(char *cmd) __noreturn;
84858 +extern void kernel_halt(void) __noreturn;
84859 +extern void kernel_power_off(void) __noreturn;
84860
84861 extern int C_A_D; /* for sysctl */
84862 void ctrl_alt_del(void);
84863 @@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84864 * Emergency restart, callable from an interrupt handler.
84865 */
84866
84867 -extern void emergency_restart(void);
84868 +extern void emergency_restart(void) __noreturn;
84869 #include <asm/emergency-restart.h>
84870
84871 #endif /* _LINUX_REBOOT_H */
84872 diff --git a/include/linux/regset.h b/include/linux/regset.h
84873 index 8e0c9fe..ac4d221 100644
84874 --- a/include/linux/regset.h
84875 +++ b/include/linux/regset.h
84876 @@ -161,7 +161,8 @@ struct user_regset {
84877 unsigned int align;
84878 unsigned int bias;
84879 unsigned int core_note_type;
84880 -};
84881 +} __do_const;
84882 +typedef struct user_regset __no_const user_regset_no_const;
84883
84884 /**
84885 * struct user_regset_view - available regsets
84886 diff --git a/include/linux/relay.h b/include/linux/relay.h
84887 index d7c8359..818daf5 100644
84888 --- a/include/linux/relay.h
84889 +++ b/include/linux/relay.h
84890 @@ -157,7 +157,7 @@ struct rchan_callbacks
84891 * The callback should return 0 if successful, negative if not.
84892 */
84893 int (*remove_buf_file)(struct dentry *dentry);
84894 -};
84895 +} __no_const;
84896
84897 /*
84898 * CONFIG_RELAY kernel API, kernel/relay.c
84899 diff --git a/include/linux/rio.h b/include/linux/rio.h
84900 index 6bda06f..bf39a9b 100644
84901 --- a/include/linux/rio.h
84902 +++ b/include/linux/rio.h
84903 @@ -358,7 +358,7 @@ struct rio_ops {
84904 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84905 u64 rstart, u32 size, u32 flags);
84906 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84907 -};
84908 +} __no_const;
84909
84910 #define RIO_RESOURCE_MEM 0x00000100
84911 #define RIO_RESOURCE_DOORBELL 0x00000200
84912 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84913 index c0c2bce..4813524 100644
84914 --- a/include/linux/rmap.h
84915 +++ b/include/linux/rmap.h
84916 @@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84917 void anon_vma_init(void); /* create anon_vma_cachep */
84918 int anon_vma_prepare(struct vm_area_struct *);
84919 void unlink_anon_vmas(struct vm_area_struct *);
84920 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84921 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84922 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84923 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84924
84925 static inline void anon_vma_merge(struct vm_area_struct *vma,
84926 struct vm_area_struct *next)
84927 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84928 index ed8f9e7..999bc96 100644
84929 --- a/include/linux/scatterlist.h
84930 +++ b/include/linux/scatterlist.h
84931 @@ -1,6 +1,7 @@
84932 #ifndef _LINUX_SCATTERLIST_H
84933 #define _LINUX_SCATTERLIST_H
84934
84935 +#include <linux/sched.h>
84936 #include <linux/string.h>
84937 #include <linux/bug.h>
84938 #include <linux/mm.h>
84939 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84940 #ifdef CONFIG_DEBUG_SG
84941 BUG_ON(!virt_addr_valid(buf));
84942 #endif
84943 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84944 + if (object_starts_on_stack(buf)) {
84945 + void *adjbuf = buf - current->stack + current->lowmem_stack;
84946 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84947 + } else
84948 +#endif
84949 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84950 }
84951
84952 diff --git a/include/linux/sched.h b/include/linux/sched.h
84953 index 5e344bb..0743255 100644
84954 --- a/include/linux/sched.h
84955 +++ b/include/linux/sched.h
84956 @@ -133,6 +133,7 @@ struct fs_struct;
84957 struct perf_event_context;
84958 struct blk_plug;
84959 struct filename;
84960 +struct linux_binprm;
84961
84962 #define VMACACHE_BITS 2
84963 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84964 @@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84965 extern int in_sched_functions(unsigned long addr);
84966
84967 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84968 -extern signed long schedule_timeout(signed long timeout);
84969 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84970 extern signed long schedule_timeout_interruptible(signed long timeout);
84971 extern signed long schedule_timeout_killable(signed long timeout);
84972 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84973 @@ -387,6 +388,19 @@ struct nsproxy;
84974 struct user_namespace;
84975
84976 #ifdef CONFIG_MMU
84977 +
84978 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84979 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84980 +#else
84981 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84982 +{
84983 + return 0;
84984 +}
84985 +#endif
84986 +
84987 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84988 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84989 +
84990 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84991 extern unsigned long
84992 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84993 @@ -685,6 +699,17 @@ struct signal_struct {
84994 #ifdef CONFIG_TASKSTATS
84995 struct taskstats *stats;
84996 #endif
84997 +
84998 +#ifdef CONFIG_GRKERNSEC
84999 + u32 curr_ip;
85000 + u32 saved_ip;
85001 + u32 gr_saddr;
85002 + u32 gr_daddr;
85003 + u16 gr_sport;
85004 + u16 gr_dport;
85005 + u8 used_accept:1;
85006 +#endif
85007 +
85008 #ifdef CONFIG_AUDIT
85009 unsigned audit_tty;
85010 unsigned audit_tty_log_passwd;
85011 @@ -711,7 +736,7 @@ struct signal_struct {
85012 struct mutex cred_guard_mutex; /* guard against foreign influences on
85013 * credential calculations
85014 * (notably. ptrace) */
85015 -};
85016 +} __randomize_layout;
85017
85018 /*
85019 * Bits in flags field of signal_struct.
85020 @@ -764,6 +789,14 @@ struct user_struct {
85021 struct key *session_keyring; /* UID's default session keyring */
85022 #endif
85023
85024 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85025 + unsigned char kernel_banned;
85026 +#endif
85027 +#ifdef CONFIG_GRKERNSEC_BRUTE
85028 + unsigned char suid_banned;
85029 + unsigned long suid_ban_expires;
85030 +#endif
85031 +
85032 /* Hash table maintenance information */
85033 struct hlist_node uidhash_node;
85034 kuid_t uid;
85035 @@ -771,7 +804,7 @@ struct user_struct {
85036 #ifdef CONFIG_PERF_EVENTS
85037 atomic_long_t locked_vm;
85038 #endif
85039 -};
85040 +} __randomize_layout;
85041
85042 extern int uids_sysfs_init(void);
85043
85044 @@ -1235,6 +1268,9 @@ enum perf_event_task_context {
85045 struct task_struct {
85046 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85047 void *stack;
85048 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85049 + void *lowmem_stack;
85050 +#endif
85051 atomic_t usage;
85052 unsigned int flags; /* per process flags, defined below */
85053 unsigned int ptrace;
85054 @@ -1362,8 +1398,8 @@ struct task_struct {
85055 struct list_head thread_node;
85056
85057 struct completion *vfork_done; /* for vfork() */
85058 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85059 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85060 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85061 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85062
85063 cputime_t utime, stime, utimescaled, stimescaled;
85064 cputime_t gtime;
85065 @@ -1388,11 +1424,6 @@ struct task_struct {
85066 struct task_cputime cputime_expires;
85067 struct list_head cpu_timers[3];
85068
85069 -/* process credentials */
85070 - const struct cred __rcu *real_cred; /* objective and real subjective task
85071 - * credentials (COW) */
85072 - const struct cred __rcu *cred; /* effective (overridable) subjective task
85073 - * credentials (COW) */
85074 char comm[TASK_COMM_LEN]; /* executable name excluding path
85075 - access with [gs]et_task_comm (which lock
85076 it with task_lock())
85077 @@ -1410,6 +1441,10 @@ struct task_struct {
85078 #endif
85079 /* CPU-specific state of this task */
85080 struct thread_struct thread;
85081 +/* thread_info moved to task_struct */
85082 +#ifdef CONFIG_X86
85083 + struct thread_info tinfo;
85084 +#endif
85085 /* filesystem information */
85086 struct fs_struct *fs;
85087 /* open file information */
85088 @@ -1484,6 +1519,10 @@ struct task_struct {
85089 gfp_t lockdep_reclaim_gfp;
85090 #endif
85091
85092 +/* process credentials */
85093 + const struct cred __rcu *real_cred; /* objective and real subjective task
85094 + * credentials (COW) */
85095 +
85096 /* journalling filesystem info */
85097 void *journal_info;
85098
85099 @@ -1522,6 +1561,10 @@ struct task_struct {
85100 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85101 struct list_head cg_list;
85102 #endif
85103 +
85104 + const struct cred __rcu *cred; /* effective (overridable) subjective task
85105 + * credentials (COW) */
85106 +
85107 #ifdef CONFIG_FUTEX
85108 struct robust_list_head __user *robust_list;
85109 #ifdef CONFIG_COMPAT
85110 @@ -1635,7 +1678,7 @@ struct task_struct {
85111 * Number of functions that haven't been traced
85112 * because of depth overrun.
85113 */
85114 - atomic_t trace_overrun;
85115 + atomic_unchecked_t trace_overrun;
85116 /* Pause for the tracing */
85117 atomic_t tracing_graph_pause;
85118 #endif
85119 @@ -1661,7 +1704,78 @@ struct task_struct {
85120 unsigned int sequential_io;
85121 unsigned int sequential_io_avg;
85122 #endif
85123 -};
85124 +
85125 +#ifdef CONFIG_GRKERNSEC
85126 + /* grsecurity */
85127 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85128 + u64 exec_id;
85129 +#endif
85130 +#ifdef CONFIG_GRKERNSEC_SETXID
85131 + const struct cred *delayed_cred;
85132 +#endif
85133 + struct dentry *gr_chroot_dentry;
85134 + struct acl_subject_label *acl;
85135 + struct acl_subject_label *tmpacl;
85136 + struct acl_role_label *role;
85137 + struct file *exec_file;
85138 + unsigned long brute_expires;
85139 + u16 acl_role_id;
85140 + u8 inherited;
85141 + /* is this the task that authenticated to the special role */
85142 + u8 acl_sp_role;
85143 + u8 is_writable;
85144 + u8 brute;
85145 + u8 gr_is_chrooted;
85146 +#endif
85147 +
85148 +} __randomize_layout;
85149 +
85150 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85151 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85152 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85153 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85154 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85155 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85156 +
85157 +#ifdef CONFIG_PAX_SOFTMODE
85158 +extern int pax_softmode;
85159 +#endif
85160 +
85161 +extern int pax_check_flags(unsigned long *);
85162 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85163 +
85164 +/* if tsk != current then task_lock must be held on it */
85165 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85166 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
85167 +{
85168 + if (likely(tsk->mm))
85169 + return tsk->mm->pax_flags;
85170 + else
85171 + return 0UL;
85172 +}
85173 +
85174 +/* if tsk != current then task_lock must be held on it */
85175 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85176 +{
85177 + if (likely(tsk->mm)) {
85178 + tsk->mm->pax_flags = flags;
85179 + return 0;
85180 + }
85181 + return -EINVAL;
85182 +}
85183 +#endif
85184 +
85185 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85186 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
85187 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85188 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85189 +#endif
85190 +
85191 +struct path;
85192 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85193 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85194 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85195 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
85196
85197 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85198 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85199 @@ -1743,7 +1857,7 @@ struct pid_namespace;
85200 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85201 struct pid_namespace *ns);
85202
85203 -static inline pid_t task_pid_nr(struct task_struct *tsk)
85204 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
85205 {
85206 return tsk->pid;
85207 }
85208 @@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
85209
85210 extern void sched_clock_init(void);
85211
85212 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85213 +static inline void populate_stack(void)
85214 +{
85215 + struct task_struct *curtask = current;
85216 + int c;
85217 + int *ptr = curtask->stack;
85218 + int *end = curtask->stack + THREAD_SIZE;
85219 +
85220 + while (ptr < end) {
85221 + c = *(volatile int *)ptr;
85222 + ptr += PAGE_SIZE/sizeof(int);
85223 + }
85224 +}
85225 +#else
85226 +static inline void populate_stack(void)
85227 +{
85228 +}
85229 +#endif
85230 +
85231 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85232 static inline void sched_clock_tick(void)
85233 {
85234 @@ -2239,7 +2372,9 @@ void yield(void);
85235 extern struct exec_domain default_exec_domain;
85236
85237 union thread_union {
85238 +#ifndef CONFIG_X86
85239 struct thread_info thread_info;
85240 +#endif
85241 unsigned long stack[THREAD_SIZE/sizeof(long)];
85242 };
85243
85244 @@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
85245 */
85246
85247 extern struct task_struct *find_task_by_vpid(pid_t nr);
85248 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85249 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85250 struct pid_namespace *ns);
85251
85252 @@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85253 extern void exit_itimers(struct signal_struct *);
85254 extern void flush_itimer_signals(void);
85255
85256 -extern void do_group_exit(int);
85257 +extern __noreturn void do_group_exit(int);
85258
85259 extern int do_execve(struct filename *,
85260 const char __user * const __user *,
85261 @@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85262 #define task_stack_end_corrupted(task) \
85263 (*(end_of_stack(task)) != STACK_END_MAGIC)
85264
85265 -static inline int object_is_on_stack(void *obj)
85266 +static inline int object_starts_on_stack(const void *obj)
85267 {
85268 - void *stack = task_stack_page(current);
85269 + const void *stack = task_stack_page(current);
85270
85271 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85272 }
85273 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85274 index 596a0e0..bea77ec 100644
85275 --- a/include/linux/sched/sysctl.h
85276 +++ b/include/linux/sched/sysctl.h
85277 @@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85278 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85279
85280 extern int sysctl_max_map_count;
85281 +extern unsigned long sysctl_heap_stack_gap;
85282
85283 extern unsigned int sysctl_sched_latency;
85284 extern unsigned int sysctl_sched_min_granularity;
85285 diff --git a/include/linux/security.h b/include/linux/security.h
85286 index ba96471..74fb3f6 100644
85287 --- a/include/linux/security.h
85288 +++ b/include/linux/security.h
85289 @@ -27,6 +27,7 @@
85290 #include <linux/slab.h>
85291 #include <linux/err.h>
85292 #include <linux/string.h>
85293 +#include <linux/grsecurity.h>
85294
85295 struct linux_binprm;
85296 struct cred;
85297 @@ -116,8 +117,6 @@ struct seq_file;
85298
85299 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85300
85301 -void reset_security_ops(void);
85302 -
85303 #ifdef CONFIG_MMU
85304 extern unsigned long mmap_min_addr;
85305 extern unsigned long dac_mmap_min_addr;
85306 @@ -1729,7 +1728,7 @@ struct security_operations {
85307 struct audit_context *actx);
85308 void (*audit_rule_free) (void *lsmrule);
85309 #endif /* CONFIG_AUDIT */
85310 -};
85311 +} __randomize_layout;
85312
85313 /* prototypes */
85314 extern int security_init(void);
85315 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85316 index dc368b8..e895209 100644
85317 --- a/include/linux/semaphore.h
85318 +++ b/include/linux/semaphore.h
85319 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85320 }
85321
85322 extern void down(struct semaphore *sem);
85323 -extern int __must_check down_interruptible(struct semaphore *sem);
85324 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85325 extern int __must_check down_killable(struct semaphore *sem);
85326 extern int __must_check down_trylock(struct semaphore *sem);
85327 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85328 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85329 index 52e0097..383f21d 100644
85330 --- a/include/linux/seq_file.h
85331 +++ b/include/linux/seq_file.h
85332 @@ -27,6 +27,9 @@ struct seq_file {
85333 struct mutex lock;
85334 const struct seq_operations *op;
85335 int poll_event;
85336 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85337 + u64 exec_id;
85338 +#endif
85339 #ifdef CONFIG_USER_NS
85340 struct user_namespace *user_ns;
85341 #endif
85342 @@ -39,6 +42,7 @@ struct seq_operations {
85343 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85344 int (*show) (struct seq_file *m, void *v);
85345 };
85346 +typedef struct seq_operations __no_const seq_operations_no_const;
85347
85348 #define SEQ_SKIP 1
85349
85350 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85351
85352 char *mangle_path(char *s, const char *p, const char *esc);
85353 int seq_open(struct file *, const struct seq_operations *);
85354 +int seq_open_restrict(struct file *, const struct seq_operations *);
85355 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85356 loff_t seq_lseek(struct file *, loff_t, int);
85357 int seq_release(struct inode *, struct file *);
85358 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85359 }
85360
85361 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85362 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85363 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85364 int single_release(struct inode *, struct file *);
85365 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85366 diff --git a/include/linux/shm.h b/include/linux/shm.h
85367 index 6fb8016..ab4465e 100644
85368 --- a/include/linux/shm.h
85369 +++ b/include/linux/shm.h
85370 @@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85371 /* The task created the shm object. NULL if the task is dead. */
85372 struct task_struct *shm_creator;
85373 struct list_head shm_clist; /* list by creator */
85374 +#ifdef CONFIG_GRKERNSEC
85375 + u64 shm_createtime;
85376 + pid_t shm_lapid;
85377 +#endif
85378 };
85379
85380 /* shm_mode upper byte flags */
85381 diff --git a/include/linux/signal.h b/include/linux/signal.h
85382 index ab1e039..ad4229e 100644
85383 --- a/include/linux/signal.h
85384 +++ b/include/linux/signal.h
85385 @@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85386 * know it'll be handled, so that they don't get converted to
85387 * SIGKILL or just silently dropped.
85388 */
85389 - kernel_sigaction(sig, (__force __sighandler_t)2);
85390 + kernel_sigaction(sig, (__force_user __sighandler_t)2);
85391 }
85392
85393 static inline void disallow_signal(int sig)
85394 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85395 index 6c8b6f6..5a0f4bd 100644
85396 --- a/include/linux/skbuff.h
85397 +++ b/include/linux/skbuff.h
85398 @@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85399 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85400 int node);
85401 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85402 -static inline struct sk_buff *alloc_skb(unsigned int size,
85403 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85404 gfp_t priority)
85405 {
85406 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85407 @@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85408 return skb->inner_transport_header - skb->inner_network_header;
85409 }
85410
85411 -static inline int skb_network_offset(const struct sk_buff *skb)
85412 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85413 {
85414 return skb_network_header(skb) - skb->data;
85415 }
85416 @@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85417 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85418 */
85419 #ifndef NET_SKB_PAD
85420 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85421 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85422 #endif
85423
85424 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85425 @@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85426 int *err);
85427 unsigned int datagram_poll(struct file *file, struct socket *sock,
85428 struct poll_table_struct *wait);
85429 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85430 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85431 struct iovec *to, int size);
85432 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85433 struct iovec *iov);
85434 @@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85435 nf_bridge_put(skb->nf_bridge);
85436 skb->nf_bridge = NULL;
85437 #endif
85438 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85439 + skb->nf_trace = 0;
85440 +#endif
85441 }
85442
85443 static inline void nf_reset_trace(struct sk_buff *skb)
85444 diff --git a/include/linux/slab.h b/include/linux/slab.h
85445 index c265bec..4867d28 100644
85446 --- a/include/linux/slab.h
85447 +++ b/include/linux/slab.h
85448 @@ -14,15 +14,29 @@
85449 #include <linux/gfp.h>
85450 #include <linux/types.h>
85451 #include <linux/workqueue.h>
85452 -
85453 +#include <linux/err.h>
85454
85455 /*
85456 * Flags to pass to kmem_cache_create().
85457 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85458 */
85459 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85460 +
85461 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85462 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85463 +#else
85464 +#define SLAB_USERCOPY 0x00000000UL
85465 +#endif
85466 +
85467 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85468 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85469 +
85470 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85471 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85472 +#else
85473 +#define SLAB_NO_SANITIZE 0x00000000UL
85474 +#endif
85475 +
85476 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85477 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85478 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85479 @@ -98,10 +112,13 @@
85480 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85481 * Both make kfree a no-op.
85482 */
85483 -#define ZERO_SIZE_PTR ((void *)16)
85484 +#define ZERO_SIZE_PTR \
85485 +({ \
85486 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85487 + (void *)(-MAX_ERRNO-1L); \
85488 +})
85489
85490 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85491 - (unsigned long)ZERO_SIZE_PTR)
85492 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85493
85494 #include <linux/kmemleak.h>
85495
85496 @@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85497 void kfree(const void *);
85498 void kzfree(const void *);
85499 size_t ksize(const void *);
85500 +const char *check_heap_object(const void *ptr, unsigned long n);
85501 +bool is_usercopy_object(const void *ptr);
85502
85503 /*
85504 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85505 @@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85506 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85507 #endif
85508
85509 +#ifdef CONFIG_PAX_USERCOPY_SLABS
85510 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85511 +#endif
85512 +
85513 /*
85514 * Figure out which kmalloc slab an allocation of a certain size
85515 * belongs to.
85516 @@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85517 * 2 = 120 .. 192 bytes
85518 * n = 2^(n-1) .. 2^n -1
85519 */
85520 -static __always_inline int kmalloc_index(size_t size)
85521 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85522 {
85523 if (!size)
85524 return 0;
85525 @@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85526 }
85527 #endif /* !CONFIG_SLOB */
85528
85529 -void *__kmalloc(size_t size, gfp_t flags);
85530 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85531 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85532
85533 #ifdef CONFIG_NUMA
85534 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
85535 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85536 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85537 #else
85538 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85539 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85540 index b869d16..1453c73 100644
85541 --- a/include/linux/slab_def.h
85542 +++ b/include/linux/slab_def.h
85543 @@ -40,7 +40,7 @@ struct kmem_cache {
85544 /* 4) cache creation/removal */
85545 const char *name;
85546 struct list_head list;
85547 - int refcount;
85548 + atomic_t refcount;
85549 int object_size;
85550 int align;
85551
85552 @@ -56,10 +56,14 @@ struct kmem_cache {
85553 unsigned long node_allocs;
85554 unsigned long node_frees;
85555 unsigned long node_overflow;
85556 - atomic_t allochit;
85557 - atomic_t allocmiss;
85558 - atomic_t freehit;
85559 - atomic_t freemiss;
85560 + atomic_unchecked_t allochit;
85561 + atomic_unchecked_t allocmiss;
85562 + atomic_unchecked_t freehit;
85563 + atomic_unchecked_t freemiss;
85564 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
85565 + atomic_unchecked_t sanitized;
85566 + atomic_unchecked_t not_sanitized;
85567 +#endif
85568
85569 /*
85570 * If debugging is enabled, then the allocator can add additional
85571 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85572 index d82abd4..408c3a0 100644
85573 --- a/include/linux/slub_def.h
85574 +++ b/include/linux/slub_def.h
85575 @@ -74,7 +74,7 @@ struct kmem_cache {
85576 struct kmem_cache_order_objects max;
85577 struct kmem_cache_order_objects min;
85578 gfp_t allocflags; /* gfp flags to use on each alloc */
85579 - int refcount; /* Refcount for slab cache destroy */
85580 + atomic_t refcount; /* Refcount for slab cache destroy */
85581 void (*ctor)(void *);
85582 int inuse; /* Offset to metadata */
85583 int align; /* Alignment */
85584 diff --git a/include/linux/smp.h b/include/linux/smp.h
85585 index 93dff5f..933c561 100644
85586 --- a/include/linux/smp.h
85587 +++ b/include/linux/smp.h
85588 @@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85589 #endif
85590
85591 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85592 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85593 #define put_cpu() preempt_enable()
85594 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85595
85596 /*
85597 * Callback to arch code if there's nosmp or maxcpus=0 on the
85598 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85599 index 46cca4c..3323536 100644
85600 --- a/include/linux/sock_diag.h
85601 +++ b/include/linux/sock_diag.h
85602 @@ -11,7 +11,7 @@ struct sock;
85603 struct sock_diag_handler {
85604 __u8 family;
85605 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85606 -};
85607 +} __do_const;
85608
85609 int sock_diag_register(const struct sock_diag_handler *h);
85610 void sock_diag_unregister(const struct sock_diag_handler *h);
85611 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85612 index 680f9a3..f13aeb0 100644
85613 --- a/include/linux/sonet.h
85614 +++ b/include/linux/sonet.h
85615 @@ -7,7 +7,7 @@
85616 #include <uapi/linux/sonet.h>
85617
85618 struct k_sonet_stats {
85619 -#define __HANDLE_ITEM(i) atomic_t i
85620 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
85621 __SONET_ITEMS
85622 #undef __HANDLE_ITEM
85623 };
85624 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85625 index 07d8e53..dc934c9 100644
85626 --- a/include/linux/sunrpc/addr.h
85627 +++ b/include/linux/sunrpc/addr.h
85628 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85629 {
85630 switch (sap->sa_family) {
85631 case AF_INET:
85632 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
85633 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85634 case AF_INET6:
85635 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85636 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85637 }
85638 return 0;
85639 }
85640 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85641 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85642 const struct sockaddr *src)
85643 {
85644 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85645 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85646 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85647
85648 dsin->sin_family = ssin->sin_family;
85649 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85650 if (sa->sa_family != AF_INET6)
85651 return 0;
85652
85653 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85654 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85655 }
85656
85657 #endif /* _LINUX_SUNRPC_ADDR_H */
85658 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85659 index b363a0f..f09861d 100644
85660 --- a/include/linux/sunrpc/clnt.h
85661 +++ b/include/linux/sunrpc/clnt.h
85662 @@ -97,7 +97,7 @@ struct rpc_procinfo {
85663 unsigned int p_timer; /* Which RTT timer to use */
85664 u32 p_statidx; /* Which procedure to account */
85665 const char * p_name; /* name of procedure */
85666 -};
85667 +} __do_const;
85668
85669 #ifdef __KERNEL__
85670
85671 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85672 index 2167846..0648fc3 100644
85673 --- a/include/linux/sunrpc/svc.h
85674 +++ b/include/linux/sunrpc/svc.h
85675 @@ -416,7 +416,7 @@ struct svc_procedure {
85676 unsigned int pc_count; /* call count */
85677 unsigned int pc_cachetype; /* cache info (NFS) */
85678 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85679 -};
85680 +} __do_const;
85681
85682 /*
85683 * Function prototypes.
85684 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85685 index 975da75..318c083 100644
85686 --- a/include/linux/sunrpc/svc_rdma.h
85687 +++ b/include/linux/sunrpc/svc_rdma.h
85688 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85689 extern unsigned int svcrdma_max_requests;
85690 extern unsigned int svcrdma_max_req_size;
85691
85692 -extern atomic_t rdma_stat_recv;
85693 -extern atomic_t rdma_stat_read;
85694 -extern atomic_t rdma_stat_write;
85695 -extern atomic_t rdma_stat_sq_starve;
85696 -extern atomic_t rdma_stat_rq_starve;
85697 -extern atomic_t rdma_stat_rq_poll;
85698 -extern atomic_t rdma_stat_rq_prod;
85699 -extern atomic_t rdma_stat_sq_poll;
85700 -extern atomic_t rdma_stat_sq_prod;
85701 +extern atomic_unchecked_t rdma_stat_recv;
85702 +extern atomic_unchecked_t rdma_stat_read;
85703 +extern atomic_unchecked_t rdma_stat_write;
85704 +extern atomic_unchecked_t rdma_stat_sq_starve;
85705 +extern atomic_unchecked_t rdma_stat_rq_starve;
85706 +extern atomic_unchecked_t rdma_stat_rq_poll;
85707 +extern atomic_unchecked_t rdma_stat_rq_prod;
85708 +extern atomic_unchecked_t rdma_stat_sq_poll;
85709 +extern atomic_unchecked_t rdma_stat_sq_prod;
85710
85711 #define RPCRDMA_VERSION 1
85712
85713 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85714 index 8d71d65..f79586e 100644
85715 --- a/include/linux/sunrpc/svcauth.h
85716 +++ b/include/linux/sunrpc/svcauth.h
85717 @@ -120,7 +120,7 @@ struct auth_ops {
85718 int (*release)(struct svc_rqst *rq);
85719 void (*domain_release)(struct auth_domain *);
85720 int (*set_client)(struct svc_rqst *rq);
85721 -};
85722 +} __do_const;
85723
85724 #define SVC_GARBAGE 1
85725 #define SVC_SYSERR 2
85726 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85727 index e7a018e..49f8b17 100644
85728 --- a/include/linux/swiotlb.h
85729 +++ b/include/linux/swiotlb.h
85730 @@ -60,7 +60,8 @@ extern void
85731
85732 extern void
85733 swiotlb_free_coherent(struct device *hwdev, size_t size,
85734 - void *vaddr, dma_addr_t dma_handle);
85735 + void *vaddr, dma_addr_t dma_handle,
85736 + struct dma_attrs *attrs);
85737
85738 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85739 unsigned long offset, size_t size,
85740 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85741 index bda9b81..629e06e 100644
85742 --- a/include/linux/syscalls.h
85743 +++ b/include/linux/syscalls.h
85744 @@ -99,10 +99,16 @@ union bpf_attr;
85745 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85746
85747 #define __SC_DECL(t, a) t a
85748 +#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))
85749 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85750 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85751 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85752 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85753 +#define __SC_LONG(t, a) __typeof( \
85754 + __builtin_choose_expr( \
85755 + sizeof(t) > sizeof(int), \
85756 + (t) 0, \
85757 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85758 + )) a
85759 #define __SC_CAST(t, a) (t) a
85760 #define __SC_ARGS(t, a) a
85761 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85762 @@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85763 asmlinkage long sys_fsync(unsigned int fd);
85764 asmlinkage long sys_fdatasync(unsigned int fd);
85765 asmlinkage long sys_bdflush(int func, long data);
85766 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85767 - char __user *type, unsigned long flags,
85768 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85769 + const char __user *type, unsigned long flags,
85770 void __user *data);
85771 -asmlinkage long sys_umount(char __user *name, int flags);
85772 -asmlinkage long sys_oldumount(char __user *name);
85773 +asmlinkage long sys_umount(const char __user *name, int flags);
85774 +asmlinkage long sys_oldumount(const char __user *name);
85775 asmlinkage long sys_truncate(const char __user *path, long length);
85776 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85777 asmlinkage long sys_stat(const char __user *filename,
85778 @@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85779 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85780 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85781 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85782 - struct sockaddr __user *, int);
85783 + struct sockaddr __user *, int) __intentional_overflow(0);
85784 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85785 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85786 unsigned int vlen, unsigned flags);
85787 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85788 index 27b3b0b..e093dd9 100644
85789 --- a/include/linux/syscore_ops.h
85790 +++ b/include/linux/syscore_ops.h
85791 @@ -16,7 +16,7 @@ struct syscore_ops {
85792 int (*suspend)(void);
85793 void (*resume)(void);
85794 void (*shutdown)(void);
85795 -};
85796 +} __do_const;
85797
85798 extern void register_syscore_ops(struct syscore_ops *ops);
85799 extern void unregister_syscore_ops(struct syscore_ops *ops);
85800 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85801 index b7361f8..341a15a 100644
85802 --- a/include/linux/sysctl.h
85803 +++ b/include/linux/sysctl.h
85804 @@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85805
85806 extern int proc_dostring(struct ctl_table *, int,
85807 void __user *, size_t *, loff_t *);
85808 +extern int proc_dostring_modpriv(struct ctl_table *, int,
85809 + void __user *, size_t *, loff_t *);
85810 extern int proc_dointvec(struct ctl_table *, int,
85811 void __user *, size_t *, loff_t *);
85812 extern int proc_dointvec_minmax(struct ctl_table *, int,
85813 @@ -113,7 +115,8 @@ struct ctl_table
85814 struct ctl_table_poll *poll;
85815 void *extra1;
85816 void *extra2;
85817 -};
85818 +} __do_const __randomize_layout;
85819 +typedef struct ctl_table __no_const ctl_table_no_const;
85820
85821 struct ctl_node {
85822 struct rb_node node;
85823 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85824 index f97d0db..c1187dc 100644
85825 --- a/include/linux/sysfs.h
85826 +++ b/include/linux/sysfs.h
85827 @@ -34,7 +34,8 @@ struct attribute {
85828 struct lock_class_key *key;
85829 struct lock_class_key skey;
85830 #endif
85831 -};
85832 +} __do_const;
85833 +typedef struct attribute __no_const attribute_no_const;
85834
85835 /**
85836 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85837 @@ -63,7 +64,8 @@ struct attribute_group {
85838 struct attribute *, int);
85839 struct attribute **attrs;
85840 struct bin_attribute **bin_attrs;
85841 -};
85842 +} __do_const;
85843 +typedef struct attribute_group __no_const attribute_group_no_const;
85844
85845 /**
85846 * Use these macros to make defining attributes easier. See include/linux/device.h
85847 @@ -128,7 +130,8 @@ struct bin_attribute {
85848 char *, loff_t, size_t);
85849 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85850 struct vm_area_struct *vma);
85851 -};
85852 +} __do_const;
85853 +typedef struct bin_attribute __no_const bin_attribute_no_const;
85854
85855 /**
85856 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85857 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85858 index 387fa7d..3fcde6b 100644
85859 --- a/include/linux/sysrq.h
85860 +++ b/include/linux/sysrq.h
85861 @@ -16,6 +16,7 @@
85862
85863 #include <linux/errno.h>
85864 #include <linux/types.h>
85865 +#include <linux/compiler.h>
85866
85867 /* Possible values of bitmask for enabling sysrq functions */
85868 /* 0x0001 is reserved for enable everything */
85869 @@ -33,7 +34,7 @@ struct sysrq_key_op {
85870 char *help_msg;
85871 char *action_msg;
85872 int enable_mask;
85873 -};
85874 +} __do_const;
85875
85876 #ifdef CONFIG_MAGIC_SYSRQ
85877
85878 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85879 index ff307b5..f1a4468 100644
85880 --- a/include/linux/thread_info.h
85881 +++ b/include/linux/thread_info.h
85882 @@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85883 #error "no set_restore_sigmask() provided and default one won't work"
85884 #endif
85885
85886 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85887 +
85888 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85889 +{
85890 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85891 +}
85892 +
85893 #endif /* __KERNEL__ */
85894
85895 #endif /* _LINUX_THREAD_INFO_H */
85896 diff --git a/include/linux/tty.h b/include/linux/tty.h
85897 index 5171ef8..1048d83e 100644
85898 --- a/include/linux/tty.h
85899 +++ b/include/linux/tty.h
85900 @@ -202,7 +202,7 @@ struct tty_port {
85901 const struct tty_port_operations *ops; /* Port operations */
85902 spinlock_t lock; /* Lock protecting tty field */
85903 int blocked_open; /* Waiting to open */
85904 - int count; /* Usage count */
85905 + atomic_t count; /* Usage count */
85906 wait_queue_head_t open_wait; /* Open waiters */
85907 wait_queue_head_t close_wait; /* Close waiters */
85908 wait_queue_head_t delta_msr_wait; /* Modem status change */
85909 @@ -290,7 +290,7 @@ struct tty_struct {
85910 /* If the tty has a pending do_SAK, queue it here - akpm */
85911 struct work_struct SAK_work;
85912 struct tty_port *port;
85913 -};
85914 +} __randomize_layout;
85915
85916 /* Each of a tty's open files has private_data pointing to tty_file_private */
85917 struct tty_file_private {
85918 @@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85919 struct tty_struct *tty, struct file *filp);
85920 static inline int tty_port_users(struct tty_port *port)
85921 {
85922 - return port->count + port->blocked_open;
85923 + return atomic_read(&port->count) + port->blocked_open;
85924 }
85925
85926 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85927 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85928 index 92e337c..f46757b 100644
85929 --- a/include/linux/tty_driver.h
85930 +++ b/include/linux/tty_driver.h
85931 @@ -291,7 +291,7 @@ struct tty_operations {
85932 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85933 #endif
85934 const struct file_operations *proc_fops;
85935 -};
85936 +} __do_const __randomize_layout;
85937
85938 struct tty_driver {
85939 int magic; /* magic number for this structure */
85940 @@ -325,7 +325,7 @@ struct tty_driver {
85941
85942 const struct tty_operations *ops;
85943 struct list_head tty_drivers;
85944 -};
85945 +} __randomize_layout;
85946
85947 extern struct list_head tty_drivers;
85948
85949 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85950 index 00c9d68..bc0188b 100644
85951 --- a/include/linux/tty_ldisc.h
85952 +++ b/include/linux/tty_ldisc.h
85953 @@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85954
85955 struct module *owner;
85956
85957 - int refcount;
85958 + atomic_t refcount;
85959 };
85960
85961 struct tty_ldisc {
85962 diff --git a/include/linux/types.h b/include/linux/types.h
85963 index a0bb704..f511c77 100644
85964 --- a/include/linux/types.h
85965 +++ b/include/linux/types.h
85966 @@ -177,10 +177,26 @@ typedef struct {
85967 int counter;
85968 } atomic_t;
85969
85970 +#ifdef CONFIG_PAX_REFCOUNT
85971 +typedef struct {
85972 + int counter;
85973 +} atomic_unchecked_t;
85974 +#else
85975 +typedef atomic_t atomic_unchecked_t;
85976 +#endif
85977 +
85978 #ifdef CONFIG_64BIT
85979 typedef struct {
85980 long counter;
85981 } atomic64_t;
85982 +
85983 +#ifdef CONFIG_PAX_REFCOUNT
85984 +typedef struct {
85985 + long counter;
85986 +} atomic64_unchecked_t;
85987 +#else
85988 +typedef atomic64_t atomic64_unchecked_t;
85989 +#endif
85990 #endif
85991
85992 struct list_head {
85993 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85994 index ecd3319..8a36ded 100644
85995 --- a/include/linux/uaccess.h
85996 +++ b/include/linux/uaccess.h
85997 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85998 long ret; \
85999 mm_segment_t old_fs = get_fs(); \
86000 \
86001 - set_fs(KERNEL_DS); \
86002 pagefault_disable(); \
86003 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86004 - pagefault_enable(); \
86005 + set_fs(KERNEL_DS); \
86006 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86007 set_fs(old_fs); \
86008 + pagefault_enable(); \
86009 ret; \
86010 })
86011
86012 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86013 index 2d1f9b6..d7a9fce 100644
86014 --- a/include/linux/uidgid.h
86015 +++ b/include/linux/uidgid.h
86016 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86017
86018 #endif /* CONFIG_USER_NS */
86019
86020 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86021 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86022 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86023 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86024 +
86025 #endif /* _LINUX_UIDGID_H */
86026 diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
86027 index baa8171..9ca98ba 100644
86028 --- a/include/linux/uio_driver.h
86029 +++ b/include/linux/uio_driver.h
86030 @@ -67,7 +67,7 @@ struct uio_device {
86031 struct module *owner;
86032 struct device *dev;
86033 int minor;
86034 - atomic_t event;
86035 + atomic_unchecked_t event;
86036 struct fasync_struct *async_queue;
86037 wait_queue_head_t wait;
86038 struct uio_info *info;
86039 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86040 index 99c1b4d..562e6f3 100644
86041 --- a/include/linux/unaligned/access_ok.h
86042 +++ b/include/linux/unaligned/access_ok.h
86043 @@ -4,34 +4,34 @@
86044 #include <linux/kernel.h>
86045 #include <asm/byteorder.h>
86046
86047 -static inline u16 get_unaligned_le16(const void *p)
86048 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86049 {
86050 - return le16_to_cpup((__le16 *)p);
86051 + return le16_to_cpup((const __le16 *)p);
86052 }
86053
86054 -static inline u32 get_unaligned_le32(const void *p)
86055 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86056 {
86057 - return le32_to_cpup((__le32 *)p);
86058 + return le32_to_cpup((const __le32 *)p);
86059 }
86060
86061 -static inline u64 get_unaligned_le64(const void *p)
86062 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86063 {
86064 - return le64_to_cpup((__le64 *)p);
86065 + return le64_to_cpup((const __le64 *)p);
86066 }
86067
86068 -static inline u16 get_unaligned_be16(const void *p)
86069 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86070 {
86071 - return be16_to_cpup((__be16 *)p);
86072 + return be16_to_cpup((const __be16 *)p);
86073 }
86074
86075 -static inline u32 get_unaligned_be32(const void *p)
86076 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86077 {
86078 - return be32_to_cpup((__be32 *)p);
86079 + return be32_to_cpup((const __be32 *)p);
86080 }
86081
86082 -static inline u64 get_unaligned_be64(const void *p)
86083 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86084 {
86085 - return be64_to_cpup((__be64 *)p);
86086 + return be64_to_cpup((const __be64 *)p);
86087 }
86088
86089 static inline void put_unaligned_le16(u16 val, void *p)
86090 diff --git a/include/linux/usb.h b/include/linux/usb.h
86091 index 3827bff..f1730fc 100644
86092 --- a/include/linux/usb.h
86093 +++ b/include/linux/usb.h
86094 @@ -566,7 +566,7 @@ struct usb_device {
86095 int maxchild;
86096
86097 u32 quirks;
86098 - atomic_t urbnum;
86099 + atomic_unchecked_t urbnum;
86100
86101 unsigned long active_duration;
86102
86103 @@ -1650,7 +1650,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86104
86105 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86106 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86107 - void *data, __u16 size, int timeout);
86108 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
86109 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86110 void *data, int len, int *actual_length, int timeout);
86111 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86112 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86113 index d5952bb..9a626d4 100644
86114 --- a/include/linux/usb/renesas_usbhs.h
86115 +++ b/include/linux/usb/renesas_usbhs.h
86116 @@ -39,7 +39,7 @@ enum {
86117 */
86118 struct renesas_usbhs_driver_callback {
86119 int (*notify_hotplug)(struct platform_device *pdev);
86120 -};
86121 +} __no_const;
86122
86123 /*
86124 * callback functions for platform
86125 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86126 index 9f3579f..3b2afa5 100644
86127 --- a/include/linux/user_namespace.h
86128 +++ b/include/linux/user_namespace.h
86129 @@ -38,7 +38,7 @@ struct user_namespace {
86130 struct key *persistent_keyring_register;
86131 struct rw_semaphore persistent_keyring_register_sem;
86132 #endif
86133 -};
86134 +} __randomize_layout;
86135
86136 extern struct user_namespace init_user_ns;
86137
86138 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86139 index 239e277..22a5cf5 100644
86140 --- a/include/linux/utsname.h
86141 +++ b/include/linux/utsname.h
86142 @@ -24,7 +24,7 @@ struct uts_namespace {
86143 struct new_utsname name;
86144 struct user_namespace *user_ns;
86145 unsigned int proc_inum;
86146 -};
86147 +} __randomize_layout;
86148 extern struct uts_namespace init_uts_ns;
86149
86150 #ifdef CONFIG_UTS_NS
86151 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86152 index 6f8fbcf..4efc177 100644
86153 --- a/include/linux/vermagic.h
86154 +++ b/include/linux/vermagic.h
86155 @@ -25,9 +25,42 @@
86156 #define MODULE_ARCH_VERMAGIC ""
86157 #endif
86158
86159 +#ifdef CONFIG_PAX_REFCOUNT
86160 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
86161 +#else
86162 +#define MODULE_PAX_REFCOUNT ""
86163 +#endif
86164 +
86165 +#ifdef CONSTIFY_PLUGIN
86166 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86167 +#else
86168 +#define MODULE_CONSTIFY_PLUGIN ""
86169 +#endif
86170 +
86171 +#ifdef STACKLEAK_PLUGIN
86172 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86173 +#else
86174 +#define MODULE_STACKLEAK_PLUGIN ""
86175 +#endif
86176 +
86177 +#ifdef RANDSTRUCT_PLUGIN
86178 +#include <generated/randomize_layout_hash.h>
86179 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86180 +#else
86181 +#define MODULE_RANDSTRUCT_PLUGIN
86182 +#endif
86183 +
86184 +#ifdef CONFIG_GRKERNSEC
86185 +#define MODULE_GRSEC "GRSEC "
86186 +#else
86187 +#define MODULE_GRSEC ""
86188 +#endif
86189 +
86190 #define VERMAGIC_STRING \
86191 UTS_RELEASE " " \
86192 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86193 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86194 - MODULE_ARCH_VERMAGIC
86195 + MODULE_ARCH_VERMAGIC \
86196 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86197 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86198
86199 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86200 index b483abd..af305ad 100644
86201 --- a/include/linux/vga_switcheroo.h
86202 +++ b/include/linux/vga_switcheroo.h
86203 @@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86204
86205 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86206
86207 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86208 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86209 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86210 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86211 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86212 #else
86213
86214 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86215 @@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86216
86217 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86218
86219 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86220 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86221 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86222 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86223 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86224
86225 #endif
86226 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86227 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86228 index b87696f..1d11de7 100644
86229 --- a/include/linux/vmalloc.h
86230 +++ b/include/linux/vmalloc.h
86231 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86232 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86233 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86234 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86235 +
86236 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86237 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86238 +#endif
86239 +
86240 /* bits [20..32] reserved for arch specific ioremap internals */
86241
86242 /*
86243 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86244 unsigned long flags, pgprot_t prot);
86245 extern void vunmap(const void *addr);
86246
86247 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86248 +extern void unmap_process_stacks(struct task_struct *task);
86249 +#endif
86250 +
86251 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86252 unsigned long uaddr, void *kaddr,
86253 unsigned long size);
86254 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86255
86256 /* for /dev/kmem */
86257 extern long vread(char *buf, char *addr, unsigned long count);
86258 -extern long vwrite(char *buf, char *addr, unsigned long count);
86259 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86260
86261 /*
86262 * Internals. Dont't use..
86263 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86264 index 82e7db7..f8ce3d0 100644
86265 --- a/include/linux/vmstat.h
86266 +++ b/include/linux/vmstat.h
86267 @@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86268 /*
86269 * Zone based page accounting with per cpu differentials.
86270 */
86271 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86272 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86273
86274 static inline void zone_page_state_add(long x, struct zone *zone,
86275 enum zone_stat_item item)
86276 {
86277 - atomic_long_add(x, &zone->vm_stat[item]);
86278 - atomic_long_add(x, &vm_stat[item]);
86279 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86280 + atomic_long_add_unchecked(x, &vm_stat[item]);
86281 }
86282
86283 -static inline unsigned long global_page_state(enum zone_stat_item item)
86284 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86285 {
86286 - long x = atomic_long_read(&vm_stat[item]);
86287 + long x = atomic_long_read_unchecked(&vm_stat[item]);
86288 #ifdef CONFIG_SMP
86289 if (x < 0)
86290 x = 0;
86291 @@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86292 return x;
86293 }
86294
86295 -static inline unsigned long zone_page_state(struct zone *zone,
86296 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86297 enum zone_stat_item item)
86298 {
86299 - long x = atomic_long_read(&zone->vm_stat[item]);
86300 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86301 #ifdef CONFIG_SMP
86302 if (x < 0)
86303 x = 0;
86304 @@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86305 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86306 enum zone_stat_item item)
86307 {
86308 - long x = atomic_long_read(&zone->vm_stat[item]);
86309 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86310
86311 #ifdef CONFIG_SMP
86312 int cpu;
86313 @@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86314
86315 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86316 {
86317 - atomic_long_inc(&zone->vm_stat[item]);
86318 - atomic_long_inc(&vm_stat[item]);
86319 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
86320 + atomic_long_inc_unchecked(&vm_stat[item]);
86321 }
86322
86323 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86324 {
86325 - atomic_long_dec(&zone->vm_stat[item]);
86326 - atomic_long_dec(&vm_stat[item]);
86327 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
86328 + atomic_long_dec_unchecked(&vm_stat[item]);
86329 }
86330
86331 static inline void __inc_zone_page_state(struct page *page,
86332 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86333 index 91b0a68..0e9adf6 100644
86334 --- a/include/linux/xattr.h
86335 +++ b/include/linux/xattr.h
86336 @@ -28,7 +28,7 @@ struct xattr_handler {
86337 size_t size, int handler_flags);
86338 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86339 size_t size, int flags, int handler_flags);
86340 -};
86341 +} __do_const;
86342
86343 struct xattr {
86344 const char *name;
86345 @@ -37,6 +37,9 @@ struct xattr {
86346 };
86347
86348 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86349 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86350 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
86351 +#endif
86352 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86353 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86354 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86355 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86356 index 92dbbd3..13ab0b3 100644
86357 --- a/include/linux/zlib.h
86358 +++ b/include/linux/zlib.h
86359 @@ -31,6 +31,7 @@
86360 #define _ZLIB_H
86361
86362 #include <linux/zconf.h>
86363 +#include <linux/compiler.h>
86364
86365 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86366 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86367 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86368
86369 /* basic functions */
86370
86371 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86372 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86373 /*
86374 Returns the number of bytes that needs to be allocated for a per-
86375 stream workspace with the specified parameters. A pointer to this
86376 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86377 index eb76cfd..9fd0e7c 100644
86378 --- a/include/media/v4l2-dev.h
86379 +++ b/include/media/v4l2-dev.h
86380 @@ -75,7 +75,7 @@ struct v4l2_file_operations {
86381 int (*mmap) (struct file *, struct vm_area_struct *);
86382 int (*open) (struct file *);
86383 int (*release) (struct file *);
86384 -};
86385 +} __do_const;
86386
86387 /*
86388 * Newer version of video_device, handled by videodev2.c
86389 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86390 index ffb69da..040393e 100644
86391 --- a/include/media/v4l2-device.h
86392 +++ b/include/media/v4l2-device.h
86393 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86394 this function returns 0. If the name ends with a digit (e.g. cx18),
86395 then the name will be set to cx18-0 since cx180 looks really odd. */
86396 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86397 - atomic_t *instance);
86398 + atomic_unchecked_t *instance);
86399
86400 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86401 Since the parent disappears this ensures that v4l2_dev doesn't have an
86402 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86403 index 2a25dec..bf6dd8a 100644
86404 --- a/include/net/9p/transport.h
86405 +++ b/include/net/9p/transport.h
86406 @@ -62,7 +62,7 @@ struct p9_trans_module {
86407 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86408 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86409 char *, char *, int , int, int, int);
86410 -};
86411 +} __do_const;
86412
86413 void v9fs_register_trans(struct p9_trans_module *m);
86414 void v9fs_unregister_trans(struct p9_trans_module *m);
86415 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86416 index a175ba4..196eb8242 100644
86417 --- a/include/net/af_unix.h
86418 +++ b/include/net/af_unix.h
86419 @@ -36,7 +36,7 @@ struct unix_skb_parms {
86420 u32 secid; /* Security ID */
86421 #endif
86422 u32 consumed;
86423 -};
86424 +} __randomize_layout;
86425
86426 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86427 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86428 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86429 index ead99f0..6263c4b 100644
86430 --- a/include/net/bluetooth/l2cap.h
86431 +++ b/include/net/bluetooth/l2cap.h
86432 @@ -608,7 +608,7 @@ struct l2cap_ops {
86433 unsigned char *kdata,
86434 struct iovec *iov,
86435 int len);
86436 -};
86437 +} __do_const;
86438
86439 struct l2cap_conn {
86440 struct hci_conn *hcon;
86441 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86442 index f2ae33d..c457cf0 100644
86443 --- a/include/net/caif/cfctrl.h
86444 +++ b/include/net/caif/cfctrl.h
86445 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
86446 void (*radioset_rsp)(void);
86447 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86448 struct cflayer *client_layer);
86449 -};
86450 +} __no_const;
86451
86452 /* Link Setup Parameters for CAIF-Links. */
86453 struct cfctrl_link_param {
86454 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
86455 struct cfctrl {
86456 struct cfsrvl serv;
86457 struct cfctrl_rsp res;
86458 - atomic_t req_seq_no;
86459 - atomic_t rsp_seq_no;
86460 + atomic_unchecked_t req_seq_no;
86461 + atomic_unchecked_t rsp_seq_no;
86462 struct list_head list;
86463 /* Protects from simultaneous access to first_req list */
86464 spinlock_t info_list_lock;
86465 diff --git a/include/net/flow.h b/include/net/flow.h
86466 index 8109a15..504466d 100644
86467 --- a/include/net/flow.h
86468 +++ b/include/net/flow.h
86469 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86470
86471 void flow_cache_flush(struct net *net);
86472 void flow_cache_flush_deferred(struct net *net);
86473 -extern atomic_t flow_cache_genid;
86474 +extern atomic_unchecked_t flow_cache_genid;
86475
86476 #endif
86477 diff --git a/include/net/flow_keys.h b/include/net/flow_keys.h
86478 index 7ee2df0..dc8fd81 100644
86479 --- a/include/net/flow_keys.h
86480 +++ b/include/net/flow_keys.h
86481 @@ -22,9 +22,9 @@ struct flow_keys {
86482 __be32 ports;
86483 __be16 port16[2];
86484 };
86485 - u16 thoff;
86486 - u16 n_proto;
86487 - u8 ip_proto;
86488 + u16 thoff;
86489 + __be16 n_proto;
86490 + u8 ip_proto;
86491 };
86492
86493 bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
86494 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86495 index af10c2c..a431cc5 100644
86496 --- a/include/net/genetlink.h
86497 +++ b/include/net/genetlink.h
86498 @@ -120,7 +120,7 @@ struct genl_ops {
86499 u8 cmd;
86500 u8 internal_flags;
86501 u8 flags;
86502 -};
86503 +} __do_const;
86504
86505 int __genl_register_family(struct genl_family *family);
86506
86507 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86508 index 734d9b5..48a9a4b 100644
86509 --- a/include/net/gro_cells.h
86510 +++ b/include/net/gro_cells.h
86511 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86512 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86513
86514 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86515 - atomic_long_inc(&dev->rx_dropped);
86516 + atomic_long_inc_unchecked(&dev->rx_dropped);
86517 kfree_skb(skb);
86518 return;
86519 }
86520 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86521 index 848e85c..051c7de 100644
86522 --- a/include/net/inet_connection_sock.h
86523 +++ b/include/net/inet_connection_sock.h
86524 @@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86525 int (*bind_conflict)(const struct sock *sk,
86526 const struct inet_bind_bucket *tb, bool relax);
86527 void (*mtu_reduced)(struct sock *sk);
86528 -};
86529 +} __do_const;
86530
86531 /** inet_connection_sock - INET connection oriented sock
86532 *
86533 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86534 index 80479ab..0c3f647 100644
86535 --- a/include/net/inetpeer.h
86536 +++ b/include/net/inetpeer.h
86537 @@ -47,7 +47,7 @@ struct inet_peer {
86538 */
86539 union {
86540 struct {
86541 - atomic_t rid; /* Frag reception counter */
86542 + atomic_unchecked_t rid; /* Frag reception counter */
86543 };
86544 struct rcu_head rcu;
86545 struct inet_peer *gc_next;
86546 diff --git a/include/net/ip.h b/include/net/ip.h
86547 index 09cf5ae..ab62fcf 100644
86548 --- a/include/net/ip.h
86549 +++ b/include/net/ip.h
86550 @@ -317,7 +317,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86551 }
86552 }
86553
86554 -u32 ip_idents_reserve(u32 hash, int segs);
86555 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86556 void __ip_select_ident(struct iphdr *iph, int segs);
86557
86558 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86559 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86560 index dc9d2a2..d985691 100644
86561 --- a/include/net/ip_fib.h
86562 +++ b/include/net/ip_fib.h
86563 @@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86564
86565 #define FIB_RES_SADDR(net, res) \
86566 ((FIB_RES_NH(res).nh_saddr_genid == \
86567 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86568 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86569 FIB_RES_NH(res).nh_saddr : \
86570 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86571 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86572 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86573 index 615b20b..fd4cbd8 100644
86574 --- a/include/net/ip_vs.h
86575 +++ b/include/net/ip_vs.h
86576 @@ -534,7 +534,7 @@ struct ip_vs_conn {
86577 struct ip_vs_conn *control; /* Master control connection */
86578 atomic_t n_control; /* Number of controlled ones */
86579 struct ip_vs_dest *dest; /* real server */
86580 - atomic_t in_pkts; /* incoming packet counter */
86581 + atomic_unchecked_t in_pkts; /* incoming packet counter */
86582
86583 /* Packet transmitter for different forwarding methods. If it
86584 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86585 @@ -682,7 +682,7 @@ struct ip_vs_dest {
86586 __be16 port; /* port number of the server */
86587 union nf_inet_addr addr; /* IP address of the server */
86588 volatile unsigned int flags; /* dest status flags */
86589 - atomic_t conn_flags; /* flags to copy to conn */
86590 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
86591 atomic_t weight; /* server weight */
86592
86593 atomic_t refcnt; /* reference counter */
86594 @@ -928,11 +928,11 @@ struct netns_ipvs {
86595 /* ip_vs_lblc */
86596 int sysctl_lblc_expiration;
86597 struct ctl_table_header *lblc_ctl_header;
86598 - struct ctl_table *lblc_ctl_table;
86599 + ctl_table_no_const *lblc_ctl_table;
86600 /* ip_vs_lblcr */
86601 int sysctl_lblcr_expiration;
86602 struct ctl_table_header *lblcr_ctl_header;
86603 - struct ctl_table *lblcr_ctl_table;
86604 + ctl_table_no_const *lblcr_ctl_table;
86605 /* ip_vs_est */
86606 struct list_head est_list; /* estimator list */
86607 spinlock_t est_lock;
86608 diff --git a/include/net/ipv6.h b/include/net/ipv6.h
86609 index 4292929..7e21d2e 100644
86610 --- a/include/net/ipv6.h
86611 +++ b/include/net/ipv6.h
86612 @@ -708,7 +708,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86613 __be32 flowlabel, bool autolabel)
86614 {
86615 if (!flowlabel && (autolabel || net->ipv6.sysctl.auto_flowlabels)) {
86616 - __be32 hash;
86617 + u32 hash;
86618
86619 hash = skb_get_hash(skb);
86620
86621 @@ -718,7 +718,7 @@ static inline __be32 ip6_make_flowlabel(struct net *net, struct sk_buff *skb,
86622 */
86623 hash ^= hash >> 12;
86624
86625 - flowlabel = hash & IPV6_FLOWLABEL_MASK;
86626 + flowlabel = (__force __be32)hash & IPV6_FLOWLABEL_MASK;
86627 }
86628
86629 return flowlabel;
86630 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86631 index 8d4f588..2e37ad2 100644
86632 --- a/include/net/irda/ircomm_tty.h
86633 +++ b/include/net/irda/ircomm_tty.h
86634 @@ -33,6 +33,7 @@
86635 #include <linux/termios.h>
86636 #include <linux/timer.h>
86637 #include <linux/tty.h> /* struct tty_struct */
86638 +#include <asm/local.h>
86639
86640 #include <net/irda/irias_object.h>
86641 #include <net/irda/ircomm_core.h>
86642 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86643 index 714cc9a..ea05f3e 100644
86644 --- a/include/net/iucv/af_iucv.h
86645 +++ b/include/net/iucv/af_iucv.h
86646 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
86647 struct iucv_sock_list {
86648 struct hlist_head head;
86649 rwlock_t lock;
86650 - atomic_t autobind_name;
86651 + atomic_unchecked_t autobind_name;
86652 };
86653
86654 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86655 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86656 index f3be818..bf46196 100644
86657 --- a/include/net/llc_c_ac.h
86658 +++ b/include/net/llc_c_ac.h
86659 @@ -87,7 +87,7 @@
86660 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86661 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86662
86663 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86664 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86665
86666 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86667 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86668 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86669 index 3948cf1..83b28c4 100644
86670 --- a/include/net/llc_c_ev.h
86671 +++ b/include/net/llc_c_ev.h
86672 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86673 return (struct llc_conn_state_ev *)skb->cb;
86674 }
86675
86676 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86677 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86678 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86679 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86680
86681 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86682 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86683 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86684 index 0e79cfb..f46db31 100644
86685 --- a/include/net/llc_c_st.h
86686 +++ b/include/net/llc_c_st.h
86687 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86688 u8 next_state;
86689 llc_conn_ev_qfyr_t *ev_qualifiers;
86690 llc_conn_action_t *ev_actions;
86691 -};
86692 +} __do_const;
86693
86694 struct llc_conn_state {
86695 u8 current_state;
86696 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86697 index a61b98c..aade1eb 100644
86698 --- a/include/net/llc_s_ac.h
86699 +++ b/include/net/llc_s_ac.h
86700 @@ -23,7 +23,7 @@
86701 #define SAP_ACT_TEST_IND 9
86702
86703 /* All action functions must look like this */
86704 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86705 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86706
86707 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86708 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86709 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86710 index 567c681..cd73ac02 100644
86711 --- a/include/net/llc_s_st.h
86712 +++ b/include/net/llc_s_st.h
86713 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86714 llc_sap_ev_t ev;
86715 u8 next_state;
86716 llc_sap_action_t *ev_actions;
86717 -};
86718 +} __do_const;
86719
86720 struct llc_sap_state {
86721 u8 curr_state;
86722 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86723 index a9de1da..df72057 100644
86724 --- a/include/net/mac80211.h
86725 +++ b/include/net/mac80211.h
86726 @@ -4645,7 +4645,7 @@ struct rate_control_ops {
86727 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86728
86729 u32 (*get_expected_throughput)(void *priv_sta);
86730 -};
86731 +} __do_const;
86732
86733 static inline int rate_supported(struct ieee80211_sta *sta,
86734 enum ieee80211_band band,
86735 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86736 index f60558d..e5ed9bd 100644
86737 --- a/include/net/neighbour.h
86738 +++ b/include/net/neighbour.h
86739 @@ -163,7 +163,7 @@ struct neigh_ops {
86740 void (*error_report)(struct neighbour *, struct sk_buff *);
86741 int (*output)(struct neighbour *, struct sk_buff *);
86742 int (*connected_output)(struct neighbour *, struct sk_buff *);
86743 -};
86744 +} __do_const;
86745
86746 struct pneigh_entry {
86747 struct pneigh_entry *next;
86748 @@ -217,7 +217,7 @@ struct neigh_table {
86749 struct neigh_statistics __percpu *stats;
86750 struct neigh_hash_table __rcu *nht;
86751 struct pneigh_entry **phash_buckets;
86752 -};
86753 +} __randomize_layout;
86754
86755 static inline int neigh_parms_family(struct neigh_parms *p)
86756 {
86757 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86758 index e0d6466..e2f3003 100644
86759 --- a/include/net/net_namespace.h
86760 +++ b/include/net/net_namespace.h
86761 @@ -129,8 +129,8 @@ struct net {
86762 struct netns_ipvs *ipvs;
86763 #endif
86764 struct sock *diag_nlsk;
86765 - atomic_t fnhe_genid;
86766 -};
86767 + atomic_unchecked_t fnhe_genid;
86768 +} __randomize_layout;
86769
86770 #include <linux/seq_file_net.h>
86771
86772 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86773 #define __net_init __init
86774 #define __net_exit __exit_refok
86775 #define __net_initdata __initdata
86776 +#ifdef CONSTIFY_PLUGIN
86777 #define __net_initconst __initconst
86778 +#else
86779 +#define __net_initconst __initdata
86780 +#endif
86781 #endif
86782
86783 struct pernet_operations {
86784 @@ -296,7 +300,7 @@ struct pernet_operations {
86785 void (*exit_batch)(struct list_head *net_exit_list);
86786 int *id;
86787 size_t size;
86788 -};
86789 +} __do_const;
86790
86791 /*
86792 * Use these carefully. If you implement a network device and it
86793 @@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86794
86795 static inline int rt_genid_ipv4(struct net *net)
86796 {
86797 - return atomic_read(&net->ipv4.rt_genid);
86798 + return atomic_read_unchecked(&net->ipv4.rt_genid);
86799 }
86800
86801 static inline void rt_genid_bump_ipv4(struct net *net)
86802 {
86803 - atomic_inc(&net->ipv4.rt_genid);
86804 + atomic_inc_unchecked(&net->ipv4.rt_genid);
86805 }
86806
86807 extern void (*__fib6_flush_trees)(struct net *net);
86808 @@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86809
86810 static inline int fnhe_genid(struct net *net)
86811 {
86812 - return atomic_read(&net->fnhe_genid);
86813 + return atomic_read_unchecked(&net->fnhe_genid);
86814 }
86815
86816 static inline void fnhe_genid_bump(struct net *net)
86817 {
86818 - atomic_inc(&net->fnhe_genid);
86819 + atomic_inc_unchecked(&net->fnhe_genid);
86820 }
86821
86822 #endif /* __NET_NET_NAMESPACE_H */
86823 diff --git a/include/net/netlink.h b/include/net/netlink.h
86824 index 7b903e1..ad9ca4b 100644
86825 --- a/include/net/netlink.h
86826 +++ b/include/net/netlink.h
86827 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86828 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86829 {
86830 if (mark)
86831 - skb_trim(skb, (unsigned char *) mark - skb->data);
86832 + skb_trim(skb, (const unsigned char *) mark - skb->data);
86833 }
86834
86835 /**
86836 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86837 index 29d6a94..235d3d84 100644
86838 --- a/include/net/netns/conntrack.h
86839 +++ b/include/net/netns/conntrack.h
86840 @@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86841 struct nf_proto_net {
86842 #ifdef CONFIG_SYSCTL
86843 struct ctl_table_header *ctl_table_header;
86844 - struct ctl_table *ctl_table;
86845 + ctl_table_no_const *ctl_table;
86846 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86847 struct ctl_table_header *ctl_compat_header;
86848 - struct ctl_table *ctl_compat_table;
86849 + ctl_table_no_const *ctl_compat_table;
86850 #endif
86851 #endif
86852 unsigned int users;
86853 @@ -60,7 +60,7 @@ struct nf_ip_net {
86854 struct nf_icmp_net icmpv6;
86855 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86856 struct ctl_table_header *ctl_table_header;
86857 - struct ctl_table *ctl_table;
86858 + ctl_table_no_const *ctl_table;
86859 #endif
86860 };
86861
86862 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86863 index 0ffef1a..2ce1ceb 100644
86864 --- a/include/net/netns/ipv4.h
86865 +++ b/include/net/netns/ipv4.h
86866 @@ -84,7 +84,7 @@ struct netns_ipv4 {
86867
86868 struct ping_group_range ping_group_range;
86869
86870 - atomic_t dev_addr_genid;
86871 + atomic_unchecked_t dev_addr_genid;
86872
86873 #ifdef CONFIG_SYSCTL
86874 unsigned long *sysctl_local_reserved_ports;
86875 @@ -98,6 +98,6 @@ struct netns_ipv4 {
86876 struct fib_rules_ops *mr_rules_ops;
86877 #endif
86878 #endif
86879 - atomic_t rt_genid;
86880 + atomic_unchecked_t rt_genid;
86881 };
86882 #endif
86883 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86884 index 69ae41f..4f94868 100644
86885 --- a/include/net/netns/ipv6.h
86886 +++ b/include/net/netns/ipv6.h
86887 @@ -75,8 +75,8 @@ struct netns_ipv6 {
86888 struct fib_rules_ops *mr6_rules_ops;
86889 #endif
86890 #endif
86891 - atomic_t dev_addr_genid;
86892 - atomic_t fib6_sernum;
86893 + atomic_unchecked_t dev_addr_genid;
86894 + atomic_unchecked_t fib6_sernum;
86895 };
86896
86897 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86898 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86899 index 9da7982..099321b9 100644
86900 --- a/include/net/netns/xfrm.h
86901 +++ b/include/net/netns/xfrm.h
86902 @@ -78,7 +78,7 @@ struct netns_xfrm {
86903
86904 /* flow cache part */
86905 struct flow_cache flow_cache_global;
86906 - atomic_t flow_cache_genid;
86907 + atomic_unchecked_t flow_cache_genid;
86908 struct list_head flow_cache_gc_list;
86909 spinlock_t flow_cache_gc_lock;
86910 struct work_struct flow_cache_gc_work;
86911 diff --git a/include/net/ping.h b/include/net/ping.h
86912 index 026479b..d9b2829 100644
86913 --- a/include/net/ping.h
86914 +++ b/include/net/ping.h
86915 @@ -54,7 +54,7 @@ struct ping_iter_state {
86916
86917 extern struct proto ping_prot;
86918 #if IS_ENABLED(CONFIG_IPV6)
86919 -extern struct pingv6_ops pingv6_ops;
86920 +extern struct pingv6_ops *pingv6_ops;
86921 #endif
86922
86923 struct pingfakehdr {
86924 diff --git a/include/net/protocol.h b/include/net/protocol.h
86925 index d6fcc1f..ca277058 100644
86926 --- a/include/net/protocol.h
86927 +++ b/include/net/protocol.h
86928 @@ -49,7 +49,7 @@ struct net_protocol {
86929 * socket lookup?
86930 */
86931 icmp_strict_tag_validation:1;
86932 -};
86933 +} __do_const;
86934
86935 #if IS_ENABLED(CONFIG_IPV6)
86936 struct inet6_protocol {
86937 @@ -62,7 +62,7 @@ struct inet6_protocol {
86938 u8 type, u8 code, int offset,
86939 __be32 info);
86940 unsigned int flags; /* INET6_PROTO_xxx */
86941 -};
86942 +} __do_const;
86943
86944 #define INET6_PROTO_NOPOLICY 0x1
86945 #define INET6_PROTO_FINAL 0x2
86946 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86947 index e21b9f9..0191ef0 100644
86948 --- a/include/net/rtnetlink.h
86949 +++ b/include/net/rtnetlink.h
86950 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
86951 int (*fill_slave_info)(struct sk_buff *skb,
86952 const struct net_device *dev,
86953 const struct net_device *slave_dev);
86954 -};
86955 +} __do_const;
86956
86957 int __rtnl_link_register(struct rtnl_link_ops *ops);
86958 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86959 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86960 index 4a5b9a3..ca27d73 100644
86961 --- a/include/net/sctp/checksum.h
86962 +++ b/include/net/sctp/checksum.h
86963 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86964 unsigned int offset)
86965 {
86966 struct sctphdr *sh = sctp_hdr(skb);
86967 - __le32 ret, old = sh->checksum;
86968 - const struct skb_checksum_ops ops = {
86969 + __le32 ret, old = sh->checksum;
86970 + static const struct skb_checksum_ops ops = {
86971 .update = sctp_csum_update,
86972 .combine = sctp_csum_combine,
86973 };
86974 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86975 index 72a31db..aaa63d9 100644
86976 --- a/include/net/sctp/sm.h
86977 +++ b/include/net/sctp/sm.h
86978 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86979 typedef struct {
86980 sctp_state_fn_t *fn;
86981 const char *name;
86982 -} sctp_sm_table_entry_t;
86983 +} __do_const sctp_sm_table_entry_t;
86984
86985 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86986 * currently in use.
86987 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86988 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86989
86990 /* Extern declarations for major data structures. */
86991 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86992 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86993
86994
86995 /* Get the size of a DATA chunk payload. */
86996 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86997 index 4ff3f67..89ae38e 100644
86998 --- a/include/net/sctp/structs.h
86999 +++ b/include/net/sctp/structs.h
87000 @@ -509,7 +509,7 @@ struct sctp_pf {
87001 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
87002 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
87003 struct sctp_af *af;
87004 -};
87005 +} __do_const;
87006
87007
87008 /* Structure to track chunk fragments that have been acked, but peer
87009 diff --git a/include/net/sock.h b/include/net/sock.h
87010 index 7db3db1..a915cca 100644
87011 --- a/include/net/sock.h
87012 +++ b/include/net/sock.h
87013 @@ -355,7 +355,7 @@ struct sock {
87014 unsigned int sk_napi_id;
87015 unsigned int sk_ll_usec;
87016 #endif
87017 - atomic_t sk_drops;
87018 + atomic_unchecked_t sk_drops;
87019 int sk_rcvbuf;
87020
87021 struct sk_filter __rcu *sk_filter;
87022 @@ -1048,7 +1048,7 @@ struct proto {
87023 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87024 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87025 #endif
87026 -};
87027 +} __randomize_layout;
87028
87029 /*
87030 * Bits in struct cg_proto.flags
87031 @@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87032 return ret >> PAGE_SHIFT;
87033 }
87034
87035 -static inline long
87036 +static inline long __intentional_overflow(-1)
87037 sk_memory_allocated(const struct sock *sk)
87038 {
87039 struct proto *prot = sk->sk_prot;
87040 @@ -1380,7 +1380,7 @@ struct sock_iocb {
87041 struct scm_cookie *scm;
87042 struct msghdr *msg, async_msg;
87043 struct kiocb *kiocb;
87044 -};
87045 +} __randomize_layout;
87046
87047 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87048 {
87049 @@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87050 }
87051
87052 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87053 - char __user *from, char *to,
87054 + char __user *from, unsigned char *to,
87055 int copy, int offset)
87056 {
87057 if (skb->ip_summed == CHECKSUM_NONE) {
87058 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87059 }
87060 }
87061
87062 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87063 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87064
87065 /**
87066 * sk_page_frag - return an appropriate page_frag
87067 diff --git a/include/net/tcp.h b/include/net/tcp.h
87068 index 4062b4f..9ff45e7 100644
87069 --- a/include/net/tcp.h
87070 +++ b/include/net/tcp.h
87071 @@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
87072 void tcp_xmit_retransmit_queue(struct sock *);
87073 void tcp_simple_retransmit(struct sock *);
87074 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87075 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87076 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87077
87078 void tcp_send_probe0(struct sock *);
87079 void tcp_send_partial(struct sock *);
87080 @@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
87081 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
87082 */
87083 struct tcp_skb_cb {
87084 - __u32 seq; /* Starting sequence number */
87085 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87086 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
87087 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87088 union {
87089 /* Note : tcp_tw_isn is used in input path only
87090 * (isn chosen by tcp_timewait_state_process())
87091 @@ -718,7 +718,7 @@ struct tcp_skb_cb {
87092
87093 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87094 /* 1 byte hole */
87095 - __u32 ack_seq; /* Sequence number ACK'd */
87096 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87097 union {
87098 struct inet_skb_parm h4;
87099 #if IS_ENABLED(CONFIG_IPV6)
87100 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87101 index dc4865e..152ee4c 100644
87102 --- a/include/net/xfrm.h
87103 +++ b/include/net/xfrm.h
87104 @@ -285,7 +285,6 @@ struct xfrm_dst;
87105 struct xfrm_policy_afinfo {
87106 unsigned short family;
87107 struct dst_ops *dst_ops;
87108 - void (*garbage_collect)(struct net *net);
87109 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87110 const xfrm_address_t *saddr,
87111 const xfrm_address_t *daddr);
87112 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87113 struct net_device *dev,
87114 const struct flowi *fl);
87115 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87116 -};
87117 +} __do_const;
87118
87119 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87120 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87121 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87122 int (*transport_finish)(struct sk_buff *skb,
87123 int async);
87124 void (*local_error)(struct sk_buff *skb, u32 mtu);
87125 -};
87126 +} __do_const;
87127
87128 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87129 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87130 @@ -437,7 +436,7 @@ struct xfrm_mode {
87131 struct module *owner;
87132 unsigned int encap;
87133 int flags;
87134 -};
87135 +} __do_const;
87136
87137 /* Flags for xfrm_mode. */
87138 enum {
87139 @@ -534,7 +533,7 @@ struct xfrm_policy {
87140 struct timer_list timer;
87141
87142 struct flow_cache_object flo;
87143 - atomic_t genid;
87144 + atomic_unchecked_t genid;
87145 u32 priority;
87146 u32 index;
87147 struct xfrm_mark mark;
87148 @@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87149 }
87150
87151 void xfrm_garbage_collect(struct net *net);
87152 +void xfrm_garbage_collect_deferred(struct net *net);
87153
87154 #else
87155
87156 @@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87157 static inline void xfrm_garbage_collect(struct net *net)
87158 {
87159 }
87160 +static inline void xfrm_garbage_collect_deferred(struct net *net)
87161 +{
87162 +}
87163 #endif
87164
87165 static __inline__
87166 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87167 index 1017e0b..227aa4d 100644
87168 --- a/include/rdma/iw_cm.h
87169 +++ b/include/rdma/iw_cm.h
87170 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
87171 int backlog);
87172
87173 int (*destroy_listen)(struct iw_cm_id *cm_id);
87174 -};
87175 +} __no_const;
87176
87177 /**
87178 * iw_create_cm_id - Create an IW CM identifier.
87179 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87180 index 52beadf..598734c 100644
87181 --- a/include/scsi/libfc.h
87182 +++ b/include/scsi/libfc.h
87183 @@ -771,6 +771,7 @@ struct libfc_function_template {
87184 */
87185 void (*disc_stop_final) (struct fc_lport *);
87186 };
87187 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87188
87189 /**
87190 * struct fc_disc - Discovery context
87191 @@ -875,7 +876,7 @@ struct fc_lport {
87192 struct fc_vport *vport;
87193
87194 /* Operational Information */
87195 - struct libfc_function_template tt;
87196 + libfc_function_template_no_const tt;
87197 u8 link_up;
87198 u8 qfull;
87199 enum fc_lport_state state;
87200 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87201 index 27ecee7..5f42632 100644
87202 --- a/include/scsi/scsi_device.h
87203 +++ b/include/scsi/scsi_device.h
87204 @@ -186,9 +186,9 @@ struct scsi_device {
87205 unsigned int max_device_blocked; /* what device_blocked counts down from */
87206 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87207
87208 - atomic_t iorequest_cnt;
87209 - atomic_t iodone_cnt;
87210 - atomic_t ioerr_cnt;
87211 + atomic_unchecked_t iorequest_cnt;
87212 + atomic_unchecked_t iodone_cnt;
87213 + atomic_unchecked_t ioerr_cnt;
87214
87215 struct device sdev_gendev,
87216 sdev_dev;
87217 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87218 index 007a0bc..7188db8 100644
87219 --- a/include/scsi/scsi_transport_fc.h
87220 +++ b/include/scsi/scsi_transport_fc.h
87221 @@ -756,7 +756,8 @@ struct fc_function_template {
87222 unsigned long show_host_system_hostname:1;
87223
87224 unsigned long disable_target_scan:1;
87225 -};
87226 +} __do_const;
87227 +typedef struct fc_function_template __no_const fc_function_template_no_const;
87228
87229
87230 /**
87231 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87232 index ae6c3b8..fd748ac 100644
87233 --- a/include/sound/compress_driver.h
87234 +++ b/include/sound/compress_driver.h
87235 @@ -128,7 +128,7 @@ struct snd_compr_ops {
87236 struct snd_compr_caps *caps);
87237 int (*get_codec_caps) (struct snd_compr_stream *stream,
87238 struct snd_compr_codec_caps *codec);
87239 -};
87240 +} __no_const;
87241
87242 /**
87243 * struct snd_compr: Compressed device
87244 diff --git a/include/sound/soc.h b/include/sound/soc.h
87245 index 7ba7130..d46594d 100644
87246 --- a/include/sound/soc.h
87247 +++ b/include/sound/soc.h
87248 @@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
87249 enum snd_soc_dapm_type, int);
87250
87251 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
87252 -};
87253 +} __do_const;
87254
87255 /* SoC platform interface */
87256 struct snd_soc_platform_driver {
87257 @@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
87258 const struct snd_compr_ops *compr_ops;
87259
87260 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87261 -};
87262 +} __do_const;
87263
87264 struct snd_soc_dai_link_component {
87265 const char *name;
87266 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87267 index 23c518a..d6ef510 100644
87268 --- a/include/target/target_core_base.h
87269 +++ b/include/target/target_core_base.h
87270 @@ -764,7 +764,7 @@ struct se_device {
87271 atomic_long_t write_bytes;
87272 /* Active commands on this virtual SE device */
87273 atomic_t simple_cmds;
87274 - atomic_t dev_ordered_id;
87275 + atomic_unchecked_t dev_ordered_id;
87276 atomic_t dev_ordered_sync;
87277 atomic_t dev_qf_count;
87278 int export_count;
87279 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87280 new file mode 100644
87281 index 0000000..fb634b7
87282 --- /dev/null
87283 +++ b/include/trace/events/fs.h
87284 @@ -0,0 +1,53 @@
87285 +#undef TRACE_SYSTEM
87286 +#define TRACE_SYSTEM fs
87287 +
87288 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87289 +#define _TRACE_FS_H
87290 +
87291 +#include <linux/fs.h>
87292 +#include <linux/tracepoint.h>
87293 +
87294 +TRACE_EVENT(do_sys_open,
87295 +
87296 + TP_PROTO(const char *filename, int flags, int mode),
87297 +
87298 + TP_ARGS(filename, flags, mode),
87299 +
87300 + TP_STRUCT__entry(
87301 + __string( filename, filename )
87302 + __field( int, flags )
87303 + __field( int, mode )
87304 + ),
87305 +
87306 + TP_fast_assign(
87307 + __assign_str(filename, filename);
87308 + __entry->flags = flags;
87309 + __entry->mode = mode;
87310 + ),
87311 +
87312 + TP_printk("\"%s\" %x %o",
87313 + __get_str(filename), __entry->flags, __entry->mode)
87314 +);
87315 +
87316 +TRACE_EVENT(open_exec,
87317 +
87318 + TP_PROTO(const char *filename),
87319 +
87320 + TP_ARGS(filename),
87321 +
87322 + TP_STRUCT__entry(
87323 + __string( filename, filename )
87324 + ),
87325 +
87326 + TP_fast_assign(
87327 + __assign_str(filename, filename);
87328 + ),
87329 +
87330 + TP_printk("\"%s\"",
87331 + __get_str(filename))
87332 +);
87333 +
87334 +#endif /* _TRACE_FS_H */
87335 +
87336 +/* This part must be outside protection */
87337 +#include <trace/define_trace.h>
87338 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87339 index 3608beb..df39d8a 100644
87340 --- a/include/trace/events/irq.h
87341 +++ b/include/trace/events/irq.h
87342 @@ -36,7 +36,7 @@ struct softirq_action;
87343 */
87344 TRACE_EVENT(irq_handler_entry,
87345
87346 - TP_PROTO(int irq, struct irqaction *action),
87347 + TP_PROTO(int irq, const struct irqaction *action),
87348
87349 TP_ARGS(irq, action),
87350
87351 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87352 */
87353 TRACE_EVENT(irq_handler_exit,
87354
87355 - TP_PROTO(int irq, struct irqaction *action, int ret),
87356 + TP_PROTO(int irq, const struct irqaction *action, int ret),
87357
87358 TP_ARGS(irq, action, ret),
87359
87360 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87361 index 7caf44c..23c6f27 100644
87362 --- a/include/uapi/linux/a.out.h
87363 +++ b/include/uapi/linux/a.out.h
87364 @@ -39,6 +39,14 @@ enum machine_type {
87365 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87366 };
87367
87368 +/* Constants for the N_FLAGS field */
87369 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87370 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87371 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87372 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87373 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87374 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87375 +
87376 #if !defined (N_MAGIC)
87377 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87378 #endif
87379 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87380 index 22b6ad3..aeba37e 100644
87381 --- a/include/uapi/linux/bcache.h
87382 +++ b/include/uapi/linux/bcache.h
87383 @@ -5,6 +5,7 @@
87384 * Bcache on disk data structures
87385 */
87386
87387 +#include <linux/compiler.h>
87388 #include <asm/types.h>
87389
87390 #define BITMASK(name, type, field, offset, size) \
87391 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87392 /* Btree keys - all units are in sectors */
87393
87394 struct bkey {
87395 - __u64 high;
87396 - __u64 low;
87397 + __u64 high __intentional_overflow(-1);
87398 + __u64 low __intentional_overflow(-1);
87399 __u64 ptr[];
87400 };
87401
87402 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87403 index d876736..ccce5c0 100644
87404 --- a/include/uapi/linux/byteorder/little_endian.h
87405 +++ b/include/uapi/linux/byteorder/little_endian.h
87406 @@ -42,51 +42,51 @@
87407
87408 static inline __le64 __cpu_to_le64p(const __u64 *p)
87409 {
87410 - return (__force __le64)*p;
87411 + return (__force const __le64)*p;
87412 }
87413 -static inline __u64 __le64_to_cpup(const __le64 *p)
87414 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87415 {
87416 - return (__force __u64)*p;
87417 + return (__force const __u64)*p;
87418 }
87419 static inline __le32 __cpu_to_le32p(const __u32 *p)
87420 {
87421 - return (__force __le32)*p;
87422 + return (__force const __le32)*p;
87423 }
87424 static inline __u32 __le32_to_cpup(const __le32 *p)
87425 {
87426 - return (__force __u32)*p;
87427 + return (__force const __u32)*p;
87428 }
87429 static inline __le16 __cpu_to_le16p(const __u16 *p)
87430 {
87431 - return (__force __le16)*p;
87432 + return (__force const __le16)*p;
87433 }
87434 static inline __u16 __le16_to_cpup(const __le16 *p)
87435 {
87436 - return (__force __u16)*p;
87437 + return (__force const __u16)*p;
87438 }
87439 static inline __be64 __cpu_to_be64p(const __u64 *p)
87440 {
87441 - return (__force __be64)__swab64p(p);
87442 + return (__force const __be64)__swab64p(p);
87443 }
87444 static inline __u64 __be64_to_cpup(const __be64 *p)
87445 {
87446 - return __swab64p((__u64 *)p);
87447 + return __swab64p((const __u64 *)p);
87448 }
87449 static inline __be32 __cpu_to_be32p(const __u32 *p)
87450 {
87451 - return (__force __be32)__swab32p(p);
87452 + return (__force const __be32)__swab32p(p);
87453 }
87454 -static inline __u32 __be32_to_cpup(const __be32 *p)
87455 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87456 {
87457 - return __swab32p((__u32 *)p);
87458 + return __swab32p((const __u32 *)p);
87459 }
87460 static inline __be16 __cpu_to_be16p(const __u16 *p)
87461 {
87462 - return (__force __be16)__swab16p(p);
87463 + return (__force const __be16)__swab16p(p);
87464 }
87465 static inline __u16 __be16_to_cpup(const __be16 *p)
87466 {
87467 - return __swab16p((__u16 *)p);
87468 + return __swab16p((const __u16 *)p);
87469 }
87470 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87471 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87472 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87473 index ea9bf25..5140c61 100644
87474 --- a/include/uapi/linux/elf.h
87475 +++ b/include/uapi/linux/elf.h
87476 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87477 #define PT_GNU_EH_FRAME 0x6474e550
87478
87479 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87480 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87481 +
87482 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87483 +
87484 +/* Constants for the e_flags field */
87485 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87486 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87487 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87488 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87489 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87490 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87491
87492 /*
87493 * Extended Numbering
87494 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87495 #define DT_DEBUG 21
87496 #define DT_TEXTREL 22
87497 #define DT_JMPREL 23
87498 +#define DT_FLAGS 30
87499 + #define DF_TEXTREL 0x00000004
87500 #define DT_ENCODING 32
87501 #define OLD_DT_LOOS 0x60000000
87502 #define DT_LOOS 0x6000000d
87503 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87504 #define PF_W 0x2
87505 #define PF_X 0x1
87506
87507 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87508 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87509 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87510 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87511 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87512 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87513 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87514 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87515 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87516 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87517 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87518 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87519 +
87520 typedef struct elf32_phdr{
87521 Elf32_Word p_type;
87522 Elf32_Off p_offset;
87523 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87524 #define EI_OSABI 7
87525 #define EI_PAD 8
87526
87527 +#define EI_PAX 14
87528 +
87529 #define ELFMAG0 0x7f /* EI_MAG */
87530 #define ELFMAG1 'E'
87531 #define ELFMAG2 'L'
87532 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87533 index aa169c4..6a2771d 100644
87534 --- a/include/uapi/linux/personality.h
87535 +++ b/include/uapi/linux/personality.h
87536 @@ -30,6 +30,7 @@ enum {
87537 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87538 ADDR_NO_RANDOMIZE | \
87539 ADDR_COMPAT_LAYOUT | \
87540 + ADDR_LIMIT_3GB | \
87541 MMAP_PAGE_ZERO)
87542
87543 /*
87544 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87545 index 7530e74..e714828 100644
87546 --- a/include/uapi/linux/screen_info.h
87547 +++ b/include/uapi/linux/screen_info.h
87548 @@ -43,7 +43,8 @@ struct screen_info {
87549 __u16 pages; /* 0x32 */
87550 __u16 vesa_attributes; /* 0x34 */
87551 __u32 capabilities; /* 0x36 */
87552 - __u8 _reserved[6]; /* 0x3a */
87553 + __u16 vesapm_size; /* 0x3a */
87554 + __u8 _reserved[4]; /* 0x3c */
87555 } __attribute__((packed));
87556
87557 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87558 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87559 index 0e011eb..82681b1 100644
87560 --- a/include/uapi/linux/swab.h
87561 +++ b/include/uapi/linux/swab.h
87562 @@ -43,7 +43,7 @@
87563 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87564 */
87565
87566 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
87567 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87568 {
87569 #ifdef __HAVE_BUILTIN_BSWAP16__
87570 return __builtin_bswap16(val);
87571 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87572 #endif
87573 }
87574
87575 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
87576 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87577 {
87578 #ifdef __HAVE_BUILTIN_BSWAP32__
87579 return __builtin_bswap32(val);
87580 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87581 #endif
87582 }
87583
87584 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
87585 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87586 {
87587 #ifdef __HAVE_BUILTIN_BSWAP64__
87588 return __builtin_bswap64(val);
87589 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87590 index 43aaba1..1c30b48 100644
87591 --- a/include/uapi/linux/sysctl.h
87592 +++ b/include/uapi/linux/sysctl.h
87593 @@ -155,8 +155,6 @@ enum
87594 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87595 };
87596
87597 -
87598 -
87599 /* CTL_VM names: */
87600 enum
87601 {
87602 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87603 index 1590c49..5eab462 100644
87604 --- a/include/uapi/linux/xattr.h
87605 +++ b/include/uapi/linux/xattr.h
87606 @@ -73,5 +73,9 @@
87607 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87608 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87609
87610 +/* User namespace */
87611 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87612 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
87613 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87614
87615 #endif /* _UAPI_LINUX_XATTR_H */
87616 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87617 index f9466fa..f4e2b81 100644
87618 --- a/include/video/udlfb.h
87619 +++ b/include/video/udlfb.h
87620 @@ -53,10 +53,10 @@ struct dlfb_data {
87621 u32 pseudo_palette[256];
87622 int blank_mode; /*one of FB_BLANK_ */
87623 /* blit-only rendering path metrics, exposed through sysfs */
87624 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87625 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87626 - atomic_t bytes_sent; /* to usb, after compression including overhead */
87627 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87628 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87629 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87630 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87631 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87632 };
87633
87634 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87635 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87636 index 30f5362..8ed8ac9 100644
87637 --- a/include/video/uvesafb.h
87638 +++ b/include/video/uvesafb.h
87639 @@ -122,6 +122,7 @@ struct uvesafb_par {
87640 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87641 u8 pmi_setpal; /* PMI for palette changes */
87642 u16 *pmi_base; /* protected mode interface location */
87643 + u8 *pmi_code; /* protected mode code location */
87644 void *pmi_start;
87645 void *pmi_pal;
87646 u8 *vbe_state_orig; /*
87647 diff --git a/init/Kconfig b/init/Kconfig
87648 index 2081a4d..98d1149 100644
87649 --- a/init/Kconfig
87650 +++ b/init/Kconfig
87651 @@ -1150,6 +1150,7 @@ endif # CGROUPS
87652
87653 config CHECKPOINT_RESTORE
87654 bool "Checkpoint/restore support" if EXPERT
87655 + depends on !GRKERNSEC
87656 default n
87657 help
87658 Enables additional kernel features in a sake of checkpoint/restore.
87659 @@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87660
87661 config COMPAT_BRK
87662 bool "Disable heap randomization"
87663 - default y
87664 + default n
87665 help
87666 Randomizing heap placement makes heap exploits harder, but it
87667 also breaks ancient binaries (including anything libc5 based).
87668 @@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87669 config STOP_MACHINE
87670 bool
87671 default y
87672 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87673 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87674 help
87675 Need stop_machine() primitive.
87676
87677 diff --git a/init/Makefile b/init/Makefile
87678 index 7bc47ee..6da2dc7 100644
87679 --- a/init/Makefile
87680 +++ b/init/Makefile
87681 @@ -2,6 +2,9 @@
87682 # Makefile for the linux kernel.
87683 #
87684
87685 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
87686 +asflags-y := $(GCC_PLUGINS_AFLAGS)
87687 +
87688 obj-y := main.o version.o mounts.o
87689 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87690 obj-y += noinitramfs.o
87691 diff --git a/init/do_mounts.c b/init/do_mounts.c
87692 index 9b3565c..3f90cf9 100644
87693 --- a/init/do_mounts.c
87694 +++ b/init/do_mounts.c
87695 @@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87696 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87697 {
87698 struct super_block *s;
87699 - int err = sys_mount(name, "/root", fs, flags, data);
87700 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87701 if (err)
87702 return err;
87703
87704 - sys_chdir("/root");
87705 + sys_chdir((const char __force_user *)"/root");
87706 s = current->fs->pwd.dentry->d_sb;
87707 ROOT_DEV = s->s_dev;
87708 printk(KERN_INFO
87709 @@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87710 va_start(args, fmt);
87711 vsprintf(buf, fmt, args);
87712 va_end(args);
87713 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87714 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87715 if (fd >= 0) {
87716 sys_ioctl(fd, FDEJECT, 0);
87717 sys_close(fd);
87718 }
87719 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87720 - fd = sys_open("/dev/console", O_RDWR, 0);
87721 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87722 if (fd >= 0) {
87723 sys_ioctl(fd, TCGETS, (long)&termios);
87724 termios.c_lflag &= ~ICANON;
87725 sys_ioctl(fd, TCSETSF, (long)&termios);
87726 - sys_read(fd, &c, 1);
87727 + sys_read(fd, (char __user *)&c, 1);
87728 termios.c_lflag |= ICANON;
87729 sys_ioctl(fd, TCSETSF, (long)&termios);
87730 sys_close(fd);
87731 @@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87732 mount_root();
87733 out:
87734 devtmpfs_mount("dev");
87735 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87736 - sys_chroot(".");
87737 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87738 + sys_chroot((const char __force_user *)".");
87739 }
87740
87741 static bool is_tmpfs;
87742 diff --git a/init/do_mounts.h b/init/do_mounts.h
87743 index f5b978a..69dbfe8 100644
87744 --- a/init/do_mounts.h
87745 +++ b/init/do_mounts.h
87746 @@ -15,15 +15,15 @@ extern int root_mountflags;
87747
87748 static inline int create_dev(char *name, dev_t dev)
87749 {
87750 - sys_unlink(name);
87751 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87752 + sys_unlink((char __force_user *)name);
87753 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87754 }
87755
87756 #if BITS_PER_LONG == 32
87757 static inline u32 bstat(char *name)
87758 {
87759 struct stat64 stat;
87760 - if (sys_stat64(name, &stat) != 0)
87761 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87762 return 0;
87763 if (!S_ISBLK(stat.st_mode))
87764 return 0;
87765 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87766 static inline u32 bstat(char *name)
87767 {
87768 struct stat stat;
87769 - if (sys_newstat(name, &stat) != 0)
87770 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87771 return 0;
87772 if (!S_ISBLK(stat.st_mode))
87773 return 0;
87774 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87775 index 3e0878e..8a9d7a0 100644
87776 --- a/init/do_mounts_initrd.c
87777 +++ b/init/do_mounts_initrd.c
87778 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87779 {
87780 sys_unshare(CLONE_FS | CLONE_FILES);
87781 /* stdin/stdout/stderr for /linuxrc */
87782 - sys_open("/dev/console", O_RDWR, 0);
87783 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87784 sys_dup(0);
87785 sys_dup(0);
87786 /* move initrd over / and chdir/chroot in initrd root */
87787 - sys_chdir("/root");
87788 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
87789 - sys_chroot(".");
87790 + sys_chdir((const char __force_user *)"/root");
87791 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87792 + sys_chroot((const char __force_user *)".");
87793 sys_setsid();
87794 return 0;
87795 }
87796 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87797 create_dev("/dev/root.old", Root_RAM0);
87798 /* mount initrd on rootfs' /root */
87799 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87800 - sys_mkdir("/old", 0700);
87801 - sys_chdir("/old");
87802 + sys_mkdir((const char __force_user *)"/old", 0700);
87803 + sys_chdir((const char __force_user *)"/old");
87804
87805 /* try loading default modules from initrd */
87806 load_default_modules();
87807 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87808 current->flags &= ~PF_FREEZER_SKIP;
87809
87810 /* move initrd to rootfs' /old */
87811 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
87812 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87813 /* switch root and cwd back to / of rootfs */
87814 - sys_chroot("..");
87815 + sys_chroot((const char __force_user *)"..");
87816
87817 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87818 - sys_chdir("/old");
87819 + sys_chdir((const char __force_user *)"/old");
87820 return;
87821 }
87822
87823 - sys_chdir("/");
87824 + sys_chdir((const char __force_user *)"/");
87825 ROOT_DEV = new_decode_dev(real_root_dev);
87826 mount_root();
87827
87828 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87829 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87830 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87831 if (!error)
87832 printk("okay\n");
87833 else {
87834 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
87835 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87836 if (error == -ENOENT)
87837 printk("/initrd does not exist. Ignored.\n");
87838 else
87839 printk("failed\n");
87840 printk(KERN_NOTICE "Unmounting old root\n");
87841 - sys_umount("/old", MNT_DETACH);
87842 + sys_umount((char __force_user *)"/old", MNT_DETACH);
87843 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87844 if (fd < 0) {
87845 error = fd;
87846 @@ -127,11 +127,11 @@ int __init initrd_load(void)
87847 * mounted in the normal path.
87848 */
87849 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87850 - sys_unlink("/initrd.image");
87851 + sys_unlink((const char __force_user *)"/initrd.image");
87852 handle_initrd();
87853 return 1;
87854 }
87855 }
87856 - sys_unlink("/initrd.image");
87857 + sys_unlink((const char __force_user *)"/initrd.image");
87858 return 0;
87859 }
87860 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87861 index 8cb6db5..d729f50 100644
87862 --- a/init/do_mounts_md.c
87863 +++ b/init/do_mounts_md.c
87864 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87865 partitioned ? "_d" : "", minor,
87866 md_setup_args[ent].device_names);
87867
87868 - fd = sys_open(name, 0, 0);
87869 + fd = sys_open((char __force_user *)name, 0, 0);
87870 if (fd < 0) {
87871 printk(KERN_ERR "md: open failed - cannot start "
87872 "array %s\n", name);
87873 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87874 * array without it
87875 */
87876 sys_close(fd);
87877 - fd = sys_open(name, 0, 0);
87878 + fd = sys_open((char __force_user *)name, 0, 0);
87879 sys_ioctl(fd, BLKRRPART, 0);
87880 }
87881 sys_close(fd);
87882 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87883
87884 wait_for_device_probe();
87885
87886 - fd = sys_open("/dev/md0", 0, 0);
87887 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87888 if (fd >= 0) {
87889 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87890 sys_close(fd);
87891 diff --git a/init/init_task.c b/init/init_task.c
87892 index ba0a7f36..2bcf1d5 100644
87893 --- a/init/init_task.c
87894 +++ b/init/init_task.c
87895 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87896 * Initial thread structure. Alignment of this is handled by a special
87897 * linker map entry.
87898 */
87899 +#ifdef CONFIG_X86
87900 +union thread_union init_thread_union __init_task_data;
87901 +#else
87902 union thread_union init_thread_union __init_task_data =
87903 { INIT_THREAD_INFO(init_task) };
87904 +#endif
87905 diff --git a/init/initramfs.c b/init/initramfs.c
87906 index ad1bd77..dca2c1b 100644
87907 --- a/init/initramfs.c
87908 +++ b/init/initramfs.c
87909 @@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87910
87911 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87912 while (count) {
87913 - ssize_t rv = sys_write(fd, p, count);
87914 + ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87915
87916 if (rv < 0) {
87917 if (rv == -EINTR || rv == -EAGAIN)
87918 @@ -107,7 +107,7 @@ static void __init free_hash(void)
87919 }
87920 }
87921
87922 -static long __init do_utime(char *filename, time_t mtime)
87923 +static long __init do_utime(char __force_user *filename, time_t mtime)
87924 {
87925 struct timespec t[2];
87926
87927 @@ -142,7 +142,7 @@ static void __init dir_utime(void)
87928 struct dir_entry *de, *tmp;
87929 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87930 list_del(&de->list);
87931 - do_utime(de->name, de->mtime);
87932 + do_utime((char __force_user *)de->name, de->mtime);
87933 kfree(de->name);
87934 kfree(de);
87935 }
87936 @@ -304,7 +304,7 @@ static int __init maybe_link(void)
87937 if (nlink >= 2) {
87938 char *old = find_link(major, minor, ino, mode, collected);
87939 if (old)
87940 - return (sys_link(old, collected) < 0) ? -1 : 1;
87941 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87942 }
87943 return 0;
87944 }
87945 @@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87946 {
87947 struct stat st;
87948
87949 - if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87950 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87951 if (S_ISDIR(st.st_mode))
87952 - sys_rmdir(path);
87953 + sys_rmdir((char __force_user *)path);
87954 else
87955 - sys_unlink(path);
87956 + sys_unlink((char __force_user *)path);
87957 }
87958 }
87959
87960 @@ -338,7 +338,7 @@ static int __init do_name(void)
87961 int openflags = O_WRONLY|O_CREAT;
87962 if (ml != 1)
87963 openflags |= O_TRUNC;
87964 - wfd = sys_open(collected, openflags, mode);
87965 + wfd = sys_open((char __force_user *)collected, openflags, mode);
87966
87967 if (wfd >= 0) {
87968 sys_fchown(wfd, uid, gid);
87969 @@ -350,17 +350,17 @@ static int __init do_name(void)
87970 }
87971 }
87972 } else if (S_ISDIR(mode)) {
87973 - sys_mkdir(collected, mode);
87974 - sys_chown(collected, uid, gid);
87975 - sys_chmod(collected, mode);
87976 + sys_mkdir((char __force_user *)collected, mode);
87977 + sys_chown((char __force_user *)collected, uid, gid);
87978 + sys_chmod((char __force_user *)collected, mode);
87979 dir_add(collected, mtime);
87980 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87981 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87982 if (maybe_link() == 0) {
87983 - sys_mknod(collected, mode, rdev);
87984 - sys_chown(collected, uid, gid);
87985 - sys_chmod(collected, mode);
87986 - do_utime(collected, mtime);
87987 + sys_mknod((char __force_user *)collected, mode, rdev);
87988 + sys_chown((char __force_user *)collected, uid, gid);
87989 + sys_chmod((char __force_user *)collected, mode);
87990 + do_utime((char __force_user *)collected, mtime);
87991 }
87992 }
87993 return 0;
87994 @@ -372,7 +372,7 @@ static int __init do_copy(void)
87995 if (xwrite(wfd, victim, body_len) != body_len)
87996 error("write error");
87997 sys_close(wfd);
87998 - do_utime(vcollected, mtime);
87999 + do_utime((char __force_user *)vcollected, mtime);
88000 kfree(vcollected);
88001 eat(body_len);
88002 state = SkipIt;
88003 @@ -390,9 +390,9 @@ static int __init do_symlink(void)
88004 {
88005 collected[N_ALIGN(name_len) + body_len] = '\0';
88006 clean_path(collected, 0);
88007 - sys_symlink(collected + N_ALIGN(name_len), collected);
88008 - sys_lchown(collected, uid, gid);
88009 - do_utime(collected, mtime);
88010 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88011 + sys_lchown((char __force_user *)collected, uid, gid);
88012 + do_utime((char __force_user *)collected, mtime);
88013 state = SkipIt;
88014 next_state = Reset;
88015 return 0;
88016 diff --git a/init/main.c b/init/main.c
88017 index 321d0ce..91b53e5 100644
88018 --- a/init/main.c
88019 +++ b/init/main.c
88020 @@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88021 static inline void mark_rodata_ro(void) { }
88022 #endif
88023
88024 +extern void grsecurity_init(void);
88025 +
88026 /*
88027 * Debug helper: via this flag we know that we are in 'early bootup code'
88028 * where only the boot processor is running with IRQ disabled. This means
88029 @@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88030
88031 __setup("reset_devices", set_reset_devices);
88032
88033 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88034 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88035 +static int __init setup_grsec_proc_gid(char *str)
88036 +{
88037 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88038 + return 1;
88039 +}
88040 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88041 +#endif
88042 +
88043 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88044 +unsigned long pax_user_shadow_base __read_only;
88045 +EXPORT_SYMBOL(pax_user_shadow_base);
88046 +extern char pax_enter_kernel_user[];
88047 +extern char pax_exit_kernel_user[];
88048 +#endif
88049 +
88050 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88051 +static int __init setup_pax_nouderef(char *str)
88052 +{
88053 +#ifdef CONFIG_X86_32
88054 + unsigned int cpu;
88055 + struct desc_struct *gdt;
88056 +
88057 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88058 + gdt = get_cpu_gdt_table(cpu);
88059 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88060 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88061 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88062 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88063 + }
88064 + loadsegment(ds, __KERNEL_DS);
88065 + loadsegment(es, __KERNEL_DS);
88066 + loadsegment(ss, __KERNEL_DS);
88067 +#else
88068 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88069 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88070 + clone_pgd_mask = ~(pgdval_t)0UL;
88071 + pax_user_shadow_base = 0UL;
88072 + setup_clear_cpu_cap(X86_FEATURE_PCID);
88073 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88074 +#endif
88075 +
88076 + return 0;
88077 +}
88078 +early_param("pax_nouderef", setup_pax_nouderef);
88079 +
88080 +#ifdef CONFIG_X86_64
88081 +static int __init setup_pax_weakuderef(char *str)
88082 +{
88083 + if (clone_pgd_mask != ~(pgdval_t)0UL)
88084 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88085 + return 1;
88086 +}
88087 +__setup("pax_weakuderef", setup_pax_weakuderef);
88088 +#endif
88089 +#endif
88090 +
88091 +#ifdef CONFIG_PAX_SOFTMODE
88092 +int pax_softmode;
88093 +
88094 +static int __init setup_pax_softmode(char *str)
88095 +{
88096 + get_option(&str, &pax_softmode);
88097 + return 1;
88098 +}
88099 +__setup("pax_softmode=", setup_pax_softmode);
88100 +#endif
88101 +
88102 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88103 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88104 static const char *panic_later, *panic_param;
88105 @@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88106 struct blacklist_entry *entry;
88107 char *fn_name;
88108
88109 - fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88110 + fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88111 if (!fn_name)
88112 return false;
88113
88114 @@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88115 {
88116 int count = preempt_count();
88117 int ret;
88118 - char msgbuf[64];
88119 + const char *msg1 = "", *msg2 = "";
88120
88121 if (initcall_blacklisted(fn))
88122 return -EPERM;
88123 @@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88124 else
88125 ret = fn();
88126
88127 - msgbuf[0] = 0;
88128 -
88129 if (preempt_count() != count) {
88130 - sprintf(msgbuf, "preemption imbalance ");
88131 + msg1 = " preemption imbalance";
88132 preempt_count_set(count);
88133 }
88134 if (irqs_disabled()) {
88135 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88136 + msg2 = " disabled interrupts";
88137 local_irq_enable();
88138 }
88139 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88140 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88141
88142 + add_latent_entropy();
88143 return ret;
88144 }
88145
88146 @@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
88147 {
88148 argv_init[0] = init_filename;
88149 return do_execve(getname_kernel(init_filename),
88150 - (const char __user *const __user *)argv_init,
88151 - (const char __user *const __user *)envp_init);
88152 + (const char __user *const __force_user *)argv_init,
88153 + (const char __user *const __force_user *)envp_init);
88154 }
88155
88156 static int try_to_run_init_process(const char *init_filename)
88157 @@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
88158 return ret;
88159 }
88160
88161 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88162 +extern int gr_init_ran;
88163 +#endif
88164 +
88165 static noinline void __init kernel_init_freeable(void);
88166
88167 static int __ref kernel_init(void *unused)
88168 @@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
88169 ramdisk_execute_command, ret);
88170 }
88171
88172 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88173 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
88174 + gr_init_ran = 1;
88175 +#endif
88176 +
88177 /*
88178 * We try each of these until one succeeds.
88179 *
88180 @@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
88181 do_basic_setup();
88182
88183 /* Open the /dev/console on the rootfs, this should never fail */
88184 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88185 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88186 pr_err("Warning: unable to open an initial console.\n");
88187
88188 (void) sys_dup(0);
88189 @@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
88190 if (!ramdisk_execute_command)
88191 ramdisk_execute_command = "/init";
88192
88193 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88194 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88195 ramdisk_execute_command = NULL;
88196 prepare_namespace();
88197 }
88198
88199 + grsecurity_init();
88200 +
88201 /*
88202 * Ok, we have completed the initial bootup, and
88203 * we're essentially up and running. Get rid of the
88204 diff --git a/ipc/compat.c b/ipc/compat.c
88205 index 9b3c85f..1c4d897 100644
88206 --- a/ipc/compat.c
88207 +++ b/ipc/compat.c
88208 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88209 COMPAT_SHMLBA);
88210 if (err < 0)
88211 return err;
88212 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88213 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88214 }
88215 case SHMDT:
88216 return sys_shmdt(compat_ptr(ptr));
88217 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88218 index e8075b2..76f2c6a 100644
88219 --- a/ipc/ipc_sysctl.c
88220 +++ b/ipc/ipc_sysctl.c
88221 @@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88222 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88223 void __user *buffer, size_t *lenp, loff_t *ppos)
88224 {
88225 - struct ctl_table ipc_table;
88226 + ctl_table_no_const ipc_table;
88227
88228 memcpy(&ipc_table, table, sizeof(ipc_table));
88229 ipc_table.data = get_ipc(table);
88230 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88231 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88232 void __user *buffer, size_t *lenp, loff_t *ppos)
88233 {
88234 - struct ctl_table ipc_table;
88235 + ctl_table_no_const ipc_table;
88236
88237 memcpy(&ipc_table, table, sizeof(ipc_table));
88238 ipc_table.data = get_ipc(table);
88239 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88240 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88241 void __user *buffer, size_t *lenp, loff_t *ppos)
88242 {
88243 - struct ctl_table ipc_table;
88244 + ctl_table_no_const ipc_table;
88245 size_t lenp_bef = *lenp;
88246 int rc;
88247
88248 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88249 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88250 void __user *buffer, size_t *lenp, loff_t *ppos)
88251 {
88252 - struct ctl_table ipc_table;
88253 + ctl_table_no_const ipc_table;
88254 memcpy(&ipc_table, table, sizeof(ipc_table));
88255 ipc_table.data = get_ipc(table);
88256
88257 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88258 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88259 void __user *buffer, size_t *lenp, loff_t *ppos)
88260 {
88261 - struct ctl_table ipc_table;
88262 + ctl_table_no_const ipc_table;
88263 int oldval;
88264 int rc;
88265
88266 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88267 index 68d4e95..1477ded 100644
88268 --- a/ipc/mq_sysctl.c
88269 +++ b/ipc/mq_sysctl.c
88270 @@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88271 static int proc_mq_dointvec(struct ctl_table *table, int write,
88272 void __user *buffer, size_t *lenp, loff_t *ppos)
88273 {
88274 - struct ctl_table mq_table;
88275 + ctl_table_no_const mq_table;
88276 memcpy(&mq_table, table, sizeof(mq_table));
88277 mq_table.data = get_mq(table);
88278
88279 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88280 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88281 void __user *buffer, size_t *lenp, loff_t *ppos)
88282 {
88283 - struct ctl_table mq_table;
88284 + ctl_table_no_const mq_table;
88285 memcpy(&mq_table, table, sizeof(mq_table));
88286 mq_table.data = get_mq(table);
88287
88288 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88289 index 4fcf39a..d3cc2ec 100644
88290 --- a/ipc/mqueue.c
88291 +++ b/ipc/mqueue.c
88292 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88293 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88294 info->attr.mq_msgsize);
88295
88296 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88297 spin_lock(&mq_lock);
88298 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88299 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88300 diff --git a/ipc/shm.c b/ipc/shm.c
88301 index 0145479..3d27947 100644
88302 --- a/ipc/shm.c
88303 +++ b/ipc/shm.c
88304 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88305 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88306 #endif
88307
88308 +#ifdef CONFIG_GRKERNSEC
88309 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88310 + const u64 shm_createtime, const kuid_t cuid,
88311 + const int shmid);
88312 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88313 + const u64 shm_createtime);
88314 +#endif
88315 +
88316 void shm_init_ns(struct ipc_namespace *ns)
88317 {
88318 ns->shm_ctlmax = SHMMAX;
88319 @@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88320 shp->shm_lprid = 0;
88321 shp->shm_atim = shp->shm_dtim = 0;
88322 shp->shm_ctim = get_seconds();
88323 +#ifdef CONFIG_GRKERNSEC
88324 + shp->shm_createtime = ktime_get_ns();
88325 +#endif
88326 shp->shm_segsz = size;
88327 shp->shm_nattch = 0;
88328 shp->shm_file = file;
88329 @@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88330 f_mode = FMODE_READ | FMODE_WRITE;
88331 }
88332 if (shmflg & SHM_EXEC) {
88333 +
88334 +#ifdef CONFIG_PAX_MPROTECT
88335 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
88336 + goto out;
88337 +#endif
88338 +
88339 prot |= PROT_EXEC;
88340 acc_mode |= S_IXUGO;
88341 }
88342 @@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88343 if (err)
88344 goto out_unlock;
88345
88346 +#ifdef CONFIG_GRKERNSEC
88347 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88348 + shp->shm_perm.cuid, shmid) ||
88349 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88350 + err = -EACCES;
88351 + goto out_unlock;
88352 + }
88353 +#endif
88354 +
88355 ipc_lock_object(&shp->shm_perm);
88356
88357 /* check if shm_destroy() is tearing down shp */
88358 @@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88359 path = shp->shm_file->f_path;
88360 path_get(&path);
88361 shp->shm_nattch++;
88362 +#ifdef CONFIG_GRKERNSEC
88363 + shp->shm_lapid = current->pid;
88364 +#endif
88365 size = i_size_read(path.dentry->d_inode);
88366 ipc_unlock_object(&shp->shm_perm);
88367 rcu_read_unlock();
88368 diff --git a/ipc/util.c b/ipc/util.c
88369 index 88adc32..3867c68 100644
88370 --- a/ipc/util.c
88371 +++ b/ipc/util.c
88372 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
88373 int (*show)(struct seq_file *, void *);
88374 };
88375
88376 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88377 +
88378 static void ipc_memory_notifier(struct work_struct *work)
88379 {
88380 ipcns_notify(IPCNS_MEMCHANGED);
88381 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88382 granted_mode >>= 6;
88383 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88384 granted_mode >>= 3;
88385 +
88386 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88387 + return -1;
88388 +
88389 /* is there some bit set in requested_mode but not in granted_mode? */
88390 if ((requested_mode & ~granted_mode & 0007) &&
88391 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88392 diff --git a/kernel/audit.c b/kernel/audit.c
88393 index c6df990..fde80b4 100644
88394 --- a/kernel/audit.c
88395 +++ b/kernel/audit.c
88396 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88397 3) suppressed due to audit_rate_limit
88398 4) suppressed due to audit_backlog_limit
88399 */
88400 -static atomic_t audit_lost = ATOMIC_INIT(0);
88401 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88402
88403 /* The netlink socket. */
88404 static struct sock *audit_sock;
88405 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88406 unsigned long now;
88407 int print;
88408
88409 - atomic_inc(&audit_lost);
88410 + atomic_inc_unchecked(&audit_lost);
88411
88412 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88413
88414 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88415 if (print) {
88416 if (printk_ratelimit())
88417 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88418 - atomic_read(&audit_lost),
88419 + atomic_read_unchecked(&audit_lost),
88420 audit_rate_limit,
88421 audit_backlog_limit);
88422 audit_panic(message);
88423 @@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88424 s.pid = audit_pid;
88425 s.rate_limit = audit_rate_limit;
88426 s.backlog_limit = audit_backlog_limit;
88427 - s.lost = atomic_read(&audit_lost);
88428 + s.lost = atomic_read_unchecked(&audit_lost);
88429 s.backlog = skb_queue_len(&audit_skb_queue);
88430 s.version = AUDIT_VERSION_LATEST;
88431 s.backlog_wait_time = audit_backlog_wait_time;
88432 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88433 index e420a0c..38137fa 100644
88434 --- a/kernel/auditsc.c
88435 +++ b/kernel/auditsc.c
88436 @@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88437 }
88438
88439 /* global counter which is incremented every time something logs in */
88440 -static atomic_t session_id = ATOMIC_INIT(0);
88441 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88442
88443 static int audit_set_loginuid_perm(kuid_t loginuid)
88444 {
88445 @@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88446
88447 /* are we setting or clearing? */
88448 if (uid_valid(loginuid))
88449 - sessionid = (unsigned int)atomic_inc_return(&session_id);
88450 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88451
88452 task->sessionid = sessionid;
88453 task->loginuid = loginuid;
88454 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88455 index d6594e4..597264b 100644
88456 --- a/kernel/bpf/core.c
88457 +++ b/kernel/bpf/core.c
88458 @@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88459 * random section of illegal instructions.
88460 */
88461 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88462 - hdr = module_alloc(size);
88463 + hdr = module_alloc_exec(size);
88464 if (hdr == NULL)
88465 return NULL;
88466
88467 /* Fill space with illegal/arch-dep instructions. */
88468 bpf_fill_ill_insns(hdr, size);
88469
88470 + pax_open_kernel();
88471 hdr->pages = size / PAGE_SIZE;
88472 + pax_close_kernel();
88473 +
88474 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88475 PAGE_SIZE - sizeof(*hdr));
88476 start = (prandom_u32() % hole) & ~(alignment - 1);
88477 @@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88478
88479 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88480 {
88481 - module_free(NULL, hdr);
88482 + module_free_exec(NULL, hdr);
88483 }
88484 #endif /* CONFIG_BPF_JIT */
88485
88486 diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88487 index ba61c8c..c60c486 100644
88488 --- a/kernel/bpf/syscall.c
88489 +++ b/kernel/bpf/syscall.c
88490 @@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88491 int err;
88492
88493 /* the syscall is limited to root temporarily. This restriction will be
88494 - * lifted when security audit is clean. Note that eBPF+tracing must have
88495 - * this restriction, since it may pass kernel data to user space
88496 + * lifted by upstream when a half-assed security audit is clean. Note
88497 + * that eBPF+tracing must have this restriction, since it may pass
88498 + * kernel data to user space
88499 */
88500 if (!capable(CAP_SYS_ADMIN))
88501 return -EPERM;
88502 +#ifdef CONFIG_GRKERNSEC
88503 + return -EPERM;
88504 +#endif
88505
88506 if (!access_ok(VERIFY_READ, uattr, 1))
88507 return -EFAULT;
88508 diff --git a/kernel/capability.c b/kernel/capability.c
88509 index 989f5bf..d317ca0 100644
88510 --- a/kernel/capability.c
88511 +++ b/kernel/capability.c
88512 @@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88513 * before modification is attempted and the application
88514 * fails.
88515 */
88516 + if (tocopy > ARRAY_SIZE(kdata))
88517 + return -EFAULT;
88518 +
88519 if (copy_to_user(dataptr, kdata, tocopy
88520 * sizeof(struct __user_cap_data_struct))) {
88521 return -EFAULT;
88522 @@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88523 int ret;
88524
88525 rcu_read_lock();
88526 - ret = security_capable(__task_cred(t), ns, cap);
88527 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88528 + gr_task_is_capable(t, __task_cred(t), cap);
88529 rcu_read_unlock();
88530
88531 - return (ret == 0);
88532 + return ret;
88533 }
88534
88535 /**
88536 @@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88537 int ret;
88538
88539 rcu_read_lock();
88540 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
88541 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88542 rcu_read_unlock();
88543
88544 - return (ret == 0);
88545 + return ret;
88546 }
88547
88548 /**
88549 @@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88550 BUG();
88551 }
88552
88553 - if (security_capable(current_cred(), ns, cap) == 0) {
88554 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88555 current->flags |= PF_SUPERPRIV;
88556 return true;
88557 }
88558 @@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88559 }
88560 EXPORT_SYMBOL(ns_capable);
88561
88562 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
88563 +{
88564 + if (unlikely(!cap_valid(cap))) {
88565 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88566 + BUG();
88567 + }
88568 +
88569 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88570 + current->flags |= PF_SUPERPRIV;
88571 + return true;
88572 + }
88573 + return false;
88574 +}
88575 +EXPORT_SYMBOL(ns_capable_nolog);
88576 +
88577 /**
88578 * file_ns_capable - Determine if the file's opener had a capability in effect
88579 * @file: The file we want to check
88580 @@ -427,6 +446,12 @@ bool capable(int cap)
88581 }
88582 EXPORT_SYMBOL(capable);
88583
88584 +bool capable_nolog(int cap)
88585 +{
88586 + return ns_capable_nolog(&init_user_ns, cap);
88587 +}
88588 +EXPORT_SYMBOL(capable_nolog);
88589 +
88590 /**
88591 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88592 * @inode: The inode in question
88593 @@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88594 kgid_has_mapping(ns, inode->i_gid);
88595 }
88596 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88597 +
88598 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88599 +{
88600 + struct user_namespace *ns = current_user_ns();
88601 +
88602 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88603 + kgid_has_mapping(ns, inode->i_gid);
88604 +}
88605 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88606 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88607 index 136ecea..45157a6 100644
88608 --- a/kernel/cgroup.c
88609 +++ b/kernel/cgroup.c
88610 @@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88611 if (!pathbuf || !agentbuf)
88612 goto out;
88613
88614 + if (agentbuf[0] == '\0')
88615 + goto out;
88616 +
88617 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88618 if (!path)
88619 goto out;
88620 @@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88621 struct task_struct *task;
88622 int count = 0;
88623
88624 - seq_printf(seq, "css_set %p\n", cset);
88625 + seq_printf(seq, "css_set %pK\n", cset);
88626
88627 list_for_each_entry(task, &cset->tasks, cg_list) {
88628 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88629 diff --git a/kernel/compat.c b/kernel/compat.c
88630 index ebb3c36..1df606e 100644
88631 --- a/kernel/compat.c
88632 +++ b/kernel/compat.c
88633 @@ -13,6 +13,7 @@
88634
88635 #include <linux/linkage.h>
88636 #include <linux/compat.h>
88637 +#include <linux/module.h>
88638 #include <linux/errno.h>
88639 #include <linux/time.h>
88640 #include <linux/signal.h>
88641 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88642 mm_segment_t oldfs;
88643 long ret;
88644
88645 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88646 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88647 oldfs = get_fs();
88648 set_fs(KERNEL_DS);
88649 ret = hrtimer_nanosleep_restart(restart);
88650 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88651 oldfs = get_fs();
88652 set_fs(KERNEL_DS);
88653 ret = hrtimer_nanosleep(&tu,
88654 - rmtp ? (struct timespec __user *)&rmt : NULL,
88655 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
88656 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88657 set_fs(oldfs);
88658
88659 @@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88660 mm_segment_t old_fs = get_fs();
88661
88662 set_fs(KERNEL_DS);
88663 - ret = sys_sigpending((old_sigset_t __user *) &s);
88664 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
88665 set_fs(old_fs);
88666 if (ret == 0)
88667 ret = put_user(s, set);
88668 @@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88669 mm_segment_t old_fs = get_fs();
88670
88671 set_fs(KERNEL_DS);
88672 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88673 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88674 set_fs(old_fs);
88675
88676 if (!ret) {
88677 @@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88678 set_fs (KERNEL_DS);
88679 ret = sys_wait4(pid,
88680 (stat_addr ?
88681 - (unsigned int __user *) &status : NULL),
88682 - options, (struct rusage __user *) &r);
88683 + (unsigned int __force_user *) &status : NULL),
88684 + options, (struct rusage __force_user *) &r);
88685 set_fs (old_fs);
88686
88687 if (ret > 0) {
88688 @@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88689 memset(&info, 0, sizeof(info));
88690
88691 set_fs(KERNEL_DS);
88692 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88693 - uru ? (struct rusage __user *)&ru : NULL);
88694 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88695 + uru ? (struct rusage __force_user *)&ru : NULL);
88696 set_fs(old_fs);
88697
88698 if ((ret < 0) || (info.si_signo == 0))
88699 @@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88700 oldfs = get_fs();
88701 set_fs(KERNEL_DS);
88702 err = sys_timer_settime(timer_id, flags,
88703 - (struct itimerspec __user *) &newts,
88704 - (struct itimerspec __user *) &oldts);
88705 + (struct itimerspec __force_user *) &newts,
88706 + (struct itimerspec __force_user *) &oldts);
88707 set_fs(oldfs);
88708 if (!err && old && put_compat_itimerspec(old, &oldts))
88709 return -EFAULT;
88710 @@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88711 oldfs = get_fs();
88712 set_fs(KERNEL_DS);
88713 err = sys_timer_gettime(timer_id,
88714 - (struct itimerspec __user *) &ts);
88715 + (struct itimerspec __force_user *) &ts);
88716 set_fs(oldfs);
88717 if (!err && put_compat_itimerspec(setting, &ts))
88718 return -EFAULT;
88719 @@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88720 oldfs = get_fs();
88721 set_fs(KERNEL_DS);
88722 err = sys_clock_settime(which_clock,
88723 - (struct timespec __user *) &ts);
88724 + (struct timespec __force_user *) &ts);
88725 set_fs(oldfs);
88726 return err;
88727 }
88728 @@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88729 oldfs = get_fs();
88730 set_fs(KERNEL_DS);
88731 err = sys_clock_gettime(which_clock,
88732 - (struct timespec __user *) &ts);
88733 + (struct timespec __force_user *) &ts);
88734 set_fs(oldfs);
88735 if (!err && compat_put_timespec(&ts, tp))
88736 return -EFAULT;
88737 @@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88738
88739 oldfs = get_fs();
88740 set_fs(KERNEL_DS);
88741 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88742 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88743 set_fs(oldfs);
88744
88745 err = compat_put_timex(utp, &txc);
88746 @@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88747 oldfs = get_fs();
88748 set_fs(KERNEL_DS);
88749 err = sys_clock_getres(which_clock,
88750 - (struct timespec __user *) &ts);
88751 + (struct timespec __force_user *) &ts);
88752 set_fs(oldfs);
88753 if (!err && tp && compat_put_timespec(&ts, tp))
88754 return -EFAULT;
88755 @@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88756 struct timespec tu;
88757 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88758
88759 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88760 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88761 oldfs = get_fs();
88762 set_fs(KERNEL_DS);
88763 err = clock_nanosleep_restart(restart);
88764 @@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88765 oldfs = get_fs();
88766 set_fs(KERNEL_DS);
88767 err = sys_clock_nanosleep(which_clock, flags,
88768 - (struct timespec __user *) &in,
88769 - (struct timespec __user *) &out);
88770 + (struct timespec __force_user *) &in,
88771 + (struct timespec __force_user *) &out);
88772 set_fs(oldfs);
88773
88774 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88775 @@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88776 mm_segment_t old_fs = get_fs();
88777
88778 set_fs(KERNEL_DS);
88779 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88780 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88781 set_fs(old_fs);
88782 if (compat_put_timespec(&t, interval))
88783 return -EFAULT;
88784 diff --git a/kernel/configs.c b/kernel/configs.c
88785 index c18b1f1..b9a0132 100644
88786 --- a/kernel/configs.c
88787 +++ b/kernel/configs.c
88788 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88789 struct proc_dir_entry *entry;
88790
88791 /* create the current config file */
88792 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88793 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88794 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88795 + &ikconfig_file_ops);
88796 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88797 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88798 + &ikconfig_file_ops);
88799 +#endif
88800 +#else
88801 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88802 &ikconfig_file_ops);
88803 +#endif
88804 +
88805 if (!entry)
88806 return -ENOMEM;
88807
88808 diff --git a/kernel/cred.c b/kernel/cred.c
88809 index e0573a4..26c0fd3 100644
88810 --- a/kernel/cred.c
88811 +++ b/kernel/cred.c
88812 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88813 validate_creds(cred);
88814 alter_cred_subscribers(cred, -1);
88815 put_cred(cred);
88816 +
88817 +#ifdef CONFIG_GRKERNSEC_SETXID
88818 + cred = (struct cred *) tsk->delayed_cred;
88819 + if (cred != NULL) {
88820 + tsk->delayed_cred = NULL;
88821 + validate_creds(cred);
88822 + alter_cred_subscribers(cred, -1);
88823 + put_cred(cred);
88824 + }
88825 +#endif
88826 }
88827
88828 /**
88829 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88830 * Always returns 0 thus allowing this function to be tail-called at the end
88831 * of, say, sys_setgid().
88832 */
88833 -int commit_creds(struct cred *new)
88834 +static int __commit_creds(struct cred *new)
88835 {
88836 struct task_struct *task = current;
88837 const struct cred *old = task->real_cred;
88838 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88839
88840 get_cred(new); /* we will require a ref for the subj creds too */
88841
88842 + gr_set_role_label(task, new->uid, new->gid);
88843 +
88844 /* dumpability changes */
88845 if (!uid_eq(old->euid, new->euid) ||
88846 !gid_eq(old->egid, new->egid) ||
88847 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88848 put_cred(old);
88849 return 0;
88850 }
88851 +#ifdef CONFIG_GRKERNSEC_SETXID
88852 +extern int set_user(struct cred *new);
88853 +
88854 +void gr_delayed_cred_worker(void)
88855 +{
88856 + const struct cred *new = current->delayed_cred;
88857 + struct cred *ncred;
88858 +
88859 + current->delayed_cred = NULL;
88860 +
88861 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88862 + // from doing get_cred on it when queueing this
88863 + put_cred(new);
88864 + return;
88865 + } else if (new == NULL)
88866 + return;
88867 +
88868 + ncred = prepare_creds();
88869 + if (!ncred)
88870 + goto die;
88871 + // uids
88872 + ncred->uid = new->uid;
88873 + ncred->euid = new->euid;
88874 + ncred->suid = new->suid;
88875 + ncred->fsuid = new->fsuid;
88876 + // gids
88877 + ncred->gid = new->gid;
88878 + ncred->egid = new->egid;
88879 + ncred->sgid = new->sgid;
88880 + ncred->fsgid = new->fsgid;
88881 + // groups
88882 + set_groups(ncred, new->group_info);
88883 + // caps
88884 + ncred->securebits = new->securebits;
88885 + ncred->cap_inheritable = new->cap_inheritable;
88886 + ncred->cap_permitted = new->cap_permitted;
88887 + ncred->cap_effective = new->cap_effective;
88888 + ncred->cap_bset = new->cap_bset;
88889 +
88890 + if (set_user(ncred)) {
88891 + abort_creds(ncred);
88892 + goto die;
88893 + }
88894 +
88895 + // from doing get_cred on it when queueing this
88896 + put_cred(new);
88897 +
88898 + __commit_creds(ncred);
88899 + return;
88900 +die:
88901 + // from doing get_cred on it when queueing this
88902 + put_cred(new);
88903 + do_group_exit(SIGKILL);
88904 +}
88905 +#endif
88906 +
88907 +int commit_creds(struct cred *new)
88908 +{
88909 +#ifdef CONFIG_GRKERNSEC_SETXID
88910 + int ret;
88911 + int schedule_it = 0;
88912 + struct task_struct *t;
88913 + unsigned oldsecurebits = current_cred()->securebits;
88914 +
88915 + /* we won't get called with tasklist_lock held for writing
88916 + and interrupts disabled as the cred struct in that case is
88917 + init_cred
88918 + */
88919 + if (grsec_enable_setxid && !current_is_single_threaded() &&
88920 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88921 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88922 + schedule_it = 1;
88923 + }
88924 + ret = __commit_creds(new);
88925 + if (schedule_it) {
88926 + rcu_read_lock();
88927 + read_lock(&tasklist_lock);
88928 + for (t = next_thread(current); t != current;
88929 + t = next_thread(t)) {
88930 + /* we'll check if the thread has uid 0 in
88931 + * the delayed worker routine
88932 + */
88933 + if (task_securebits(t) == oldsecurebits &&
88934 + t->delayed_cred == NULL) {
88935 + t->delayed_cred = get_cred(new);
88936 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88937 + set_tsk_need_resched(t);
88938 + }
88939 + }
88940 + read_unlock(&tasklist_lock);
88941 + rcu_read_unlock();
88942 + }
88943 +
88944 + return ret;
88945 +#else
88946 + return __commit_creds(new);
88947 +#endif
88948 +}
88949 +
88950 EXPORT_SYMBOL(commit_creds);
88951
88952 /**
88953 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88954 index 1adf62b..7736e06 100644
88955 --- a/kernel/debug/debug_core.c
88956 +++ b/kernel/debug/debug_core.c
88957 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88958 */
88959 static atomic_t masters_in_kgdb;
88960 static atomic_t slaves_in_kgdb;
88961 -static atomic_t kgdb_break_tasklet_var;
88962 +static atomic_unchecked_t kgdb_break_tasklet_var;
88963 atomic_t kgdb_setting_breakpoint;
88964
88965 struct task_struct *kgdb_usethread;
88966 @@ -134,7 +134,7 @@ int kgdb_single_step;
88967 static pid_t kgdb_sstep_pid;
88968
88969 /* to keep track of the CPU which is doing the single stepping*/
88970 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88971 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88972
88973 /*
88974 * If you are debugging a problem where roundup (the collection of
88975 @@ -549,7 +549,7 @@ return_normal:
88976 * kernel will only try for the value of sstep_tries before
88977 * giving up and continuing on.
88978 */
88979 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88980 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88981 (kgdb_info[cpu].task &&
88982 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88983 atomic_set(&kgdb_active, -1);
88984 @@ -647,8 +647,8 @@ cpu_master_loop:
88985 }
88986
88987 kgdb_restore:
88988 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88989 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88990 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88991 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88992 if (kgdb_info[sstep_cpu].task)
88993 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88994 else
88995 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88996 static void kgdb_tasklet_bpt(unsigned long ing)
88997 {
88998 kgdb_breakpoint();
88999 - atomic_set(&kgdb_break_tasklet_var, 0);
89000 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89001 }
89002
89003 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89004
89005 void kgdb_schedule_breakpoint(void)
89006 {
89007 - if (atomic_read(&kgdb_break_tasklet_var) ||
89008 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89009 atomic_read(&kgdb_active) != -1 ||
89010 atomic_read(&kgdb_setting_breakpoint))
89011 return;
89012 - atomic_inc(&kgdb_break_tasklet_var);
89013 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
89014 tasklet_schedule(&kgdb_tasklet_breakpoint);
89015 }
89016 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89017 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89018 index 6ffdc96..af24441 100644
89019 --- a/kernel/debug/kdb/kdb_main.c
89020 +++ b/kernel/debug/kdb/kdb_main.c
89021 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89022 continue;
89023
89024 kdb_printf("%-20s%8u 0x%p ", mod->name,
89025 - mod->core_size, (void *)mod);
89026 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
89027 #ifdef CONFIG_MODULE_UNLOAD
89028 kdb_printf("%4ld ", module_refcount(mod));
89029 #endif
89030 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89031 kdb_printf(" (Loading)");
89032 else
89033 kdb_printf(" (Live)");
89034 - kdb_printf(" 0x%p", mod->module_core);
89035 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89036
89037 #ifdef CONFIG_MODULE_UNLOAD
89038 {
89039 diff --git a/kernel/events/core.c b/kernel/events/core.c
89040 index 2ab0238..bf89262f5 100644
89041 --- a/kernel/events/core.c
89042 +++ b/kernel/events/core.c
89043 @@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
89044 * 0 - disallow raw tracepoint access for unpriv
89045 * 1 - disallow cpu events for unpriv
89046 * 2 - disallow kernel profiling for unpriv
89047 + * 3 - disallow all unpriv perf event use
89048 */
89049 -int sysctl_perf_event_paranoid __read_mostly = 1;
89050 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89051 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89052 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89053 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89054 +#else
89055 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89056 +#endif
89057
89058 /* Minimum for 512 kiB + 1 user control page */
89059 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89060 @@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
89061
89062 tmp *= sysctl_perf_cpu_time_max_percent;
89063 do_div(tmp, 100);
89064 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89065 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89066 }
89067
89068 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89069 @@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89070 }
89071 }
89072
89073 -static atomic64_t perf_event_id;
89074 +static atomic64_unchecked_t perf_event_id;
89075
89076 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89077 enum event_type_t event_type);
89078 @@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
89079
89080 static inline u64 perf_event_count(struct perf_event *event)
89081 {
89082 - return local64_read(&event->count) + atomic64_read(&event->child_count);
89083 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89084 }
89085
89086 static u64 perf_event_read(struct perf_event *event)
89087 @@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89088 mutex_lock(&event->child_mutex);
89089 total += perf_event_read(event);
89090 *enabled += event->total_time_enabled +
89091 - atomic64_read(&event->child_total_time_enabled);
89092 + atomic64_read_unchecked(&event->child_total_time_enabled);
89093 *running += event->total_time_running +
89094 - atomic64_read(&event->child_total_time_running);
89095 + atomic64_read_unchecked(&event->child_total_time_running);
89096
89097 list_for_each_entry(child, &event->child_list, child_list) {
89098 total += perf_event_read(child);
89099 @@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
89100 userpg->offset -= local64_read(&event->hw.prev_count);
89101
89102 userpg->time_enabled = enabled +
89103 - atomic64_read(&event->child_total_time_enabled);
89104 + atomic64_read_unchecked(&event->child_total_time_enabled);
89105
89106 userpg->time_running = running +
89107 - atomic64_read(&event->child_total_time_running);
89108 + atomic64_read_unchecked(&event->child_total_time_running);
89109
89110 arch_perf_update_userpage(userpg, now);
89111
89112 @@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89113
89114 /* Data. */
89115 sp = perf_user_stack_pointer(regs);
89116 - rem = __output_copy_user(handle, (void *) sp, dump_size);
89117 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89118 dyn_size = dump_size - rem;
89119
89120 perf_output_skip(handle, rem);
89121 @@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89122 values[n++] = perf_event_count(event);
89123 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89124 values[n++] = enabled +
89125 - atomic64_read(&event->child_total_time_enabled);
89126 + atomic64_read_unchecked(&event->child_total_time_enabled);
89127 }
89128 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89129 values[n++] = running +
89130 - atomic64_read(&event->child_total_time_running);
89131 + atomic64_read_unchecked(&event->child_total_time_running);
89132 }
89133 if (read_format & PERF_FORMAT_ID)
89134 values[n++] = primary_event_id(event);
89135 @@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89136 event->parent = parent_event;
89137
89138 event->ns = get_pid_ns(task_active_pid_ns(current));
89139 - event->id = atomic64_inc_return(&perf_event_id);
89140 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
89141
89142 event->state = PERF_EVENT_STATE_INACTIVE;
89143
89144 @@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
89145 if (flags & ~PERF_FLAG_ALL)
89146 return -EINVAL;
89147
89148 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89149 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89150 + return -EACCES;
89151 +#endif
89152 +
89153 err = perf_copy_attr(attr_uptr, &attr);
89154 if (err)
89155 return err;
89156 @@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
89157 /*
89158 * Add back the child's count to the parent's count:
89159 */
89160 - atomic64_add(child_val, &parent_event->child_count);
89161 - atomic64_add(child_event->total_time_enabled,
89162 + atomic64_add_unchecked(child_val, &parent_event->child_count);
89163 + atomic64_add_unchecked(child_event->total_time_enabled,
89164 &parent_event->child_total_time_enabled);
89165 - atomic64_add(child_event->total_time_running,
89166 + atomic64_add_unchecked(child_event->total_time_running,
89167 &parent_event->child_total_time_running);
89168
89169 /*
89170 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89171 index 569b2187..19940d9 100644
89172 --- a/kernel/events/internal.h
89173 +++ b/kernel/events/internal.h
89174 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89175 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89176 }
89177
89178 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89179 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89180 static inline unsigned long \
89181 func_name(struct perf_output_handle *handle, \
89182 - const void *buf, unsigned long len) \
89183 + const void user *buf, unsigned long len) \
89184 { \
89185 unsigned long size, written; \
89186 \
89187 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89188 return 0;
89189 }
89190
89191 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89192 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89193
89194 static inline unsigned long
89195 memcpy_skip(void *dst, const void *src, unsigned long n)
89196 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89197 return 0;
89198 }
89199
89200 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89201 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89202
89203 #ifndef arch_perf_out_copy_user
89204 #define arch_perf_out_copy_user arch_perf_out_copy_user
89205 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89206 }
89207 #endif
89208
89209 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89210 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89211
89212 /* Callchain handling */
89213 extern struct perf_callchain_entry *
89214 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89215 index ed8f2cd..fe8030c 100644
89216 --- a/kernel/events/uprobes.c
89217 +++ b/kernel/events/uprobes.c
89218 @@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89219 {
89220 struct page *page;
89221 uprobe_opcode_t opcode;
89222 - int result;
89223 + long result;
89224
89225 pagefault_disable();
89226 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89227 diff --git a/kernel/exit.c b/kernel/exit.c
89228 index 2116aac..d95df2a 100644
89229 --- a/kernel/exit.c
89230 +++ b/kernel/exit.c
89231 @@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
89232 struct task_struct *leader;
89233 int zap_leader;
89234 repeat:
89235 +#ifdef CONFIG_NET
89236 + gr_del_task_from_ip_table(p);
89237 +#endif
89238 +
89239 /* don't need to get the RCU readlock here - the process is dead and
89240 * can't be modifying its own credentials. But shut RCU-lockdep up */
89241 rcu_read_lock();
89242 @@ -670,6 +674,8 @@ void do_exit(long code)
89243 int group_dead;
89244 TASKS_RCU(int tasks_rcu_i);
89245
89246 + set_fs(USER_DS);
89247 +
89248 profile_task_exit(tsk);
89249
89250 WARN_ON(blk_needs_flush_plug(tsk));
89251 @@ -686,7 +692,6 @@ void do_exit(long code)
89252 * mm_release()->clear_child_tid() from writing to a user-controlled
89253 * kernel address.
89254 */
89255 - set_fs(USER_DS);
89256
89257 ptrace_event(PTRACE_EVENT_EXIT, code);
89258
89259 @@ -744,6 +749,9 @@ void do_exit(long code)
89260 tsk->exit_code = code;
89261 taskstats_exit(tsk, group_dead);
89262
89263 + gr_acl_handle_psacct(tsk, code);
89264 + gr_acl_handle_exit();
89265 +
89266 exit_mm(tsk);
89267
89268 if (group_dead)
89269 @@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89270 * Take down every thread in the group. This is called by fatal signals
89271 * as well as by sys_exit_group (below).
89272 */
89273 -void
89274 +__noreturn void
89275 do_group_exit(int exit_code)
89276 {
89277 struct signal_struct *sig = current->signal;
89278 diff --git a/kernel/fork.c b/kernel/fork.c
89279 index 9b7d746..6083ebb 100644
89280 --- a/kernel/fork.c
89281 +++ b/kernel/fork.c
89282 @@ -177,12 +177,54 @@ static void free_thread_info(struct thread_info *ti)
89283 void thread_info_cache_init(void)
89284 {
89285 thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
89286 - THREAD_SIZE, 0, NULL);
89287 + THREAD_SIZE, SLAB_USERCOPY, NULL);
89288 BUG_ON(thread_info_cache == NULL);
89289 }
89290 # endif
89291 #endif
89292
89293 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89294 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89295 + int node, void **lowmem_stack)
89296 +{
89297 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
89298 + void *ret = NULL;
89299 + unsigned int i;
89300 +
89301 + *lowmem_stack = alloc_thread_info_node(tsk, node);
89302 + if (*lowmem_stack == NULL)
89303 + goto out;
89304 +
89305 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89306 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89307 +
89308 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89309 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89310 + if (ret == NULL) {
89311 + free_thread_info(*lowmem_stack);
89312 + *lowmem_stack = NULL;
89313 + }
89314 +
89315 +out:
89316 + return ret;
89317 +}
89318 +
89319 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89320 +{
89321 + unmap_process_stacks(tsk);
89322 +}
89323 +#else
89324 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89325 + int node, void **lowmem_stack)
89326 +{
89327 + return alloc_thread_info_node(tsk, node);
89328 +}
89329 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89330 +{
89331 + free_thread_info(ti);
89332 +}
89333 +#endif
89334 +
89335 /* SLAB cache for signal_struct structures (tsk->signal) */
89336 static struct kmem_cache *signal_cachep;
89337
89338 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89339 /* SLAB cache for mm_struct structures (tsk->mm) */
89340 static struct kmem_cache *mm_cachep;
89341
89342 -static void account_kernel_stack(struct thread_info *ti, int account)
89343 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89344 {
89345 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89346 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89347 +#else
89348 struct zone *zone = page_zone(virt_to_page(ti));
89349 +#endif
89350
89351 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89352 }
89353
89354 void free_task(struct task_struct *tsk)
89355 {
89356 - account_kernel_stack(tsk->stack, -1);
89357 + account_kernel_stack(tsk, tsk->stack, -1);
89358 arch_release_thread_info(tsk->stack);
89359 - free_thread_info(tsk->stack);
89360 + gr_free_thread_info(tsk, tsk->stack);
89361 rt_mutex_debug_task_free(tsk);
89362 ftrace_graph_exit_task(tsk);
89363 put_seccomp_filter(tsk);
89364 @@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89365 {
89366 struct task_struct *tsk;
89367 struct thread_info *ti;
89368 + void *lowmem_stack;
89369 int node = tsk_fork_get_node(orig);
89370 int err;
89371
89372 @@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89373 if (!tsk)
89374 return NULL;
89375
89376 - ti = alloc_thread_info_node(tsk, node);
89377 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89378 if (!ti)
89379 goto free_tsk;
89380
89381 @@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89382 goto free_ti;
89383
89384 tsk->stack = ti;
89385 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89386 + tsk->lowmem_stack = lowmem_stack;
89387 +#endif
89388 #ifdef CONFIG_SECCOMP
89389 /*
89390 * We must handle setting up seccomp filters once we're under
89391 @@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89392 set_task_stack_end_magic(tsk);
89393
89394 #ifdef CONFIG_CC_STACKPROTECTOR
89395 - tsk->stack_canary = get_random_int();
89396 + tsk->stack_canary = pax_get_random_long();
89397 #endif
89398
89399 /*
89400 @@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89401 tsk->splice_pipe = NULL;
89402 tsk->task_frag.page = NULL;
89403
89404 - account_kernel_stack(ti, 1);
89405 + account_kernel_stack(tsk, ti, 1);
89406
89407 return tsk;
89408
89409 free_ti:
89410 - free_thread_info(ti);
89411 + gr_free_thread_info(tsk, ti);
89412 free_tsk:
89413 free_task_struct(tsk);
89414 return NULL;
89415 }
89416
89417 #ifdef CONFIG_MMU
89418 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89419 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89420 +{
89421 + struct vm_area_struct *tmp;
89422 + unsigned long charge;
89423 + struct file *file;
89424 + int retval;
89425 +
89426 + charge = 0;
89427 + if (mpnt->vm_flags & VM_ACCOUNT) {
89428 + unsigned long len = vma_pages(mpnt);
89429 +
89430 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89431 + goto fail_nomem;
89432 + charge = len;
89433 + }
89434 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89435 + if (!tmp)
89436 + goto fail_nomem;
89437 + *tmp = *mpnt;
89438 + tmp->vm_mm = mm;
89439 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
89440 + retval = vma_dup_policy(mpnt, tmp);
89441 + if (retval)
89442 + goto fail_nomem_policy;
89443 + if (anon_vma_fork(tmp, mpnt))
89444 + goto fail_nomem_anon_vma_fork;
89445 + tmp->vm_flags &= ~VM_LOCKED;
89446 + tmp->vm_next = tmp->vm_prev = NULL;
89447 + tmp->vm_mirror = NULL;
89448 + file = tmp->vm_file;
89449 + if (file) {
89450 + struct inode *inode = file_inode(file);
89451 + struct address_space *mapping = file->f_mapping;
89452 +
89453 + get_file(file);
89454 + if (tmp->vm_flags & VM_DENYWRITE)
89455 + atomic_dec(&inode->i_writecount);
89456 + mutex_lock(&mapping->i_mmap_mutex);
89457 + if (tmp->vm_flags & VM_SHARED)
89458 + atomic_inc(&mapping->i_mmap_writable);
89459 + flush_dcache_mmap_lock(mapping);
89460 + /* insert tmp into the share list, just after mpnt */
89461 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89462 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89463 + else
89464 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89465 + flush_dcache_mmap_unlock(mapping);
89466 + mutex_unlock(&mapping->i_mmap_mutex);
89467 + }
89468 +
89469 + /*
89470 + * Clear hugetlb-related page reserves for children. This only
89471 + * affects MAP_PRIVATE mappings. Faults generated by the child
89472 + * are not guaranteed to succeed, even if read-only
89473 + */
89474 + if (is_vm_hugetlb_page(tmp))
89475 + reset_vma_resv_huge_pages(tmp);
89476 +
89477 + return tmp;
89478 +
89479 +fail_nomem_anon_vma_fork:
89480 + mpol_put(vma_policy(tmp));
89481 +fail_nomem_policy:
89482 + kmem_cache_free(vm_area_cachep, tmp);
89483 +fail_nomem:
89484 + vm_unacct_memory(charge);
89485 + return NULL;
89486 +}
89487 +
89488 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89489 {
89490 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89491 struct rb_node **rb_link, *rb_parent;
89492 int retval;
89493 - unsigned long charge;
89494
89495 uprobe_start_dup_mmap();
89496 down_write(&oldmm->mmap_sem);
89497 @@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89498
89499 prev = NULL;
89500 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89501 - struct file *file;
89502 -
89503 if (mpnt->vm_flags & VM_DONTCOPY) {
89504 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89505 -vma_pages(mpnt));
89506 continue;
89507 }
89508 - charge = 0;
89509 - if (mpnt->vm_flags & VM_ACCOUNT) {
89510 - unsigned long len = vma_pages(mpnt);
89511 -
89512 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89513 - goto fail_nomem;
89514 - charge = len;
89515 - }
89516 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89517 - if (!tmp)
89518 - goto fail_nomem;
89519 - *tmp = *mpnt;
89520 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
89521 - retval = vma_dup_policy(mpnt, tmp);
89522 - if (retval)
89523 - goto fail_nomem_policy;
89524 - tmp->vm_mm = mm;
89525 - if (anon_vma_fork(tmp, mpnt))
89526 - goto fail_nomem_anon_vma_fork;
89527 - tmp->vm_flags &= ~VM_LOCKED;
89528 - tmp->vm_next = tmp->vm_prev = NULL;
89529 - file = tmp->vm_file;
89530 - if (file) {
89531 - struct inode *inode = file_inode(file);
89532 - struct address_space *mapping = file->f_mapping;
89533 -
89534 - get_file(file);
89535 - if (tmp->vm_flags & VM_DENYWRITE)
89536 - atomic_dec(&inode->i_writecount);
89537 - mutex_lock(&mapping->i_mmap_mutex);
89538 - if (tmp->vm_flags & VM_SHARED)
89539 - atomic_inc(&mapping->i_mmap_writable);
89540 - flush_dcache_mmap_lock(mapping);
89541 - /* insert tmp into the share list, just after mpnt */
89542 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89543 - vma_nonlinear_insert(tmp,
89544 - &mapping->i_mmap_nonlinear);
89545 - else
89546 - vma_interval_tree_insert_after(tmp, mpnt,
89547 - &mapping->i_mmap);
89548 - flush_dcache_mmap_unlock(mapping);
89549 - mutex_unlock(&mapping->i_mmap_mutex);
89550 + tmp = dup_vma(mm, oldmm, mpnt);
89551 + if (!tmp) {
89552 + retval = -ENOMEM;
89553 + goto out;
89554 }
89555
89556 /*
89557 @@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89558 if (retval)
89559 goto out;
89560 }
89561 +
89562 +#ifdef CONFIG_PAX_SEGMEXEC
89563 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89564 + struct vm_area_struct *mpnt_m;
89565 +
89566 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89567 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89568 +
89569 + if (!mpnt->vm_mirror)
89570 + continue;
89571 +
89572 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89573 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89574 + mpnt->vm_mirror = mpnt_m;
89575 + } else {
89576 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89577 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89578 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89579 + mpnt->vm_mirror->vm_mirror = mpnt;
89580 + }
89581 + }
89582 + BUG_ON(mpnt_m);
89583 + }
89584 +#endif
89585 +
89586 /* a new mm has just been created */
89587 arch_dup_mmap(oldmm, mm);
89588 retval = 0;
89589 @@ -486,14 +589,6 @@ out:
89590 up_write(&oldmm->mmap_sem);
89591 uprobe_end_dup_mmap();
89592 return retval;
89593 -fail_nomem_anon_vma_fork:
89594 - mpol_put(vma_policy(tmp));
89595 -fail_nomem_policy:
89596 - kmem_cache_free(vm_area_cachep, tmp);
89597 -fail_nomem:
89598 - retval = -ENOMEM;
89599 - vm_unacct_memory(charge);
89600 - goto out;
89601 }
89602
89603 static inline int mm_alloc_pgd(struct mm_struct *mm)
89604 @@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89605 return ERR_PTR(err);
89606
89607 mm = get_task_mm(task);
89608 - if (mm && mm != current->mm &&
89609 - !ptrace_may_access(task, mode)) {
89610 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89611 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89612 mmput(mm);
89613 mm = ERR_PTR(-EACCES);
89614 }
89615 @@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89616 spin_unlock(&fs->lock);
89617 return -EAGAIN;
89618 }
89619 - fs->users++;
89620 + atomic_inc(&fs->users);
89621 spin_unlock(&fs->lock);
89622 return 0;
89623 }
89624 tsk->fs = copy_fs_struct(fs);
89625 if (!tsk->fs)
89626 return -ENOMEM;
89627 + /* Carry through gr_chroot_dentry and is_chrooted instead
89628 + of recomputing it here. Already copied when the task struct
89629 + is duplicated. This allows pivot_root to not be treated as
89630 + a chroot
89631 + */
89632 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
89633 +
89634 return 0;
89635 }
89636
89637 @@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89638 * parts of the process environment (as per the clone
89639 * flags). The actual kick-off is left to the caller.
89640 */
89641 -static struct task_struct *copy_process(unsigned long clone_flags,
89642 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89643 unsigned long stack_start,
89644 unsigned long stack_size,
89645 int __user *child_tidptr,
89646 @@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89647 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89648 #endif
89649 retval = -EAGAIN;
89650 +
89651 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89652 +
89653 if (atomic_read(&p->real_cred->user->processes) >=
89654 task_rlimit(p, RLIMIT_NPROC)) {
89655 if (p->real_cred->user != INIT_USER &&
89656 @@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89657 goto bad_fork_free_pid;
89658 }
89659
89660 + /* synchronizes with gr_set_acls()
89661 + we need to call this past the point of no return for fork()
89662 + */
89663 + gr_copy_label(p);
89664 +
89665 if (likely(p->pid)) {
89666 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89667
89668 @@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89669 bad_fork_free:
89670 free_task(p);
89671 fork_out:
89672 + gr_log_forkfail(retval);
89673 +
89674 return ERR_PTR(retval);
89675 }
89676
89677 @@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89678
89679 p = copy_process(clone_flags, stack_start, stack_size,
89680 child_tidptr, NULL, trace);
89681 + add_latent_entropy();
89682 /*
89683 * Do this prior waking up the new thread - the thread pointer
89684 * might get invalid after that point, if the thread exits quickly.
89685 @@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89686 if (clone_flags & CLONE_PARENT_SETTID)
89687 put_user(nr, parent_tidptr);
89688
89689 + gr_handle_brute_check();
89690 +
89691 if (clone_flags & CLONE_VFORK) {
89692 p->vfork_done = &vfork;
89693 init_completion(&vfork);
89694 @@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89695 mm_cachep = kmem_cache_create("mm_struct",
89696 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89697 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89698 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89699 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89700 mmap_init();
89701 nsproxy_cache_init();
89702 }
89703 @@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89704 return 0;
89705
89706 /* don't need lock here; in the worst case we'll do useless copy */
89707 - if (fs->users == 1)
89708 + if (atomic_read(&fs->users) == 1)
89709 return 0;
89710
89711 *new_fsp = copy_fs_struct(fs);
89712 @@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89713 fs = current->fs;
89714 spin_lock(&fs->lock);
89715 current->fs = new_fs;
89716 - if (--fs->users)
89717 + gr_set_chroot_entries(current, &current->fs->root);
89718 + if (atomic_dec_return(&fs->users))
89719 new_fs = NULL;
89720 else
89721 new_fs = fs;
89722 diff --git a/kernel/futex.c b/kernel/futex.c
89723 index 63678b5..512f9af 100644
89724 --- a/kernel/futex.c
89725 +++ b/kernel/futex.c
89726 @@ -201,7 +201,7 @@ struct futex_pi_state {
89727 atomic_t refcount;
89728
89729 union futex_key key;
89730 -};
89731 +} __randomize_layout;
89732
89733 /**
89734 * struct futex_q - The hashed futex queue entry, one per waiting task
89735 @@ -235,7 +235,7 @@ struct futex_q {
89736 struct rt_mutex_waiter *rt_waiter;
89737 union futex_key *requeue_pi_key;
89738 u32 bitset;
89739 -};
89740 +} __randomize_layout;
89741
89742 static const struct futex_q futex_q_init = {
89743 /* list gets initialized in queue_me()*/
89744 @@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89745 struct page *page, *page_head;
89746 int err, ro = 0;
89747
89748 +#ifdef CONFIG_PAX_SEGMEXEC
89749 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89750 + return -EFAULT;
89751 +#endif
89752 +
89753 /*
89754 * The futex address must be "naturally" aligned.
89755 */
89756 @@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89757
89758 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89759 {
89760 - int ret;
89761 + unsigned long ret;
89762
89763 pagefault_disable();
89764 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89765 @@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89766 {
89767 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89768 u32 curval;
89769 + mm_segment_t oldfs;
89770
89771 /*
89772 * This will fail and we want it. Some arch implementations do
89773 @@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89774 * implementation, the non-functional ones will return
89775 * -ENOSYS.
89776 */
89777 + oldfs = get_fs();
89778 + set_fs(USER_DS);
89779 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89780 futex_cmpxchg_enabled = 1;
89781 + set_fs(oldfs);
89782 #endif
89783 }
89784
89785 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89786 index 55c8c93..9ba7ad6 100644
89787 --- a/kernel/futex_compat.c
89788 +++ b/kernel/futex_compat.c
89789 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89790 return 0;
89791 }
89792
89793 -static void __user *futex_uaddr(struct robust_list __user *entry,
89794 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89795 compat_long_t futex_offset)
89796 {
89797 compat_uptr_t base = ptr_to_compat(entry);
89798 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89799 index b358a80..fc25240 100644
89800 --- a/kernel/gcov/base.c
89801 +++ b/kernel/gcov/base.c
89802 @@ -114,11 +114,6 @@ void gcov_enable_events(void)
89803 }
89804
89805 #ifdef CONFIG_MODULES
89806 -static inline int within(void *addr, void *start, unsigned long size)
89807 -{
89808 - return ((addr >= start) && (addr < start + size));
89809 -}
89810 -
89811 /* Update list and generate events when modules are unloaded. */
89812 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89813 void *data)
89814 @@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89815
89816 /* Remove entries located in module from linked list. */
89817 while ((info = gcov_info_next(info))) {
89818 - if (within(info, mod->module_core, mod->core_size)) {
89819 + if (within_module_core_rw((unsigned long)info, mod)) {
89820 gcov_info_unlink(prev, info);
89821 if (gcov_events_enabled)
89822 gcov_event(GCOV_REMOVE, info);
89823 diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
89824 index 0a9104b..fc260e4 100644
89825 --- a/kernel/irq/manage.c
89826 +++ b/kernel/irq/manage.c
89827 @@ -869,7 +869,7 @@ static int irq_thread(void *data)
89828
89829 action_ret = handler_fn(desc, action);
89830 if (action_ret == IRQ_HANDLED)
89831 - atomic_inc(&desc->threads_handled);
89832 + atomic_inc_unchecked(&desc->threads_handled);
89833
89834 wake_threads_waitq(desc);
89835 }
89836 diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
89837 index e2514b0..de3dfe0 100644
89838 --- a/kernel/irq/spurious.c
89839 +++ b/kernel/irq/spurious.c
89840 @@ -337,7 +337,7 @@ void note_interrupt(unsigned int irq, struct irq_desc *desc,
89841 * count. We just care about the count being
89842 * different than the one we saw before.
89843 */
89844 - handled = atomic_read(&desc->threads_handled);
89845 + handled = atomic_read_unchecked(&desc->threads_handled);
89846 handled |= SPURIOUS_DEFERRED;
89847 if (handled != desc->threads_handled_last) {
89848 action_ret = IRQ_HANDLED;
89849 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89850 index 9019f15..9a3c42e 100644
89851 --- a/kernel/jump_label.c
89852 +++ b/kernel/jump_label.c
89853 @@ -14,6 +14,7 @@
89854 #include <linux/err.h>
89855 #include <linux/static_key.h>
89856 #include <linux/jump_label_ratelimit.h>
89857 +#include <linux/mm.h>
89858
89859 #ifdef HAVE_JUMP_LABEL
89860
89861 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89862
89863 size = (((unsigned long)stop - (unsigned long)start)
89864 / sizeof(struct jump_entry));
89865 + pax_open_kernel();
89866 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89867 + pax_close_kernel();
89868 }
89869
89870 static void jump_label_update(struct static_key *key, int enable);
89871 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89872 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89873 struct jump_entry *iter;
89874
89875 + pax_open_kernel();
89876 for (iter = iter_start; iter < iter_stop; iter++) {
89877 if (within_module_init(iter->code, mod))
89878 iter->code = 0;
89879 }
89880 + pax_close_kernel();
89881 }
89882
89883 static int
89884 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89885 index 5c5987f..bc502b0 100644
89886 --- a/kernel/kallsyms.c
89887 +++ b/kernel/kallsyms.c
89888 @@ -11,6 +11,9 @@
89889 * Changed the compression method from stem compression to "table lookup"
89890 * compression (see scripts/kallsyms.c for a more complete description)
89891 */
89892 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89893 +#define __INCLUDED_BY_HIDESYM 1
89894 +#endif
89895 #include <linux/kallsyms.h>
89896 #include <linux/module.h>
89897 #include <linux/init.h>
89898 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89899
89900 static inline int is_kernel_inittext(unsigned long addr)
89901 {
89902 + if (system_state != SYSTEM_BOOTING)
89903 + return 0;
89904 +
89905 if (addr >= (unsigned long)_sinittext
89906 && addr <= (unsigned long)_einittext)
89907 return 1;
89908 return 0;
89909 }
89910
89911 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89912 +#ifdef CONFIG_MODULES
89913 +static inline int is_module_text(unsigned long addr)
89914 +{
89915 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89916 + return 1;
89917 +
89918 + addr = ktla_ktva(addr);
89919 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89920 +}
89921 +#else
89922 +static inline int is_module_text(unsigned long addr)
89923 +{
89924 + return 0;
89925 +}
89926 +#endif
89927 +#endif
89928 +
89929 static inline int is_kernel_text(unsigned long addr)
89930 {
89931 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89932 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89933
89934 static inline int is_kernel(unsigned long addr)
89935 {
89936 +
89937 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89938 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
89939 + return 1;
89940 +
89941 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89942 +#else
89943 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89944 +#endif
89945 +
89946 return 1;
89947 return in_gate_area_no_mm(addr);
89948 }
89949
89950 static int is_ksym_addr(unsigned long addr)
89951 {
89952 +
89953 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89954 + if (is_module_text(addr))
89955 + return 0;
89956 +#endif
89957 +
89958 if (all_var)
89959 return is_kernel(addr);
89960
89961 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89962
89963 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89964 {
89965 - iter->name[0] = '\0';
89966 iter->nameoff = get_symbol_offset(new_pos);
89967 iter->pos = new_pos;
89968 }
89969 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89970 {
89971 struct kallsym_iter *iter = m->private;
89972
89973 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89974 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89975 + return 0;
89976 +#endif
89977 +
89978 /* Some debugging symbols have no name. Ignore them. */
89979 if (!iter->name[0])
89980 return 0;
89981 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89982 */
89983 type = iter->exported ? toupper(iter->type) :
89984 tolower(iter->type);
89985 +
89986 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89987 type, iter->name, iter->module_name);
89988 } else
89989 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89990 index 0aa69ea..a7fcafb 100644
89991 --- a/kernel/kcmp.c
89992 +++ b/kernel/kcmp.c
89993 @@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89994 struct task_struct *task1, *task2;
89995 int ret;
89996
89997 +#ifdef CONFIG_GRKERNSEC
89998 + return -ENOSYS;
89999 +#endif
90000 +
90001 rcu_read_lock();
90002
90003 /*
90004 diff --git a/kernel/kexec.c b/kernel/kexec.c
90005 index 2abf9f6..c40cf85 100644
90006 --- a/kernel/kexec.c
90007 +++ b/kernel/kexec.c
90008 @@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90009 compat_ulong_t, flags)
90010 {
90011 struct compat_kexec_segment in;
90012 - struct kexec_segment out, __user *ksegments;
90013 + struct kexec_segment out;
90014 + struct kexec_segment __user *ksegments;
90015 unsigned long i, result;
90016
90017 /* Don't allow clients that don't understand the native
90018 diff --git a/kernel/kmod.c b/kernel/kmod.c
90019 index 80f7a6d..3c476d3 100644
90020 --- a/kernel/kmod.c
90021 +++ b/kernel/kmod.c
90022 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90023 kfree(info->argv);
90024 }
90025
90026 -static int call_modprobe(char *module_name, int wait)
90027 +static int call_modprobe(char *module_name, char *module_param, int wait)
90028 {
90029 struct subprocess_info *info;
90030 static char *envp[] = {
90031 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90032 NULL
90033 };
90034
90035 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90036 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90037 if (!argv)
90038 goto out;
90039
90040 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90041 argv[1] = "-q";
90042 argv[2] = "--";
90043 argv[3] = module_name; /* check free_modprobe_argv() */
90044 - argv[4] = NULL;
90045 + argv[4] = module_param;
90046 + argv[5] = NULL;
90047
90048 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90049 NULL, free_modprobe_argv, NULL);
90050 @@ -129,9 +130,8 @@ out:
90051 * If module auto-loading support is disabled then this function
90052 * becomes a no-operation.
90053 */
90054 -int __request_module(bool wait, const char *fmt, ...)
90055 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90056 {
90057 - va_list args;
90058 char module_name[MODULE_NAME_LEN];
90059 unsigned int max_modprobes;
90060 int ret;
90061 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90062 if (!modprobe_path[0])
90063 return 0;
90064
90065 - va_start(args, fmt);
90066 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90067 - va_end(args);
90068 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90069 if (ret >= MODULE_NAME_LEN)
90070 return -ENAMETOOLONG;
90071
90072 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90073 if (ret)
90074 return ret;
90075
90076 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90077 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90078 + /* hack to workaround consolekit/udisks stupidity */
90079 + read_lock(&tasklist_lock);
90080 + if (!strcmp(current->comm, "mount") &&
90081 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90082 + read_unlock(&tasklist_lock);
90083 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90084 + return -EPERM;
90085 + }
90086 + read_unlock(&tasklist_lock);
90087 + }
90088 +#endif
90089 +
90090 /* If modprobe needs a service that is in a module, we get a recursive
90091 * loop. Limit the number of running kmod threads to max_threads/2 or
90092 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90093 @@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
90094
90095 trace_module_request(module_name, wait, _RET_IP_);
90096
90097 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90098 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90099
90100 atomic_dec(&kmod_concurrent);
90101 return ret;
90102 }
90103 +
90104 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90105 +{
90106 + va_list args;
90107 + int ret;
90108 +
90109 + va_start(args, fmt);
90110 + ret = ____request_module(wait, module_param, fmt, args);
90111 + va_end(args);
90112 +
90113 + return ret;
90114 +}
90115 +
90116 +int __request_module(bool wait, const char *fmt, ...)
90117 +{
90118 + va_list args;
90119 + int ret;
90120 +
90121 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90122 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90123 + char module_param[MODULE_NAME_LEN];
90124 +
90125 + memset(module_param, 0, sizeof(module_param));
90126 +
90127 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90128 +
90129 + va_start(args, fmt);
90130 + ret = ____request_module(wait, module_param, fmt, args);
90131 + va_end(args);
90132 +
90133 + return ret;
90134 + }
90135 +#endif
90136 +
90137 + va_start(args, fmt);
90138 + ret = ____request_module(wait, NULL, fmt, args);
90139 + va_end(args);
90140 +
90141 + return ret;
90142 +}
90143 +
90144 EXPORT_SYMBOL(__request_module);
90145 #endif /* CONFIG_MODULES */
90146
90147 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90148 {
90149 +#ifdef CONFIG_GRKERNSEC
90150 + kfree(info->path);
90151 + info->path = info->origpath;
90152 +#endif
90153 if (info->cleanup)
90154 (*info->cleanup)(info);
90155 kfree(info);
90156 @@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
90157 */
90158 set_user_nice(current, 0);
90159
90160 +#ifdef CONFIG_GRKERNSEC
90161 + /* this is race-free as far as userland is concerned as we copied
90162 + out the path to be used prior to this point and are now operating
90163 + on that copy
90164 + */
90165 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90166 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90167 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90168 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90169 + retval = -EPERM;
90170 + goto out;
90171 + }
90172 +#endif
90173 +
90174 retval = -ENOMEM;
90175 new = prepare_kernel_cred(current);
90176 if (!new)
90177 @@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
90178 commit_creds(new);
90179
90180 retval = do_execve(getname_kernel(sub_info->path),
90181 - (const char __user *const __user *)sub_info->argv,
90182 - (const char __user *const __user *)sub_info->envp);
90183 + (const char __user *const __force_user *)sub_info->argv,
90184 + (const char __user *const __force_user *)sub_info->envp);
90185 out:
90186 sub_info->retval = retval;
90187 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
90188 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
90189 *
90190 * Thus the __user pointer cast is valid here.
90191 */
90192 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
90193 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90194
90195 /*
90196 * If ret is 0, either ____call_usermodehelper failed and the
90197 @@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90198 goto out;
90199
90200 INIT_WORK(&sub_info->work, __call_usermodehelper);
90201 +#ifdef CONFIG_GRKERNSEC
90202 + sub_info->origpath = path;
90203 + sub_info->path = kstrdup(path, gfp_mask);
90204 +#else
90205 sub_info->path = path;
90206 +#endif
90207 sub_info->argv = argv;
90208 sub_info->envp = envp;
90209
90210 @@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90211 static int proc_cap_handler(struct ctl_table *table, int write,
90212 void __user *buffer, size_t *lenp, loff_t *ppos)
90213 {
90214 - struct ctl_table t;
90215 + ctl_table_no_const t;
90216 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90217 kernel_cap_t new_cap;
90218 int err, i;
90219 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90220 index 3995f54..e247879 100644
90221 --- a/kernel/kprobes.c
90222 +++ b/kernel/kprobes.c
90223 @@ -31,6 +31,9 @@
90224 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90225 * <prasanna@in.ibm.com> added function-return probes.
90226 */
90227 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90228 +#define __INCLUDED_BY_HIDESYM 1
90229 +#endif
90230 #include <linux/kprobes.h>
90231 #include <linux/hash.h>
90232 #include <linux/init.h>
90233 @@ -122,12 +125,12 @@ enum kprobe_slot_state {
90234
90235 static void *alloc_insn_page(void)
90236 {
90237 - return module_alloc(PAGE_SIZE);
90238 + return module_alloc_exec(PAGE_SIZE);
90239 }
90240
90241 static void free_insn_page(void *page)
90242 {
90243 - module_free(NULL, page);
90244 + module_free_exec(NULL, page);
90245 }
90246
90247 struct kprobe_insn_cache kprobe_insn_slots = {
90248 @@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90249 kprobe_type = "k";
90250
90251 if (sym)
90252 - seq_printf(pi, "%p %s %s+0x%x %s ",
90253 + seq_printf(pi, "%pK %s %s+0x%x %s ",
90254 p->addr, kprobe_type, sym, offset,
90255 (modname ? modname : " "));
90256 else
90257 - seq_printf(pi, "%p %s %p ",
90258 + seq_printf(pi, "%pK %s %pK ",
90259 p->addr, kprobe_type, p->addr);
90260
90261 if (!pp)
90262 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90263 index 6683cce..daf8999 100644
90264 --- a/kernel/ksysfs.c
90265 +++ b/kernel/ksysfs.c
90266 @@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90267 {
90268 if (count+1 > UEVENT_HELPER_PATH_LEN)
90269 return -ENOENT;
90270 + if (!capable(CAP_SYS_ADMIN))
90271 + return -EPERM;
90272 memcpy(uevent_helper, buf, count);
90273 uevent_helper[count] = '\0';
90274 if (count && uevent_helper[count-1] == '\n')
90275 @@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90276 return count;
90277 }
90278
90279 -static struct bin_attribute notes_attr = {
90280 +static bin_attribute_no_const notes_attr __read_only = {
90281 .attr = {
90282 .name = "notes",
90283 .mode = S_IRUGO,
90284 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90285 index 88d0d44..e9ce0ee 100644
90286 --- a/kernel/locking/lockdep.c
90287 +++ b/kernel/locking/lockdep.c
90288 @@ -599,6 +599,10 @@ static int static_obj(void *obj)
90289 end = (unsigned long) &_end,
90290 addr = (unsigned long) obj;
90291
90292 +#ifdef CONFIG_PAX_KERNEXEC
90293 + start = ktla_ktva(start);
90294 +#endif
90295 +
90296 /*
90297 * static variable?
90298 */
90299 @@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90300 if (!static_obj(lock->key)) {
90301 debug_locks_off();
90302 printk("INFO: trying to register non-static key.\n");
90303 + printk("lock:%pS key:%pS.\n", lock, lock->key);
90304 printk("the code is fine but needs lockdep annotation.\n");
90305 printk("turning off the locking correctness validator.\n");
90306 dump_stack();
90307 @@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90308 if (!class)
90309 return 0;
90310 }
90311 - atomic_inc((atomic_t *)&class->ops);
90312 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90313 if (very_verbose(class)) {
90314 printk("\nacquire class [%p] %s", class->key, class->name);
90315 if (class->name_version > 1)
90316 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90317 index ef43ac4..2720dfa 100644
90318 --- a/kernel/locking/lockdep_proc.c
90319 +++ b/kernel/locking/lockdep_proc.c
90320 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90321 return 0;
90322 }
90323
90324 - seq_printf(m, "%p", class->key);
90325 + seq_printf(m, "%pK", class->key);
90326 #ifdef CONFIG_DEBUG_LOCKDEP
90327 seq_printf(m, " OPS:%8ld", class->ops);
90328 #endif
90329 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90330
90331 list_for_each_entry(entry, &class->locks_after, entry) {
90332 if (entry->distance == 1) {
90333 - seq_printf(m, " -> [%p] ", entry->class->key);
90334 + seq_printf(m, " -> [%pK] ", entry->class->key);
90335 print_name(m, entry->class);
90336 seq_puts(m, "\n");
90337 }
90338 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90339 if (!class->key)
90340 continue;
90341
90342 - seq_printf(m, "[%p] ", class->key);
90343 + seq_printf(m, "[%pK] ", class->key);
90344 print_name(m, class);
90345 seq_puts(m, "\n");
90346 }
90347 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90348 if (!i)
90349 seq_line(m, '-', 40-namelen, namelen);
90350
90351 - snprintf(ip, sizeof(ip), "[<%p>]",
90352 + snprintf(ip, sizeof(ip), "[<%pK>]",
90353 (void *)class->contention_point[i]);
90354 seq_printf(m, "%40s %14lu %29s %pS\n",
90355 name, stats->contention_point[i],
90356 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90357 if (!i)
90358 seq_line(m, '-', 40-namelen, namelen);
90359
90360 - snprintf(ip, sizeof(ip), "[<%p>]",
90361 + snprintf(ip, sizeof(ip), "[<%pK>]",
90362 (void *)class->contending_point[i]);
90363 seq_printf(m, "%40s %14lu %29s %pS\n",
90364 name, stats->contending_point[i],
90365 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90366 index 9887a90..0cd2b1d 100644
90367 --- a/kernel/locking/mcs_spinlock.c
90368 +++ b/kernel/locking/mcs_spinlock.c
90369 @@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90370
90371 prev = decode_cpu(old);
90372 node->prev = prev;
90373 - ACCESS_ONCE(prev->next) = node;
90374 + ACCESS_ONCE_RW(prev->next) = node;
90375
90376 /*
90377 * Normally @prev is untouchable after the above store; because at that
90378 @@ -172,8 +172,8 @@ unqueue:
90379 * it will wait in Step-A.
90380 */
90381
90382 - ACCESS_ONCE(next->prev) = prev;
90383 - ACCESS_ONCE(prev->next) = next;
90384 + ACCESS_ONCE_RW(next->prev) = prev;
90385 + ACCESS_ONCE_RW(prev->next) = next;
90386
90387 return false;
90388 }
90389 @@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90390 node = this_cpu_ptr(&osq_node);
90391 next = xchg(&node->next, NULL);
90392 if (next) {
90393 - ACCESS_ONCE(next->locked) = 1;
90394 + ACCESS_ONCE_RW(next->locked) = 1;
90395 return;
90396 }
90397
90398 next = osq_wait_next(lock, node, NULL);
90399 if (next)
90400 - ACCESS_ONCE(next->locked) = 1;
90401 + ACCESS_ONCE_RW(next->locked) = 1;
90402 }
90403
90404 #endif
90405 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90406 index 4d60986..5d351c1 100644
90407 --- a/kernel/locking/mcs_spinlock.h
90408 +++ b/kernel/locking/mcs_spinlock.h
90409 @@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90410 */
90411 return;
90412 }
90413 - ACCESS_ONCE(prev->next) = node;
90414 + ACCESS_ONCE_RW(prev->next) = node;
90415
90416 /* Wait until the lock holder passes the lock down. */
90417 arch_mcs_spin_lock_contended(&node->locked);
90418 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90419 index 5cf6731..ce3bc5a 100644
90420 --- a/kernel/locking/mutex-debug.c
90421 +++ b/kernel/locking/mutex-debug.c
90422 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90423 }
90424
90425 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90426 - struct thread_info *ti)
90427 + struct task_struct *task)
90428 {
90429 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90430
90431 /* Mark the current thread as blocked on the lock: */
90432 - ti->task->blocked_on = waiter;
90433 + task->blocked_on = waiter;
90434 }
90435
90436 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90437 - struct thread_info *ti)
90438 + struct task_struct *task)
90439 {
90440 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90441 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90442 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90443 - ti->task->blocked_on = NULL;
90444 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
90445 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90446 + task->blocked_on = NULL;
90447
90448 list_del_init(&waiter->list);
90449 waiter->task = NULL;
90450 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90451 index 0799fd3..d06ae3b 100644
90452 --- a/kernel/locking/mutex-debug.h
90453 +++ b/kernel/locking/mutex-debug.h
90454 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90455 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90456 extern void debug_mutex_add_waiter(struct mutex *lock,
90457 struct mutex_waiter *waiter,
90458 - struct thread_info *ti);
90459 + struct task_struct *task);
90460 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90461 - struct thread_info *ti);
90462 + struct task_struct *task);
90463 extern void debug_mutex_unlock(struct mutex *lock);
90464 extern void debug_mutex_init(struct mutex *lock, const char *name,
90465 struct lock_class_key *key);
90466 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90467 index dadbf88..4500507 100644
90468 --- a/kernel/locking/mutex.c
90469 +++ b/kernel/locking/mutex.c
90470 @@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90471 goto skip_wait;
90472
90473 debug_mutex_lock_common(lock, &waiter);
90474 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90475 + debug_mutex_add_waiter(lock, &waiter, task);
90476
90477 /* add waiting tasks to the end of the waitqueue (FIFO): */
90478 list_add_tail(&waiter.list, &lock->wait_list);
90479 @@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90480 schedule_preempt_disabled();
90481 spin_lock_mutex(&lock->wait_lock, flags);
90482 }
90483 - mutex_remove_waiter(lock, &waiter, current_thread_info());
90484 + mutex_remove_waiter(lock, &waiter, task);
90485 /* set it to 0 if there are no waiters left: */
90486 if (likely(list_empty(&lock->wait_list)))
90487 atomic_set(&lock->count, 0);
90488 @@ -600,7 +600,7 @@ skip_wait:
90489 return 0;
90490
90491 err:
90492 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90493 + mutex_remove_waiter(lock, &waiter, task);
90494 spin_unlock_mutex(&lock->wait_lock, flags);
90495 debug_mutex_free_waiter(&waiter);
90496 mutex_release(&lock->dep_map, 1, ip);
90497 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90498 index 1d96dd0..994ff19 100644
90499 --- a/kernel/locking/rtmutex-tester.c
90500 +++ b/kernel/locking/rtmutex-tester.c
90501 @@ -22,7 +22,7 @@
90502 #define MAX_RT_TEST_MUTEXES 8
90503
90504 static spinlock_t rttest_lock;
90505 -static atomic_t rttest_event;
90506 +static atomic_unchecked_t rttest_event;
90507
90508 struct test_thread_data {
90509 int opcode;
90510 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90511
90512 case RTTEST_LOCKCONT:
90513 td->mutexes[td->opdata] = 1;
90514 - td->event = atomic_add_return(1, &rttest_event);
90515 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90516 return 0;
90517
90518 case RTTEST_RESET:
90519 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90520 return 0;
90521
90522 case RTTEST_RESETEVENT:
90523 - atomic_set(&rttest_event, 0);
90524 + atomic_set_unchecked(&rttest_event, 0);
90525 return 0;
90526
90527 default:
90528 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90529 return ret;
90530
90531 td->mutexes[id] = 1;
90532 - td->event = atomic_add_return(1, &rttest_event);
90533 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90534 rt_mutex_lock(&mutexes[id]);
90535 - td->event = atomic_add_return(1, &rttest_event);
90536 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90537 td->mutexes[id] = 4;
90538 return 0;
90539
90540 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90541 return ret;
90542
90543 td->mutexes[id] = 1;
90544 - td->event = atomic_add_return(1, &rttest_event);
90545 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90546 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90547 - td->event = atomic_add_return(1, &rttest_event);
90548 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90549 td->mutexes[id] = ret ? 0 : 4;
90550 return ret ? -EINTR : 0;
90551
90552 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90553 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90554 return ret;
90555
90556 - td->event = atomic_add_return(1, &rttest_event);
90557 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90558 rt_mutex_unlock(&mutexes[id]);
90559 - td->event = atomic_add_return(1, &rttest_event);
90560 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90561 td->mutexes[id] = 0;
90562 return 0;
90563
90564 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90565 break;
90566
90567 td->mutexes[dat] = 2;
90568 - td->event = atomic_add_return(1, &rttest_event);
90569 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90570 break;
90571
90572 default:
90573 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90574 return;
90575
90576 td->mutexes[dat] = 3;
90577 - td->event = atomic_add_return(1, &rttest_event);
90578 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90579 break;
90580
90581 case RTTEST_LOCKNOWAIT:
90582 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90583 return;
90584
90585 td->mutexes[dat] = 1;
90586 - td->event = atomic_add_return(1, &rttest_event);
90587 + td->event = atomic_add_return_unchecked(1, &rttest_event);
90588 return;
90589
90590 default:
90591 diff --git a/kernel/module.c b/kernel/module.c
90592 index 88cec1d..d097c28 100644
90593 --- a/kernel/module.c
90594 +++ b/kernel/module.c
90595 @@ -60,6 +60,7 @@
90596 #include <linux/jump_label.h>
90597 #include <linux/pfn.h>
90598 #include <linux/bsearch.h>
90599 +#include <linux/grsecurity.h>
90600 #include <uapi/linux/module.h>
90601 #include "module-internal.h"
90602
90603 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90604
90605 /* Bounds of module allocation, for speeding __module_address.
90606 * Protected by module_mutex. */
90607 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90608 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90609 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90610
90611 int register_module_notifier(struct notifier_block * nb)
90612 {
90613 @@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90614 return true;
90615
90616 list_for_each_entry_rcu(mod, &modules, list) {
90617 - struct symsearch arr[] = {
90618 + struct symsearch modarr[] = {
90619 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90620 NOT_GPL_ONLY, false },
90621 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90622 @@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90623 if (mod->state == MODULE_STATE_UNFORMED)
90624 continue;
90625
90626 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90627 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90628 return true;
90629 }
90630 return false;
90631 @@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90632 if (!pcpusec->sh_size)
90633 return 0;
90634
90635 - if (align > PAGE_SIZE) {
90636 + if (align-1 >= PAGE_SIZE) {
90637 pr_warn("%s: per-cpu alignment %li > %li\n",
90638 mod->name, align, PAGE_SIZE);
90639 align = PAGE_SIZE;
90640 @@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90641 static ssize_t show_coresize(struct module_attribute *mattr,
90642 struct module_kobject *mk, char *buffer)
90643 {
90644 - return sprintf(buffer, "%u\n", mk->mod->core_size);
90645 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90646 }
90647
90648 static struct module_attribute modinfo_coresize =
90649 @@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90650 static ssize_t show_initsize(struct module_attribute *mattr,
90651 struct module_kobject *mk, char *buffer)
90652 {
90653 - return sprintf(buffer, "%u\n", mk->mod->init_size);
90654 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90655 }
90656
90657 static struct module_attribute modinfo_initsize =
90658 @@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90659 goto bad_version;
90660 }
90661
90662 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90663 + /*
90664 + * avoid potentially printing jibberish on attempted load
90665 + * of a module randomized with a different seed
90666 + */
90667 + pr_warn("no symbol version for %s\n", symname);
90668 +#else
90669 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90670 +#endif
90671 return 0;
90672
90673 bad_version:
90674 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90675 + /*
90676 + * avoid potentially printing jibberish on attempted load
90677 + * of a module randomized with a different seed
90678 + */
90679 + printk("attempted module disagrees about version of symbol %s\n",
90680 + symname);
90681 +#else
90682 printk("%s: disagrees about version of symbol %s\n",
90683 mod->name, symname);
90684 +#endif
90685 return 0;
90686 }
90687
90688 @@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90689 */
90690 #ifdef CONFIG_SYSFS
90691
90692 -#ifdef CONFIG_KALLSYMS
90693 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90694 static inline bool sect_empty(const Elf_Shdr *sect)
90695 {
90696 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90697 @@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90698 {
90699 unsigned int notes, loaded, i;
90700 struct module_notes_attrs *notes_attrs;
90701 - struct bin_attribute *nattr;
90702 + bin_attribute_no_const *nattr;
90703
90704 /* failed to create section attributes, so can't create notes */
90705 if (!mod->sect_attrs)
90706 @@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90707 static int module_add_modinfo_attrs(struct module *mod)
90708 {
90709 struct module_attribute *attr;
90710 - struct module_attribute *temp_attr;
90711 + module_attribute_no_const *temp_attr;
90712 int error = 0;
90713 int i;
90714
90715 @@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90716
90717 static void unset_module_core_ro_nx(struct module *mod)
90718 {
90719 - set_page_attributes(mod->module_core + mod->core_text_size,
90720 - mod->module_core + mod->core_size,
90721 + set_page_attributes(mod->module_core_rw,
90722 + mod->module_core_rw + mod->core_size_rw,
90723 set_memory_x);
90724 - set_page_attributes(mod->module_core,
90725 - mod->module_core + mod->core_ro_size,
90726 + set_page_attributes(mod->module_core_rx,
90727 + mod->module_core_rx + mod->core_size_rx,
90728 set_memory_rw);
90729 }
90730
90731 static void unset_module_init_ro_nx(struct module *mod)
90732 {
90733 - set_page_attributes(mod->module_init + mod->init_text_size,
90734 - mod->module_init + mod->init_size,
90735 + set_page_attributes(mod->module_init_rw,
90736 + mod->module_init_rw + mod->init_size_rw,
90737 set_memory_x);
90738 - set_page_attributes(mod->module_init,
90739 - mod->module_init + mod->init_ro_size,
90740 + set_page_attributes(mod->module_init_rx,
90741 + mod->module_init_rx + mod->init_size_rx,
90742 set_memory_rw);
90743 }
90744
90745 @@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90746 list_for_each_entry_rcu(mod, &modules, list) {
90747 if (mod->state == MODULE_STATE_UNFORMED)
90748 continue;
90749 - if ((mod->module_core) && (mod->core_text_size)) {
90750 - set_page_attributes(mod->module_core,
90751 - mod->module_core + mod->core_text_size,
90752 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90753 + set_page_attributes(mod->module_core_rx,
90754 + mod->module_core_rx + mod->core_size_rx,
90755 set_memory_rw);
90756 }
90757 - if ((mod->module_init) && (mod->init_text_size)) {
90758 - set_page_attributes(mod->module_init,
90759 - mod->module_init + mod->init_text_size,
90760 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90761 + set_page_attributes(mod->module_init_rx,
90762 + mod->module_init_rx + mod->init_size_rx,
90763 set_memory_rw);
90764 }
90765 }
90766 @@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90767 list_for_each_entry_rcu(mod, &modules, list) {
90768 if (mod->state == MODULE_STATE_UNFORMED)
90769 continue;
90770 - if ((mod->module_core) && (mod->core_text_size)) {
90771 - set_page_attributes(mod->module_core,
90772 - mod->module_core + mod->core_text_size,
90773 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
90774 + set_page_attributes(mod->module_core_rx,
90775 + mod->module_core_rx + mod->core_size_rx,
90776 set_memory_ro);
90777 }
90778 - if ((mod->module_init) && (mod->init_text_size)) {
90779 - set_page_attributes(mod->module_init,
90780 - mod->module_init + mod->init_text_size,
90781 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
90782 + set_page_attributes(mod->module_init_rx,
90783 + mod->module_init_rx + mod->init_size_rx,
90784 set_memory_ro);
90785 }
90786 }
90787 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90788
90789 /* This may be NULL, but that's OK */
90790 unset_module_init_ro_nx(mod);
90791 - module_free(mod, mod->module_init);
90792 + module_free(mod, mod->module_init_rw);
90793 + module_free_exec(mod, mod->module_init_rx);
90794 kfree(mod->args);
90795 percpu_modfree(mod);
90796
90797 /* Free lock-classes: */
90798 - lockdep_free_key_range(mod->module_core, mod->core_size);
90799 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90800 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90801
90802 /* Finally, free the core (containing the module structure) */
90803 unset_module_core_ro_nx(mod);
90804 - module_free(mod, mod->module_core);
90805 + module_free_exec(mod, mod->module_core_rx);
90806 + module_free(mod, mod->module_core_rw);
90807
90808 #ifdef CONFIG_MPU
90809 update_protections(current->mm);
90810 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90811 int ret = 0;
90812 const struct kernel_symbol *ksym;
90813
90814 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90815 + int is_fs_load = 0;
90816 + int register_filesystem_found = 0;
90817 + char *p;
90818 +
90819 + p = strstr(mod->args, "grsec_modharden_fs");
90820 + if (p) {
90821 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90822 + /* copy \0 as well */
90823 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90824 + is_fs_load = 1;
90825 + }
90826 +#endif
90827 +
90828 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90829 const char *name = info->strtab + sym[i].st_name;
90830
90831 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90832 + /* it's a real shame this will never get ripped and copied
90833 + upstream! ;(
90834 + */
90835 + if (is_fs_load && !strcmp(name, "register_filesystem"))
90836 + register_filesystem_found = 1;
90837 +#endif
90838 +
90839 switch (sym[i].st_shndx) {
90840 case SHN_COMMON:
90841 /* Ignore common symbols */
90842 @@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90843 ksym = resolve_symbol_wait(mod, info, name);
90844 /* Ok if resolved. */
90845 if (ksym && !IS_ERR(ksym)) {
90846 + pax_open_kernel();
90847 sym[i].st_value = ksym->value;
90848 + pax_close_kernel();
90849 break;
90850 }
90851
90852 @@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90853 secbase = (unsigned long)mod_percpu(mod);
90854 else
90855 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90856 + pax_open_kernel();
90857 sym[i].st_value += secbase;
90858 + pax_close_kernel();
90859 break;
90860 }
90861 }
90862
90863 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
90864 + if (is_fs_load && !register_filesystem_found) {
90865 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90866 + ret = -EPERM;
90867 + }
90868 +#endif
90869 +
90870 return ret;
90871 }
90872
90873 @@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90874 || s->sh_entsize != ~0UL
90875 || strstarts(sname, ".init"))
90876 continue;
90877 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90878 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90879 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90880 + else
90881 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90882 pr_debug("\t%s\n", sname);
90883 }
90884 - switch (m) {
90885 - case 0: /* executable */
90886 - mod->core_size = debug_align(mod->core_size);
90887 - mod->core_text_size = mod->core_size;
90888 - break;
90889 - case 1: /* RO: text and ro-data */
90890 - mod->core_size = debug_align(mod->core_size);
90891 - mod->core_ro_size = mod->core_size;
90892 - break;
90893 - case 3: /* whole core */
90894 - mod->core_size = debug_align(mod->core_size);
90895 - break;
90896 - }
90897 }
90898
90899 pr_debug("Init section allocation order:\n");
90900 @@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90901 || s->sh_entsize != ~0UL
90902 || !strstarts(sname, ".init"))
90903 continue;
90904 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90905 - | INIT_OFFSET_MASK);
90906 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90907 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90908 + else
90909 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90910 + s->sh_entsize |= INIT_OFFSET_MASK;
90911 pr_debug("\t%s\n", sname);
90912 }
90913 - switch (m) {
90914 - case 0: /* executable */
90915 - mod->init_size = debug_align(mod->init_size);
90916 - mod->init_text_size = mod->init_size;
90917 - break;
90918 - case 1: /* RO: text and ro-data */
90919 - mod->init_size = debug_align(mod->init_size);
90920 - mod->init_ro_size = mod->init_size;
90921 - break;
90922 - case 3: /* whole init */
90923 - mod->init_size = debug_align(mod->init_size);
90924 - break;
90925 - }
90926 }
90927 }
90928
90929 @@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90930
90931 /* Put symbol section at end of init part of module. */
90932 symsect->sh_flags |= SHF_ALLOC;
90933 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90934 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90935 info->index.sym) | INIT_OFFSET_MASK;
90936 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90937
90938 @@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90939 }
90940
90941 /* Append room for core symbols at end of core part. */
90942 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90943 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90944 - mod->core_size += strtab_size;
90945 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90946 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90947 + mod->core_size_rx += strtab_size;
90948
90949 /* Put string table section at end of init part of module. */
90950 strsect->sh_flags |= SHF_ALLOC;
90951 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90952 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90953 info->index.str) | INIT_OFFSET_MASK;
90954 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90955 }
90956 @@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90957 /* Make sure we get permanent strtab: don't use info->strtab. */
90958 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90959
90960 + pax_open_kernel();
90961 +
90962 /* Set types up while we still have access to sections. */
90963 for (i = 0; i < mod->num_symtab; i++)
90964 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90965
90966 - mod->core_symtab = dst = mod->module_core + info->symoffs;
90967 - mod->core_strtab = s = mod->module_core + info->stroffs;
90968 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90969 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90970 src = mod->symtab;
90971 for (ndst = i = 0; i < mod->num_symtab; i++) {
90972 if (i == 0 ||
90973 @@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90974 }
90975 }
90976 mod->core_num_syms = ndst;
90977 +
90978 + pax_close_kernel();
90979 }
90980 #else
90981 static inline void layout_symtab(struct module *mod, struct load_info *info)
90982 @@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90983 return vmalloc_exec(size);
90984 }
90985
90986 -static void *module_alloc_update_bounds(unsigned long size)
90987 +static void *module_alloc_update_bounds_rw(unsigned long size)
90988 {
90989 void *ret = module_alloc(size);
90990
90991 if (ret) {
90992 mutex_lock(&module_mutex);
90993 /* Update module bounds. */
90994 - if ((unsigned long)ret < module_addr_min)
90995 - module_addr_min = (unsigned long)ret;
90996 - if ((unsigned long)ret + size > module_addr_max)
90997 - module_addr_max = (unsigned long)ret + size;
90998 + if ((unsigned long)ret < module_addr_min_rw)
90999 + module_addr_min_rw = (unsigned long)ret;
91000 + if ((unsigned long)ret + size > module_addr_max_rw)
91001 + module_addr_max_rw = (unsigned long)ret + size;
91002 + mutex_unlock(&module_mutex);
91003 + }
91004 + return ret;
91005 +}
91006 +
91007 +static void *module_alloc_update_bounds_rx(unsigned long size)
91008 +{
91009 + void *ret = module_alloc_exec(size);
91010 +
91011 + if (ret) {
91012 + mutex_lock(&module_mutex);
91013 + /* Update module bounds. */
91014 + if ((unsigned long)ret < module_addr_min_rx)
91015 + module_addr_min_rx = (unsigned long)ret;
91016 + if ((unsigned long)ret + size > module_addr_max_rx)
91017 + module_addr_max_rx = (unsigned long)ret + size;
91018 mutex_unlock(&module_mutex);
91019 }
91020 return ret;
91021 @@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91022 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91023
91024 if (info->index.sym == 0) {
91025 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91026 + /*
91027 + * avoid potentially printing jibberish on attempted load
91028 + * of a module randomized with a different seed
91029 + */
91030 + pr_warn("module has no symbols (stripped?)\n");
91031 +#else
91032 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91033 +#endif
91034 return ERR_PTR(-ENOEXEC);
91035 }
91036
91037 @@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91038 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91039 {
91040 const char *modmagic = get_modinfo(info, "vermagic");
91041 + const char *license = get_modinfo(info, "license");
91042 int err;
91043
91044 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91045 + if (!license || !license_is_gpl_compatible(license))
91046 + return -ENOEXEC;
91047 +#endif
91048 +
91049 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91050 modmagic = NULL;
91051
91052 @@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91053 }
91054
91055 /* Set up license info based on the info section */
91056 - set_license(mod, get_modinfo(info, "license"));
91057 + set_license(mod, license);
91058
91059 return 0;
91060 }
91061 @@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91062 void *ptr;
91063
91064 /* Do the allocs. */
91065 - ptr = module_alloc_update_bounds(mod->core_size);
91066 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91067 /*
91068 * The pointer to this block is stored in the module structure
91069 * which is inside the block. Just mark it as not being a
91070 @@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91071 if (!ptr)
91072 return -ENOMEM;
91073
91074 - memset(ptr, 0, mod->core_size);
91075 - mod->module_core = ptr;
91076 + memset(ptr, 0, mod->core_size_rw);
91077 + mod->module_core_rw = ptr;
91078
91079 - if (mod->init_size) {
91080 - ptr = module_alloc_update_bounds(mod->init_size);
91081 + if (mod->init_size_rw) {
91082 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91083 /*
91084 * The pointer to this block is stored in the module structure
91085 * which is inside the block. This block doesn't need to be
91086 @@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91087 */
91088 kmemleak_ignore(ptr);
91089 if (!ptr) {
91090 - module_free(mod, mod->module_core);
91091 + module_free(mod, mod->module_core_rw);
91092 return -ENOMEM;
91093 }
91094 - memset(ptr, 0, mod->init_size);
91095 - mod->module_init = ptr;
91096 + memset(ptr, 0, mod->init_size_rw);
91097 + mod->module_init_rw = ptr;
91098 } else
91099 - mod->module_init = NULL;
91100 + mod->module_init_rw = NULL;
91101 +
91102 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91103 + kmemleak_not_leak(ptr);
91104 + if (!ptr) {
91105 + if (mod->module_init_rw)
91106 + module_free(mod, mod->module_init_rw);
91107 + module_free(mod, mod->module_core_rw);
91108 + return -ENOMEM;
91109 + }
91110 +
91111 + pax_open_kernel();
91112 + memset(ptr, 0, mod->core_size_rx);
91113 + pax_close_kernel();
91114 + mod->module_core_rx = ptr;
91115 +
91116 + if (mod->init_size_rx) {
91117 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91118 + kmemleak_ignore(ptr);
91119 + if (!ptr && mod->init_size_rx) {
91120 + module_free_exec(mod, mod->module_core_rx);
91121 + if (mod->module_init_rw)
91122 + module_free(mod, mod->module_init_rw);
91123 + module_free(mod, mod->module_core_rw);
91124 + return -ENOMEM;
91125 + }
91126 +
91127 + pax_open_kernel();
91128 + memset(ptr, 0, mod->init_size_rx);
91129 + pax_close_kernel();
91130 + mod->module_init_rx = ptr;
91131 + } else
91132 + mod->module_init_rx = NULL;
91133
91134 /* Transfer each section which specifies SHF_ALLOC */
91135 pr_debug("final section addresses:\n");
91136 @@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91137 if (!(shdr->sh_flags & SHF_ALLOC))
91138 continue;
91139
91140 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
91141 - dest = mod->module_init
91142 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91143 - else
91144 - dest = mod->module_core + shdr->sh_entsize;
91145 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91146 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91147 + dest = mod->module_init_rw
91148 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91149 + else
91150 + dest = mod->module_init_rx
91151 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91152 + } else {
91153 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91154 + dest = mod->module_core_rw + shdr->sh_entsize;
91155 + else
91156 + dest = mod->module_core_rx + shdr->sh_entsize;
91157 + }
91158 +
91159 + if (shdr->sh_type != SHT_NOBITS) {
91160 +
91161 +#ifdef CONFIG_PAX_KERNEXEC
91162 +#ifdef CONFIG_X86_64
91163 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91164 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91165 +#endif
91166 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91167 + pax_open_kernel();
91168 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91169 + pax_close_kernel();
91170 + } else
91171 +#endif
91172
91173 - if (shdr->sh_type != SHT_NOBITS)
91174 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91175 + }
91176 /* Update sh_addr to point to copy in image. */
91177 - shdr->sh_addr = (unsigned long)dest;
91178 +
91179 +#ifdef CONFIG_PAX_KERNEXEC
91180 + if (shdr->sh_flags & SHF_EXECINSTR)
91181 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
91182 + else
91183 +#endif
91184 +
91185 + shdr->sh_addr = (unsigned long)dest;
91186 pr_debug("\t0x%lx %s\n",
91187 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91188 }
91189 @@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91190 * Do it before processing of module parameters, so the module
91191 * can provide parameter accessor functions of its own.
91192 */
91193 - if (mod->module_init)
91194 - flush_icache_range((unsigned long)mod->module_init,
91195 - (unsigned long)mod->module_init
91196 - + mod->init_size);
91197 - flush_icache_range((unsigned long)mod->module_core,
91198 - (unsigned long)mod->module_core + mod->core_size);
91199 + if (mod->module_init_rx)
91200 + flush_icache_range((unsigned long)mod->module_init_rx,
91201 + (unsigned long)mod->module_init_rx
91202 + + mod->init_size_rx);
91203 + flush_icache_range((unsigned long)mod->module_core_rx,
91204 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
91205
91206 set_fs(old_fs);
91207 }
91208 @@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91209 static void module_deallocate(struct module *mod, struct load_info *info)
91210 {
91211 percpu_modfree(mod);
91212 - module_free(mod, mod->module_init);
91213 - module_free(mod, mod->module_core);
91214 + module_free_exec(mod, mod->module_init_rx);
91215 + module_free_exec(mod, mod->module_core_rx);
91216 + module_free(mod, mod->module_init_rw);
91217 + module_free(mod, mod->module_core_rw);
91218 }
91219
91220 int __weak module_finalize(const Elf_Ehdr *hdr,
91221 @@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91222 static int post_relocation(struct module *mod, const struct load_info *info)
91223 {
91224 /* Sort exception table now relocations are done. */
91225 + pax_open_kernel();
91226 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91227 + pax_close_kernel();
91228
91229 /* Copy relocated percpu area over. */
91230 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91231 @@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91232 mod->strtab = mod->core_strtab;
91233 #endif
91234 unset_module_init_ro_nx(mod);
91235 - module_free(mod, mod->module_init);
91236 - mod->module_init = NULL;
91237 - mod->init_size = 0;
91238 - mod->init_ro_size = 0;
91239 - mod->init_text_size = 0;
91240 + module_free(mod, mod->module_init_rw);
91241 + module_free_exec(mod, mod->module_init_rx);
91242 + mod->module_init_rw = NULL;
91243 + mod->module_init_rx = NULL;
91244 + mod->init_size_rw = 0;
91245 + mod->init_size_rx = 0;
91246 mutex_unlock(&module_mutex);
91247 wake_up_all(&module_wq);
91248
91249 @@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91250 module_bug_finalize(info->hdr, info->sechdrs, mod);
91251
91252 /* Set RO and NX regions for core */
91253 - set_section_ro_nx(mod->module_core,
91254 - mod->core_text_size,
91255 - mod->core_ro_size,
91256 - mod->core_size);
91257 + set_section_ro_nx(mod->module_core_rx,
91258 + mod->core_size_rx,
91259 + mod->core_size_rx,
91260 + mod->core_size_rx);
91261
91262 /* Set RO and NX regions for init */
91263 - set_section_ro_nx(mod->module_init,
91264 - mod->init_text_size,
91265 - mod->init_ro_size,
91266 - mod->init_size);
91267 + set_section_ro_nx(mod->module_init_rx,
91268 + mod->init_size_rx,
91269 + mod->init_size_rx,
91270 + mod->init_size_rx);
91271
91272 /* Mark state as coming so strong_try_module_get() ignores us,
91273 * but kallsyms etc. can see us. */
91274 @@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91275 if (err)
91276 goto free_unload;
91277
91278 + /* Now copy in args */
91279 + mod->args = strndup_user(uargs, ~0UL >> 1);
91280 + if (IS_ERR(mod->args)) {
91281 + err = PTR_ERR(mod->args);
91282 + goto free_unload;
91283 + }
91284 +
91285 /* Set up MODINFO_ATTR fields */
91286 setup_modinfo(mod, info);
91287
91288 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
91289 + {
91290 + char *p, *p2;
91291 +
91292 + if (strstr(mod->args, "grsec_modharden_netdev")) {
91293 + 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);
91294 + err = -EPERM;
91295 + goto free_modinfo;
91296 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91297 + p += sizeof("grsec_modharden_normal") - 1;
91298 + p2 = strstr(p, "_");
91299 + if (p2) {
91300 + *p2 = '\0';
91301 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91302 + *p2 = '_';
91303 + }
91304 + err = -EPERM;
91305 + goto free_modinfo;
91306 + }
91307 + }
91308 +#endif
91309 +
91310 /* Fix up syms, so that st_value is a pointer to location. */
91311 err = simplify_symbols(mod, info);
91312 if (err < 0)
91313 @@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91314
91315 flush_module_icache(mod);
91316
91317 - /* Now copy in args */
91318 - mod->args = strndup_user(uargs, ~0UL >> 1);
91319 - if (IS_ERR(mod->args)) {
91320 - err = PTR_ERR(mod->args);
91321 - goto free_arch_cleanup;
91322 - }
91323 -
91324 dynamic_debug_setup(info->debug, info->num_debug);
91325
91326 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91327 @@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91328 ddebug_cleanup:
91329 dynamic_debug_remove(info->debug);
91330 synchronize_sched();
91331 - kfree(mod->args);
91332 - free_arch_cleanup:
91333 module_arch_cleanup(mod);
91334 free_modinfo:
91335 free_modinfo(mod);
91336 + kfree(mod->args);
91337 free_unload:
91338 module_unload_free(mod);
91339 unlink_mod:
91340 @@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91341 unsigned long nextval;
91342
91343 /* At worse, next value is at end of module */
91344 - if (within_module_init(addr, mod))
91345 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
91346 + if (within_module_init_rx(addr, mod))
91347 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91348 + else if (within_module_init_rw(addr, mod))
91349 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91350 + else if (within_module_core_rx(addr, mod))
91351 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91352 + else if (within_module_core_rw(addr, mod))
91353 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91354 else
91355 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
91356 + return NULL;
91357
91358 /* Scan for closest preceding symbol, and next symbol. (ELF
91359 starts real symbols at 1). */
91360 @@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91361 return 0;
91362
91363 seq_printf(m, "%s %u",
91364 - mod->name, mod->init_size + mod->core_size);
91365 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91366 print_unload_info(m, mod);
91367
91368 /* Informative for users. */
91369 @@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91370 mod->state == MODULE_STATE_COMING ? "Loading":
91371 "Live");
91372 /* Used by oprofile and other similar tools. */
91373 - seq_printf(m, " 0x%pK", mod->module_core);
91374 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91375
91376 /* Taints info */
91377 if (mod->taints)
91378 @@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91379
91380 static int __init proc_modules_init(void)
91381 {
91382 +#ifndef CONFIG_GRKERNSEC_HIDESYM
91383 +#ifdef CONFIG_GRKERNSEC_PROC_USER
91384 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91385 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91386 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91387 +#else
91388 proc_create("modules", 0, NULL, &proc_modules_operations);
91389 +#endif
91390 +#else
91391 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91392 +#endif
91393 return 0;
91394 }
91395 module_init(proc_modules_init);
91396 @@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91397 {
91398 struct module *mod;
91399
91400 - if (addr < module_addr_min || addr > module_addr_max)
91401 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91402 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
91403 return NULL;
91404
91405 list_for_each_entry_rcu(mod, &modules, list) {
91406 @@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91407 */
91408 struct module *__module_text_address(unsigned long addr)
91409 {
91410 - struct module *mod = __module_address(addr);
91411 + struct module *mod;
91412 +
91413 +#ifdef CONFIG_X86_32
91414 + addr = ktla_ktva(addr);
91415 +#endif
91416 +
91417 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91418 + return NULL;
91419 +
91420 + mod = __module_address(addr);
91421 +
91422 if (mod) {
91423 /* Make sure it's within the text section. */
91424 - if (!within(addr, mod->module_init, mod->init_text_size)
91425 - && !within(addr, mod->module_core, mod->core_text_size))
91426 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91427 mod = NULL;
91428 }
91429 return mod;
91430 diff --git a/kernel/notifier.c b/kernel/notifier.c
91431 index 4803da6..1c5eea6 100644
91432 --- a/kernel/notifier.c
91433 +++ b/kernel/notifier.c
91434 @@ -5,6 +5,7 @@
91435 #include <linux/rcupdate.h>
91436 #include <linux/vmalloc.h>
91437 #include <linux/reboot.h>
91438 +#include <linux/mm.h>
91439
91440 /*
91441 * Notifier list for kernel code which wants to be called
91442 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91443 while ((*nl) != NULL) {
91444 if (n->priority > (*nl)->priority)
91445 break;
91446 - nl = &((*nl)->next);
91447 + nl = (struct notifier_block **)&((*nl)->next);
91448 }
91449 - n->next = *nl;
91450 + pax_open_kernel();
91451 + *(const void **)&n->next = *nl;
91452 rcu_assign_pointer(*nl, n);
91453 + pax_close_kernel();
91454 return 0;
91455 }
91456
91457 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91458 return 0;
91459 if (n->priority > (*nl)->priority)
91460 break;
91461 - nl = &((*nl)->next);
91462 + nl = (struct notifier_block **)&((*nl)->next);
91463 }
91464 - n->next = *nl;
91465 + pax_open_kernel();
91466 + *(const void **)&n->next = *nl;
91467 rcu_assign_pointer(*nl, n);
91468 + pax_close_kernel();
91469 return 0;
91470 }
91471
91472 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91473 {
91474 while ((*nl) != NULL) {
91475 if ((*nl) == n) {
91476 + pax_open_kernel();
91477 rcu_assign_pointer(*nl, n->next);
91478 + pax_close_kernel();
91479 return 0;
91480 }
91481 - nl = &((*nl)->next);
91482 + nl = (struct notifier_block **)&((*nl)->next);
91483 }
91484 return -ENOENT;
91485 }
91486 diff --git a/kernel/padata.c b/kernel/padata.c
91487 index 161402f..598814c 100644
91488 --- a/kernel/padata.c
91489 +++ b/kernel/padata.c
91490 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91491 * seq_nr mod. number of cpus in use.
91492 */
91493
91494 - seq_nr = atomic_inc_return(&pd->seq_nr);
91495 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91496 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91497
91498 return padata_index_to_cpu(pd, cpu_index);
91499 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91500 padata_init_pqueues(pd);
91501 padata_init_squeues(pd);
91502 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91503 - atomic_set(&pd->seq_nr, -1);
91504 + atomic_set_unchecked(&pd->seq_nr, -1);
91505 atomic_set(&pd->reorder_objects, 0);
91506 atomic_set(&pd->refcnt, 0);
91507 pd->pinst = pinst;
91508 diff --git a/kernel/panic.c b/kernel/panic.c
91509 index cf80672..f6771b2 100644
91510 --- a/kernel/panic.c
91511 +++ b/kernel/panic.c
91512 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91513 /*
91514 * Stop ourself in panic -- architecture code may override this
91515 */
91516 -void __weak panic_smp_self_stop(void)
91517 +void __weak __noreturn panic_smp_self_stop(void)
91518 {
91519 while (1)
91520 cpu_relax();
91521 @@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91522 disable_trace_on_warning();
91523
91524 pr_warn("------------[ cut here ]------------\n");
91525 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91526 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91527 raw_smp_processor_id(), current->pid, file, line, caller);
91528
91529 if (args)
91530 @@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91531 */
91532 __visible void __stack_chk_fail(void)
91533 {
91534 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
91535 + dump_stack();
91536 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91537 __builtin_return_address(0));
91538 }
91539 EXPORT_SYMBOL(__stack_chk_fail);
91540 diff --git a/kernel/pid.c b/kernel/pid.c
91541 index 82430c8..53d7793 100644
91542 --- a/kernel/pid.c
91543 +++ b/kernel/pid.c
91544 @@ -33,6 +33,7 @@
91545 #include <linux/rculist.h>
91546 #include <linux/bootmem.h>
91547 #include <linux/hash.h>
91548 +#include <linux/security.h>
91549 #include <linux/pid_namespace.h>
91550 #include <linux/init_task.h>
91551 #include <linux/syscalls.h>
91552 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91553
91554 int pid_max = PID_MAX_DEFAULT;
91555
91556 -#define RESERVED_PIDS 300
91557 +#define RESERVED_PIDS 500
91558
91559 int pid_max_min = RESERVED_PIDS + 1;
91560 int pid_max_max = PID_MAX_LIMIT;
91561 @@ -447,10 +448,18 @@ EXPORT_SYMBOL(pid_task);
91562 */
91563 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91564 {
91565 + struct task_struct *task;
91566 +
91567 rcu_lockdep_assert(rcu_read_lock_held(),
91568 "find_task_by_pid_ns() needs rcu_read_lock()"
91569 " protection");
91570 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91571 +
91572 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91573 +
91574 + if (gr_pid_is_chrooted(task))
91575 + return NULL;
91576 +
91577 + return task;
91578 }
91579
91580 struct task_struct *find_task_by_vpid(pid_t vnr)
91581 @@ -458,6 +467,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91582 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91583 }
91584
91585 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91586 +{
91587 + rcu_lockdep_assert(rcu_read_lock_held(),
91588 + "find_task_by_pid_ns() needs rcu_read_lock()"
91589 + " protection");
91590 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91591 +}
91592 +
91593 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91594 {
91595 struct pid *pid;
91596 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91597 index db95d8e..a0ca23f 100644
91598 --- a/kernel/pid_namespace.c
91599 +++ b/kernel/pid_namespace.c
91600 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91601 void __user *buffer, size_t *lenp, loff_t *ppos)
91602 {
91603 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91604 - struct ctl_table tmp = *table;
91605 + ctl_table_no_const tmp = *table;
91606
91607 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91608 return -EPERM;
91609 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91610 index bbef57f..5f94462 100644
91611 --- a/kernel/power/Kconfig
91612 +++ b/kernel/power/Kconfig
91613 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91614 config HIBERNATION
91615 bool "Hibernation (aka 'suspend to disk')"
91616 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91617 + depends on !GRKERNSEC_KMEM
91618 + depends on !PAX_MEMORY_SANITIZE
91619 select HIBERNATE_CALLBACKS
91620 select LZO_COMPRESS
91621 select LZO_DECOMPRESS
91622 diff --git a/kernel/power/process.c b/kernel/power/process.c
91623 index 5a6ec86..3a8c884 100644
91624 --- a/kernel/power/process.c
91625 +++ b/kernel/power/process.c
91626 @@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91627 unsigned int elapsed_msecs;
91628 bool wakeup = false;
91629 int sleep_usecs = USEC_PER_MSEC;
91630 + bool timedout = false;
91631
91632 do_gettimeofday(&start);
91633
91634 @@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91635
91636 while (true) {
91637 todo = 0;
91638 + if (time_after(jiffies, end_time))
91639 + timedout = true;
91640 read_lock(&tasklist_lock);
91641 for_each_process_thread(g, p) {
91642 if (p == current || !freeze_task(p))
91643 continue;
91644
91645 - if (!freezer_should_skip(p))
91646 + if (!freezer_should_skip(p)) {
91647 todo++;
91648 + if (timedout) {
91649 + printk(KERN_ERR "Task refusing to freeze:\n");
91650 + sched_show_task(p);
91651 + }
91652 + }
91653 }
91654 read_unlock(&tasklist_lock);
91655
91656 @@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91657 todo += wq_busy;
91658 }
91659
91660 - if (!todo || time_after(jiffies, end_time))
91661 + if (!todo || timedout)
91662 break;
91663
91664 if (pm_wakeup_pending()) {
91665 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91666 index ced2b84..ffc4791 100644
91667 --- a/kernel/printk/printk.c
91668 +++ b/kernel/printk/printk.c
91669 @@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91670 if (from_file && type != SYSLOG_ACTION_OPEN)
91671 return 0;
91672
91673 +#ifdef CONFIG_GRKERNSEC_DMESG
91674 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91675 + return -EPERM;
91676 +#endif
91677 +
91678 if (syslog_action_restricted(type)) {
91679 if (capable(CAP_SYSLOG))
91680 return 0;
91681 diff --git a/kernel/profile.c b/kernel/profile.c
91682 index 54bf5ba..df6e0a2 100644
91683 --- a/kernel/profile.c
91684 +++ b/kernel/profile.c
91685 @@ -37,7 +37,7 @@ struct profile_hit {
91686 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91687 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91688
91689 -static atomic_t *prof_buffer;
91690 +static atomic_unchecked_t *prof_buffer;
91691 static unsigned long prof_len, prof_shift;
91692
91693 int prof_on __read_mostly;
91694 @@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91695 hits[i].pc = 0;
91696 continue;
91697 }
91698 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91699 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91700 hits[i].hits = hits[i].pc = 0;
91701 }
91702 }
91703 @@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91704 * Add the current hit(s) and flush the write-queue out
91705 * to the global buffer:
91706 */
91707 - atomic_add(nr_hits, &prof_buffer[pc]);
91708 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91709 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91710 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91711 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91712 hits[i].pc = hits[i].hits = 0;
91713 }
91714 out:
91715 @@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91716 {
91717 unsigned long pc;
91718 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91719 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91720 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91721 }
91722 #endif /* !CONFIG_SMP */
91723
91724 @@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91725 return -EFAULT;
91726 buf++; p++; count--; read++;
91727 }
91728 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91729 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91730 if (copy_to_user(buf, (void *)pnt, count))
91731 return -EFAULT;
91732 read += count;
91733 @@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91734 }
91735 #endif
91736 profile_discard_flip_buffers();
91737 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91738 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91739 return count;
91740 }
91741
91742 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91743 index 54e7522..5b82dd6 100644
91744 --- a/kernel/ptrace.c
91745 +++ b/kernel/ptrace.c
91746 @@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91747 if (seize)
91748 flags |= PT_SEIZED;
91749 rcu_read_lock();
91750 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91751 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91752 flags |= PT_PTRACE_CAP;
91753 rcu_read_unlock();
91754 task->ptrace = flags;
91755 @@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91756 break;
91757 return -EIO;
91758 }
91759 - if (copy_to_user(dst, buf, retval))
91760 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91761 return -EFAULT;
91762 copied += retval;
91763 src += retval;
91764 @@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91765 bool seized = child->ptrace & PT_SEIZED;
91766 int ret = -EIO;
91767 siginfo_t siginfo, *si;
91768 - void __user *datavp = (void __user *) data;
91769 + void __user *datavp = (__force void __user *) data;
91770 unsigned long __user *datalp = datavp;
91771 unsigned long flags;
91772
91773 @@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91774 goto out;
91775 }
91776
91777 + if (gr_handle_ptrace(child, request)) {
91778 + ret = -EPERM;
91779 + goto out_put_task_struct;
91780 + }
91781 +
91782 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91783 ret = ptrace_attach(child, request, addr, data);
91784 /*
91785 * Some architectures need to do book-keeping after
91786 * a ptrace attach.
91787 */
91788 - if (!ret)
91789 + if (!ret) {
91790 arch_ptrace_attach(child);
91791 + gr_audit_ptrace(child);
91792 + }
91793 goto out_put_task_struct;
91794 }
91795
91796 @@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91797 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91798 if (copied != sizeof(tmp))
91799 return -EIO;
91800 - return put_user(tmp, (unsigned long __user *)data);
91801 + return put_user(tmp, (__force unsigned long __user *)data);
91802 }
91803
91804 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91805 @@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91806 }
91807
91808 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91809 - compat_long_t, addr, compat_long_t, data)
91810 + compat_ulong_t, addr, compat_ulong_t, data)
91811 {
91812 struct task_struct *child;
91813 long ret;
91814 @@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91815 goto out;
91816 }
91817
91818 + if (gr_handle_ptrace(child, request)) {
91819 + ret = -EPERM;
91820 + goto out_put_task_struct;
91821 + }
91822 +
91823 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91824 ret = ptrace_attach(child, request, addr, data);
91825 /*
91826 * Some architectures need to do book-keeping after
91827 * a ptrace attach.
91828 */
91829 - if (!ret)
91830 + if (!ret) {
91831 arch_ptrace_attach(child);
91832 + gr_audit_ptrace(child);
91833 + }
91834 goto out_put_task_struct;
91835 }
91836
91837 diff --git a/kernel/range.c b/kernel/range.c
91838 index 322ea8e..82cfc28 100644
91839 --- a/kernel/range.c
91840 +++ b/kernel/range.c
91841 @@ -113,12 +113,12 @@ static int cmp_range(const void *x1, const void *x2)
91842 {
91843 const struct range *r1 = x1;
91844 const struct range *r2 = x2;
91845 - s64 start1, start2;
91846
91847 - start1 = r1->start;
91848 - start2 = r2->start;
91849 -
91850 - return start1 - start2;
91851 + if (r1->start < r2->start)
91852 + return -1;
91853 + if (r1->start > r2->start)
91854 + return 1;
91855 + return 0;
91856 }
91857
91858 int clean_sort_range(struct range *range, int az)
91859 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91860 index 240fa90..5fa56bd 100644
91861 --- a/kernel/rcu/rcutorture.c
91862 +++ b/kernel/rcu/rcutorture.c
91863 @@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91864 rcu_torture_count) = { 0 };
91865 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91866 rcu_torture_batch) = { 0 };
91867 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91868 -static atomic_t n_rcu_torture_alloc;
91869 -static atomic_t n_rcu_torture_alloc_fail;
91870 -static atomic_t n_rcu_torture_free;
91871 -static atomic_t n_rcu_torture_mberror;
91872 -static atomic_t n_rcu_torture_error;
91873 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91874 +static atomic_unchecked_t n_rcu_torture_alloc;
91875 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
91876 +static atomic_unchecked_t n_rcu_torture_free;
91877 +static atomic_unchecked_t n_rcu_torture_mberror;
91878 +static atomic_unchecked_t n_rcu_torture_error;
91879 static long n_rcu_torture_barrier_error;
91880 static long n_rcu_torture_boost_ktrerror;
91881 static long n_rcu_torture_boost_rterror;
91882 @@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91883 static long n_rcu_torture_timers;
91884 static long n_barrier_attempts;
91885 static long n_barrier_successes;
91886 -static atomic_long_t n_cbfloods;
91887 +static atomic_long_unchecked_t n_cbfloods;
91888 static struct list_head rcu_torture_removed;
91889
91890 static int rcu_torture_writer_state;
91891 @@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91892
91893 spin_lock_bh(&rcu_torture_lock);
91894 if (list_empty(&rcu_torture_freelist)) {
91895 - atomic_inc(&n_rcu_torture_alloc_fail);
91896 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91897 spin_unlock_bh(&rcu_torture_lock);
91898 return NULL;
91899 }
91900 - atomic_inc(&n_rcu_torture_alloc);
91901 + atomic_inc_unchecked(&n_rcu_torture_alloc);
91902 p = rcu_torture_freelist.next;
91903 list_del_init(p);
91904 spin_unlock_bh(&rcu_torture_lock);
91905 @@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91906 static void
91907 rcu_torture_free(struct rcu_torture *p)
91908 {
91909 - atomic_inc(&n_rcu_torture_free);
91910 + atomic_inc_unchecked(&n_rcu_torture_free);
91911 spin_lock_bh(&rcu_torture_lock);
91912 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91913 spin_unlock_bh(&rcu_torture_lock);
91914 @@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91915 i = rp->rtort_pipe_count;
91916 if (i > RCU_TORTURE_PIPE_LEN)
91917 i = RCU_TORTURE_PIPE_LEN;
91918 - atomic_inc(&rcu_torture_wcount[i]);
91919 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91920 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91921 rp->rtort_mbtest = 0;
91922 return true;
91923 @@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91924 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91925 do {
91926 schedule_timeout_interruptible(cbflood_inter_holdoff);
91927 - atomic_long_inc(&n_cbfloods);
91928 + atomic_long_inc_unchecked(&n_cbfloods);
91929 WARN_ON(signal_pending(current));
91930 for (i = 0; i < cbflood_n_burst; i++) {
91931 for (j = 0; j < cbflood_n_per_burst; j++) {
91932 @@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91933 i = old_rp->rtort_pipe_count;
91934 if (i > RCU_TORTURE_PIPE_LEN)
91935 i = RCU_TORTURE_PIPE_LEN;
91936 - atomic_inc(&rcu_torture_wcount[i]);
91937 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
91938 old_rp->rtort_pipe_count++;
91939 switch (synctype[torture_random(&rand) % nsynctypes]) {
91940 case RTWS_DEF_FREE:
91941 @@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91942 return;
91943 }
91944 if (p->rtort_mbtest == 0)
91945 - atomic_inc(&n_rcu_torture_mberror);
91946 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91947 spin_lock(&rand_lock);
91948 cur_ops->read_delay(&rand);
91949 n_rcu_torture_timers++;
91950 @@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91951 continue;
91952 }
91953 if (p->rtort_mbtest == 0)
91954 - atomic_inc(&n_rcu_torture_mberror);
91955 + atomic_inc_unchecked(&n_rcu_torture_mberror);
91956 cur_ops->read_delay(&rand);
91957 preempt_disable();
91958 pipe_count = p->rtort_pipe_count;
91959 @@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91960 rcu_torture_current,
91961 rcu_torture_current_version,
91962 list_empty(&rcu_torture_freelist),
91963 - atomic_read(&n_rcu_torture_alloc),
91964 - atomic_read(&n_rcu_torture_alloc_fail),
91965 - atomic_read(&n_rcu_torture_free));
91966 + atomic_read_unchecked(&n_rcu_torture_alloc),
91967 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91968 + atomic_read_unchecked(&n_rcu_torture_free));
91969 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91970 - atomic_read(&n_rcu_torture_mberror),
91971 + atomic_read_unchecked(&n_rcu_torture_mberror),
91972 n_rcu_torture_boost_ktrerror,
91973 n_rcu_torture_boost_rterror);
91974 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91975 @@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91976 n_barrier_successes,
91977 n_barrier_attempts,
91978 n_rcu_torture_barrier_error);
91979 - pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91980 + pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91981
91982 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91983 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91984 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91985 n_rcu_torture_barrier_error != 0 ||
91986 n_rcu_torture_boost_ktrerror != 0 ||
91987 n_rcu_torture_boost_rterror != 0 ||
91988 n_rcu_torture_boost_failure != 0 ||
91989 i > 1) {
91990 pr_cont("%s", "!!! ");
91991 - atomic_inc(&n_rcu_torture_error);
91992 + atomic_inc_unchecked(&n_rcu_torture_error);
91993 WARN_ON_ONCE(1);
91994 }
91995 pr_cont("Reader Pipe: ");
91996 @@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91997 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91998 pr_cont("Free-Block Circulation: ");
91999 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92000 - pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
92001 + pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
92002 }
92003 pr_cont("\n");
92004
92005 @@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
92006
92007 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
92008
92009 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92010 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92011 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
92012 else if (torture_onoff_failures())
92013 rcu_torture_print_module_parms(cur_ops,
92014 @@ -1684,18 +1684,18 @@ rcu_torture_init(void)
92015
92016 rcu_torture_current = NULL;
92017 rcu_torture_current_version = 0;
92018 - atomic_set(&n_rcu_torture_alloc, 0);
92019 - atomic_set(&n_rcu_torture_alloc_fail, 0);
92020 - atomic_set(&n_rcu_torture_free, 0);
92021 - atomic_set(&n_rcu_torture_mberror, 0);
92022 - atomic_set(&n_rcu_torture_error, 0);
92023 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
92024 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
92025 + atomic_set_unchecked(&n_rcu_torture_free, 0);
92026 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
92027 + atomic_set_unchecked(&n_rcu_torture_error, 0);
92028 n_rcu_torture_barrier_error = 0;
92029 n_rcu_torture_boost_ktrerror = 0;
92030 n_rcu_torture_boost_rterror = 0;
92031 n_rcu_torture_boost_failure = 0;
92032 n_rcu_torture_boosts = 0;
92033 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
92034 - atomic_set(&rcu_torture_wcount[i], 0);
92035 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92036 for_each_possible_cpu(cpu) {
92037 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92038 per_cpu(rcu_torture_count, cpu)[i] = 0;
92039 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92040 index c0623fc..329c091 100644
92041 --- a/kernel/rcu/tiny.c
92042 +++ b/kernel/rcu/tiny.c
92043 @@ -42,7 +42,7 @@
92044 /* Forward declarations for tiny_plugin.h. */
92045 struct rcu_ctrlblk;
92046 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92047 -static void rcu_process_callbacks(struct softirq_action *unused);
92048 +static void rcu_process_callbacks(void);
92049 static void __call_rcu(struct rcu_head *head,
92050 void (*func)(struct rcu_head *rcu),
92051 struct rcu_ctrlblk *rcp);
92052 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92053 false));
92054 }
92055
92056 -static void rcu_process_callbacks(struct softirq_action *unused)
92057 +static __latent_entropy void rcu_process_callbacks(void)
92058 {
92059 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92060 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92061 diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92062 index 858c565..7efd915 100644
92063 --- a/kernel/rcu/tiny_plugin.h
92064 +++ b/kernel/rcu/tiny_plugin.h
92065 @@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92066 dump_stack();
92067 }
92068 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92069 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92070 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92071 3 * rcu_jiffies_till_stall_check() + 3;
92072 else if (ULONG_CMP_GE(j, js))
92073 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92074 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92075 }
92076
92077 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92078 {
92079 rcp->ticks_this_gp = 0;
92080 rcp->gp_start = jiffies;
92081 - ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92082 + ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92083 }
92084
92085 static void check_cpu_stalls(void)
92086 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92087 index 9815447..2cdf92a 100644
92088 --- a/kernel/rcu/tree.c
92089 +++ b/kernel/rcu/tree.c
92090 @@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
92091 */
92092 rdtp = this_cpu_ptr(&rcu_dynticks);
92093 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92094 - atomic_add(2, &rdtp->dynticks); /* QS. */
92095 + atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92096 smp_mb__after_atomic(); /* Later stuff after QS. */
92097 break;
92098 }
92099 @@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92100 rcu_prepare_for_idle(smp_processor_id());
92101 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92102 smp_mb__before_atomic(); /* See above. */
92103 - atomic_inc(&rdtp->dynticks);
92104 + atomic_inc_unchecked(&rdtp->dynticks);
92105 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92106 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92107 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92108 rcu_dynticks_task_enter();
92109
92110 /*
92111 @@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92112 {
92113 rcu_dynticks_task_exit();
92114 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92115 - atomic_inc(&rdtp->dynticks);
92116 + atomic_inc_unchecked(&rdtp->dynticks);
92117 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92118 smp_mb__after_atomic(); /* See above. */
92119 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92120 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92121 rcu_cleanup_after_idle(smp_processor_id());
92122 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92123 if (!user && !is_idle_task(current)) {
92124 @@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
92125 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92126
92127 if (rdtp->dynticks_nmi_nesting == 0 &&
92128 - (atomic_read(&rdtp->dynticks) & 0x1))
92129 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92130 return;
92131 rdtp->dynticks_nmi_nesting++;
92132 smp_mb__before_atomic(); /* Force delay from prior write. */
92133 - atomic_inc(&rdtp->dynticks);
92134 + atomic_inc_unchecked(&rdtp->dynticks);
92135 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92136 smp_mb__after_atomic(); /* See above. */
92137 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92138 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92139 }
92140
92141 /**
92142 @@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
92143 return;
92144 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92145 smp_mb__before_atomic(); /* See above. */
92146 - atomic_inc(&rdtp->dynticks);
92147 + atomic_inc_unchecked(&rdtp->dynticks);
92148 smp_mb__after_atomic(); /* Force delay to next write. */
92149 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92150 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92151 }
92152
92153 /**
92154 @@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
92155 */
92156 bool notrace __rcu_is_watching(void)
92157 {
92158 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92159 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92160 }
92161
92162 /**
92163 @@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92164 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92165 bool *isidle, unsigned long *maxj)
92166 {
92167 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92168 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92169 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92170 if ((rdp->dynticks_snap & 0x1) == 0) {
92171 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92172 @@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92173 int *rcrmp;
92174 unsigned int snap;
92175
92176 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92177 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92178 snap = (unsigned int)rdp->dynticks_snap;
92179
92180 /*
92181 @@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92182 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92183 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92184 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92185 - ACCESS_ONCE(rdp->cond_resched_completed) =
92186 + ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92187 ACCESS_ONCE(rdp->mynode->completed);
92188 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92189 - ACCESS_ONCE(*rcrmp) =
92190 + ACCESS_ONCE_RW(*rcrmp) =
92191 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92192 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92193 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92194 @@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92195 rsp->gp_start = j;
92196 smp_wmb(); /* Record start time before stall time. */
92197 j1 = rcu_jiffies_till_stall_check();
92198 - ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92199 + ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92200 rsp->jiffies_resched = j + j1 / 2;
92201 }
92202
92203 @@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92204 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92205 return;
92206 }
92207 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92208 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92209 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92210
92211 /*
92212 @@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92213
92214 raw_spin_lock_irqsave(&rnp->lock, flags);
92215 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92216 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92217 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92218 3 * rcu_jiffies_till_stall_check() + 3;
92219 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92220
92221 @@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
92222 struct rcu_state *rsp;
92223
92224 for_each_rcu_flavor(rsp)
92225 - ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92226 + ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92227 }
92228
92229 /*
92230 @@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92231 raw_spin_unlock_irq(&rnp->lock);
92232 return 0;
92233 }
92234 - ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92235 + ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92236
92237 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92238 /*
92239 @@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92240 rdp = this_cpu_ptr(rsp->rda);
92241 rcu_preempt_check_blocked_tasks(rnp);
92242 rnp->qsmask = rnp->qsmaskinit;
92243 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92244 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92245 WARN_ON_ONCE(rnp->completed != rsp->completed);
92246 - ACCESS_ONCE(rnp->completed) = rsp->completed;
92247 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92248 if (rnp == rdp->mynode)
92249 (void)__note_gp_changes(rsp, rnp, rdp);
92250 rcu_preempt_boost_start_gp(rnp);
92251 @@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92252 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92253 raw_spin_lock_irq(&rnp->lock);
92254 smp_mb__after_unlock_lock();
92255 - ACCESS_ONCE(rsp->gp_flags) =
92256 + ACCESS_ONCE_RW(rsp->gp_flags) =
92257 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
92258 raw_spin_unlock_irq(&rnp->lock);
92259 }
92260 @@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92261 rcu_for_each_node_breadth_first(rsp, rnp) {
92262 raw_spin_lock_irq(&rnp->lock);
92263 smp_mb__after_unlock_lock();
92264 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92265 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92266 rdp = this_cpu_ptr(rsp->rda);
92267 if (rnp == rdp->mynode)
92268 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92269 @@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92270 rcu_nocb_gp_set(rnp, nocb);
92271
92272 /* Declare grace period done. */
92273 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92274 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92275 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92276 rsp->fqs_state = RCU_GP_IDLE;
92277 rdp = this_cpu_ptr(rsp->rda);
92278 /* Advance CBs to reduce false positives below. */
92279 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92280 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92281 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92282 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92283 trace_rcu_grace_period(rsp->name,
92284 ACCESS_ONCE(rsp->gpnum),
92285 TPS("newreq"));
92286 @@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92287 */
92288 return false;
92289 }
92290 - ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92291 + ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92292 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92293 TPS("newreq"));
92294
92295 @@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92296 rsp->qlen += rdp->qlen;
92297 rdp->n_cbs_orphaned += rdp->qlen;
92298 rdp->qlen_lazy = 0;
92299 - ACCESS_ONCE(rdp->qlen) = 0;
92300 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92301 }
92302
92303 /*
92304 @@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92305 }
92306 smp_mb(); /* List handling before counting for rcu_barrier(). */
92307 rdp->qlen_lazy -= count_lazy;
92308 - ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92309 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92310 rdp->n_cbs_invoked += count;
92311
92312 /* Reinstate batch limit if we have worked down the excess. */
92313 @@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92314 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92315 return; /* Someone beat us to it. */
92316 }
92317 - ACCESS_ONCE(rsp->gp_flags) =
92318 + ACCESS_ONCE_RW(rsp->gp_flags) =
92319 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
92320 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92321 rcu_gp_kthread_wake(rsp);
92322 @@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92323 /*
92324 * Do RCU core processing for the current CPU.
92325 */
92326 -static void rcu_process_callbacks(struct softirq_action *unused)
92327 +static void rcu_process_callbacks(void)
92328 {
92329 struct rcu_state *rsp;
92330
92331 @@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92332 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92333 if (debug_rcu_head_queue(head)) {
92334 /* Probable double call_rcu(), so leak the callback. */
92335 - ACCESS_ONCE(head->func) = rcu_leak_callback;
92336 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92337 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92338 return;
92339 }
92340 @@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92341 local_irq_restore(flags);
92342 return;
92343 }
92344 - ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92345 + ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92346 if (lazy)
92347 rdp->qlen_lazy++;
92348 else
92349 @@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
92350 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92351 * course be required on a 64-bit system.
92352 */
92353 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92354 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92355 (ulong)atomic_long_read(&rsp->expedited_done) +
92356 ULONG_MAX / 8)) {
92357 synchronize_sched();
92358 - atomic_long_inc(&rsp->expedited_wrap);
92359 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
92360 return;
92361 }
92362
92363 @@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
92364 * Take a ticket. Note that atomic_inc_return() implies a
92365 * full memory barrier.
92366 */
92367 - snap = atomic_long_inc_return(&rsp->expedited_start);
92368 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92369 firstsnap = snap;
92370 if (!try_get_online_cpus()) {
92371 /* CPU hotplug operation in flight, fall back to normal GP. */
92372 wait_rcu_gp(call_rcu_sched);
92373 - atomic_long_inc(&rsp->expedited_normal);
92374 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92375 return;
92376 }
92377 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92378 @@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
92379 synchronize_sched_expedited_cpu_stop,
92380 NULL) == -EAGAIN) {
92381 put_online_cpus();
92382 - atomic_long_inc(&rsp->expedited_tryfail);
92383 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92384
92385 /* Check to see if someone else did our work for us. */
92386 s = atomic_long_read(&rsp->expedited_done);
92387 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92388 /* ensure test happens before caller kfree */
92389 smp_mb__before_atomic(); /* ^^^ */
92390 - atomic_long_inc(&rsp->expedited_workdone1);
92391 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92392 return;
92393 }
92394
92395 @@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
92396 udelay(trycount * num_online_cpus());
92397 } else {
92398 wait_rcu_gp(call_rcu_sched);
92399 - atomic_long_inc(&rsp->expedited_normal);
92400 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92401 return;
92402 }
92403
92404 @@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
92405 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92406 /* ensure test happens before caller kfree */
92407 smp_mb__before_atomic(); /* ^^^ */
92408 - atomic_long_inc(&rsp->expedited_workdone2);
92409 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92410 return;
92411 }
92412
92413 @@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
92414 if (!try_get_online_cpus()) {
92415 /* CPU hotplug operation in flight, use normal GP. */
92416 wait_rcu_gp(call_rcu_sched);
92417 - atomic_long_inc(&rsp->expedited_normal);
92418 + atomic_long_inc_unchecked(&rsp->expedited_normal);
92419 return;
92420 }
92421 - snap = atomic_long_read(&rsp->expedited_start);
92422 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
92423 smp_mb(); /* ensure read is before try_stop_cpus(). */
92424 }
92425 - atomic_long_inc(&rsp->expedited_stoppedcpus);
92426 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92427
92428 /*
92429 * Everyone up to our most recent fetch is covered by our grace
92430 @@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92431 * than we did already did their update.
92432 */
92433 do {
92434 - atomic_long_inc(&rsp->expedited_done_tries);
92435 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92436 s = atomic_long_read(&rsp->expedited_done);
92437 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92438 /* ensure test happens before caller kfree */
92439 smp_mb__before_atomic(); /* ^^^ */
92440 - atomic_long_inc(&rsp->expedited_done_lost);
92441 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92442 break;
92443 }
92444 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92445 - atomic_long_inc(&rsp->expedited_done_exit);
92446 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92447
92448 put_online_cpus();
92449 }
92450 @@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92451 * ACCESS_ONCE() to prevent the compiler from speculating
92452 * the increment to precede the early-exit check.
92453 */
92454 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92455 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92456 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92457 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92458 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92459 @@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92460
92461 /* Increment ->n_barrier_done to prevent duplicate work. */
92462 smp_mb(); /* Keep increment after above mechanism. */
92463 - ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92464 + ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92465 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92466 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92467 smp_mb(); /* Keep increment before caller's subsequent code. */
92468 @@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92469 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92470 init_callback_list(rdp);
92471 rdp->qlen_lazy = 0;
92472 - ACCESS_ONCE(rdp->qlen) = 0;
92473 + ACCESS_ONCE_RW(rdp->qlen) = 0;
92474 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92475 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92476 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92477 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92478 rdp->cpu = cpu;
92479 rdp->rsp = rsp;
92480 rcu_boot_init_nocb_percpu_data(rdp);
92481 @@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92482 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92483 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92484 rcu_sysidle_init_percpu_data(rdp->dynticks);
92485 - atomic_set(&rdp->dynticks->dynticks,
92486 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92487 + atomic_set_unchecked(&rdp->dynticks->dynticks,
92488 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92489 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92490
92491 /* Add CPU to rcu_node bitmasks. */
92492 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92493 index bbdc45d..c882ccb 100644
92494 --- a/kernel/rcu/tree.h
92495 +++ b/kernel/rcu/tree.h
92496 @@ -87,11 +87,11 @@ struct rcu_dynticks {
92497 long long dynticks_nesting; /* Track irq/process nesting level. */
92498 /* Process level is worth LLONG_MAX/2. */
92499 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92500 - atomic_t dynticks; /* Even value for idle, else odd. */
92501 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92502 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92503 long long dynticks_idle_nesting;
92504 /* irq/process nesting level from idle. */
92505 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
92506 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92507 /* "Idle" excludes userspace execution. */
92508 unsigned long dynticks_idle_jiffies;
92509 /* End of last non-NMI non-idle period. */
92510 @@ -466,17 +466,17 @@ struct rcu_state {
92511 /* _rcu_barrier(). */
92512 /* End of fields guarded by barrier_mutex. */
92513
92514 - atomic_long_t expedited_start; /* Starting ticket. */
92515 - atomic_long_t expedited_done; /* Done ticket. */
92516 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92517 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
92518 - atomic_long_t expedited_workdone1; /* # done by others #1. */
92519 - atomic_long_t expedited_workdone2; /* # done by others #2. */
92520 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
92521 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92522 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
92523 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92524 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92525 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92526 + atomic_long_t expedited_done; /* Done ticket. */
92527 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92528 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92529 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92530 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92531 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92532 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92533 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92534 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92535 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92536
92537 unsigned long jiffies_force_qs; /* Time at which to invoke */
92538 /* force_quiescent_state(). */
92539 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92540 index c1d7f27..a64bf49 100644
92541 --- a/kernel/rcu/tree_plugin.h
92542 +++ b/kernel/rcu/tree_plugin.h
92543 @@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92544 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92545 {
92546 return !rcu_preempted_readers_exp(rnp) &&
92547 - ACCESS_ONCE(rnp->expmask) == 0;
92548 + ACCESS_ONCE_RW(rnp->expmask) == 0;
92549 }
92550
92551 /*
92552 @@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92553
92554 /* Clean up and exit. */
92555 smp_mb(); /* ensure expedited GP seen before counter increment. */
92556 - ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92557 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92558 sync_rcu_preempt_exp_count + 1;
92559 unlock_mb_ret:
92560 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92561 @@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92562 free_cpumask_var(cm);
92563 }
92564
92565 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92566 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92567 .store = &rcu_cpu_kthread_task,
92568 .thread_should_run = rcu_cpu_kthread_should_run,
92569 .thread_fn = rcu_cpu_kthread,
92570 @@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92571 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92572 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92573 cpu, ticks_value, ticks_title,
92574 - atomic_read(&rdtp->dynticks) & 0xfff,
92575 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92576 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92577 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92578 fast_no_hz);
92579 @@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92580 return;
92581 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92582 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92583 - ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92584 + ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92585 wake_up(&rdp_leader->nocb_wq);
92586 }
92587 }
92588 @@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92589
92590 /* Enqueue the callback on the nocb list and update counts. */
92591 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92592 - ACCESS_ONCE(*old_rhpp) = rhp;
92593 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
92594 atomic_long_add(rhcount, &rdp->nocb_q_count);
92595 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92596 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92597 @@ -2286,7 +2286,7 @@ wait_again:
92598 continue; /* No CBs here, try next follower. */
92599
92600 /* Move callbacks to wait-for-GP list, which is empty. */
92601 - ACCESS_ONCE(rdp->nocb_head) = NULL;
92602 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92603 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92604 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92605 rdp->nocb_gp_count_lazy =
92606 @@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92607 list = ACCESS_ONCE(rdp->nocb_follower_head);
92608 BUG_ON(!list);
92609 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92610 - ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92611 + ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92612 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92613 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92614 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92615 @@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92616 list = next;
92617 }
92618 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92619 - ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92620 - ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92621 + ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92622 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92623 rdp->nocb_p_count_lazy - cl;
92624 rdp->n_nocbs_invoked += c;
92625 }
92626 @@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92627 if (!rcu_nocb_need_deferred_wakeup(rdp))
92628 return;
92629 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92630 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92631 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92632 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92633 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92634 }
92635 @@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92636 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92637 "rcuo%c/%d", rsp->abbr, cpu);
92638 BUG_ON(IS_ERR(t));
92639 - ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92640 + ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92641 }
92642
92643 /*
92644 @@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92645
92646 /* Record start of fully idle period. */
92647 j = jiffies;
92648 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92649 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92650 smp_mb__before_atomic();
92651 - atomic_inc(&rdtp->dynticks_idle);
92652 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92653 smp_mb__after_atomic();
92654 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92655 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92656 }
92657
92658 /*
92659 @@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92660
92661 /* Record end of idle period. */
92662 smp_mb__before_atomic();
92663 - atomic_inc(&rdtp->dynticks_idle);
92664 + atomic_inc_unchecked(&rdtp->dynticks_idle);
92665 smp_mb__after_atomic();
92666 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92667 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92668
92669 /*
92670 * If we are the timekeeping CPU, we are permitted to be non-idle
92671 @@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92672 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92673
92674 /* Pick up current idle and NMI-nesting counter and check. */
92675 - cur = atomic_read(&rdtp->dynticks_idle);
92676 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92677 if (cur & 0x1) {
92678 *isidle = false; /* We are not idle! */
92679 return;
92680 @@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92681 case RCU_SYSIDLE_NOT:
92682
92683 /* First time all are idle, so note a short idle period. */
92684 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92685 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92686 break;
92687
92688 case RCU_SYSIDLE_SHORT:
92689 @@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92690 {
92691 smp_mb();
92692 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92693 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92694 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92695 }
92696
92697 /*
92698 @@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92699 smp_mb(); /* grace period precedes setting inuse. */
92700
92701 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92702 - ACCESS_ONCE(rshp->inuse) = 0;
92703 + ACCESS_ONCE_RW(rshp->inuse) = 0;
92704 }
92705
92706 /*
92707 @@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92708 static void rcu_dynticks_task_enter(void)
92709 {
92710 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92711 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92712 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92713 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92714 }
92715
92716 @@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92717 static void rcu_dynticks_task_exit(void)
92718 {
92719 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92720 - ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92721 + ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92722 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92723 }
92724 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92725 index 5cdc62e..cc52e88 100644
92726 --- a/kernel/rcu/tree_trace.c
92727 +++ b/kernel/rcu/tree_trace.c
92728 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92729 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92730 rdp->passed_quiesce, rdp->qs_pending);
92731 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92732 - atomic_read(&rdp->dynticks->dynticks),
92733 + atomic_read_unchecked(&rdp->dynticks->dynticks),
92734 rdp->dynticks->dynticks_nesting,
92735 rdp->dynticks->dynticks_nmi_nesting,
92736 rdp->dynticks_fqs);
92737 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92738 struct rcu_state *rsp = (struct rcu_state *)m->private;
92739
92740 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",
92741 - atomic_long_read(&rsp->expedited_start),
92742 + atomic_long_read_unchecked(&rsp->expedited_start),
92743 atomic_long_read(&rsp->expedited_done),
92744 - atomic_long_read(&rsp->expedited_wrap),
92745 - atomic_long_read(&rsp->expedited_tryfail),
92746 - atomic_long_read(&rsp->expedited_workdone1),
92747 - atomic_long_read(&rsp->expedited_workdone2),
92748 - atomic_long_read(&rsp->expedited_normal),
92749 - atomic_long_read(&rsp->expedited_stoppedcpus),
92750 - atomic_long_read(&rsp->expedited_done_tries),
92751 - atomic_long_read(&rsp->expedited_done_lost),
92752 - atomic_long_read(&rsp->expedited_done_exit));
92753 + atomic_long_read_unchecked(&rsp->expedited_wrap),
92754 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
92755 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
92756 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
92757 + atomic_long_read_unchecked(&rsp->expedited_normal),
92758 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92759 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
92760 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
92761 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
92762 return 0;
92763 }
92764
92765 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92766 index 3ef8ba5..8c5ebfb6 100644
92767 --- a/kernel/rcu/update.c
92768 +++ b/kernel/rcu/update.c
92769 @@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92770 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92771 */
92772 if (till_stall_check < 3) {
92773 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92774 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92775 till_stall_check = 3;
92776 } else if (till_stall_check > 300) {
92777 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92778 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92779 till_stall_check = 300;
92780 }
92781 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92782 @@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92783 !ACCESS_ONCE(t->on_rq) ||
92784 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92785 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92786 - ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92787 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92788 list_del_init(&t->rcu_tasks_holdout_list);
92789 put_task_struct(t);
92790 return;
92791 @@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92792 !is_idle_task(t)) {
92793 get_task_struct(t);
92794 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92795 - ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92796 + ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92797 list_add(&t->rcu_tasks_holdout_list,
92798 &rcu_tasks_holdouts);
92799 }
92800 @@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92801 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92802 BUG_ON(IS_ERR(t));
92803 smp_mb(); /* Ensure others see full kthread. */
92804 - ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92805 + ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92806 mutex_unlock(&rcu_tasks_kthread_mutex);
92807 }
92808
92809 diff --git a/kernel/resource.c b/kernel/resource.c
92810 index 0bcebff..e7cd5b2 100644
92811 --- a/kernel/resource.c
92812 +++ b/kernel/resource.c
92813 @@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92814
92815 static int __init ioresources_init(void)
92816 {
92817 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
92818 +#ifdef CONFIG_GRKERNSEC_PROC_USER
92819 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92820 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92821 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92822 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92823 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92824 +#endif
92825 +#else
92826 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92827 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92828 +#endif
92829 return 0;
92830 }
92831 __initcall(ioresources_init);
92832 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92833 index 8a2e230..6020954 100644
92834 --- a/kernel/sched/auto_group.c
92835 +++ b/kernel/sched/auto_group.c
92836 @@ -11,7 +11,7 @@
92837
92838 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92839 static struct autogroup autogroup_default;
92840 -static atomic_t autogroup_seq_nr;
92841 +static atomic_unchecked_t autogroup_seq_nr;
92842
92843 void __init autogroup_init(struct task_struct *init_task)
92844 {
92845 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92846
92847 kref_init(&ag->kref);
92848 init_rwsem(&ag->lock);
92849 - ag->id = atomic_inc_return(&autogroup_seq_nr);
92850 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92851 ag->tg = tg;
92852 #ifdef CONFIG_RT_GROUP_SCHED
92853 /*
92854 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92855 index a63f4dc..349bbb0 100644
92856 --- a/kernel/sched/completion.c
92857 +++ b/kernel/sched/completion.c
92858 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92859 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92860 * or number of jiffies left till timeout) if completed.
92861 */
92862 -long __sched
92863 +long __sched __intentional_overflow(-1)
92864 wait_for_completion_interruptible_timeout(struct completion *x,
92865 unsigned long timeout)
92866 {
92867 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92868 *
92869 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92870 */
92871 -int __sched wait_for_completion_killable(struct completion *x)
92872 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92873 {
92874 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92875 if (t == -ERESTARTSYS)
92876 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92877 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92878 * or number of jiffies left till timeout) if completed.
92879 */
92880 -long __sched
92881 +long __sched __intentional_overflow(-1)
92882 wait_for_completion_killable_timeout(struct completion *x,
92883 unsigned long timeout)
92884 {
92885 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92886 index efdca2f..e361dfb 100644
92887 --- a/kernel/sched/core.c
92888 +++ b/kernel/sched/core.c
92889 @@ -1890,7 +1890,7 @@ void set_numabalancing_state(bool enabled)
92890 int sysctl_numa_balancing(struct ctl_table *table, int write,
92891 void __user *buffer, size_t *lenp, loff_t *ppos)
92892 {
92893 - struct ctl_table t;
92894 + ctl_table_no_const t;
92895 int err;
92896 int state = numabalancing_enabled;
92897
92898 @@ -2353,8 +2353,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92899 next->active_mm = oldmm;
92900 atomic_inc(&oldmm->mm_count);
92901 enter_lazy_tlb(oldmm, next);
92902 - } else
92903 + } else {
92904 switch_mm(oldmm, mm, next);
92905 + populate_stack();
92906 + }
92907
92908 if (!prev->mm) {
92909 prev->active_mm = NULL;
92910 @@ -3165,6 +3167,8 @@ int can_nice(const struct task_struct *p, const int nice)
92911 /* convert nice value [19,-20] to rlimit style value [1,40] */
92912 int nice_rlim = nice_to_rlimit(nice);
92913
92914 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92915 +
92916 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92917 capable(CAP_SYS_NICE));
92918 }
92919 @@ -3191,7 +3195,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92920 nice = task_nice(current) + increment;
92921
92922 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92923 - if (increment < 0 && !can_nice(current, nice))
92924 + if (increment < 0 && (!can_nice(current, nice) ||
92925 + gr_handle_chroot_nice()))
92926 return -EPERM;
92927
92928 retval = security_task_setnice(current, nice);
92929 @@ -3470,6 +3475,7 @@ recheck:
92930 if (policy != p->policy && !rlim_rtprio)
92931 return -EPERM;
92932
92933 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92934 /* can't increase priority */
92935 if (attr->sched_priority > p->rt_priority &&
92936 attr->sched_priority > rlim_rtprio)
92937 @@ -4890,6 +4896,7 @@ void idle_task_exit(void)
92938
92939 if (mm != &init_mm) {
92940 switch_mm(mm, &init_mm, current);
92941 + populate_stack();
92942 finish_arch_post_lock_switch();
92943 }
92944 mmdrop(mm);
92945 @@ -4985,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92946
92947 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92948
92949 -static struct ctl_table sd_ctl_dir[] = {
92950 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
92951 {
92952 .procname = "sched_domain",
92953 .mode = 0555,
92954 @@ -5002,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
92955 {}
92956 };
92957
92958 -static struct ctl_table *sd_alloc_ctl_entry(int n)
92959 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92960 {
92961 - struct ctl_table *entry =
92962 + ctl_table_no_const *entry =
92963 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92964
92965 return entry;
92966 }
92967
92968 -static void sd_free_ctl_entry(struct ctl_table **tablep)
92969 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92970 {
92971 - struct ctl_table *entry;
92972 + ctl_table_no_const *entry;
92973
92974 /*
92975 * In the intermediate directories, both the child directory and
92976 @@ -5020,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92977 * will always be set. In the lowest directory the names are
92978 * static strings and all have proc handlers.
92979 */
92980 - for (entry = *tablep; entry->mode; entry++) {
92981 - if (entry->child)
92982 - sd_free_ctl_entry(&entry->child);
92983 + for (entry = tablep; entry->mode; entry++) {
92984 + if (entry->child) {
92985 + sd_free_ctl_entry(entry->child);
92986 + pax_open_kernel();
92987 + entry->child = NULL;
92988 + pax_close_kernel();
92989 + }
92990 if (entry->proc_handler == NULL)
92991 kfree(entry->procname);
92992 }
92993
92994 - kfree(*tablep);
92995 - *tablep = NULL;
92996 + kfree(tablep);
92997 }
92998
92999 static int min_load_idx = 0;
93000 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93001
93002 static void
93003 -set_table_entry(struct ctl_table *entry,
93004 +set_table_entry(ctl_table_no_const *entry,
93005 const char *procname, void *data, int maxlen,
93006 umode_t mode, proc_handler *proc_handler,
93007 bool load_idx)
93008 @@ -5055,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
93009 static struct ctl_table *
93010 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93011 {
93012 - struct ctl_table *table = sd_alloc_ctl_entry(14);
93013 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93014
93015 if (table == NULL)
93016 return NULL;
93017 @@ -5093,9 +5103,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
93018 return table;
93019 }
93020
93021 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
93022 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
93023 {
93024 - struct ctl_table *entry, *table;
93025 + ctl_table_no_const *entry, *table;
93026 struct sched_domain *sd;
93027 int domain_num = 0, i;
93028 char buf[32];
93029 @@ -5122,11 +5132,13 @@ static struct ctl_table_header *sd_sysctl_header;
93030 static void register_sched_domain_sysctl(void)
93031 {
93032 int i, cpu_num = num_possible_cpus();
93033 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
93034 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93035 char buf[32];
93036
93037 WARN_ON(sd_ctl_dir[0].child);
93038 + pax_open_kernel();
93039 sd_ctl_dir[0].child = entry;
93040 + pax_close_kernel();
93041
93042 if (entry == NULL)
93043 return;
93044 @@ -5149,8 +5161,12 @@ static void unregister_sched_domain_sysctl(void)
93045 if (sd_sysctl_header)
93046 unregister_sysctl_table(sd_sysctl_header);
93047 sd_sysctl_header = NULL;
93048 - if (sd_ctl_dir[0].child)
93049 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
93050 + if (sd_ctl_dir[0].child) {
93051 + sd_free_ctl_entry(sd_ctl_dir[0].child);
93052 + pax_open_kernel();
93053 + sd_ctl_dir[0].child = NULL;
93054 + pax_close_kernel();
93055 + }
93056 }
93057 #else
93058 static void register_sched_domain_sysctl(void)
93059 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93060 index ef2b104..69961f6 100644
93061 --- a/kernel/sched/fair.c
93062 +++ b/kernel/sched/fair.c
93063 @@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93064
93065 static void reset_ptenuma_scan(struct task_struct *p)
93066 {
93067 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
93068 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93069 p->mm->numa_scan_offset = 0;
93070 }
93071
93072 @@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93073 * run_rebalance_domains is triggered when needed from the scheduler tick.
93074 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93075 */
93076 -static void run_rebalance_domains(struct softirq_action *h)
93077 +static __latent_entropy void run_rebalance_domains(void)
93078 {
93079 struct rq *this_rq = this_rq();
93080 enum cpu_idle_type idle = this_rq->idle_balance ?
93081 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93082 index 2df8ef0..aae070f 100644
93083 --- a/kernel/sched/sched.h
93084 +++ b/kernel/sched/sched.h
93085 @@ -1140,7 +1140,7 @@ struct sched_class {
93086 #ifdef CONFIG_FAIR_GROUP_SCHED
93087 void (*task_move_group) (struct task_struct *p, int on_rq);
93088 #endif
93089 -};
93090 +} __do_const;
93091
93092 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93093 {
93094 diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93095 index 4ef9687..4f44028 100644
93096 --- a/kernel/seccomp.c
93097 +++ b/kernel/seccomp.c
93098 @@ -629,7 +629,9 @@ static u32 __seccomp_phase1_filter(int this_syscall, struct seccomp_data *sd)
93099
93100 switch (action) {
93101 case SECCOMP_RET_ERRNO:
93102 - /* Set the low-order 16-bits as a errno. */
93103 + /* Set low-order bits as an errno, capped at MAX_ERRNO. */
93104 + if (data > MAX_ERRNO)
93105 + data = MAX_ERRNO;
93106 syscall_set_return_value(current, task_pt_regs(current),
93107 -data, 0);
93108 goto skip;
93109 diff --git a/kernel/signal.c b/kernel/signal.c
93110 index 8f0876f..1153a5a 100644
93111 --- a/kernel/signal.c
93112 +++ b/kernel/signal.c
93113 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93114
93115 int print_fatal_signals __read_mostly;
93116
93117 -static void __user *sig_handler(struct task_struct *t, int sig)
93118 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
93119 {
93120 return t->sighand->action[sig - 1].sa.sa_handler;
93121 }
93122
93123 -static int sig_handler_ignored(void __user *handler, int sig)
93124 +static int sig_handler_ignored(__sighandler_t handler, int sig)
93125 {
93126 /* Is it explicitly or implicitly ignored? */
93127 return handler == SIG_IGN ||
93128 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93129
93130 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93131 {
93132 - void __user *handler;
93133 + __sighandler_t handler;
93134
93135 handler = sig_handler(t, sig);
93136
93137 @@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93138 atomic_inc(&user->sigpending);
93139 rcu_read_unlock();
93140
93141 + if (!override_rlimit)
93142 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93143 +
93144 if (override_rlimit ||
93145 atomic_read(&user->sigpending) <=
93146 task_rlimit(t, RLIMIT_SIGPENDING)) {
93147 @@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93148
93149 int unhandled_signal(struct task_struct *tsk, int sig)
93150 {
93151 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93152 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93153 if (is_global_init(tsk))
93154 return 1;
93155 if (handler != SIG_IGN && handler != SIG_DFL)
93156 @@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93157 }
93158 }
93159
93160 + /* allow glibc communication via tgkill to other threads in our
93161 + thread group */
93162 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93163 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93164 + && gr_handle_signal(t, sig))
93165 + return -EPERM;
93166 +
93167 return security_task_kill(t, info, sig, 0);
93168 }
93169
93170 @@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93171 return send_signal(sig, info, p, 1);
93172 }
93173
93174 -static int
93175 +int
93176 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93177 {
93178 return send_signal(sig, info, t, 0);
93179 @@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93180 unsigned long int flags;
93181 int ret, blocked, ignored;
93182 struct k_sigaction *action;
93183 + int is_unhandled = 0;
93184
93185 spin_lock_irqsave(&t->sighand->siglock, flags);
93186 action = &t->sighand->action[sig-1];
93187 @@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93188 }
93189 if (action->sa.sa_handler == SIG_DFL)
93190 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93191 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93192 + is_unhandled = 1;
93193 ret = specific_send_sig_info(sig, info, t);
93194 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93195
93196 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
93197 + normal operation */
93198 + if (is_unhandled) {
93199 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93200 + gr_handle_crash(t, sig);
93201 + }
93202 +
93203 return ret;
93204 }
93205
93206 @@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93207 ret = check_kill_permission(sig, info, p);
93208 rcu_read_unlock();
93209
93210 - if (!ret && sig)
93211 + if (!ret && sig) {
93212 ret = do_send_sig_info(sig, info, p, true);
93213 + if (!ret)
93214 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93215 + }
93216
93217 return ret;
93218 }
93219 @@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93220 int error = -ESRCH;
93221
93222 rcu_read_lock();
93223 - p = find_task_by_vpid(pid);
93224 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93225 + /* allow glibc communication via tgkill to other threads in our
93226 + thread group */
93227 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93228 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
93229 + p = find_task_by_vpid_unrestricted(pid);
93230 + else
93231 +#endif
93232 + p = find_task_by_vpid(pid);
93233 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93234 error = check_kill_permission(sig, info, p);
93235 /*
93236 @@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93237 }
93238 seg = get_fs();
93239 set_fs(KERNEL_DS);
93240 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93241 - (stack_t __force __user *) &uoss,
93242 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93243 + (stack_t __force_user *) &uoss,
93244 compat_user_stack_pointer());
93245 set_fs(seg);
93246 if (ret >= 0 && uoss_ptr) {
93247 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93248 index 60d35ac5..59d289f 100644
93249 --- a/kernel/smpboot.c
93250 +++ b/kernel/smpboot.c
93251 @@ -289,7 +289,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93252 }
93253 smpboot_unpark_thread(plug_thread, cpu);
93254 }
93255 - list_add(&plug_thread->list, &hotplug_threads);
93256 + pax_list_add(&plug_thread->list, &hotplug_threads);
93257 out:
93258 mutex_unlock(&smpboot_threads_lock);
93259 put_online_cpus();
93260 @@ -307,7 +307,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93261 {
93262 get_online_cpus();
93263 mutex_lock(&smpboot_threads_lock);
93264 - list_del(&plug_thread->list);
93265 + pax_list_del(&plug_thread->list);
93266 smpboot_destroy_threads(plug_thread);
93267 mutex_unlock(&smpboot_threads_lock);
93268 put_online_cpus();
93269 diff --git a/kernel/softirq.c b/kernel/softirq.c
93270 index 0699add..d365ad8 100644
93271 --- a/kernel/softirq.c
93272 +++ b/kernel/softirq.c
93273 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93274 EXPORT_SYMBOL(irq_stat);
93275 #endif
93276
93277 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93278 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93279
93280 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93281
93282 @@ -266,7 +266,7 @@ restart:
93283 kstat_incr_softirqs_this_cpu(vec_nr);
93284
93285 trace_softirq_entry(vec_nr);
93286 - h->action(h);
93287 + h->action();
93288 trace_softirq_exit(vec_nr);
93289 if (unlikely(prev_count != preempt_count())) {
93290 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93291 @@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93292 or_softirq_pending(1UL << nr);
93293 }
93294
93295 -void open_softirq(int nr, void (*action)(struct softirq_action *))
93296 +void __init open_softirq(int nr, void (*action)(void))
93297 {
93298 softirq_vec[nr].action = action;
93299 }
93300 @@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93301 }
93302 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93303
93304 -static void tasklet_action(struct softirq_action *a)
93305 +static void tasklet_action(void)
93306 {
93307 struct tasklet_struct *list;
93308
93309 @@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93310 }
93311 }
93312
93313 -static void tasklet_hi_action(struct softirq_action *a)
93314 +static __latent_entropy void tasklet_hi_action(void)
93315 {
93316 struct tasklet_struct *list;
93317
93318 @@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93319 .notifier_call = cpu_callback
93320 };
93321
93322 -static struct smp_hotplug_thread softirq_threads = {
93323 +static struct smp_hotplug_thread softirq_threads __read_only = {
93324 .store = &ksoftirqd,
93325 .thread_should_run = ksoftirqd_should_run,
93326 .thread_fn = run_ksoftirqd,
93327 diff --git a/kernel/sys.c b/kernel/sys.c
93328 index 1eaa2f0..d80d27c 100644
93329 --- a/kernel/sys.c
93330 +++ b/kernel/sys.c
93331 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93332 error = -EACCES;
93333 goto out;
93334 }
93335 +
93336 + if (gr_handle_chroot_setpriority(p, niceval)) {
93337 + error = -EACCES;
93338 + goto out;
93339 + }
93340 +
93341 no_nice = security_task_setnice(p, niceval);
93342 if (no_nice) {
93343 error = no_nice;
93344 @@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93345 goto error;
93346 }
93347
93348 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93349 + goto error;
93350 +
93351 + if (!gid_eq(new->gid, old->gid)) {
93352 + /* make sure we generate a learn log for what will
93353 + end up being a role transition after a full-learning
93354 + policy is generated
93355 + CAP_SETGID is required to perform a transition
93356 + we may not log a CAP_SETGID check above, e.g.
93357 + in the case where new rgid = old egid
93358 + */
93359 + gr_learn_cap(current, new, CAP_SETGID);
93360 + }
93361 +
93362 if (rgid != (gid_t) -1 ||
93363 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93364 new->sgid = new->egid;
93365 @@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93366 old = current_cred();
93367
93368 retval = -EPERM;
93369 +
93370 + if (gr_check_group_change(kgid, kgid, kgid))
93371 + goto error;
93372 +
93373 if (ns_capable(old->user_ns, CAP_SETGID))
93374 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93375 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93376 @@ -405,7 +429,7 @@ error:
93377 /*
93378 * change the user struct in a credentials set to match the new UID
93379 */
93380 -static int set_user(struct cred *new)
93381 +int set_user(struct cred *new)
93382 {
93383 struct user_struct *new_user;
93384
93385 @@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93386 goto error;
93387 }
93388
93389 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93390 + goto error;
93391 +
93392 if (!uid_eq(new->uid, old->uid)) {
93393 + /* make sure we generate a learn log for what will
93394 + end up being a role transition after a full-learning
93395 + policy is generated
93396 + CAP_SETUID is required to perform a transition
93397 + we may not log a CAP_SETUID check above, e.g.
93398 + in the case where new ruid = old euid
93399 + */
93400 + gr_learn_cap(current, new, CAP_SETUID);
93401 retval = set_user(new);
93402 if (retval < 0)
93403 goto error;
93404 @@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93405 old = current_cred();
93406
93407 retval = -EPERM;
93408 +
93409 + if (gr_check_crash_uid(kuid))
93410 + goto error;
93411 + if (gr_check_user_change(kuid, kuid, kuid))
93412 + goto error;
93413 +
93414 if (ns_capable(old->user_ns, CAP_SETUID)) {
93415 new->suid = new->uid = kuid;
93416 if (!uid_eq(kuid, old->uid)) {
93417 @@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93418 goto error;
93419 }
93420
93421 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
93422 + goto error;
93423 +
93424 if (ruid != (uid_t) -1) {
93425 new->uid = kruid;
93426 if (!uid_eq(kruid, old->uid)) {
93427 @@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93428 goto error;
93429 }
93430
93431 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
93432 + goto error;
93433 +
93434 if (rgid != (gid_t) -1)
93435 new->gid = krgid;
93436 if (egid != (gid_t) -1)
93437 @@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93438 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93439 ns_capable(old->user_ns, CAP_SETUID)) {
93440 if (!uid_eq(kuid, old->fsuid)) {
93441 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93442 + goto error;
93443 +
93444 new->fsuid = kuid;
93445 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93446 goto change_okay;
93447 }
93448 }
93449
93450 +error:
93451 abort_creds(new);
93452 return old_fsuid;
93453
93454 @@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93455 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93456 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93457 ns_capable(old->user_ns, CAP_SETGID)) {
93458 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93459 + goto error;
93460 +
93461 if (!gid_eq(kgid, old->fsgid)) {
93462 new->fsgid = kgid;
93463 goto change_okay;
93464 }
93465 }
93466
93467 +error:
93468 abort_creds(new);
93469 return old_fsgid;
93470
93471 @@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93472 return -EFAULT;
93473
93474 down_read(&uts_sem);
93475 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
93476 + error = __copy_to_user(name->sysname, &utsname()->sysname,
93477 __OLD_UTS_LEN);
93478 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93479 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93480 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
93481 __OLD_UTS_LEN);
93482 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93483 - error |= __copy_to_user(&name->release, &utsname()->release,
93484 + error |= __copy_to_user(name->release, &utsname()->release,
93485 __OLD_UTS_LEN);
93486 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93487 - error |= __copy_to_user(&name->version, &utsname()->version,
93488 + error |= __copy_to_user(name->version, &utsname()->version,
93489 __OLD_UTS_LEN);
93490 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93491 - error |= __copy_to_user(&name->machine, &utsname()->machine,
93492 + error |= __copy_to_user(name->machine, &utsname()->machine,
93493 __OLD_UTS_LEN);
93494 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93495 up_read(&uts_sem);
93496 @@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93497 */
93498 new_rlim->rlim_cur = 1;
93499 }
93500 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93501 + is changed to a lower value. Since tasks can be created by the same
93502 + user in between this limit change and an execve by this task, force
93503 + a recheck only for this task by setting PF_NPROC_EXCEEDED
93504 + */
93505 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93506 + tsk->flags |= PF_NPROC_EXCEEDED;
93507 }
93508 if (!retval) {
93509 if (old_rlim)
93510 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93511 index 15f2511..181b356 100644
93512 --- a/kernel/sysctl.c
93513 +++ b/kernel/sysctl.c
93514 @@ -94,7 +94,6 @@
93515
93516
93517 #if defined(CONFIG_SYSCTL)
93518 -
93519 /* External variables not in a header file. */
93520 extern int max_threads;
93521 extern int suid_dumpable;
93522 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93523
93524 /* Constants used for minimum and maximum */
93525 #ifdef CONFIG_LOCKUP_DETECTOR
93526 -static int sixty = 60;
93527 +static int sixty __read_only = 60;
93528 #endif
93529
93530 -static int __maybe_unused neg_one = -1;
93531 +static int __maybe_unused neg_one __read_only = -1;
93532
93533 -static int zero;
93534 -static int __maybe_unused one = 1;
93535 -static int __maybe_unused two = 2;
93536 -static int __maybe_unused four = 4;
93537 -static unsigned long one_ul = 1;
93538 -static int one_hundred = 100;
93539 +static int zero __read_only = 0;
93540 +static int __maybe_unused one __read_only = 1;
93541 +static int __maybe_unused two __read_only = 2;
93542 +static int __maybe_unused three __read_only = 3;
93543 +static int __maybe_unused four __read_only = 4;
93544 +static unsigned long one_ul __read_only = 1;
93545 +static int one_hundred __read_only = 100;
93546 #ifdef CONFIG_PRINTK
93547 -static int ten_thousand = 10000;
93548 +static int ten_thousand __read_only = 10000;
93549 #endif
93550
93551 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93552 @@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93553 void __user *buffer, size_t *lenp, loff_t *ppos);
93554 #endif
93555
93556 -#ifdef CONFIG_PRINTK
93557 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93558 void __user *buffer, size_t *lenp, loff_t *ppos);
93559 -#endif
93560
93561 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93562 void __user *buffer, size_t *lenp, loff_t *ppos);
93563 @@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93564
93565 #endif
93566
93567 +extern struct ctl_table grsecurity_table[];
93568 +
93569 static struct ctl_table kern_table[];
93570 static struct ctl_table vm_table[];
93571 static struct ctl_table fs_table[];
93572 @@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93573 int sysctl_legacy_va_layout;
93574 #endif
93575
93576 +#ifdef CONFIG_PAX_SOFTMODE
93577 +static struct ctl_table pax_table[] = {
93578 + {
93579 + .procname = "softmode",
93580 + .data = &pax_softmode,
93581 + .maxlen = sizeof(unsigned int),
93582 + .mode = 0600,
93583 + .proc_handler = &proc_dointvec,
93584 + },
93585 +
93586 + { }
93587 +};
93588 +#endif
93589 +
93590 /* The default sysctl tables: */
93591
93592 static struct ctl_table sysctl_base_table[] = {
93593 @@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93594 #endif
93595
93596 static struct ctl_table kern_table[] = {
93597 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93598 + {
93599 + .procname = "grsecurity",
93600 + .mode = 0500,
93601 + .child = grsecurity_table,
93602 + },
93603 +#endif
93604 +
93605 +#ifdef CONFIG_PAX_SOFTMODE
93606 + {
93607 + .procname = "pax",
93608 + .mode = 0500,
93609 + .child = pax_table,
93610 + },
93611 +#endif
93612 +
93613 {
93614 .procname = "sched_child_runs_first",
93615 .data = &sysctl_sched_child_runs_first,
93616 @@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93617 .data = &modprobe_path,
93618 .maxlen = KMOD_PATH_LEN,
93619 .mode = 0644,
93620 - .proc_handler = proc_dostring,
93621 + .proc_handler = proc_dostring_modpriv,
93622 },
93623 {
93624 .procname = "modules_disabled",
93625 @@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93626 .extra1 = &zero,
93627 .extra2 = &one,
93628 },
93629 +#endif
93630 {
93631 .procname = "kptr_restrict",
93632 .data = &kptr_restrict,
93633 .maxlen = sizeof(int),
93634 .mode = 0644,
93635 .proc_handler = proc_dointvec_minmax_sysadmin,
93636 +#ifdef CONFIG_GRKERNSEC_HIDESYM
93637 + .extra1 = &two,
93638 +#else
93639 .extra1 = &zero,
93640 +#endif
93641 .extra2 = &two,
93642 },
93643 -#endif
93644 {
93645 .procname = "ngroups_max",
93646 .data = &ngroups_max,
93647 @@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93648 */
93649 {
93650 .procname = "perf_event_paranoid",
93651 - .data = &sysctl_perf_event_paranoid,
93652 - .maxlen = sizeof(sysctl_perf_event_paranoid),
93653 + .data = &sysctl_perf_event_legitimately_concerned,
93654 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93655 .mode = 0644,
93656 - .proc_handler = proc_dointvec,
93657 + /* go ahead, be a hero */
93658 + .proc_handler = proc_dointvec_minmax_sysadmin,
93659 + .extra1 = &neg_one,
93660 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93661 + .extra2 = &three,
93662 +#else
93663 + .extra2 = &two,
93664 +#endif
93665 },
93666 {
93667 .procname = "perf_event_mlock_kb",
93668 @@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93669 .proc_handler = proc_dointvec_minmax,
93670 .extra1 = &zero,
93671 },
93672 + {
93673 + .procname = "heap_stack_gap",
93674 + .data = &sysctl_heap_stack_gap,
93675 + .maxlen = sizeof(sysctl_heap_stack_gap),
93676 + .mode = 0644,
93677 + .proc_handler = proc_doulongvec_minmax,
93678 + },
93679 #else
93680 {
93681 .procname = "nr_trim_pages",
93682 @@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93683 (char __user *)buffer, lenp, ppos);
93684 }
93685
93686 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93687 + void __user *buffer, size_t *lenp, loff_t *ppos)
93688 +{
93689 + if (write && !capable(CAP_SYS_MODULE))
93690 + return -EPERM;
93691 +
93692 + return _proc_do_string(table->data, table->maxlen, write,
93693 + buffer, lenp, ppos);
93694 +}
93695 +
93696 static size_t proc_skip_spaces(char **buf)
93697 {
93698 size_t ret;
93699 @@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93700 len = strlen(tmp);
93701 if (len > *size)
93702 len = *size;
93703 + if (len > sizeof(tmp))
93704 + len = sizeof(tmp);
93705 if (copy_to_user(*buf, tmp, len))
93706 return -EFAULT;
93707 *size -= len;
93708 @@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93709 static int proc_taint(struct ctl_table *table, int write,
93710 void __user *buffer, size_t *lenp, loff_t *ppos)
93711 {
93712 - struct ctl_table t;
93713 + ctl_table_no_const t;
93714 unsigned long tmptaint = get_taint();
93715 int err;
93716
93717 @@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93718 return err;
93719 }
93720
93721 -#ifdef CONFIG_PRINTK
93722 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93723 void __user *buffer, size_t *lenp, loff_t *ppos)
93724 {
93725 @@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93726
93727 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93728 }
93729 -#endif
93730
93731 struct do_proc_dointvec_minmax_conv_param {
93732 int *min;
93733 @@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93734 return -ENOSYS;
93735 }
93736
93737 +int proc_dostring_modpriv(struct ctl_table *table, int write,
93738 + void __user *buffer, size_t *lenp, loff_t *ppos)
93739 +{
93740 + return -ENOSYS;
93741 +}
93742 +
93743 int proc_dointvec(struct ctl_table *table, int write,
93744 void __user *buffer, size_t *lenp, loff_t *ppos)
93745 {
93746 @@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93747 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93748 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93749 EXPORT_SYMBOL(proc_dostring);
93750 +EXPORT_SYMBOL(proc_dostring_modpriv);
93751 EXPORT_SYMBOL(proc_doulongvec_minmax);
93752 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93753 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93754 index b312fcc7..753d72d 100644
93755 --- a/kernel/taskstats.c
93756 +++ b/kernel/taskstats.c
93757 @@ -28,9 +28,12 @@
93758 #include <linux/fs.h>
93759 #include <linux/file.h>
93760 #include <linux/pid_namespace.h>
93761 +#include <linux/grsecurity.h>
93762 #include <net/genetlink.h>
93763 #include <linux/atomic.h>
93764
93765 +extern int gr_is_taskstats_denied(int pid);
93766 +
93767 /*
93768 * Maximum length of a cpumask that can be specified in
93769 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93770 @@ -576,6 +579,9 @@ err:
93771
93772 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93773 {
93774 + if (gr_is_taskstats_denied(current->pid))
93775 + return -EACCES;
93776 +
93777 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93778 return cmd_attr_register_cpumask(info);
93779 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93780 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93781 index a7077d3..dd48a49 100644
93782 --- a/kernel/time/alarmtimer.c
93783 +++ b/kernel/time/alarmtimer.c
93784 @@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93785 struct platform_device *pdev;
93786 int error = 0;
93787 int i;
93788 - struct k_clock alarm_clock = {
93789 + static struct k_clock alarm_clock = {
93790 .clock_getres = alarm_clock_getres,
93791 .clock_get = alarm_clock_get,
93792 .timer_create = alarm_timer_create,
93793 diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93794 index d8c724c..6b331a4 100644
93795 --- a/kernel/time/hrtimer.c
93796 +++ b/kernel/time/hrtimer.c
93797 @@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93798 local_irq_restore(flags);
93799 }
93800
93801 -static void run_hrtimer_softirq(struct softirq_action *h)
93802 +static __latent_entropy void run_hrtimer_softirq(void)
93803 {
93804 hrtimer_peek_ahead_timers();
93805 }
93806 diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93807 index a16b678..8c5bd9d 100644
93808 --- a/kernel/time/posix-cpu-timers.c
93809 +++ b/kernel/time/posix-cpu-timers.c
93810 @@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93811
93812 static __init int init_posix_cpu_timers(void)
93813 {
93814 - struct k_clock process = {
93815 + static struct k_clock process = {
93816 .clock_getres = process_cpu_clock_getres,
93817 .clock_get = process_cpu_clock_get,
93818 .timer_create = process_cpu_timer_create,
93819 .nsleep = process_cpu_nsleep,
93820 .nsleep_restart = process_cpu_nsleep_restart,
93821 };
93822 - struct k_clock thread = {
93823 + static struct k_clock thread = {
93824 .clock_getres = thread_cpu_clock_getres,
93825 .clock_get = thread_cpu_clock_get,
93826 .timer_create = thread_cpu_timer_create,
93827 diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93828 index 31ea01f..7fc61ef 100644
93829 --- a/kernel/time/posix-timers.c
93830 +++ b/kernel/time/posix-timers.c
93831 @@ -43,6 +43,7 @@
93832 #include <linux/hash.h>
93833 #include <linux/posix-clock.h>
93834 #include <linux/posix-timers.h>
93835 +#include <linux/grsecurity.h>
93836 #include <linux/syscalls.h>
93837 #include <linux/wait.h>
93838 #include <linux/workqueue.h>
93839 @@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93840 * which we beg off on and pass to do_sys_settimeofday().
93841 */
93842
93843 -static struct k_clock posix_clocks[MAX_CLOCKS];
93844 +static struct k_clock *posix_clocks[MAX_CLOCKS];
93845
93846 /*
93847 * These ones are defined below.
93848 @@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93849 */
93850 static __init int init_posix_timers(void)
93851 {
93852 - struct k_clock clock_realtime = {
93853 + static struct k_clock clock_realtime = {
93854 .clock_getres = hrtimer_get_res,
93855 .clock_get = posix_clock_realtime_get,
93856 .clock_set = posix_clock_realtime_set,
93857 @@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93858 .timer_get = common_timer_get,
93859 .timer_del = common_timer_del,
93860 };
93861 - struct k_clock clock_monotonic = {
93862 + static struct k_clock clock_monotonic = {
93863 .clock_getres = hrtimer_get_res,
93864 .clock_get = posix_ktime_get_ts,
93865 .nsleep = common_nsleep,
93866 @@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93867 .timer_get = common_timer_get,
93868 .timer_del = common_timer_del,
93869 };
93870 - struct k_clock clock_monotonic_raw = {
93871 + static struct k_clock clock_monotonic_raw = {
93872 .clock_getres = hrtimer_get_res,
93873 .clock_get = posix_get_monotonic_raw,
93874 };
93875 - struct k_clock clock_realtime_coarse = {
93876 + static struct k_clock clock_realtime_coarse = {
93877 .clock_getres = posix_get_coarse_res,
93878 .clock_get = posix_get_realtime_coarse,
93879 };
93880 - struct k_clock clock_monotonic_coarse = {
93881 + static struct k_clock clock_monotonic_coarse = {
93882 .clock_getres = posix_get_coarse_res,
93883 .clock_get = posix_get_monotonic_coarse,
93884 };
93885 - struct k_clock clock_tai = {
93886 + static struct k_clock clock_tai = {
93887 .clock_getres = hrtimer_get_res,
93888 .clock_get = posix_get_tai,
93889 .nsleep = common_nsleep,
93890 @@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93891 .timer_get = common_timer_get,
93892 .timer_del = common_timer_del,
93893 };
93894 - struct k_clock clock_boottime = {
93895 + static struct k_clock clock_boottime = {
93896 .clock_getres = hrtimer_get_res,
93897 .clock_get = posix_get_boottime,
93898 .nsleep = common_nsleep,
93899 @@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93900 return;
93901 }
93902
93903 - posix_clocks[clock_id] = *new_clock;
93904 + posix_clocks[clock_id] = new_clock;
93905 }
93906 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93907
93908 @@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93909 return (id & CLOCKFD_MASK) == CLOCKFD ?
93910 &clock_posix_dynamic : &clock_posix_cpu;
93911
93912 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93913 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93914 return NULL;
93915 - return &posix_clocks[id];
93916 + return posix_clocks[id];
93917 }
93918
93919 static int common_timer_create(struct k_itimer *new_timer)
93920 @@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93921 struct k_clock *kc = clockid_to_kclock(which_clock);
93922 struct k_itimer *new_timer;
93923 int error, new_timer_id;
93924 - sigevent_t event;
93925 + sigevent_t event = { };
93926 int it_id_set = IT_ID_NOT_SET;
93927
93928 if (!kc)
93929 @@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93930 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93931 return -EFAULT;
93932
93933 + /* only the CLOCK_REALTIME clock can be set, all other clocks
93934 + have their clock_set fptr set to a nosettime dummy function
93935 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93936 + call common_clock_set, which calls do_sys_settimeofday, which
93937 + we hook
93938 + */
93939 +
93940 return kc->clock_set(which_clock, &new_tp);
93941 }
93942
93943 diff --git a/kernel/time/time.c b/kernel/time/time.c
93944 index 22d5d3b..70caeb2 100644
93945 --- a/kernel/time/time.c
93946 +++ b/kernel/time/time.c
93947 @@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93948 return error;
93949
93950 if (tz) {
93951 + /* we log in do_settimeofday called below, so don't log twice
93952 + */
93953 + if (!tv)
93954 + gr_log_timechange();
93955 +
93956 sys_tz = *tz;
93957 update_vsyscall_tz();
93958 if (firsttime) {
93959 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93960 index ec1791f..6a086cd 100644
93961 --- a/kernel/time/timekeeping.c
93962 +++ b/kernel/time/timekeeping.c
93963 @@ -15,6 +15,7 @@
93964 #include <linux/init.h>
93965 #include <linux/mm.h>
93966 #include <linux/sched.h>
93967 +#include <linux/grsecurity.h>
93968 #include <linux/syscore_ops.h>
93969 #include <linux/clocksource.h>
93970 #include <linux/jiffies.h>
93971 @@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93972 if (!timespec_valid_strict(tv))
93973 return -EINVAL;
93974
93975 + gr_log_timechange();
93976 +
93977 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93978 write_seqcount_begin(&tk_core.seq);
93979
93980 diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93981 index 3260ffd..c93cd5e 100644
93982 --- a/kernel/time/timer.c
93983 +++ b/kernel/time/timer.c
93984 @@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93985 /*
93986 * This function runs timers and the timer-tq in bottom half context.
93987 */
93988 -static void run_timer_softirq(struct softirq_action *h)
93989 +static __latent_entropy void run_timer_softirq(void)
93990 {
93991 struct tvec_base *base = __this_cpu_read(tvec_bases);
93992
93993 @@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93994 *
93995 * In all cases the return value is guaranteed to be non-negative.
93996 */
93997 -signed long __sched schedule_timeout(signed long timeout)
93998 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93999 {
94000 struct timer_list timer;
94001 unsigned long expire;
94002 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
94003 index 61ed862..3b52c65 100644
94004 --- a/kernel/time/timer_list.c
94005 +++ b/kernel/time/timer_list.c
94006 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
94007
94008 static void print_name_offset(struct seq_file *m, void *sym)
94009 {
94010 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94011 + SEQ_printf(m, "<%p>", NULL);
94012 +#else
94013 char symname[KSYM_NAME_LEN];
94014
94015 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
94016 SEQ_printf(m, "<%pK>", sym);
94017 else
94018 SEQ_printf(m, "%s", symname);
94019 +#endif
94020 }
94021
94022 static void
94023 @@ -119,7 +123,11 @@ next_one:
94024 static void
94025 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
94026 {
94027 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94028 + SEQ_printf(m, " .base: %p\n", NULL);
94029 +#else
94030 SEQ_printf(m, " .base: %pK\n", base);
94031 +#endif
94032 SEQ_printf(m, " .index: %d\n",
94033 base->index);
94034 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94035 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94036 {
94037 struct proc_dir_entry *pe;
94038
94039 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94040 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94041 +#else
94042 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94043 +#endif
94044 if (!pe)
94045 return -ENOMEM;
94046 return 0;
94047 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94048 index 1fb08f2..ca4bb1e 100644
94049 --- a/kernel/time/timer_stats.c
94050 +++ b/kernel/time/timer_stats.c
94051 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94052 static unsigned long nr_entries;
94053 static struct entry entries[MAX_ENTRIES];
94054
94055 -static atomic_t overflow_count;
94056 +static atomic_unchecked_t overflow_count;
94057
94058 /*
94059 * The entries are in a hash-table, for fast lookup:
94060 @@ -140,7 +140,7 @@ static void reset_entries(void)
94061 nr_entries = 0;
94062 memset(entries, 0, sizeof(entries));
94063 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94064 - atomic_set(&overflow_count, 0);
94065 + atomic_set_unchecked(&overflow_count, 0);
94066 }
94067
94068 static struct entry *alloc_entry(void)
94069 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94070 if (likely(entry))
94071 entry->count++;
94072 else
94073 - atomic_inc(&overflow_count);
94074 + atomic_inc_unchecked(&overflow_count);
94075
94076 out_unlock:
94077 raw_spin_unlock_irqrestore(lock, flags);
94078 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94079
94080 static void print_name_offset(struct seq_file *m, unsigned long addr)
94081 {
94082 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94083 + seq_printf(m, "<%p>", NULL);
94084 +#else
94085 char symname[KSYM_NAME_LEN];
94086
94087 if (lookup_symbol_name(addr, symname) < 0)
94088 - seq_printf(m, "<%p>", (void *)addr);
94089 + seq_printf(m, "<%pK>", (void *)addr);
94090 else
94091 seq_printf(m, "%s", symname);
94092 +#endif
94093 }
94094
94095 static int tstats_show(struct seq_file *m, void *v)
94096 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94097
94098 seq_puts(m, "Timer Stats Version: v0.3\n");
94099 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94100 - if (atomic_read(&overflow_count))
94101 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94102 + if (atomic_read_unchecked(&overflow_count))
94103 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94104 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94105
94106 for (i = 0; i < nr_entries; i++) {
94107 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94108 {
94109 struct proc_dir_entry *pe;
94110
94111 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94112 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94113 +#else
94114 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94115 +#endif
94116 if (!pe)
94117 return -ENOMEM;
94118 return 0;
94119 diff --git a/kernel/torture.c b/kernel/torture.c
94120 index dd70993..0bf694b 100644
94121 --- a/kernel/torture.c
94122 +++ b/kernel/torture.c
94123 @@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94124 mutex_lock(&fullstop_mutex);
94125 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94126 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94127 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94128 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94129 } else {
94130 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94131 }
94132 @@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
94133 if (!torture_must_stop()) {
94134 if (stutter > 1) {
94135 schedule_timeout_interruptible(stutter - 1);
94136 - ACCESS_ONCE(stutter_pause_test) = 2;
94137 + ACCESS_ONCE_RW(stutter_pause_test) = 2;
94138 }
94139 schedule_timeout_interruptible(1);
94140 - ACCESS_ONCE(stutter_pause_test) = 1;
94141 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
94142 }
94143 if (!torture_must_stop())
94144 schedule_timeout_interruptible(stutter);
94145 - ACCESS_ONCE(stutter_pause_test) = 0;
94146 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
94147 torture_shutdown_absorb("torture_stutter");
94148 } while (!torture_must_stop());
94149 torture_kthread_stopping("torture_stutter");
94150 @@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
94151 schedule_timeout_uninterruptible(10);
94152 return true;
94153 }
94154 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94155 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94156 mutex_unlock(&fullstop_mutex);
94157 torture_shutdown_cleanup();
94158 torture_shuffle_cleanup();
94159 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94160 index c1bd4ad..4b861dc 100644
94161 --- a/kernel/trace/blktrace.c
94162 +++ b/kernel/trace/blktrace.c
94163 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94164 struct blk_trace *bt = filp->private_data;
94165 char buf[16];
94166
94167 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94168 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94169
94170 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94171 }
94172 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94173 return 1;
94174
94175 bt = buf->chan->private_data;
94176 - atomic_inc(&bt->dropped);
94177 + atomic_inc_unchecked(&bt->dropped);
94178 return 0;
94179 }
94180
94181 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94182
94183 bt->dir = dir;
94184 bt->dev = dev;
94185 - atomic_set(&bt->dropped, 0);
94186 + atomic_set_unchecked(&bt->dropped, 0);
94187 INIT_LIST_HEAD(&bt->running_list);
94188
94189 ret = -EIO;
94190 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94191 index 124e2c7..762ca29 100644
94192 --- a/kernel/trace/ftrace.c
94193 +++ b/kernel/trace/ftrace.c
94194 @@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94195 if (unlikely(ftrace_disabled))
94196 return 0;
94197
94198 + ret = ftrace_arch_code_modify_prepare();
94199 + FTRACE_WARN_ON(ret);
94200 + if (ret)
94201 + return 0;
94202 +
94203 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94204 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94205 if (ret) {
94206 ftrace_bug(ret, ip);
94207 - return 0;
94208 }
94209 - return 1;
94210 + return ret ? 0 : 1;
94211 }
94212
94213 /*
94214 @@ -4529,8 +4534,10 @@ static int ftrace_process_locs(struct module *mod,
94215 if (!count)
94216 return 0;
94217
94218 + pax_open_kernel();
94219 sort(start, count, sizeof(*start),
94220 ftrace_cmp_ips, ftrace_swap_ips);
94221 + pax_close_kernel();
94222
94223 start_pg = ftrace_allocate_pages(count);
94224 if (!start_pg)
94225 @@ -5377,7 +5384,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94226
94227 if (t->ret_stack == NULL) {
94228 atomic_set(&t->tracing_graph_pause, 0);
94229 - atomic_set(&t->trace_overrun, 0);
94230 + atomic_set_unchecked(&t->trace_overrun, 0);
94231 t->curr_ret_stack = -1;
94232 /* Make sure the tasks see the -1 first: */
94233 smp_wmb();
94234 @@ -5590,7 +5597,7 @@ static void
94235 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94236 {
94237 atomic_set(&t->tracing_graph_pause, 0);
94238 - atomic_set(&t->trace_overrun, 0);
94239 + atomic_set_unchecked(&t->trace_overrun, 0);
94240 t->ftrace_timestamp = 0;
94241 /* make curr_ret_stack visible before we add the ret_stack */
94242 smp_wmb();
94243 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94244 index f4fbbfc..ebb5622 100644
94245 --- a/kernel/trace/ring_buffer.c
94246 +++ b/kernel/trace/ring_buffer.c
94247 @@ -352,9 +352,9 @@ struct buffer_data_page {
94248 */
94249 struct buffer_page {
94250 struct list_head list; /* list of buffer pages */
94251 - local_t write; /* index for next write */
94252 + local_unchecked_t write; /* index for next write */
94253 unsigned read; /* index for next read */
94254 - local_t entries; /* entries on this page */
94255 + local_unchecked_t entries; /* entries on this page */
94256 unsigned long real_end; /* real end of data */
94257 struct buffer_data_page *page; /* Actual data page */
94258 };
94259 @@ -476,8 +476,8 @@ struct ring_buffer_per_cpu {
94260 unsigned long last_overrun;
94261 local_t entries_bytes;
94262 local_t entries;
94263 - local_t overrun;
94264 - local_t commit_overrun;
94265 + local_unchecked_t overrun;
94266 + local_unchecked_t commit_overrun;
94267 local_t dropped_events;
94268 local_t committing;
94269 local_t commits;
94270 @@ -1050,8 +1050,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94271 *
94272 * We add a counter to the write field to denote this.
94273 */
94274 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94275 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94276 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94277 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94278
94279 /*
94280 * Just make sure we have seen our old_write and synchronize
94281 @@ -1079,8 +1079,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94282 * cmpxchg to only update if an interrupt did not already
94283 * do it for us. If the cmpxchg fails, we don't care.
94284 */
94285 - (void)local_cmpxchg(&next_page->write, old_write, val);
94286 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94287 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94288 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94289
94290 /*
94291 * No need to worry about races with clearing out the commit.
94292 @@ -1448,12 +1448,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94293
94294 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94295 {
94296 - return local_read(&bpage->entries) & RB_WRITE_MASK;
94297 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94298 }
94299
94300 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94301 {
94302 - return local_read(&bpage->write) & RB_WRITE_MASK;
94303 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94304 }
94305
94306 static int
94307 @@ -1548,7 +1548,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94308 * bytes consumed in ring buffer from here.
94309 * Increment overrun to account for the lost events.
94310 */
94311 - local_add(page_entries, &cpu_buffer->overrun);
94312 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
94313 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94314 }
94315
94316 @@ -2110,7 +2110,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94317 * it is our responsibility to update
94318 * the counters.
94319 */
94320 - local_add(entries, &cpu_buffer->overrun);
94321 + local_add_unchecked(entries, &cpu_buffer->overrun);
94322 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94323
94324 /*
94325 @@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94326 if (tail == BUF_PAGE_SIZE)
94327 tail_page->real_end = 0;
94328
94329 - local_sub(length, &tail_page->write);
94330 + local_sub_unchecked(length, &tail_page->write);
94331 return;
94332 }
94333
94334 @@ -2295,7 +2295,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94335 rb_event_set_padding(event);
94336
94337 /* Set the write back to the previous setting */
94338 - local_sub(length, &tail_page->write);
94339 + local_sub_unchecked(length, &tail_page->write);
94340 return;
94341 }
94342
94343 @@ -2307,7 +2307,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94344
94345 /* Set write to end of buffer */
94346 length = (tail + length) - BUF_PAGE_SIZE;
94347 - local_sub(length, &tail_page->write);
94348 + local_sub_unchecked(length, &tail_page->write);
94349 }
94350
94351 /*
94352 @@ -2333,7 +2333,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94353 * about it.
94354 */
94355 if (unlikely(next_page == commit_page)) {
94356 - local_inc(&cpu_buffer->commit_overrun);
94357 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94358 goto out_reset;
94359 }
94360
94361 @@ -2389,7 +2389,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94362 cpu_buffer->tail_page) &&
94363 (cpu_buffer->commit_page ==
94364 cpu_buffer->reader_page))) {
94365 - local_inc(&cpu_buffer->commit_overrun);
94366 + local_inc_unchecked(&cpu_buffer->commit_overrun);
94367 goto out_reset;
94368 }
94369 }
94370 @@ -2437,7 +2437,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94371 length += RB_LEN_TIME_EXTEND;
94372
94373 tail_page = cpu_buffer->tail_page;
94374 - write = local_add_return(length, &tail_page->write);
94375 + write = local_add_return_unchecked(length, &tail_page->write);
94376
94377 /* set write to only the index of the write */
94378 write &= RB_WRITE_MASK;
94379 @@ -2461,7 +2461,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94380 kmemcheck_annotate_bitfield(event, bitfield);
94381 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94382
94383 - local_inc(&tail_page->entries);
94384 + local_inc_unchecked(&tail_page->entries);
94385
94386 /*
94387 * If this is the first commit on the page, then update
94388 @@ -2494,7 +2494,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94389
94390 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94391 unsigned long write_mask =
94392 - local_read(&bpage->write) & ~RB_WRITE_MASK;
94393 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94394 unsigned long event_length = rb_event_length(event);
94395 /*
94396 * This is on the tail page. It is possible that
94397 @@ -2504,7 +2504,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94398 */
94399 old_index += write_mask;
94400 new_index += write_mask;
94401 - index = local_cmpxchg(&bpage->write, old_index, new_index);
94402 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94403 if (index == old_index) {
94404 /* update counters */
94405 local_sub(event_length, &cpu_buffer->entries_bytes);
94406 @@ -2907,7 +2907,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94407
94408 /* Do the likely case first */
94409 if (likely(bpage->page == (void *)addr)) {
94410 - local_dec(&bpage->entries);
94411 + local_dec_unchecked(&bpage->entries);
94412 return;
94413 }
94414
94415 @@ -2919,7 +2919,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94416 start = bpage;
94417 do {
94418 if (bpage->page == (void *)addr) {
94419 - local_dec(&bpage->entries);
94420 + local_dec_unchecked(&bpage->entries);
94421 return;
94422 }
94423 rb_inc_page(cpu_buffer, &bpage);
94424 @@ -3203,7 +3203,7 @@ static inline unsigned long
94425 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94426 {
94427 return local_read(&cpu_buffer->entries) -
94428 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94429 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94430 }
94431
94432 /**
94433 @@ -3292,7 +3292,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94434 return 0;
94435
94436 cpu_buffer = buffer->buffers[cpu];
94437 - ret = local_read(&cpu_buffer->overrun);
94438 + ret = local_read_unchecked(&cpu_buffer->overrun);
94439
94440 return ret;
94441 }
94442 @@ -3315,7 +3315,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94443 return 0;
94444
94445 cpu_buffer = buffer->buffers[cpu];
94446 - ret = local_read(&cpu_buffer->commit_overrun);
94447 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94448
94449 return ret;
94450 }
94451 @@ -3400,7 +3400,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94452 /* if you care about this being correct, lock the buffer */
94453 for_each_buffer_cpu(buffer, cpu) {
94454 cpu_buffer = buffer->buffers[cpu];
94455 - overruns += local_read(&cpu_buffer->overrun);
94456 + overruns += local_read_unchecked(&cpu_buffer->overrun);
94457 }
94458
94459 return overruns;
94460 @@ -3571,8 +3571,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94461 /*
94462 * Reset the reader page to size zero.
94463 */
94464 - local_set(&cpu_buffer->reader_page->write, 0);
94465 - local_set(&cpu_buffer->reader_page->entries, 0);
94466 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94467 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94468 local_set(&cpu_buffer->reader_page->page->commit, 0);
94469 cpu_buffer->reader_page->real_end = 0;
94470
94471 @@ -3606,7 +3606,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94472 * want to compare with the last_overrun.
94473 */
94474 smp_mb();
94475 - overwrite = local_read(&(cpu_buffer->overrun));
94476 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94477
94478 /*
94479 * Here's the tricky part.
94480 @@ -4178,8 +4178,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94481
94482 cpu_buffer->head_page
94483 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94484 - local_set(&cpu_buffer->head_page->write, 0);
94485 - local_set(&cpu_buffer->head_page->entries, 0);
94486 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
94487 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94488 local_set(&cpu_buffer->head_page->page->commit, 0);
94489
94490 cpu_buffer->head_page->read = 0;
94491 @@ -4189,14 +4189,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94492
94493 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94494 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94495 - local_set(&cpu_buffer->reader_page->write, 0);
94496 - local_set(&cpu_buffer->reader_page->entries, 0);
94497 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94498 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94499 local_set(&cpu_buffer->reader_page->page->commit, 0);
94500 cpu_buffer->reader_page->read = 0;
94501
94502 local_set(&cpu_buffer->entries_bytes, 0);
94503 - local_set(&cpu_buffer->overrun, 0);
94504 - local_set(&cpu_buffer->commit_overrun, 0);
94505 + local_set_unchecked(&cpu_buffer->overrun, 0);
94506 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94507 local_set(&cpu_buffer->dropped_events, 0);
94508 local_set(&cpu_buffer->entries, 0);
94509 local_set(&cpu_buffer->committing, 0);
94510 @@ -4601,8 +4601,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94511 rb_init_page(bpage);
94512 bpage = reader->page;
94513 reader->page = *data_page;
94514 - local_set(&reader->write, 0);
94515 - local_set(&reader->entries, 0);
94516 + local_set_unchecked(&reader->write, 0);
94517 + local_set_unchecked(&reader->entries, 0);
94518 reader->read = 0;
94519 *data_page = bpage;
94520
94521 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94522 index 72c7134..581f360 100644
94523 --- a/kernel/trace/trace.c
94524 +++ b/kernel/trace/trace.c
94525 @@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94526 return 0;
94527 }
94528
94529 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94530 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94531 {
94532 /* do nothing if flag is already set */
94533 if (!!(trace_flags & mask) == !!enabled)
94534 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94535 index 385391f..8d2250f 100644
94536 --- a/kernel/trace/trace.h
94537 +++ b/kernel/trace/trace.h
94538 @@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94539 void trace_printk_init_buffers(void);
94540 void trace_printk_start_comm(void);
94541 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94542 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94543 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94544
94545 /*
94546 * Normal trace_printk() and friends allocates special buffers
94547 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94548 index 57b67b1..66082a9 100644
94549 --- a/kernel/trace/trace_clock.c
94550 +++ b/kernel/trace/trace_clock.c
94551 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94552 return now;
94553 }
94554
94555 -static atomic64_t trace_counter;
94556 +static atomic64_unchecked_t trace_counter;
94557
94558 /*
94559 * trace_clock_counter(): simply an atomic counter.
94560 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94561 */
94562 u64 notrace trace_clock_counter(void)
94563 {
94564 - return atomic64_add_return(1, &trace_counter);
94565 + return atomic64_inc_return_unchecked(&trace_counter);
94566 }
94567 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94568 index 1b0df1e..4ebb965 100644
94569 --- a/kernel/trace/trace_events.c
94570 +++ b/kernel/trace/trace_events.c
94571 @@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94572 return 0;
94573 }
94574
94575 -struct ftrace_module_file_ops;
94576 static void __add_event_to_tracers(struct ftrace_event_call *call);
94577
94578 /* Add an additional event_call dynamically */
94579 diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94580 index f0a0c98..3692dc8 100644
94581 --- a/kernel/trace/trace_functions_graph.c
94582 +++ b/kernel/trace/trace_functions_graph.c
94583 @@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94584
94585 /* The return trace stack is full */
94586 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94587 - atomic_inc(&current->trace_overrun);
94588 + atomic_inc_unchecked(&current->trace_overrun);
94589 return -EBUSY;
94590 }
94591
94592 @@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94593 *ret = current->ret_stack[index].ret;
94594 trace->func = current->ret_stack[index].func;
94595 trace->calltime = current->ret_stack[index].calltime;
94596 - trace->overrun = atomic_read(&current->trace_overrun);
94597 + trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94598 trace->depth = index;
94599 }
94600
94601 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94602 index 0abd9b8..6a663a2 100644
94603 --- a/kernel/trace/trace_mmiotrace.c
94604 +++ b/kernel/trace/trace_mmiotrace.c
94605 @@ -24,7 +24,7 @@ struct header_iter {
94606 static struct trace_array *mmio_trace_array;
94607 static bool overrun_detected;
94608 static unsigned long prev_overruns;
94609 -static atomic_t dropped_count;
94610 +static atomic_unchecked_t dropped_count;
94611
94612 static void mmio_reset_data(struct trace_array *tr)
94613 {
94614 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94615
94616 static unsigned long count_overruns(struct trace_iterator *iter)
94617 {
94618 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
94619 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94620 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94621
94622 if (over > prev_overruns)
94623 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94624 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94625 sizeof(*entry), 0, pc);
94626 if (!event) {
94627 - atomic_inc(&dropped_count);
94628 + atomic_inc_unchecked(&dropped_count);
94629 return;
94630 }
94631 entry = ring_buffer_event_data(event);
94632 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94633 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94634 sizeof(*entry), 0, pc);
94635 if (!event) {
94636 - atomic_inc(&dropped_count);
94637 + atomic_inc_unchecked(&dropped_count);
94638 return;
94639 }
94640 entry = ring_buffer_event_data(event);
94641 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94642 index c6977d5..d243785 100644
94643 --- a/kernel/trace/trace_output.c
94644 +++ b/kernel/trace/trace_output.c
94645 @@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94646 goto out;
94647 }
94648
94649 + pax_open_kernel();
94650 if (event->funcs->trace == NULL)
94651 - event->funcs->trace = trace_nop_print;
94652 + *(void **)&event->funcs->trace = trace_nop_print;
94653 if (event->funcs->raw == NULL)
94654 - event->funcs->raw = trace_nop_print;
94655 + *(void **)&event->funcs->raw = trace_nop_print;
94656 if (event->funcs->hex == NULL)
94657 - event->funcs->hex = trace_nop_print;
94658 + *(void **)&event->funcs->hex = trace_nop_print;
94659 if (event->funcs->binary == NULL)
94660 - event->funcs->binary = trace_nop_print;
94661 + *(void **)&event->funcs->binary = trace_nop_print;
94662 + pax_close_kernel();
94663
94664 key = event->type & (EVENT_HASHSIZE - 1);
94665
94666 diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94667 index 1f24ed9..10407ec 100644
94668 --- a/kernel/trace/trace_seq.c
94669 +++ b/kernel/trace/trace_seq.c
94670 @@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94671
94672 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94673 if (!IS_ERR(p)) {
94674 - p = mangle_path(s->buffer + s->len, p, "\n");
94675 + p = mangle_path(s->buffer + s->len, p, "\n\\");
94676 if (p) {
94677 s->len = p - s->buffer;
94678 return 1;
94679 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94680 index 16eddb3..758b308 100644
94681 --- a/kernel/trace/trace_stack.c
94682 +++ b/kernel/trace/trace_stack.c
94683 @@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94684 return;
94685
94686 /* we do not handle interrupt stacks yet */
94687 - if (!object_is_on_stack(stack))
94688 + if (!object_starts_on_stack(stack))
94689 return;
94690
94691 local_irq_save(flags);
94692 diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94693 index 29228c4..301bc8c 100644
94694 --- a/kernel/trace/trace_syscalls.c
94695 +++ b/kernel/trace/trace_syscalls.c
94696 @@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94697 int num;
94698
94699 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94700 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94701 + return -EINVAL;
94702
94703 mutex_lock(&syscall_trace_lock);
94704 if (!sys_perf_refcount_enter)
94705 @@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94706 int num;
94707
94708 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94709 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94710 + return;
94711
94712 mutex_lock(&syscall_trace_lock);
94713 sys_perf_refcount_enter--;
94714 @@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94715 int num;
94716
94717 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94718 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94719 + return -EINVAL;
94720
94721 mutex_lock(&syscall_trace_lock);
94722 if (!sys_perf_refcount_exit)
94723 @@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94724 int num;
94725
94726 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94727 + if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94728 + return;
94729
94730 mutex_lock(&syscall_trace_lock);
94731 sys_perf_refcount_exit--;
94732 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94733 index a2e37c5..4fa859b 100644
94734 --- a/kernel/user_namespace.c
94735 +++ b/kernel/user_namespace.c
94736 @@ -83,6 +83,21 @@ int create_user_ns(struct cred *new)
94737 !kgid_has_mapping(parent_ns, group))
94738 return -EPERM;
94739
94740 +#ifdef CONFIG_GRKERNSEC
94741 + /*
94742 + * This doesn't really inspire confidence:
94743 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94744 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94745 + * Increases kernel attack surface in areas developers
94746 + * previously cared little about ("low importance due
94747 + * to requiring "root" capability")
94748 + * To be removed when this code receives *proper* review
94749 + */
94750 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94751 + !capable(CAP_SETGID))
94752 + return -EPERM;
94753 +#endif
94754 +
94755 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94756 if (!ns)
94757 return -ENOMEM;
94758 @@ -974,7 +989,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94759 if (atomic_read(&current->mm->mm_users) > 1)
94760 return -EINVAL;
94761
94762 - if (current->fs->users != 1)
94763 + if (atomic_read(&current->fs->users) != 1)
94764 return -EINVAL;
94765
94766 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94767 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94768 index c8eac43..4b5f08f 100644
94769 --- a/kernel/utsname_sysctl.c
94770 +++ b/kernel/utsname_sysctl.c
94771 @@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94772 static int proc_do_uts_string(struct ctl_table *table, int write,
94773 void __user *buffer, size_t *lenp, loff_t *ppos)
94774 {
94775 - struct ctl_table uts_table;
94776 + ctl_table_no_const uts_table;
94777 int r;
94778 memcpy(&uts_table, table, sizeof(uts_table));
94779 uts_table.data = get_uts(table, write);
94780 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94781 index 70bf118..4be3c37 100644
94782 --- a/kernel/watchdog.c
94783 +++ b/kernel/watchdog.c
94784 @@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94785 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94786 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94787
94788 -static struct smp_hotplug_thread watchdog_threads = {
94789 +static struct smp_hotplug_thread watchdog_threads __read_only = {
94790 .store = &softlockup_watchdog,
94791 .thread_should_run = watchdog_should_run,
94792 .thread_fn = watchdog,
94793 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94794 index 66940a5..a44fed0 100644
94795 --- a/kernel/workqueue.c
94796 +++ b/kernel/workqueue.c
94797 @@ -4499,7 +4499,7 @@ static void rebind_workers(struct worker_pool *pool)
94798 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94799 worker_flags |= WORKER_REBOUND;
94800 worker_flags &= ~WORKER_UNBOUND;
94801 - ACCESS_ONCE(worker->flags) = worker_flags;
94802 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
94803 }
94804
94805 spin_unlock_irq(&pool->lock);
94806 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94807 index 4e35a5d..8a1f3f0 100644
94808 --- a/lib/Kconfig.debug
94809 +++ b/lib/Kconfig.debug
94810 @@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94811
94812 config DEBUG_WW_MUTEX_SLOWPATH
94813 bool "Wait/wound mutex debugging: Slowpath testing"
94814 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94815 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94816 select DEBUG_LOCK_ALLOC
94817 select DEBUG_SPINLOCK
94818 select DEBUG_MUTEXES
94819 @@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94820
94821 config DEBUG_LOCK_ALLOC
94822 bool "Lock debugging: detect incorrect freeing of live locks"
94823 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94824 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94825 select DEBUG_SPINLOCK
94826 select DEBUG_MUTEXES
94827 select LOCKDEP
94828 @@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94829
94830 config PROVE_LOCKING
94831 bool "Lock debugging: prove locking correctness"
94832 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94833 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94834 select LOCKDEP
94835 select DEBUG_SPINLOCK
94836 select DEBUG_MUTEXES
94837 @@ -976,7 +976,7 @@ config LOCKDEP
94838
94839 config LOCK_STAT
94840 bool "Lock usage statistics"
94841 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94842 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94843 select LOCKDEP
94844 select DEBUG_SPINLOCK
94845 select DEBUG_MUTEXES
94846 @@ -1449,6 +1449,7 @@ config LATENCYTOP
94847 depends on DEBUG_KERNEL
94848 depends on STACKTRACE_SUPPORT
94849 depends on PROC_FS
94850 + depends on !GRKERNSEC_HIDESYM
94851 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94852 select KALLSYMS
94853 select KALLSYMS_ALL
94854 @@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94855 config DEBUG_STRICT_USER_COPY_CHECKS
94856 bool "Strict user copy size checks"
94857 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94858 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94859 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94860 help
94861 Enabling this option turns a certain set of sanity checks for user
94862 copy operations into compile time failures.
94863 @@ -1593,7 +1594,7 @@ endmenu # runtime tests
94864
94865 config PROVIDE_OHCI1394_DMA_INIT
94866 bool "Remote debugging over FireWire early on boot"
94867 - depends on PCI && X86
94868 + depends on PCI && X86 && !GRKERNSEC
94869 help
94870 If you want to debug problems which hang or crash the kernel early
94871 on boot and the crashing machine has a FireWire port, you can use
94872 diff --git a/lib/Makefile b/lib/Makefile
94873 index 0211d2b..93f5cc3 100644
94874 --- a/lib/Makefile
94875 +++ b/lib/Makefile
94876 @@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94877 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94878 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94879 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94880 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94881 +obj-y += list_debug.o
94882 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94883
94884 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94885 diff --git a/lib/average.c b/lib/average.c
94886 index 114d1be..ab0350c 100644
94887 --- a/lib/average.c
94888 +++ b/lib/average.c
94889 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94890 {
94891 unsigned long internal = ACCESS_ONCE(avg->internal);
94892
94893 - ACCESS_ONCE(avg->internal) = internal ?
94894 + ACCESS_ONCE_RW(avg->internal) = internal ?
94895 (((internal << avg->weight) - internal) +
94896 (val << avg->factor)) >> avg->weight :
94897 (val << avg->factor);
94898 diff --git a/lib/bitmap.c b/lib/bitmap.c
94899 index b499ab6..fbdb76c 100644
94900 --- a/lib/bitmap.c
94901 +++ b/lib/bitmap.c
94902 @@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94903 {
94904 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94905 u32 chunk;
94906 - const char __user __force *ubuf = (const char __user __force *)buf;
94907 + const char __user *ubuf = (const char __force_user *)buf;
94908
94909 bitmap_zero(maskp, nmaskbits);
94910
94911 @@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94912 {
94913 if (!access_ok(VERIFY_READ, ubuf, ulen))
94914 return -EFAULT;
94915 - return __bitmap_parse((const char __force *)ubuf,
94916 + return __bitmap_parse((const char __force_kernel *)ubuf,
94917 ulen, 1, maskp, nmaskbits);
94918
94919 }
94920 @@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94921 {
94922 unsigned a, b;
94923 int c, old_c, totaldigits;
94924 - const char __user __force *ubuf = (const char __user __force *)buf;
94925 + const char __user *ubuf = (const char __force_user *)buf;
94926 int exp_digit, in_range;
94927
94928 totaldigits = c = 0;
94929 @@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94930 {
94931 if (!access_ok(VERIFY_READ, ubuf, ulen))
94932 return -EFAULT;
94933 - return __bitmap_parselist((const char __force *)ubuf,
94934 + return __bitmap_parselist((const char __force_kernel *)ubuf,
94935 ulen, 1, maskp, nmaskbits);
94936 }
94937 EXPORT_SYMBOL(bitmap_parselist_user);
94938 diff --git a/lib/bug.c b/lib/bug.c
94939 index d1d7c78..b354235 100644
94940 --- a/lib/bug.c
94941 +++ b/lib/bug.c
94942 @@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94943 return BUG_TRAP_TYPE_NONE;
94944
94945 bug = find_bug(bugaddr);
94946 + if (!bug)
94947 + return BUG_TRAP_TYPE_NONE;
94948
94949 file = NULL;
94950 line = 0;
94951 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94952 index 547f7f9..a6d4ba0 100644
94953 --- a/lib/debugobjects.c
94954 +++ b/lib/debugobjects.c
94955 @@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94956 if (limit > 4)
94957 return;
94958
94959 - is_on_stack = object_is_on_stack(addr);
94960 + is_on_stack = object_starts_on_stack(addr);
94961 if (is_on_stack == onstack)
94962 return;
94963
94964 diff --git a/lib/div64.c b/lib/div64.c
94965 index 4382ad7..08aa558 100644
94966 --- a/lib/div64.c
94967 +++ b/lib/div64.c
94968 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94969 EXPORT_SYMBOL(__div64_32);
94970
94971 #ifndef div_s64_rem
94972 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94973 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94974 {
94975 u64 quotient;
94976
94977 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94978 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94979 */
94980 #ifndef div64_u64
94981 -u64 div64_u64(u64 dividend, u64 divisor)
94982 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94983 {
94984 u32 high = divisor >> 32;
94985 u64 quot;
94986 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94987 index add80cc..0d27550 100644
94988 --- a/lib/dma-debug.c
94989 +++ b/lib/dma-debug.c
94990 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94991
94992 void dma_debug_add_bus(struct bus_type *bus)
94993 {
94994 - struct notifier_block *nb;
94995 + notifier_block_no_const *nb;
94996
94997 if (global_disable)
94998 return;
94999 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
95000
95001 static void check_for_stack(struct device *dev, void *addr)
95002 {
95003 - if (object_is_on_stack(addr))
95004 + if (object_starts_on_stack(addr))
95005 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
95006 "stack [addr=%p]\n", addr);
95007 }
95008 diff --git a/lib/hash.c b/lib/hash.c
95009 index fea973f..386626f 100644
95010 --- a/lib/hash.c
95011 +++ b/lib/hash.c
95012 @@ -14,7 +14,7 @@
95013 #include <linux/hash.h>
95014 #include <linux/cache.h>
95015
95016 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
95017 +static struct fast_hash_ops arch_hash_ops __read_only = {
95018 .hash = jhash,
95019 .hash2 = jhash2,
95020 };
95021 diff --git a/lib/inflate.c b/lib/inflate.c
95022 index 013a761..c28f3fc 100644
95023 --- a/lib/inflate.c
95024 +++ b/lib/inflate.c
95025 @@ -269,7 +269,7 @@ static void free(void *where)
95026 malloc_ptr = free_mem_ptr;
95027 }
95028 #else
95029 -#define malloc(a) kmalloc(a, GFP_KERNEL)
95030 +#define malloc(a) kmalloc((a), GFP_KERNEL)
95031 #define free(a) kfree(a)
95032 #endif
95033
95034 diff --git a/lib/ioremap.c b/lib/ioremap.c
95035 index 0c9216c..863bd89 100644
95036 --- a/lib/ioremap.c
95037 +++ b/lib/ioremap.c
95038 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95039 unsigned long next;
95040
95041 phys_addr -= addr;
95042 - pmd = pmd_alloc(&init_mm, pud, addr);
95043 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95044 if (!pmd)
95045 return -ENOMEM;
95046 do {
95047 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95048 unsigned long next;
95049
95050 phys_addr -= addr;
95051 - pud = pud_alloc(&init_mm, pgd, addr);
95052 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95053 if (!pud)
95054 return -ENOMEM;
95055 do {
95056 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95057 index bd2bea9..6b3c95e 100644
95058 --- a/lib/is_single_threaded.c
95059 +++ b/lib/is_single_threaded.c
95060 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95061 struct task_struct *p, *t;
95062 bool ret;
95063
95064 + if (!mm)
95065 + return true;
95066 +
95067 if (atomic_read(&task->signal->live) != 1)
95068 return false;
95069
95070 diff --git a/lib/kobject.c b/lib/kobject.c
95071 index 58751bb..93a1853 100644
95072 --- a/lib/kobject.c
95073 +++ b/lib/kobject.c
95074 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95075
95076
95077 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95078 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95079 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95080
95081 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95082 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95083 {
95084 enum kobj_ns_type type = ops->type;
95085 int error;
95086 diff --git a/lib/list_debug.c b/lib/list_debug.c
95087 index c24c2f7..f0296f4 100644
95088 --- a/lib/list_debug.c
95089 +++ b/lib/list_debug.c
95090 @@ -11,7 +11,9 @@
95091 #include <linux/bug.h>
95092 #include <linux/kernel.h>
95093 #include <linux/rculist.h>
95094 +#include <linux/mm.h>
95095
95096 +#ifdef CONFIG_DEBUG_LIST
95097 /*
95098 * Insert a new entry between two known consecutive entries.
95099 *
95100 @@ -19,21 +21,40 @@
95101 * the prev/next entries already!
95102 */
95103
95104 +static bool __list_add_debug(struct list_head *new,
95105 + struct list_head *prev,
95106 + struct list_head *next)
95107 +{
95108 + if (unlikely(next->prev != prev)) {
95109 + printk(KERN_ERR "list_add corruption. next->prev should be "
95110 + "prev (%p), but was %p. (next=%p).\n",
95111 + prev, next->prev, next);
95112 + BUG();
95113 + return false;
95114 + }
95115 + if (unlikely(prev->next != next)) {
95116 + printk(KERN_ERR "list_add corruption. prev->next should be "
95117 + "next (%p), but was %p. (prev=%p).\n",
95118 + next, prev->next, prev);
95119 + BUG();
95120 + return false;
95121 + }
95122 + if (unlikely(new == prev || new == next)) {
95123 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95124 + new, prev, next);
95125 + BUG();
95126 + return false;
95127 + }
95128 + return true;
95129 +}
95130 +
95131 void __list_add(struct list_head *new,
95132 - struct list_head *prev,
95133 - struct list_head *next)
95134 + struct list_head *prev,
95135 + struct list_head *next)
95136 {
95137 - WARN(next->prev != prev,
95138 - "list_add corruption. next->prev should be "
95139 - "prev (%p), but was %p. (next=%p).\n",
95140 - prev, next->prev, next);
95141 - WARN(prev->next != next,
95142 - "list_add corruption. prev->next should be "
95143 - "next (%p), but was %p. (prev=%p).\n",
95144 - next, prev->next, prev);
95145 - WARN(new == prev || new == next,
95146 - "list_add double add: new=%p, prev=%p, next=%p.\n",
95147 - new, prev, next);
95148 + if (!__list_add_debug(new, prev, next))
95149 + return;
95150 +
95151 next->prev = new;
95152 new->next = next;
95153 new->prev = prev;
95154 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95155 }
95156 EXPORT_SYMBOL(__list_add);
95157
95158 -void __list_del_entry(struct list_head *entry)
95159 +static bool __list_del_entry_debug(struct list_head *entry)
95160 {
95161 struct list_head *prev, *next;
95162
95163 prev = entry->prev;
95164 next = entry->next;
95165
95166 - if (WARN(next == LIST_POISON1,
95167 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95168 - entry, LIST_POISON1) ||
95169 - WARN(prev == LIST_POISON2,
95170 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95171 - entry, LIST_POISON2) ||
95172 - WARN(prev->next != entry,
95173 - "list_del corruption. prev->next should be %p, "
95174 - "but was %p\n", entry, prev->next) ||
95175 - WARN(next->prev != entry,
95176 - "list_del corruption. next->prev should be %p, "
95177 - "but was %p\n", entry, next->prev))
95178 + if (unlikely(next == LIST_POISON1)) {
95179 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95180 + entry, LIST_POISON1);
95181 + BUG();
95182 + return false;
95183 + }
95184 + if (unlikely(prev == LIST_POISON2)) {
95185 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95186 + entry, LIST_POISON2);
95187 + BUG();
95188 + return false;
95189 + }
95190 + if (unlikely(entry->prev->next != entry)) {
95191 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95192 + "but was %p\n", entry, prev->next);
95193 + BUG();
95194 + return false;
95195 + }
95196 + if (unlikely(entry->next->prev != entry)) {
95197 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95198 + "but was %p\n", entry, next->prev);
95199 + BUG();
95200 + return false;
95201 + }
95202 + return true;
95203 +}
95204 +
95205 +void __list_del_entry(struct list_head *entry)
95206 +{
95207 + if (!__list_del_entry_debug(entry))
95208 return;
95209
95210 - __list_del(prev, next);
95211 + __list_del(entry->prev, entry->next);
95212 }
95213 EXPORT_SYMBOL(__list_del_entry);
95214
95215 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95216 void __list_add_rcu(struct list_head *new,
95217 struct list_head *prev, struct list_head *next)
95218 {
95219 - WARN(next->prev != prev,
95220 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95221 - prev, next->prev, next);
95222 - WARN(prev->next != next,
95223 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95224 - next, prev->next, prev);
95225 + if (!__list_add_debug(new, prev, next))
95226 + return;
95227 +
95228 new->next = next;
95229 new->prev = prev;
95230 rcu_assign_pointer(list_next_rcu(prev), new);
95231 next->prev = new;
95232 }
95233 EXPORT_SYMBOL(__list_add_rcu);
95234 +#endif
95235 +
95236 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95237 +{
95238 +#ifdef CONFIG_DEBUG_LIST
95239 + if (!__list_add_debug(new, prev, next))
95240 + return;
95241 +#endif
95242 +
95243 + pax_open_kernel();
95244 + next->prev = new;
95245 + new->next = next;
95246 + new->prev = prev;
95247 + prev->next = new;
95248 + pax_close_kernel();
95249 +}
95250 +EXPORT_SYMBOL(__pax_list_add);
95251 +
95252 +void pax_list_del(struct list_head *entry)
95253 +{
95254 +#ifdef CONFIG_DEBUG_LIST
95255 + if (!__list_del_entry_debug(entry))
95256 + return;
95257 +#endif
95258 +
95259 + pax_open_kernel();
95260 + __list_del(entry->prev, entry->next);
95261 + entry->next = LIST_POISON1;
95262 + entry->prev = LIST_POISON2;
95263 + pax_close_kernel();
95264 +}
95265 +EXPORT_SYMBOL(pax_list_del);
95266 +
95267 +void pax_list_del_init(struct list_head *entry)
95268 +{
95269 + pax_open_kernel();
95270 + __list_del(entry->prev, entry->next);
95271 + INIT_LIST_HEAD(entry);
95272 + pax_close_kernel();
95273 +}
95274 +EXPORT_SYMBOL(pax_list_del_init);
95275 +
95276 +void __pax_list_add_rcu(struct list_head *new,
95277 + struct list_head *prev, struct list_head *next)
95278 +{
95279 +#ifdef CONFIG_DEBUG_LIST
95280 + if (!__list_add_debug(new, prev, next))
95281 + return;
95282 +#endif
95283 +
95284 + pax_open_kernel();
95285 + new->next = next;
95286 + new->prev = prev;
95287 + rcu_assign_pointer(list_next_rcu(prev), new);
95288 + next->prev = new;
95289 + pax_close_kernel();
95290 +}
95291 +EXPORT_SYMBOL(__pax_list_add_rcu);
95292 +
95293 +void pax_list_del_rcu(struct list_head *entry)
95294 +{
95295 +#ifdef CONFIG_DEBUG_LIST
95296 + if (!__list_del_entry_debug(entry))
95297 + return;
95298 +#endif
95299 +
95300 + pax_open_kernel();
95301 + __list_del(entry->prev, entry->next);
95302 + entry->next = LIST_POISON1;
95303 + entry->prev = LIST_POISON2;
95304 + pax_close_kernel();
95305 +}
95306 +EXPORT_SYMBOL(pax_list_del_rcu);
95307 diff --git a/lib/lockref.c b/lib/lockref.c
95308 index d2233de..fa1a2f6 100644
95309 --- a/lib/lockref.c
95310 +++ b/lib/lockref.c
95311 @@ -48,13 +48,13 @@
95312 void lockref_get(struct lockref *lockref)
95313 {
95314 CMPXCHG_LOOP(
95315 - new.count++;
95316 + __lockref_inc(&new);
95317 ,
95318 return;
95319 );
95320
95321 spin_lock(&lockref->lock);
95322 - lockref->count++;
95323 + __lockref_inc(lockref);
95324 spin_unlock(&lockref->lock);
95325 }
95326 EXPORT_SYMBOL(lockref_get);
95327 @@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95328 int retval;
95329
95330 CMPXCHG_LOOP(
95331 - new.count++;
95332 + __lockref_inc(&new);
95333 if (!old.count)
95334 return 0;
95335 ,
95336 @@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95337 spin_lock(&lockref->lock);
95338 retval = 0;
95339 if (lockref->count) {
95340 - lockref->count++;
95341 + __lockref_inc(lockref);
95342 retval = 1;
95343 }
95344 spin_unlock(&lockref->lock);
95345 @@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95346 int lockref_get_or_lock(struct lockref *lockref)
95347 {
95348 CMPXCHG_LOOP(
95349 - new.count++;
95350 + __lockref_inc(&new);
95351 if (!old.count)
95352 break;
95353 ,
95354 @@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95355 spin_lock(&lockref->lock);
95356 if (!lockref->count)
95357 return 0;
95358 - lockref->count++;
95359 + __lockref_inc(lockref);
95360 spin_unlock(&lockref->lock);
95361 return 1;
95362 }
95363 @@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95364 int lockref_put_or_lock(struct lockref *lockref)
95365 {
95366 CMPXCHG_LOOP(
95367 - new.count--;
95368 + __lockref_dec(&new);
95369 if (old.count <= 1)
95370 break;
95371 ,
95372 @@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95373 spin_lock(&lockref->lock);
95374 if (lockref->count <= 1)
95375 return 0;
95376 - lockref->count--;
95377 + __lockref_dec(lockref);
95378 spin_unlock(&lockref->lock);
95379 return 1;
95380 }
95381 @@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95382 int retval;
95383
95384 CMPXCHG_LOOP(
95385 - new.count++;
95386 + __lockref_inc(&new);
95387 if ((int)old.count < 0)
95388 return 0;
95389 ,
95390 @@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95391 spin_lock(&lockref->lock);
95392 retval = 0;
95393 if ((int) lockref->count >= 0) {
95394 - lockref->count++;
95395 + __lockref_inc(lockref);
95396 retval = 1;
95397 }
95398 spin_unlock(&lockref->lock);
95399 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95400 index 6111bcb..02e816b 100644
95401 --- a/lib/percpu-refcount.c
95402 +++ b/lib/percpu-refcount.c
95403 @@ -31,7 +31,7 @@
95404 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
95405 */
95406
95407 -#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
95408 +#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
95409
95410 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
95411
95412 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95413 index 3291a8e..346a91e 100644
95414 --- a/lib/radix-tree.c
95415 +++ b/lib/radix-tree.c
95416 @@ -67,7 +67,7 @@ struct radix_tree_preload {
95417 int nr;
95418 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95419 };
95420 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95421 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95422
95423 static inline void *ptr_to_indirect(void *ptr)
95424 {
95425 diff --git a/lib/random32.c b/lib/random32.c
95426 index 0bee183..526f12f 100644
95427 --- a/lib/random32.c
95428 +++ b/lib/random32.c
95429 @@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
95430 }
95431 #endif
95432
95433 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95434 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95435
95436 /**
95437 * prandom_u32_state - seeded pseudo-random number generator.
95438 diff --git a/lib/rbtree.c b/lib/rbtree.c
95439 index c16c81a..4dcbda1 100644
95440 --- a/lib/rbtree.c
95441 +++ b/lib/rbtree.c
95442 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95443 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95444
95445 static const struct rb_augment_callbacks dummy_callbacks = {
95446 - dummy_propagate, dummy_copy, dummy_rotate
95447 + .propagate = dummy_propagate,
95448 + .copy = dummy_copy,
95449 + .rotate = dummy_rotate
95450 };
95451
95452 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95453 diff --git a/lib/show_mem.c b/lib/show_mem.c
95454 index 5e25627..3ed9d7f 100644
95455 --- a/lib/show_mem.c
95456 +++ b/lib/show_mem.c
95457 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95458 quicklist_total_size());
95459 #endif
95460 #ifdef CONFIG_MEMORY_FAILURE
95461 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95462 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95463 #endif
95464 }
95465 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95466 index bb2b201..46abaf9 100644
95467 --- a/lib/strncpy_from_user.c
95468 +++ b/lib/strncpy_from_user.c
95469 @@ -21,7 +21,7 @@
95470 */
95471 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95472 {
95473 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95474 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95475 long res = 0;
95476
95477 /*
95478 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95479 index a28df52..3d55877 100644
95480 --- a/lib/strnlen_user.c
95481 +++ b/lib/strnlen_user.c
95482 @@ -26,7 +26,7 @@
95483 */
95484 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95485 {
95486 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95487 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95488 long align, res = 0;
95489 unsigned long c;
95490
95491 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95492 index 4abda07..b9d3765 100644
95493 --- a/lib/swiotlb.c
95494 +++ b/lib/swiotlb.c
95495 @@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95496
95497 void
95498 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95499 - dma_addr_t dev_addr)
95500 + dma_addr_t dev_addr, struct dma_attrs *attrs)
95501 {
95502 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95503
95504 diff --git a/lib/usercopy.c b/lib/usercopy.c
95505 index 4f5b1dd..7cab418 100644
95506 --- a/lib/usercopy.c
95507 +++ b/lib/usercopy.c
95508 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95509 WARN(1, "Buffer overflow detected!\n");
95510 }
95511 EXPORT_SYMBOL(copy_from_user_overflow);
95512 +
95513 +void copy_to_user_overflow(void)
95514 +{
95515 + WARN(1, "Buffer overflow detected!\n");
95516 +}
95517 +EXPORT_SYMBOL(copy_to_user_overflow);
95518 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95519 index ec337f6..8484eb2 100644
95520 --- a/lib/vsprintf.c
95521 +++ b/lib/vsprintf.c
95522 @@ -16,6 +16,9 @@
95523 * - scnprintf and vscnprintf
95524 */
95525
95526 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95527 +#define __INCLUDED_BY_HIDESYM 1
95528 +#endif
95529 #include <stdarg.h>
95530 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95531 #include <linux/types.h>
95532 @@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95533 #ifdef CONFIG_KALLSYMS
95534 if (*fmt == 'B')
95535 sprint_backtrace(sym, value);
95536 - else if (*fmt != 'f' && *fmt != 's')
95537 + else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95538 sprint_symbol(sym, value);
95539 else
95540 sprint_symbol_no_offset(sym, value);
95541 @@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95542 return number(buf, end, num, spec);
95543 }
95544
95545 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95546 +int kptr_restrict __read_mostly = 2;
95547 +#else
95548 int kptr_restrict __read_mostly;
95549 +#endif
95550
95551 /*
95552 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95553 @@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95554 *
95555 * - 'F' For symbolic function descriptor pointers with offset
95556 * - 'f' For simple symbolic function names without offset
95557 + * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95558 * - 'S' For symbolic direct pointers with offset
95559 * - 's' For symbolic direct pointers without offset
95560 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95561 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95562 * - 'B' For backtraced symbolic direct pointers with offset
95563 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95564 @@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95565
95566 if (!ptr && *fmt != 'K') {
95567 /*
95568 - * Print (null) with the same width as a pointer so it makes
95569 + * Print (nil) with the same width as a pointer so it makes
95570 * tabular output look nice.
95571 */
95572 if (spec.field_width == -1)
95573 spec.field_width = default_width;
95574 - return string(buf, end, "(null)", spec);
95575 + return string(buf, end, "(nil)", spec);
95576 }
95577
95578 switch (*fmt) {
95579 @@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95580 /* Fallthrough */
95581 case 'S':
95582 case 's':
95583 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95584 + break;
95585 +#else
95586 + return symbol_string(buf, end, ptr, spec, fmt);
95587 +#endif
95588 + case 'X':
95589 + ptr = dereference_function_descriptor(ptr);
95590 + case 'A':
95591 case 'B':
95592 return symbol_string(buf, end, ptr, spec, fmt);
95593 case 'R':
95594 @@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95595 va_end(va);
95596 return buf;
95597 }
95598 + case 'P':
95599 + break;
95600 case 'K':
95601 /*
95602 * %pK cannot be used in IRQ context because its test
95603 @@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95604 ((const struct file *)ptr)->f_path.dentry,
95605 spec, fmt);
95606 }
95607 +
95608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95609 + /* 'P' = approved pointers to copy to userland,
95610 + as in the /proc/kallsyms case, as we make it display nothing
95611 + for non-root users, and the real contents for root users
95612 + 'X' = approved simple symbols
95613 + Also ignore 'K' pointers, since we force their NULLing for non-root users
95614 + above
95615 + */
95616 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95617 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95618 + dump_stack();
95619 + ptr = NULL;
95620 + }
95621 +#endif
95622 +
95623 spec.flags |= SMALL;
95624 if (spec.field_width == -1) {
95625 spec.field_width = default_width;
95626 @@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95627 typeof(type) value; \
95628 if (sizeof(type) == 8) { \
95629 args = PTR_ALIGN(args, sizeof(u32)); \
95630 - *(u32 *)&value = *(u32 *)args; \
95631 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95632 + *(u32 *)&value = *(const u32 *)args; \
95633 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95634 } else { \
95635 args = PTR_ALIGN(args, sizeof(type)); \
95636 - value = *(typeof(type) *)args; \
95637 + value = *(const typeof(type) *)args; \
95638 } \
95639 args += sizeof(type); \
95640 value; \
95641 @@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95642 case FORMAT_TYPE_STR: {
95643 const char *str_arg = args;
95644 args += strlen(str_arg) + 1;
95645 - str = string(str, end, (char *)str_arg, spec);
95646 + str = string(str, end, str_arg, spec);
95647 break;
95648 }
95649
95650 diff --git a/localversion-grsec b/localversion-grsec
95651 new file mode 100644
95652 index 0000000..7cd6065
95653 --- /dev/null
95654 +++ b/localversion-grsec
95655 @@ -0,0 +1 @@
95656 +-grsec
95657 diff --git a/mm/Kconfig b/mm/Kconfig
95658 index 1d1ae6b..0f05885 100644
95659 --- a/mm/Kconfig
95660 +++ b/mm/Kconfig
95661 @@ -341,10 +341,11 @@ config KSM
95662 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95663
95664 config DEFAULT_MMAP_MIN_ADDR
95665 - int "Low address space to protect from user allocation"
95666 + int "Low address space to protect from user allocation"
95667 depends on MMU
95668 - default 4096
95669 - help
95670 + default 32768 if ALPHA || ARM || PARISC || SPARC32
95671 + default 65536
95672 + help
95673 This is the portion of low virtual memory which should be protected
95674 from userspace allocation. Keeping a user from writing to low pages
95675 can help reduce the impact of kernel NULL pointer bugs.
95676 @@ -375,7 +376,7 @@ config MEMORY_FAILURE
95677
95678 config HWPOISON_INJECT
95679 tristate "HWPoison pages injector"
95680 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95681 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95682 select PROC_PAGE_MONITOR
95683
95684 config NOMMU_INITIAL_TRIM_EXCESS
95685 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95686 index 0ae0df5..82ac56b 100644
95687 --- a/mm/backing-dev.c
95688 +++ b/mm/backing-dev.c
95689 @@ -12,7 +12,7 @@
95690 #include <linux/device.h>
95691 #include <trace/events/writeback.h>
95692
95693 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95694 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95695
95696 struct backing_dev_info default_backing_dev_info = {
95697 .name = "default",
95698 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95699 return err;
95700
95701 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95702 - atomic_long_inc_return(&bdi_seq));
95703 + atomic_long_inc_return_unchecked(&bdi_seq));
95704 if (err) {
95705 bdi_destroy(bdi);
95706 return err;
95707 diff --git a/mm/filemap.c b/mm/filemap.c
95708 index 37beab9..2c55a85 100644
95709 --- a/mm/filemap.c
95710 +++ b/mm/filemap.c
95711 @@ -2097,7 +2097,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95712 struct address_space *mapping = file->f_mapping;
95713
95714 if (!mapping->a_ops->readpage)
95715 - return -ENOEXEC;
95716 + return -ENODEV;
95717 file_accessed(file);
95718 vma->vm_ops = &generic_file_vm_ops;
95719 return 0;
95720 @@ -2275,6 +2275,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95721 *pos = i_size_read(inode);
95722
95723 if (limit != RLIM_INFINITY) {
95724 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95725 if (*pos >= limit) {
95726 send_sig(SIGXFSZ, current, 0);
95727 return -EFBIG;
95728 diff --git a/mm/fremap.c b/mm/fremap.c
95729 index 72b8fa3..c5b39f1 100644
95730 --- a/mm/fremap.c
95731 +++ b/mm/fremap.c
95732 @@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95733 retry:
95734 vma = find_vma(mm, start);
95735
95736 +#ifdef CONFIG_PAX_SEGMEXEC
95737 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95738 + goto out;
95739 +#endif
95740 +
95741 /*
95742 * Make sure the vma is shared, that it supports prefaulting,
95743 * and that the remapped range is valid and fully within
95744 diff --git a/mm/gup.c b/mm/gup.c
95745 index a0d57ec..79d469ce 100644
95746 --- a/mm/gup.c
95747 +++ b/mm/gup.c
95748 @@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95749 unsigned int fault_flags = 0;
95750 int ret;
95751
95752 - /* For mlock, just skip the stack guard page. */
95753 - if ((*flags & FOLL_MLOCK) &&
95754 - (stack_guard_page_start(vma, address) ||
95755 - stack_guard_page_end(vma, address + PAGE_SIZE)))
95756 - return -ENOENT;
95757 if (*flags & FOLL_WRITE)
95758 fault_flags |= FAULT_FLAG_WRITE;
95759 if (nonblocking)
95760 @@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95761 if (!(gup_flags & FOLL_FORCE))
95762 gup_flags |= FOLL_NUMA;
95763
95764 - do {
95765 + while (nr_pages) {
95766 struct page *page;
95767 unsigned int foll_flags = gup_flags;
95768 unsigned int page_increm;
95769
95770 /* first iteration or cross vma bound */
95771 if (!vma || start >= vma->vm_end) {
95772 - vma = find_extend_vma(mm, start);
95773 + vma = find_vma(mm, start);
95774 if (!vma && in_gate_area(mm, start)) {
95775 int ret;
95776 ret = get_gate_page(mm, start & PAGE_MASK,
95777 @@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95778 goto next_page;
95779 }
95780
95781 - if (!vma || check_vma_flags(vma, gup_flags))
95782 + if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95783 return i ? : -EFAULT;
95784 if (is_vm_hugetlb_page(vma)) {
95785 i = follow_hugetlb_page(mm, vma, pages, vmas,
95786 @@ -518,7 +513,7 @@ next_page:
95787 i += page_increm;
95788 start += page_increm * PAGE_SIZE;
95789 nr_pages -= page_increm;
95790 - } while (nr_pages);
95791 + }
95792 return i;
95793 }
95794 EXPORT_SYMBOL(__get_user_pages);
95795 diff --git a/mm/highmem.c b/mm/highmem.c
95796 index 123bcd3..0de52ba 100644
95797 --- a/mm/highmem.c
95798 +++ b/mm/highmem.c
95799 @@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95800 * So no dangers, even with speculative execution.
95801 */
95802 page = pte_page(pkmap_page_table[i]);
95803 + pax_open_kernel();
95804 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95805 -
95806 + pax_close_kernel();
95807 set_page_address(page, NULL);
95808 need_flush = 1;
95809 }
95810 @@ -259,9 +260,11 @@ start:
95811 }
95812 }
95813 vaddr = PKMAP_ADDR(last_pkmap_nr);
95814 +
95815 + pax_open_kernel();
95816 set_pte_at(&init_mm, vaddr,
95817 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95818 -
95819 + pax_close_kernel();
95820 pkmap_count[last_pkmap_nr] = 1;
95821 set_page_address(page, (void *)vaddr);
95822
95823 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95824 index f08fec7..8742ef8 100644
95825 --- a/mm/hugetlb.c
95826 +++ b/mm/hugetlb.c
95827 @@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95828 struct ctl_table *table, int write,
95829 void __user *buffer, size_t *length, loff_t *ppos)
95830 {
95831 + ctl_table_no_const t;
95832 struct hstate *h = &default_hstate;
95833 unsigned long tmp = h->max_huge_pages;
95834 int ret;
95835 @@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95836 if (!hugepages_supported())
95837 return -ENOTSUPP;
95838
95839 - table->data = &tmp;
95840 - table->maxlen = sizeof(unsigned long);
95841 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95842 + t = *table;
95843 + t.data = &tmp;
95844 + t.maxlen = sizeof(unsigned long);
95845 + ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95846 if (ret)
95847 goto out;
95848
95849 @@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95850 struct hstate *h = &default_hstate;
95851 unsigned long tmp;
95852 int ret;
95853 + ctl_table_no_const hugetlb_table;
95854
95855 if (!hugepages_supported())
95856 return -ENOTSUPP;
95857 @@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95858 if (write && hstate_is_gigantic(h))
95859 return -EINVAL;
95860
95861 - table->data = &tmp;
95862 - table->maxlen = sizeof(unsigned long);
95863 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95864 + hugetlb_table = *table;
95865 + hugetlb_table.data = &tmp;
95866 + hugetlb_table.maxlen = sizeof(unsigned long);
95867 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95868 if (ret)
95869 goto out;
95870
95871 @@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95872 mutex_unlock(&mapping->i_mmap_mutex);
95873 }
95874
95875 +#ifdef CONFIG_PAX_SEGMEXEC
95876 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95877 +{
95878 + struct mm_struct *mm = vma->vm_mm;
95879 + struct vm_area_struct *vma_m;
95880 + unsigned long address_m;
95881 + pte_t *ptep_m;
95882 +
95883 + vma_m = pax_find_mirror_vma(vma);
95884 + if (!vma_m)
95885 + return;
95886 +
95887 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95888 + address_m = address + SEGMEXEC_TASK_SIZE;
95889 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95890 + get_page(page_m);
95891 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
95892 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95893 +}
95894 +#endif
95895 +
95896 /*
95897 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95898 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95899 @@ -2903,6 +2928,11 @@ retry_avoidcopy:
95900 make_huge_pte(vma, new_page, 1));
95901 page_remove_rmap(old_page);
95902 hugepage_add_new_anon_rmap(new_page, vma, address);
95903 +
95904 +#ifdef CONFIG_PAX_SEGMEXEC
95905 + pax_mirror_huge_pte(vma, address, new_page);
95906 +#endif
95907 +
95908 /* Make the old page be freed below */
95909 new_page = old_page;
95910 }
95911 @@ -3063,6 +3093,10 @@ retry:
95912 && (vma->vm_flags & VM_SHARED)));
95913 set_huge_pte_at(mm, address, ptep, new_pte);
95914
95915 +#ifdef CONFIG_PAX_SEGMEXEC
95916 + pax_mirror_huge_pte(vma, address, page);
95917 +#endif
95918 +
95919 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95920 /* Optimization, do the COW without a second fault */
95921 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95922 @@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95923 struct hstate *h = hstate_vma(vma);
95924 struct address_space *mapping;
95925
95926 +#ifdef CONFIG_PAX_SEGMEXEC
95927 + struct vm_area_struct *vma_m;
95928 +#endif
95929 +
95930 address &= huge_page_mask(h);
95931
95932 ptep = huge_pte_offset(mm, address);
95933 @@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95934 VM_FAULT_SET_HINDEX(hstate_index(h));
95935 }
95936
95937 +#ifdef CONFIG_PAX_SEGMEXEC
95938 + vma_m = pax_find_mirror_vma(vma);
95939 + if (vma_m) {
95940 + unsigned long address_m;
95941 +
95942 + if (vma->vm_start > vma_m->vm_start) {
95943 + address_m = address;
95944 + address -= SEGMEXEC_TASK_SIZE;
95945 + vma = vma_m;
95946 + h = hstate_vma(vma);
95947 + } else
95948 + address_m = address + SEGMEXEC_TASK_SIZE;
95949 +
95950 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95951 + return VM_FAULT_OOM;
95952 + address_m &= HPAGE_MASK;
95953 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95954 + }
95955 +#endif
95956 +
95957 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95958 if (!ptep)
95959 return VM_FAULT_OOM;
95960 diff --git a/mm/internal.h b/mm/internal.h
95961 index a4f90ba..fbdc32b 100644
95962 --- a/mm/internal.h
95963 +++ b/mm/internal.h
95964 @@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95965
95966 extern int __isolate_free_page(struct page *page, unsigned int order);
95967 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95968 +extern void free_compound_page(struct page *page);
95969 extern void prep_compound_page(struct page *page, unsigned long order);
95970 #ifdef CONFIG_MEMORY_FAILURE
95971 extern bool is_free_buddy_page(struct page *page);
95972 @@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95973
95974 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95975 unsigned long, unsigned long,
95976 - unsigned long, unsigned long);
95977 + unsigned long, unsigned long) __intentional_overflow(-1);
95978
95979 extern void set_pageblock_order(void);
95980 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95981 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95982 index e34a3cb..a810efe 100644
95983 --- a/mm/iov_iter.c
95984 +++ b/mm/iov_iter.c
95985 @@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95986
95987 while (bytes) {
95988 char __user *buf = iov->iov_base + base;
95989 - int copy = min(bytes, iov->iov_len - base);
95990 + size_t copy = min(bytes, iov->iov_len - base);
95991
95992 base = 0;
95993 left = __copy_from_user_inatomic(vaddr, buf, copy);
95994 @@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95995
95996 kaddr = kmap_atomic(page);
95997 if (likely(i->nr_segs == 1)) {
95998 - int left;
95999 + size_t left;
96000 char __user *buf = i->iov->iov_base + i->iov_offset;
96001 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
96002 copied = bytes - left;
96003 @@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
96004 * zero-length segments (without overruning the iovec).
96005 */
96006 while (bytes || unlikely(i->count && !iov->iov_len)) {
96007 - int copy;
96008 + size_t copy;
96009
96010 copy = min(bytes, iov->iov_len - base);
96011 BUG_ON(!i->count || i->count < copy);
96012 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
96013 index 3cda50c..032ba634 100644
96014 --- a/mm/kmemleak.c
96015 +++ b/mm/kmemleak.c
96016 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
96017
96018 for (i = 0; i < object->trace_len; i++) {
96019 void *ptr = (void *)object->trace[i];
96020 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
96021 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
96022 }
96023 }
96024
96025 @@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
96026 return -ENOMEM;
96027 }
96028
96029 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
96030 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
96031 &kmemleak_fops);
96032 if (!dentry)
96033 pr_warning("Failed to create the debugfs kmemleak file\n");
96034 diff --git a/mm/maccess.c b/mm/maccess.c
96035 index d53adf9..03a24bf 100644
96036 --- a/mm/maccess.c
96037 +++ b/mm/maccess.c
96038 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96039 set_fs(KERNEL_DS);
96040 pagefault_disable();
96041 ret = __copy_from_user_inatomic(dst,
96042 - (__force const void __user *)src, size);
96043 + (const void __force_user *)src, size);
96044 pagefault_enable();
96045 set_fs(old_fs);
96046
96047 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96048
96049 set_fs(KERNEL_DS);
96050 pagefault_disable();
96051 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96052 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96053 pagefault_enable();
96054 set_fs(old_fs);
96055
96056 diff --git a/mm/madvise.c b/mm/madvise.c
96057 index 0938b30..199abe8 100644
96058 --- a/mm/madvise.c
96059 +++ b/mm/madvise.c
96060 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96061 pgoff_t pgoff;
96062 unsigned long new_flags = vma->vm_flags;
96063
96064 +#ifdef CONFIG_PAX_SEGMEXEC
96065 + struct vm_area_struct *vma_m;
96066 +#endif
96067 +
96068 switch (behavior) {
96069 case MADV_NORMAL:
96070 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96071 @@ -126,6 +130,13 @@ success:
96072 /*
96073 * vm_flags is protected by the mmap_sem held in write mode.
96074 */
96075 +
96076 +#ifdef CONFIG_PAX_SEGMEXEC
96077 + vma_m = pax_find_mirror_vma(vma);
96078 + if (vma_m)
96079 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96080 +#endif
96081 +
96082 vma->vm_flags = new_flags;
96083
96084 out:
96085 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96086 struct vm_area_struct **prev,
96087 unsigned long start, unsigned long end)
96088 {
96089 +
96090 +#ifdef CONFIG_PAX_SEGMEXEC
96091 + struct vm_area_struct *vma_m;
96092 +#endif
96093 +
96094 *prev = vma;
96095 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96096 return -EINVAL;
96097 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96098 zap_page_range(vma, start, end - start, &details);
96099 } else
96100 zap_page_range(vma, start, end - start, NULL);
96101 +
96102 +#ifdef CONFIG_PAX_SEGMEXEC
96103 + vma_m = pax_find_mirror_vma(vma);
96104 + if (vma_m) {
96105 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96106 + struct zap_details details = {
96107 + .nonlinear_vma = vma_m,
96108 + .last_index = ULONG_MAX,
96109 + };
96110 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96111 + } else
96112 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96113 + }
96114 +#endif
96115 +
96116 return 0;
96117 }
96118
96119 @@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96120 if (end < start)
96121 return error;
96122
96123 +#ifdef CONFIG_PAX_SEGMEXEC
96124 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96125 + if (end > SEGMEXEC_TASK_SIZE)
96126 + return error;
96127 + } else
96128 +#endif
96129 +
96130 + if (end > TASK_SIZE)
96131 + return error;
96132 +
96133 error = 0;
96134 if (end == start)
96135 return error;
96136 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96137 index 8639f6b..b623882a 100644
96138 --- a/mm/memory-failure.c
96139 +++ b/mm/memory-failure.c
96140 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96141
96142 int sysctl_memory_failure_recovery __read_mostly = 1;
96143
96144 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96145 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96146
96147 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96148
96149 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96150 pfn, t->comm, t->pid);
96151 si.si_signo = SIGBUS;
96152 si.si_errno = 0;
96153 - si.si_addr = (void *)addr;
96154 + si.si_addr = (void __user *)addr;
96155 #ifdef __ARCH_SI_TRAPNO
96156 si.si_trapno = trapno;
96157 #endif
96158 @@ -791,7 +791,7 @@ static struct page_state {
96159 unsigned long res;
96160 char *msg;
96161 int (*action)(struct page *p, unsigned long pfn);
96162 -} error_states[] = {
96163 +} __do_const error_states[] = {
96164 { reserved, reserved, "reserved kernel", me_kernel },
96165 /*
96166 * free pages are specially detected outside this table:
96167 @@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96168 nr_pages = 1 << compound_order(hpage);
96169 else /* normal page or thp */
96170 nr_pages = 1;
96171 - atomic_long_add(nr_pages, &num_poisoned_pages);
96172 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96173
96174 /*
96175 * We need/can do nothing about count=0 pages.
96176 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96177 if (PageHWPoison(hpage)) {
96178 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96179 || (p != hpage && TestSetPageHWPoison(hpage))) {
96180 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96181 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96182 unlock_page(hpage);
96183 return 0;
96184 }
96185 @@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96186 */
96187 if (!PageHWPoison(p)) {
96188 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96189 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96190 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96191 put_page(hpage);
96192 res = 0;
96193 goto out;
96194 }
96195 if (hwpoison_filter(p)) {
96196 if (TestClearPageHWPoison(p))
96197 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96198 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96199 unlock_page(hpage);
96200 put_page(hpage);
96201 return 0;
96202 @@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96203 return 0;
96204 }
96205 if (TestClearPageHWPoison(p))
96206 - atomic_long_dec(&num_poisoned_pages);
96207 + atomic_long_dec_unchecked(&num_poisoned_pages);
96208 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96209 return 0;
96210 }
96211 @@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96212 */
96213 if (TestClearPageHWPoison(page)) {
96214 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96215 - atomic_long_sub(nr_pages, &num_poisoned_pages);
96216 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96217 freeit = 1;
96218 if (PageHuge(page))
96219 clear_page_hwpoison_huge_page(page);
96220 @@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96221 if (PageHuge(page)) {
96222 set_page_hwpoison_huge_page(hpage);
96223 dequeue_hwpoisoned_huge_page(hpage);
96224 - atomic_long_add(1 << compound_order(hpage),
96225 + atomic_long_add_unchecked(1 << compound_order(hpage),
96226 &num_poisoned_pages);
96227 } else {
96228 SetPageHWPoison(page);
96229 - atomic_long_inc(&num_poisoned_pages);
96230 + atomic_long_inc_unchecked(&num_poisoned_pages);
96231 }
96232 }
96233 return ret;
96234 @@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96235 put_page(page);
96236 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96237 SetPageHWPoison(page);
96238 - atomic_long_inc(&num_poisoned_pages);
96239 + atomic_long_inc_unchecked(&num_poisoned_pages);
96240 return 0;
96241 }
96242
96243 @@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96244 if (!is_free_buddy_page(page))
96245 pr_info("soft offline: %#lx: page leaked\n",
96246 pfn);
96247 - atomic_long_inc(&num_poisoned_pages);
96248 + atomic_long_inc_unchecked(&num_poisoned_pages);
96249 }
96250 } else {
96251 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96252 @@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96253 if (PageHuge(page)) {
96254 set_page_hwpoison_huge_page(hpage);
96255 dequeue_hwpoisoned_huge_page(hpage);
96256 - atomic_long_add(1 << compound_order(hpage),
96257 + atomic_long_add_unchecked(1 << compound_order(hpage),
96258 &num_poisoned_pages);
96259 } else {
96260 SetPageHWPoison(page);
96261 - atomic_long_inc(&num_poisoned_pages);
96262 + atomic_long_inc_unchecked(&num_poisoned_pages);
96263 }
96264 }
96265 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96266 diff --git a/mm/memory.c b/mm/memory.c
96267 index d442584..0600e22 100644
96268 --- a/mm/memory.c
96269 +++ b/mm/memory.c
96270 @@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96271 free_pte_range(tlb, pmd, addr);
96272 } while (pmd++, addr = next, addr != end);
96273
96274 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96275 start &= PUD_MASK;
96276 if (start < floor)
96277 return;
96278 @@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96279 pmd = pmd_offset(pud, start);
96280 pud_clear(pud);
96281 pmd_free_tlb(tlb, pmd, start);
96282 +#endif
96283 +
96284 }
96285
96286 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96287 @@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96288 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96289 } while (pud++, addr = next, addr != end);
96290
96291 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96292 start &= PGDIR_MASK;
96293 if (start < floor)
96294 return;
96295 @@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96296 pud = pud_offset(pgd, start);
96297 pgd_clear(pgd);
96298 pud_free_tlb(tlb, pud, start);
96299 +#endif
96300 +
96301 }
96302
96303 /*
96304 @@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96305 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96306 */
96307 if (vma->vm_ops)
96308 - printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96309 + printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96310 vma->vm_ops->fault);
96311 if (vma->vm_file)
96312 - printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96313 + printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96314 vma->vm_file->f_op->mmap);
96315 dump_stack();
96316 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96317 @@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96318 page_add_file_rmap(page);
96319 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96320
96321 +#ifdef CONFIG_PAX_SEGMEXEC
96322 + pax_mirror_file_pte(vma, addr, page, ptl);
96323 +#endif
96324 +
96325 retval = 0;
96326 pte_unmap_unlock(pte, ptl);
96327 return retval;
96328 @@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96329 if (!page_count(page))
96330 return -EINVAL;
96331 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96332 +
96333 +#ifdef CONFIG_PAX_SEGMEXEC
96334 + struct vm_area_struct *vma_m;
96335 +#endif
96336 +
96337 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96338 BUG_ON(vma->vm_flags & VM_PFNMAP);
96339 vma->vm_flags |= VM_MIXEDMAP;
96340 +
96341 +#ifdef CONFIG_PAX_SEGMEXEC
96342 + vma_m = pax_find_mirror_vma(vma);
96343 + if (vma_m)
96344 + vma_m->vm_flags |= VM_MIXEDMAP;
96345 +#endif
96346 +
96347 }
96348 return insert_page(vma, addr, page, vma->vm_page_prot);
96349 }
96350 @@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96351 unsigned long pfn)
96352 {
96353 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96354 + BUG_ON(vma->vm_mirror);
96355
96356 if (addr < vma->vm_start || addr >= vma->vm_end)
96357 return -EFAULT;
96358 @@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96359
96360 BUG_ON(pud_huge(*pud));
96361
96362 - pmd = pmd_alloc(mm, pud, addr);
96363 + pmd = (mm == &init_mm) ?
96364 + pmd_alloc_kernel(mm, pud, addr) :
96365 + pmd_alloc(mm, pud, addr);
96366 if (!pmd)
96367 return -ENOMEM;
96368 do {
96369 @@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96370 unsigned long next;
96371 int err;
96372
96373 - pud = pud_alloc(mm, pgd, addr);
96374 + pud = (mm == &init_mm) ?
96375 + pud_alloc_kernel(mm, pgd, addr) :
96376 + pud_alloc(mm, pgd, addr);
96377 if (!pud)
96378 return -ENOMEM;
96379 do {
96380 @@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96381 return ret;
96382 }
96383
96384 +#ifdef CONFIG_PAX_SEGMEXEC
96385 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96386 +{
96387 + struct mm_struct *mm = vma->vm_mm;
96388 + spinlock_t *ptl;
96389 + pte_t *pte, entry;
96390 +
96391 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96392 + entry = *pte;
96393 + if (!pte_present(entry)) {
96394 + if (!pte_none(entry)) {
96395 + BUG_ON(pte_file(entry));
96396 + free_swap_and_cache(pte_to_swp_entry(entry));
96397 + pte_clear_not_present_full(mm, address, pte, 0);
96398 + }
96399 + } else {
96400 + struct page *page;
96401 +
96402 + flush_cache_page(vma, address, pte_pfn(entry));
96403 + entry = ptep_clear_flush(vma, address, pte);
96404 + BUG_ON(pte_dirty(entry));
96405 + page = vm_normal_page(vma, address, entry);
96406 + if (page) {
96407 + update_hiwater_rss(mm);
96408 + if (PageAnon(page))
96409 + dec_mm_counter_fast(mm, MM_ANONPAGES);
96410 + else
96411 + dec_mm_counter_fast(mm, MM_FILEPAGES);
96412 + page_remove_rmap(page);
96413 + page_cache_release(page);
96414 + }
96415 + }
96416 + pte_unmap_unlock(pte, ptl);
96417 +}
96418 +
96419 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
96420 + *
96421 + * the ptl of the lower mapped page is held on entry and is not released on exit
96422 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96423 + */
96424 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96425 +{
96426 + struct mm_struct *mm = vma->vm_mm;
96427 + unsigned long address_m;
96428 + spinlock_t *ptl_m;
96429 + struct vm_area_struct *vma_m;
96430 + pmd_t *pmd_m;
96431 + pte_t *pte_m, entry_m;
96432 +
96433 + BUG_ON(!page_m || !PageAnon(page_m));
96434 +
96435 + vma_m = pax_find_mirror_vma(vma);
96436 + if (!vma_m)
96437 + return;
96438 +
96439 + BUG_ON(!PageLocked(page_m));
96440 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96441 + address_m = address + SEGMEXEC_TASK_SIZE;
96442 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96443 + pte_m = pte_offset_map(pmd_m, address_m);
96444 + ptl_m = pte_lockptr(mm, pmd_m);
96445 + if (ptl != ptl_m) {
96446 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96447 + if (!pte_none(*pte_m))
96448 + goto out;
96449 + }
96450 +
96451 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96452 + page_cache_get(page_m);
96453 + page_add_anon_rmap(page_m, vma_m, address_m);
96454 + inc_mm_counter_fast(mm, MM_ANONPAGES);
96455 + set_pte_at(mm, address_m, pte_m, entry_m);
96456 + update_mmu_cache(vma_m, address_m, pte_m);
96457 +out:
96458 + if (ptl != ptl_m)
96459 + spin_unlock(ptl_m);
96460 + pte_unmap(pte_m);
96461 + unlock_page(page_m);
96462 +}
96463 +
96464 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96465 +{
96466 + struct mm_struct *mm = vma->vm_mm;
96467 + unsigned long address_m;
96468 + spinlock_t *ptl_m;
96469 + struct vm_area_struct *vma_m;
96470 + pmd_t *pmd_m;
96471 + pte_t *pte_m, entry_m;
96472 +
96473 + BUG_ON(!page_m || PageAnon(page_m));
96474 +
96475 + vma_m = pax_find_mirror_vma(vma);
96476 + if (!vma_m)
96477 + return;
96478 +
96479 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96480 + address_m = address + SEGMEXEC_TASK_SIZE;
96481 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96482 + pte_m = pte_offset_map(pmd_m, address_m);
96483 + ptl_m = pte_lockptr(mm, pmd_m);
96484 + if (ptl != ptl_m) {
96485 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96486 + if (!pte_none(*pte_m))
96487 + goto out;
96488 + }
96489 +
96490 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96491 + page_cache_get(page_m);
96492 + page_add_file_rmap(page_m);
96493 + inc_mm_counter_fast(mm, MM_FILEPAGES);
96494 + set_pte_at(mm, address_m, pte_m, entry_m);
96495 + update_mmu_cache(vma_m, address_m, pte_m);
96496 +out:
96497 + if (ptl != ptl_m)
96498 + spin_unlock(ptl_m);
96499 + pte_unmap(pte_m);
96500 +}
96501 +
96502 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96503 +{
96504 + struct mm_struct *mm = vma->vm_mm;
96505 + unsigned long address_m;
96506 + spinlock_t *ptl_m;
96507 + struct vm_area_struct *vma_m;
96508 + pmd_t *pmd_m;
96509 + pte_t *pte_m, entry_m;
96510 +
96511 + vma_m = pax_find_mirror_vma(vma);
96512 + if (!vma_m)
96513 + return;
96514 +
96515 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96516 + address_m = address + SEGMEXEC_TASK_SIZE;
96517 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96518 + pte_m = pte_offset_map(pmd_m, address_m);
96519 + ptl_m = pte_lockptr(mm, pmd_m);
96520 + if (ptl != ptl_m) {
96521 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96522 + if (!pte_none(*pte_m))
96523 + goto out;
96524 + }
96525 +
96526 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96527 + set_pte_at(mm, address_m, pte_m, entry_m);
96528 +out:
96529 + if (ptl != ptl_m)
96530 + spin_unlock(ptl_m);
96531 + pte_unmap(pte_m);
96532 +}
96533 +
96534 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96535 +{
96536 + struct page *page_m;
96537 + pte_t entry;
96538 +
96539 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96540 + goto out;
96541 +
96542 + entry = *pte;
96543 + page_m = vm_normal_page(vma, address, entry);
96544 + if (!page_m)
96545 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96546 + else if (PageAnon(page_m)) {
96547 + if (pax_find_mirror_vma(vma)) {
96548 + pte_unmap_unlock(pte, ptl);
96549 + lock_page(page_m);
96550 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96551 + if (pte_same(entry, *pte))
96552 + pax_mirror_anon_pte(vma, address, page_m, ptl);
96553 + else
96554 + unlock_page(page_m);
96555 + }
96556 + } else
96557 + pax_mirror_file_pte(vma, address, page_m, ptl);
96558 +
96559 +out:
96560 + pte_unmap_unlock(pte, ptl);
96561 +}
96562 +#endif
96563 +
96564 /*
96565 * This routine handles present pages, when users try to write
96566 * to a shared page. It is done by copying the page to a new address
96567 @@ -2225,6 +2432,12 @@ gotten:
96568 */
96569 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96570 if (likely(pte_same(*page_table, orig_pte))) {
96571 +
96572 +#ifdef CONFIG_PAX_SEGMEXEC
96573 + if (pax_find_mirror_vma(vma))
96574 + BUG_ON(!trylock_page(new_page));
96575 +#endif
96576 +
96577 if (old_page) {
96578 if (!PageAnon(old_page)) {
96579 dec_mm_counter_fast(mm, MM_FILEPAGES);
96580 @@ -2278,6 +2491,10 @@ gotten:
96581 page_remove_rmap(old_page);
96582 }
96583
96584 +#ifdef CONFIG_PAX_SEGMEXEC
96585 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96586 +#endif
96587 +
96588 /* Free the old page.. */
96589 new_page = old_page;
96590 ret |= VM_FAULT_WRITE;
96591 @@ -2552,6 +2769,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96592 swap_free(entry);
96593 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96594 try_to_free_swap(page);
96595 +
96596 +#ifdef CONFIG_PAX_SEGMEXEC
96597 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96598 +#endif
96599 +
96600 unlock_page(page);
96601 if (page != swapcache) {
96602 /*
96603 @@ -2575,6 +2797,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96604
96605 /* No need to invalidate - it was non-present before */
96606 update_mmu_cache(vma, address, page_table);
96607 +
96608 +#ifdef CONFIG_PAX_SEGMEXEC
96609 + pax_mirror_anon_pte(vma, address, page, ptl);
96610 +#endif
96611 +
96612 unlock:
96613 pte_unmap_unlock(page_table, ptl);
96614 out:
96615 @@ -2594,40 +2821,6 @@ out_release:
96616 }
96617
96618 /*
96619 - * This is like a special single-page "expand_{down|up}wards()",
96620 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
96621 - * doesn't hit another vma.
96622 - */
96623 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96624 -{
96625 - address &= PAGE_MASK;
96626 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96627 - struct vm_area_struct *prev = vma->vm_prev;
96628 -
96629 - /*
96630 - * Is there a mapping abutting this one below?
96631 - *
96632 - * That's only ok if it's the same stack mapping
96633 - * that has gotten split..
96634 - */
96635 - if (prev && prev->vm_end == address)
96636 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96637 -
96638 - return expand_downwards(vma, address - PAGE_SIZE);
96639 - }
96640 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96641 - struct vm_area_struct *next = vma->vm_next;
96642 -
96643 - /* As VM_GROWSDOWN but s/below/above/ */
96644 - if (next && next->vm_start == address + PAGE_SIZE)
96645 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96646 -
96647 - return expand_upwards(vma, address + PAGE_SIZE);
96648 - }
96649 - return 0;
96650 -}
96651 -
96652 -/*
96653 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96654 * but allow concurrent faults), and pte mapped but not yet locked.
96655 * We return with mmap_sem still held, but pte unmapped and unlocked.
96656 @@ -2637,27 +2830,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96657 unsigned int flags)
96658 {
96659 struct mem_cgroup *memcg;
96660 - struct page *page;
96661 + struct page *page = NULL;
96662 spinlock_t *ptl;
96663 pte_t entry;
96664
96665 - pte_unmap(page_table);
96666 -
96667 - /* Check if we need to add a guard page to the stack */
96668 - if (check_stack_guard_page(vma, address) < 0)
96669 - return VM_FAULT_SIGSEGV;
96670 -
96671 - /* Use the zero-page for reads */
96672 if (!(flags & FAULT_FLAG_WRITE)) {
96673 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96674 vma->vm_page_prot));
96675 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96676 + ptl = pte_lockptr(mm, pmd);
96677 + spin_lock(ptl);
96678 if (!pte_none(*page_table))
96679 goto unlock;
96680 goto setpte;
96681 }
96682
96683 /* Allocate our own private page. */
96684 + pte_unmap(page_table);
96685 +
96686 if (unlikely(anon_vma_prepare(vma)))
96687 goto oom;
96688 page = alloc_zeroed_user_highpage_movable(vma, address);
96689 @@ -2681,6 +2870,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96690 if (!pte_none(*page_table))
96691 goto release;
96692
96693 +#ifdef CONFIG_PAX_SEGMEXEC
96694 + if (pax_find_mirror_vma(vma))
96695 + BUG_ON(!trylock_page(page));
96696 +#endif
96697 +
96698 inc_mm_counter_fast(mm, MM_ANONPAGES);
96699 page_add_new_anon_rmap(page, vma, address);
96700 mem_cgroup_commit_charge(page, memcg, false);
96701 @@ -2690,6 +2884,12 @@ setpte:
96702
96703 /* No need to invalidate - it was non-present before */
96704 update_mmu_cache(vma, address, page_table);
96705 +
96706 +#ifdef CONFIG_PAX_SEGMEXEC
96707 + if (page)
96708 + pax_mirror_anon_pte(vma, address, page, ptl);
96709 +#endif
96710 +
96711 unlock:
96712 pte_unmap_unlock(page_table, ptl);
96713 return 0;
96714 @@ -2920,6 +3120,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96715 return ret;
96716 }
96717 do_set_pte(vma, address, fault_page, pte, false, false);
96718 +
96719 +#ifdef CONFIG_PAX_SEGMEXEC
96720 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96721 +#endif
96722 +
96723 unlock_page(fault_page);
96724 unlock_out:
96725 pte_unmap_unlock(pte, ptl);
96726 @@ -2962,7 +3167,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96727 page_cache_release(fault_page);
96728 goto uncharge_out;
96729 }
96730 +
96731 +#ifdef CONFIG_PAX_SEGMEXEC
96732 + if (pax_find_mirror_vma(vma))
96733 + BUG_ON(!trylock_page(new_page));
96734 +#endif
96735 +
96736 do_set_pte(vma, address, new_page, pte, true, true);
96737 +
96738 +#ifdef CONFIG_PAX_SEGMEXEC
96739 + pax_mirror_anon_pte(vma, address, new_page, ptl);
96740 +#endif
96741 +
96742 mem_cgroup_commit_charge(new_page, memcg, false);
96743 lru_cache_add_active_or_unevictable(new_page, vma);
96744 pte_unmap_unlock(pte, ptl);
96745 @@ -3012,6 +3228,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96746 return ret;
96747 }
96748 do_set_pte(vma, address, fault_page, pte, true, false);
96749 +
96750 +#ifdef CONFIG_PAX_SEGMEXEC
96751 + pax_mirror_file_pte(vma, address, fault_page, ptl);
96752 +#endif
96753 +
96754 pte_unmap_unlock(pte, ptl);
96755
96756 if (set_page_dirty(fault_page))
96757 @@ -3253,6 +3474,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96758 if (flags & FAULT_FLAG_WRITE)
96759 flush_tlb_fix_spurious_fault(vma, address);
96760 }
96761 +
96762 +#ifdef CONFIG_PAX_SEGMEXEC
96763 + pax_mirror_pte(vma, address, pte, pmd, ptl);
96764 + return 0;
96765 +#endif
96766 +
96767 unlock:
96768 pte_unmap_unlock(pte, ptl);
96769 return 0;
96770 @@ -3272,9 +3499,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96771 pmd_t *pmd;
96772 pte_t *pte;
96773
96774 +#ifdef CONFIG_PAX_SEGMEXEC
96775 + struct vm_area_struct *vma_m;
96776 +#endif
96777 +
96778 if (unlikely(is_vm_hugetlb_page(vma)))
96779 return hugetlb_fault(mm, vma, address, flags);
96780
96781 +#ifdef CONFIG_PAX_SEGMEXEC
96782 + vma_m = pax_find_mirror_vma(vma);
96783 + if (vma_m) {
96784 + unsigned long address_m;
96785 + pgd_t *pgd_m;
96786 + pud_t *pud_m;
96787 + pmd_t *pmd_m;
96788 +
96789 + if (vma->vm_start > vma_m->vm_start) {
96790 + address_m = address;
96791 + address -= SEGMEXEC_TASK_SIZE;
96792 + vma = vma_m;
96793 + } else
96794 + address_m = address + SEGMEXEC_TASK_SIZE;
96795 +
96796 + pgd_m = pgd_offset(mm, address_m);
96797 + pud_m = pud_alloc(mm, pgd_m, address_m);
96798 + if (!pud_m)
96799 + return VM_FAULT_OOM;
96800 + pmd_m = pmd_alloc(mm, pud_m, address_m);
96801 + if (!pmd_m)
96802 + return VM_FAULT_OOM;
96803 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96804 + return VM_FAULT_OOM;
96805 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96806 + }
96807 +#endif
96808 +
96809 pgd = pgd_offset(mm, address);
96810 pud = pud_alloc(mm, pgd, address);
96811 if (!pud)
96812 @@ -3408,6 +3667,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96813 spin_unlock(&mm->page_table_lock);
96814 return 0;
96815 }
96816 +
96817 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96818 +{
96819 + pud_t *new = pud_alloc_one(mm, address);
96820 + if (!new)
96821 + return -ENOMEM;
96822 +
96823 + smp_wmb(); /* See comment in __pte_alloc */
96824 +
96825 + spin_lock(&mm->page_table_lock);
96826 + if (pgd_present(*pgd)) /* Another has populated it */
96827 + pud_free(mm, new);
96828 + else
96829 + pgd_populate_kernel(mm, pgd, new);
96830 + spin_unlock(&mm->page_table_lock);
96831 + return 0;
96832 +}
96833 #endif /* __PAGETABLE_PUD_FOLDED */
96834
96835 #ifndef __PAGETABLE_PMD_FOLDED
96836 @@ -3438,6 +3714,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96837 spin_unlock(&mm->page_table_lock);
96838 return 0;
96839 }
96840 +
96841 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96842 +{
96843 + pmd_t *new = pmd_alloc_one(mm, address);
96844 + if (!new)
96845 + return -ENOMEM;
96846 +
96847 + smp_wmb(); /* See comment in __pte_alloc */
96848 +
96849 + spin_lock(&mm->page_table_lock);
96850 +#ifndef __ARCH_HAS_4LEVEL_HACK
96851 + if (pud_present(*pud)) /* Another has populated it */
96852 + pmd_free(mm, new);
96853 + else
96854 + pud_populate_kernel(mm, pud, new);
96855 +#else
96856 + if (pgd_present(*pud)) /* Another has populated it */
96857 + pmd_free(mm, new);
96858 + else
96859 + pgd_populate_kernel(mm, pud, new);
96860 +#endif /* __ARCH_HAS_4LEVEL_HACK */
96861 + spin_unlock(&mm->page_table_lock);
96862 + return 0;
96863 +}
96864 #endif /* __PAGETABLE_PMD_FOLDED */
96865
96866 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96867 @@ -3547,8 +3847,8 @@ out:
96868 return ret;
96869 }
96870
96871 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96872 - void *buf, int len, int write)
96873 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96874 + void *buf, size_t len, int write)
96875 {
96876 resource_size_t phys_addr;
96877 unsigned long prot = 0;
96878 @@ -3574,8 +3874,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96879 * Access another process' address space as given in mm. If non-NULL, use the
96880 * given task for page fault accounting.
96881 */
96882 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96883 - unsigned long addr, void *buf, int len, int write)
96884 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96885 + unsigned long addr, void *buf, size_t len, int write)
96886 {
96887 struct vm_area_struct *vma;
96888 void *old_buf = buf;
96889 @@ -3583,7 +3883,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96890 down_read(&mm->mmap_sem);
96891 /* ignore errors, just check how much was successfully transferred */
96892 while (len) {
96893 - int bytes, ret, offset;
96894 + ssize_t bytes, ret, offset;
96895 void *maddr;
96896 struct page *page = NULL;
96897
96898 @@ -3644,8 +3944,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96899 *
96900 * The caller must hold a reference on @mm.
96901 */
96902 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96903 - void *buf, int len, int write)
96904 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96905 + void *buf, size_t len, int write)
96906 {
96907 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96908 }
96909 @@ -3655,11 +3955,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96910 * Source/target buffer must be kernel space,
96911 * Do not walk the page table directly, use get_user_pages
96912 */
96913 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
96914 - void *buf, int len, int write)
96915 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96916 + void *buf, size_t len, int write)
96917 {
96918 struct mm_struct *mm;
96919 - int ret;
96920 + ssize_t ret;
96921
96922 mm = get_task_mm(tsk);
96923 if (!mm)
96924 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96925 index e58725a..e0be017 100644
96926 --- a/mm/mempolicy.c
96927 +++ b/mm/mempolicy.c
96928 @@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96929 unsigned long vmstart;
96930 unsigned long vmend;
96931
96932 +#ifdef CONFIG_PAX_SEGMEXEC
96933 + struct vm_area_struct *vma_m;
96934 +#endif
96935 +
96936 vma = find_vma(mm, start);
96937 if (!vma || vma->vm_start > start)
96938 return -EFAULT;
96939 @@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96940 err = vma_replace_policy(vma, new_pol);
96941 if (err)
96942 goto out;
96943 +
96944 +#ifdef CONFIG_PAX_SEGMEXEC
96945 + vma_m = pax_find_mirror_vma(vma);
96946 + if (vma_m) {
96947 + err = vma_replace_policy(vma_m, new_pol);
96948 + if (err)
96949 + goto out;
96950 + }
96951 +#endif
96952 +
96953 }
96954
96955 out:
96956 @@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96957
96958 if (end < start)
96959 return -EINVAL;
96960 +
96961 +#ifdef CONFIG_PAX_SEGMEXEC
96962 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96963 + if (end > SEGMEXEC_TASK_SIZE)
96964 + return -EINVAL;
96965 + } else
96966 +#endif
96967 +
96968 + if (end > TASK_SIZE)
96969 + return -EINVAL;
96970 +
96971 if (end == start)
96972 return 0;
96973
96974 @@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96975 */
96976 tcred = __task_cred(task);
96977 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96978 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96979 - !capable(CAP_SYS_NICE)) {
96980 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96981 rcu_read_unlock();
96982 err = -EPERM;
96983 goto out_put;
96984 @@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96985 goto out;
96986 }
96987
96988 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96989 + if (mm != current->mm &&
96990 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96991 + mmput(mm);
96992 + err = -EPERM;
96993 + goto out;
96994 + }
96995 +#endif
96996 +
96997 err = do_migrate_pages(mm, old, new,
96998 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96999
97000 diff --git a/mm/migrate.c b/mm/migrate.c
97001 index 0143995..b294728 100644
97002 --- a/mm/migrate.c
97003 +++ b/mm/migrate.c
97004 @@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
97005 */
97006 tcred = __task_cred(task);
97007 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97008 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97009 - !capable(CAP_SYS_NICE)) {
97010 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97011 rcu_read_unlock();
97012 err = -EPERM;
97013 goto out;
97014 diff --git a/mm/mlock.c b/mm/mlock.c
97015 index 73cf098..ab547c7 100644
97016 --- a/mm/mlock.c
97017 +++ b/mm/mlock.c
97018 @@ -14,6 +14,7 @@
97019 #include <linux/pagevec.h>
97020 #include <linux/mempolicy.h>
97021 #include <linux/syscalls.h>
97022 +#include <linux/security.h>
97023 #include <linux/sched.h>
97024 #include <linux/export.h>
97025 #include <linux/rmap.h>
97026 @@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
97027 {
97028 unsigned long nstart, end, tmp;
97029 struct vm_area_struct * vma, * prev;
97030 - int error;
97031 + int error = 0;
97032
97033 VM_BUG_ON(start & ~PAGE_MASK);
97034 VM_BUG_ON(len != PAGE_ALIGN(len));
97035 @@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97036 return -EINVAL;
97037 if (end == start)
97038 return 0;
97039 + if (end > TASK_SIZE)
97040 + return -EINVAL;
97041 +
97042 vma = find_vma(current->mm, start);
97043 if (!vma || vma->vm_start > start)
97044 return -ENOMEM;
97045 @@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97046 for (nstart = start ; ; ) {
97047 vm_flags_t newflags;
97048
97049 +#ifdef CONFIG_PAX_SEGMEXEC
97050 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97051 + break;
97052 +#endif
97053 +
97054 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97055
97056 newflags = vma->vm_flags & ~VM_LOCKED;
97057 @@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97058 locked += current->mm->locked_vm;
97059
97060 /* check against resource limits */
97061 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97062 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97063 error = do_mlock(start, len, 1);
97064
97065 @@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97066 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97067 vm_flags_t newflags;
97068
97069 +#ifdef CONFIG_PAX_SEGMEXEC
97070 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97071 + break;
97072 +#endif
97073 +
97074 newflags = vma->vm_flags & ~VM_LOCKED;
97075 if (flags & MCL_CURRENT)
97076 newflags |= VM_LOCKED;
97077 @@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97078 lock_limit >>= PAGE_SHIFT;
97079
97080 ret = -ENOMEM;
97081 +
97082 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97083 +
97084 down_write(&current->mm->mmap_sem);
97085 -
97086 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97087 capable(CAP_IPC_LOCK))
97088 ret = do_mlockall(flags);
97089 diff --git a/mm/mmap.c b/mm/mmap.c
97090 index 1620adb..6b35ac8 100644
97091 --- a/mm/mmap.c
97092 +++ b/mm/mmap.c
97093 @@ -41,6 +41,7 @@
97094 #include <linux/notifier.h>
97095 #include <linux/memory.h>
97096 #include <linux/printk.h>
97097 +#include <linux/random.h>
97098
97099 #include <asm/uaccess.h>
97100 #include <asm/cacheflush.h>
97101 @@ -57,6 +58,16 @@
97102 #define arch_rebalance_pgtables(addr, len) (addr)
97103 #endif
97104
97105 +static inline void verify_mm_writelocked(struct mm_struct *mm)
97106 +{
97107 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97108 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97109 + up_read(&mm->mmap_sem);
97110 + BUG();
97111 + }
97112 +#endif
97113 +}
97114 +
97115 static void unmap_region(struct mm_struct *mm,
97116 struct vm_area_struct *vma, struct vm_area_struct *prev,
97117 unsigned long start, unsigned long end);
97118 @@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97119 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97120 *
97121 */
97122 -pgprot_t protection_map[16] = {
97123 +pgprot_t protection_map[16] __read_only = {
97124 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97125 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97126 };
97127
97128 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
97129 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97130 {
97131 - return __pgprot(pgprot_val(protection_map[vm_flags &
97132 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97133 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97134 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97135 +
97136 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97137 + if (!(__supported_pte_mask & _PAGE_NX) &&
97138 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97139 + (vm_flags & (VM_READ | VM_WRITE)))
97140 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97141 +#endif
97142 +
97143 + return prot;
97144 }
97145 EXPORT_SYMBOL(vm_get_page_prot);
97146
97147 @@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97148 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97149 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97150 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97151 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97152 /*
97153 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97154 * other variables. It can be updated by several CPUs frequently.
97155 @@ -152,7 +173,7 @@ EXPORT_SYMBOL_GPL(vm_memory_committed);
97156 */
97157 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
97158 {
97159 - unsigned long free, allowed, reserve;
97160 + long free, allowed, reserve;
97161
97162 VM_WARN_ONCE(percpu_counter_read(&vm_committed_as) <
97163 -(s64)vm_committed_as_batch * num_online_cpus(),
97164 @@ -220,7 +241,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
97165 */
97166 if (mm) {
97167 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
97168 - allowed -= min(mm->total_vm / 32, reserve);
97169 + allowed -= min_t(long, mm->total_vm / 32, reserve);
97170 }
97171
97172 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
97173 @@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97174 struct vm_area_struct *next = vma->vm_next;
97175
97176 might_sleep();
97177 + BUG_ON(vma->vm_mirror);
97178 if (vma->vm_ops && vma->vm_ops->close)
97179 vma->vm_ops->close(vma);
97180 if (vma->vm_file)
97181 @@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
97182
97183 SYSCALL_DEFINE1(brk, unsigned long, brk)
97184 {
97185 + unsigned long rlim;
97186 unsigned long retval;
97187 unsigned long newbrk, oldbrk;
97188 struct mm_struct *mm = current->mm;
97189 @@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97190 * segment grow beyond its set limit the in case where the limit is
97191 * not page aligned -Ram Gupta
97192 */
97193 - if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
97194 + rlim = rlimit(RLIMIT_DATA);
97195 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97196 + /* force a minimum 16MB brk heap on setuid/setgid binaries */
97197 + if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97198 + rlim = 4096 * PAGE_SIZE;
97199 +#endif
97200 + if (check_data_rlimit(rlim, brk, mm->start_brk,
97201 mm->end_data, mm->start_data))
97202 goto out;
97203
97204 @@ -976,6 +1005,12 @@ static int
97205 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97206 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97207 {
97208 +
97209 +#ifdef CONFIG_PAX_SEGMEXEC
97210 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97211 + return 0;
97212 +#endif
97213 +
97214 if (is_mergeable_vma(vma, file, vm_flags) &&
97215 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97216 if (vma->vm_pgoff == vm_pgoff)
97217 @@ -995,6 +1030,12 @@ static int
97218 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97219 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97220 {
97221 +
97222 +#ifdef CONFIG_PAX_SEGMEXEC
97223 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97224 + return 0;
97225 +#endif
97226 +
97227 if (is_mergeable_vma(vma, file, vm_flags) &&
97228 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97229 pgoff_t vm_pglen;
97230 @@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97231 struct vm_area_struct *area, *next;
97232 int err;
97233
97234 +#ifdef CONFIG_PAX_SEGMEXEC
97235 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97236 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97237 +
97238 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97239 +#endif
97240 +
97241 /*
97242 * We later require that vma->vm_flags == vm_flags,
97243 * so this tests vma->vm_flags & VM_SPECIAL, too.
97244 @@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97245 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97246 next = next->vm_next;
97247
97248 +#ifdef CONFIG_PAX_SEGMEXEC
97249 + if (prev)
97250 + prev_m = pax_find_mirror_vma(prev);
97251 + if (area)
97252 + area_m = pax_find_mirror_vma(area);
97253 + if (next)
97254 + next_m = pax_find_mirror_vma(next);
97255 +#endif
97256 +
97257 /*
97258 * Can it merge with the predecessor?
97259 */
97260 @@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97261 /* cases 1, 6 */
97262 err = vma_adjust(prev, prev->vm_start,
97263 next->vm_end, prev->vm_pgoff, NULL);
97264 - } else /* cases 2, 5, 7 */
97265 +
97266 +#ifdef CONFIG_PAX_SEGMEXEC
97267 + if (!err && prev_m)
97268 + err = vma_adjust(prev_m, prev_m->vm_start,
97269 + next_m->vm_end, prev_m->vm_pgoff, NULL);
97270 +#endif
97271 +
97272 + } else { /* cases 2, 5, 7 */
97273 err = vma_adjust(prev, prev->vm_start,
97274 end, prev->vm_pgoff, NULL);
97275 +
97276 +#ifdef CONFIG_PAX_SEGMEXEC
97277 + if (!err && prev_m)
97278 + err = vma_adjust(prev_m, prev_m->vm_start,
97279 + end_m, prev_m->vm_pgoff, NULL);
97280 +#endif
97281 +
97282 + }
97283 if (err)
97284 return NULL;
97285 khugepaged_enter_vma_merge(prev, vm_flags);
97286 @@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97287 mpol_equal(policy, vma_policy(next)) &&
97288 can_vma_merge_before(next, vm_flags,
97289 anon_vma, file, pgoff+pglen)) {
97290 - if (prev && addr < prev->vm_end) /* case 4 */
97291 + if (prev && addr < prev->vm_end) { /* case 4 */
97292 err = vma_adjust(prev, prev->vm_start,
97293 addr, prev->vm_pgoff, NULL);
97294 - else /* cases 3, 8 */
97295 +
97296 +#ifdef CONFIG_PAX_SEGMEXEC
97297 + if (!err && prev_m)
97298 + err = vma_adjust(prev_m, prev_m->vm_start,
97299 + addr_m, prev_m->vm_pgoff, NULL);
97300 +#endif
97301 +
97302 + } else { /* cases 3, 8 */
97303 err = vma_adjust(area, addr, next->vm_end,
97304 next->vm_pgoff - pglen, NULL);
97305 +
97306 +#ifdef CONFIG_PAX_SEGMEXEC
97307 + if (!err && area_m)
97308 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
97309 + next_m->vm_pgoff - pglen, NULL);
97310 +#endif
97311 +
97312 + }
97313 if (err)
97314 return NULL;
97315 khugepaged_enter_vma_merge(area, vm_flags);
97316 @@ -1208,8 +1295,10 @@ none:
97317 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97318 struct file *file, long pages)
97319 {
97320 - const unsigned long stack_flags
97321 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97322 +
97323 +#ifdef CONFIG_PAX_RANDMMAP
97324 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97325 +#endif
97326
97327 mm->total_vm += pages;
97328
97329 @@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97330 mm->shared_vm += pages;
97331 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97332 mm->exec_vm += pages;
97333 - } else if (flags & stack_flags)
97334 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97335 mm->stack_vm += pages;
97336 }
97337 #endif /* CONFIG_PROC_FS */
97338 @@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97339 locked += mm->locked_vm;
97340 lock_limit = rlimit(RLIMIT_MEMLOCK);
97341 lock_limit >>= PAGE_SHIFT;
97342 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97343 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97344 return -EAGAIN;
97345 }
97346 @@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97347 * (the exception is when the underlying filesystem is noexec
97348 * mounted, in which case we dont add PROT_EXEC.)
97349 */
97350 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97351 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97352 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97353 prot |= PROT_EXEC;
97354
97355 @@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97356 /* Obtain the address to map to. we verify (or select) it and ensure
97357 * that it represents a valid section of the address space.
97358 */
97359 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
97360 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97361 if (addr & ~PAGE_MASK)
97362 return addr;
97363
97364 @@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97365 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97366 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97367
97368 +#ifdef CONFIG_PAX_MPROTECT
97369 + if (mm->pax_flags & MF_PAX_MPROTECT) {
97370 +
97371 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97372 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97373 + mm->binfmt->handle_mmap)
97374 + mm->binfmt->handle_mmap(file);
97375 +#endif
97376 +
97377 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
97378 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97379 + gr_log_rwxmmap(file);
97380 +
97381 +#ifdef CONFIG_PAX_EMUPLT
97382 + vm_flags &= ~VM_EXEC;
97383 +#else
97384 + return -EPERM;
97385 +#endif
97386 +
97387 + }
97388 +
97389 + if (!(vm_flags & VM_EXEC))
97390 + vm_flags &= ~VM_MAYEXEC;
97391 +#else
97392 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97393 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97394 +#endif
97395 + else
97396 + vm_flags &= ~VM_MAYWRITE;
97397 + }
97398 +#endif
97399 +
97400 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97401 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97402 + vm_flags &= ~VM_PAGEEXEC;
97403 +#endif
97404 +
97405 if (flags & MAP_LOCKED)
97406 if (!can_do_mlock())
97407 return -EPERM;
97408 @@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97409 vm_flags |= VM_NORESERVE;
97410 }
97411
97412 + if (!gr_acl_handle_mmap(file, prot))
97413 + return -EACCES;
97414 +
97415 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97416 if (!IS_ERR_VALUE(addr) &&
97417 ((vm_flags & VM_LOCKED) ||
97418 @@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97419 vm_flags_t vm_flags = vma->vm_flags;
97420
97421 /* If it was private or non-writable, the write bit is already clear */
97422 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97423 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97424 return 0;
97425
97426 /* The backer wishes to know when pages are first written to? */
97427 @@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97428 struct rb_node **rb_link, *rb_parent;
97429 unsigned long charged = 0;
97430
97431 +#ifdef CONFIG_PAX_SEGMEXEC
97432 + struct vm_area_struct *vma_m = NULL;
97433 +#endif
97434 +
97435 + /*
97436 + * mm->mmap_sem is required to protect against another thread
97437 + * changing the mappings in case we sleep.
97438 + */
97439 + verify_mm_writelocked(mm);
97440 +
97441 /* Check against address space limit. */
97442 +
97443 +#ifdef CONFIG_PAX_RANDMMAP
97444 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97445 +#endif
97446 +
97447 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97448 unsigned long nr_pages;
97449
97450 @@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97451
97452 /* Clear old maps */
97453 error = -ENOMEM;
97454 -munmap_back:
97455 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97456 if (do_munmap(mm, addr, len))
97457 return -ENOMEM;
97458 - goto munmap_back;
97459 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97460 }
97461
97462 /*
97463 @@ -1595,6 +1739,16 @@ munmap_back:
97464 goto unacct_error;
97465 }
97466
97467 +#ifdef CONFIG_PAX_SEGMEXEC
97468 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97469 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97470 + if (!vma_m) {
97471 + error = -ENOMEM;
97472 + goto free_vma;
97473 + }
97474 + }
97475 +#endif
97476 +
97477 vma->vm_mm = mm;
97478 vma->vm_start = addr;
97479 vma->vm_end = addr + len;
97480 @@ -1625,6 +1779,13 @@ munmap_back:
97481 if (error)
97482 goto unmap_and_free_vma;
97483
97484 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97485 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97486 + vma->vm_flags |= VM_PAGEEXEC;
97487 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97488 + }
97489 +#endif
97490 +
97491 /* Can addr have changed??
97492 *
97493 * Answer: Yes, several device drivers can do it in their
97494 @@ -1643,6 +1804,12 @@ munmap_back:
97495 }
97496
97497 vma_link(mm, vma, prev, rb_link, rb_parent);
97498 +
97499 +#ifdef CONFIG_PAX_SEGMEXEC
97500 + if (vma_m)
97501 + BUG_ON(pax_mirror_vma(vma_m, vma));
97502 +#endif
97503 +
97504 /* Once vma denies write, undo our temporary denial count */
97505 if (file) {
97506 if (vm_flags & VM_SHARED)
97507 @@ -1655,6 +1822,7 @@ out:
97508 perf_event_mmap(vma);
97509
97510 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97511 + track_exec_limit(mm, addr, addr + len, vm_flags);
97512 if (vm_flags & VM_LOCKED) {
97513 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97514 vma == get_gate_vma(current->mm)))
97515 @@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97516 if (vm_flags & VM_DENYWRITE)
97517 allow_write_access(file);
97518 free_vma:
97519 +
97520 +#ifdef CONFIG_PAX_SEGMEXEC
97521 + if (vma_m)
97522 + kmem_cache_free(vm_area_cachep, vma_m);
97523 +#endif
97524 +
97525 kmem_cache_free(vm_area_cachep, vma);
97526 unacct_error:
97527 if (charged)
97528 @@ -1699,7 +1873,63 @@ unacct_error:
97529 return error;
97530 }
97531
97532 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97533 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97534 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97535 +{
97536 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97537 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97538 +
97539 + return 0;
97540 +}
97541 +#endif
97542 +
97543 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97544 +{
97545 + if (!vma) {
97546 +#ifdef CONFIG_STACK_GROWSUP
97547 + if (addr > sysctl_heap_stack_gap)
97548 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97549 + else
97550 + vma = find_vma(current->mm, 0);
97551 + if (vma && (vma->vm_flags & VM_GROWSUP))
97552 + return false;
97553 +#endif
97554 + return true;
97555 + }
97556 +
97557 + if (addr + len > vma->vm_start)
97558 + return false;
97559 +
97560 + if (vma->vm_flags & VM_GROWSDOWN)
97561 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97562 +#ifdef CONFIG_STACK_GROWSUP
97563 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97564 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97565 +#endif
97566 + else if (offset)
97567 + return offset <= vma->vm_start - addr - len;
97568 +
97569 + return true;
97570 +}
97571 +
97572 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97573 +{
97574 + if (vma->vm_start < len)
97575 + return -ENOMEM;
97576 +
97577 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
97578 + if (offset <= vma->vm_start - len)
97579 + return vma->vm_start - len - offset;
97580 + else
97581 + return -ENOMEM;
97582 + }
97583 +
97584 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
97585 + return vma->vm_start - len - sysctl_heap_stack_gap;
97586 + return -ENOMEM;
97587 +}
97588 +
97589 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97590 {
97591 /*
97592 * We implement the search by looking for an rbtree node that
97593 @@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97594 }
97595 }
97596
97597 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97598 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97599 check_current:
97600 /* Check if current node has a suitable gap */
97601 if (gap_start > high_limit)
97602 return -ENOMEM;
97603 +
97604 + if (gap_end - gap_start > info->threadstack_offset)
97605 + gap_start += info->threadstack_offset;
97606 + else
97607 + gap_start = gap_end;
97608 +
97609 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97610 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97611 + gap_start += sysctl_heap_stack_gap;
97612 + else
97613 + gap_start = gap_end;
97614 + }
97615 + if (vma->vm_flags & VM_GROWSDOWN) {
97616 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97617 + gap_end -= sysctl_heap_stack_gap;
97618 + else
97619 + gap_end = gap_start;
97620 + }
97621 if (gap_end >= low_limit && gap_end - gap_start >= length)
97622 goto found;
97623
97624 @@ -1801,7 +2049,7 @@ found:
97625 return gap_start;
97626 }
97627
97628 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97629 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97630 {
97631 struct mm_struct *mm = current->mm;
97632 struct vm_area_struct *vma;
97633 @@ -1855,6 +2103,24 @@ check_current:
97634 gap_end = vma->vm_start;
97635 if (gap_end < low_limit)
97636 return -ENOMEM;
97637 +
97638 + if (gap_end - gap_start > info->threadstack_offset)
97639 + gap_end -= info->threadstack_offset;
97640 + else
97641 + gap_end = gap_start;
97642 +
97643 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97644 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97645 + gap_start += sysctl_heap_stack_gap;
97646 + else
97647 + gap_start = gap_end;
97648 + }
97649 + if (vma->vm_flags & VM_GROWSDOWN) {
97650 + if (gap_end - gap_start > sysctl_heap_stack_gap)
97651 + gap_end -= sysctl_heap_stack_gap;
97652 + else
97653 + gap_end = gap_start;
97654 + }
97655 if (gap_start <= high_limit && gap_end - gap_start >= length)
97656 goto found;
97657
97658 @@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97659 struct mm_struct *mm = current->mm;
97660 struct vm_area_struct *vma;
97661 struct vm_unmapped_area_info info;
97662 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97663
97664 if (len > TASK_SIZE - mmap_min_addr)
97665 return -ENOMEM;
97666 @@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97667 if (flags & MAP_FIXED)
97668 return addr;
97669
97670 +#ifdef CONFIG_PAX_RANDMMAP
97671 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97672 +#endif
97673 +
97674 if (addr) {
97675 addr = PAGE_ALIGN(addr);
97676 vma = find_vma(mm, addr);
97677 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97678 - (!vma || addr + len <= vma->vm_start))
97679 + check_heap_stack_gap(vma, addr, len, offset))
97680 return addr;
97681 }
97682
97683 @@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97684 info.low_limit = mm->mmap_base;
97685 info.high_limit = TASK_SIZE;
97686 info.align_mask = 0;
97687 + info.threadstack_offset = offset;
97688 return vm_unmapped_area(&info);
97689 }
97690 #endif
97691 @@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97692 struct mm_struct *mm = current->mm;
97693 unsigned long addr = addr0;
97694 struct vm_unmapped_area_info info;
97695 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97696
97697 /* requested length too big for entire address space */
97698 if (len > TASK_SIZE - mmap_min_addr)
97699 @@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97700 if (flags & MAP_FIXED)
97701 return addr;
97702
97703 +#ifdef CONFIG_PAX_RANDMMAP
97704 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97705 +#endif
97706 +
97707 /* requesting a specific address */
97708 if (addr) {
97709 addr = PAGE_ALIGN(addr);
97710 vma = find_vma(mm, addr);
97711 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97712 - (!vma || addr + len <= vma->vm_start))
97713 + check_heap_stack_gap(vma, addr, len, offset))
97714 return addr;
97715 }
97716
97717 @@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97718 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97719 info.high_limit = mm->mmap_base;
97720 info.align_mask = 0;
97721 + info.threadstack_offset = offset;
97722 addr = vm_unmapped_area(&info);
97723
97724 /*
97725 @@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97726 VM_BUG_ON(addr != -ENOMEM);
97727 info.flags = 0;
97728 info.low_limit = TASK_UNMAPPED_BASE;
97729 +
97730 +#ifdef CONFIG_PAX_RANDMMAP
97731 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97732 + info.low_limit += mm->delta_mmap;
97733 +#endif
97734 +
97735 info.high_limit = TASK_SIZE;
97736 addr = vm_unmapped_area(&info);
97737 }
97738 @@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97739 return vma;
97740 }
97741
97742 +#ifdef CONFIG_PAX_SEGMEXEC
97743 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97744 +{
97745 + struct vm_area_struct *vma_m;
97746 +
97747 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97748 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97749 + BUG_ON(vma->vm_mirror);
97750 + return NULL;
97751 + }
97752 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97753 + vma_m = vma->vm_mirror;
97754 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97755 + BUG_ON(vma->vm_file != vma_m->vm_file);
97756 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97757 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97758 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97759 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97760 + return vma_m;
97761 +}
97762 +#endif
97763 +
97764 /*
97765 * Verify that the stack growth is acceptable and
97766 * update accounting. This is shared with both the
97767 @@ -2107,8 +2413,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97768
97769 /* Stack limit test */
97770 actual_size = size;
97771 - if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
97772 - actual_size -= PAGE_SIZE;
97773 + gr_learn_resource(current, RLIMIT_STACK, actual_size, 1);
97774 if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97775 return -ENOMEM;
97776
97777 @@ -2119,6 +2424,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97778 locked = mm->locked_vm + grow;
97779 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97780 limit >>= PAGE_SHIFT;
97781 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97782 if (locked > limit && !capable(CAP_IPC_LOCK))
97783 return -ENOMEM;
97784 }
97785 @@ -2148,37 +2454,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97786 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97787 * vma is the last one with address > vma->vm_end. Have to extend vma.
97788 */
97789 +#ifndef CONFIG_IA64
97790 +static
97791 +#endif
97792 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97793 {
97794 int error;
97795 + bool locknext;
97796
97797 if (!(vma->vm_flags & VM_GROWSUP))
97798 return -EFAULT;
97799
97800 + /* Also guard against wrapping around to address 0. */
97801 + if (address < PAGE_ALIGN(address+1))
97802 + address = PAGE_ALIGN(address+1);
97803 + else
97804 + return -ENOMEM;
97805 +
97806 /*
97807 * We must make sure the anon_vma is allocated
97808 * so that the anon_vma locking is not a noop.
97809 */
97810 if (unlikely(anon_vma_prepare(vma)))
97811 return -ENOMEM;
97812 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97813 + if (locknext && anon_vma_prepare(vma->vm_next))
97814 + return -ENOMEM;
97815 vma_lock_anon_vma(vma);
97816 + if (locknext)
97817 + vma_lock_anon_vma(vma->vm_next);
97818
97819 /*
97820 * vma->vm_start/vm_end cannot change under us because the caller
97821 * is required to hold the mmap_sem in read mode. We need the
97822 - * anon_vma lock to serialize against concurrent expand_stacks.
97823 - * Also guard against wrapping around to address 0.
97824 + * anon_vma locks to serialize against concurrent expand_stacks
97825 + * and expand_upwards.
97826 */
97827 - if (address < PAGE_ALIGN(address+4))
97828 - address = PAGE_ALIGN(address+4);
97829 - else {
97830 - vma_unlock_anon_vma(vma);
97831 - return -ENOMEM;
97832 - }
97833 error = 0;
97834
97835 /* Somebody else might have raced and expanded it already */
97836 - if (address > vma->vm_end) {
97837 + 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)
97838 + error = -ENOMEM;
97839 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97840 unsigned long size, grow;
97841
97842 size = address - vma->vm_start;
97843 @@ -2213,6 +2530,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97844 }
97845 }
97846 }
97847 + if (locknext)
97848 + vma_unlock_anon_vma(vma->vm_next);
97849 vma_unlock_anon_vma(vma);
97850 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97851 validate_mm(vma->vm_mm);
97852 @@ -2227,6 +2546,8 @@ int expand_downwards(struct vm_area_struct *vma,
97853 unsigned long address)
97854 {
97855 int error;
97856 + bool lockprev = false;
97857 + struct vm_area_struct *prev;
97858
97859 /*
97860 * We must make sure the anon_vma is allocated
97861 @@ -2240,6 +2561,15 @@ int expand_downwards(struct vm_area_struct *vma,
97862 if (error)
97863 return error;
97864
97865 + prev = vma->vm_prev;
97866 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97867 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97868 +#endif
97869 + if (lockprev && anon_vma_prepare(prev))
97870 + return -ENOMEM;
97871 + if (lockprev)
97872 + vma_lock_anon_vma(prev);
97873 +
97874 vma_lock_anon_vma(vma);
97875
97876 /*
97877 @@ -2249,9 +2579,17 @@ int expand_downwards(struct vm_area_struct *vma,
97878 */
97879
97880 /* Somebody else might have raced and expanded it already */
97881 - if (address < vma->vm_start) {
97882 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97883 + error = -ENOMEM;
97884 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97885 unsigned long size, grow;
97886
97887 +#ifdef CONFIG_PAX_SEGMEXEC
97888 + struct vm_area_struct *vma_m;
97889 +
97890 + vma_m = pax_find_mirror_vma(vma);
97891 +#endif
97892 +
97893 size = vma->vm_end - address;
97894 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97895
97896 @@ -2276,13 +2614,27 @@ int expand_downwards(struct vm_area_struct *vma,
97897 vma->vm_pgoff -= grow;
97898 anon_vma_interval_tree_post_update_vma(vma);
97899 vma_gap_update(vma);
97900 +
97901 +#ifdef CONFIG_PAX_SEGMEXEC
97902 + if (vma_m) {
97903 + anon_vma_interval_tree_pre_update_vma(vma_m);
97904 + vma_m->vm_start -= grow << PAGE_SHIFT;
97905 + vma_m->vm_pgoff -= grow;
97906 + anon_vma_interval_tree_post_update_vma(vma_m);
97907 + vma_gap_update(vma_m);
97908 + }
97909 +#endif
97910 +
97911 spin_unlock(&vma->vm_mm->page_table_lock);
97912
97913 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97914 perf_event_mmap(vma);
97915 }
97916 }
97917 }
97918 vma_unlock_anon_vma(vma);
97919 + if (lockprev)
97920 + vma_unlock_anon_vma(prev);
97921 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97922 validate_mm(vma->vm_mm);
97923 return error;
97924 @@ -2380,6 +2732,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97925 do {
97926 long nrpages = vma_pages(vma);
97927
97928 +#ifdef CONFIG_PAX_SEGMEXEC
97929 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97930 + vma = remove_vma(vma);
97931 + continue;
97932 + }
97933 +#endif
97934 +
97935 if (vma->vm_flags & VM_ACCOUNT)
97936 nr_accounted += nrpages;
97937 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97938 @@ -2424,6 +2783,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97939 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97940 vma->vm_prev = NULL;
97941 do {
97942 +
97943 +#ifdef CONFIG_PAX_SEGMEXEC
97944 + if (vma->vm_mirror) {
97945 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97946 + vma->vm_mirror->vm_mirror = NULL;
97947 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
97948 + vma->vm_mirror = NULL;
97949 + }
97950 +#endif
97951 +
97952 vma_rb_erase(vma, &mm->mm_rb);
97953 mm->map_count--;
97954 tail_vma = vma;
97955 @@ -2451,14 +2820,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97956 struct vm_area_struct *new;
97957 int err = -ENOMEM;
97958
97959 +#ifdef CONFIG_PAX_SEGMEXEC
97960 + struct vm_area_struct *vma_m, *new_m = NULL;
97961 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97962 +#endif
97963 +
97964 if (is_vm_hugetlb_page(vma) && (addr &
97965 ~(huge_page_mask(hstate_vma(vma)))))
97966 return -EINVAL;
97967
97968 +#ifdef CONFIG_PAX_SEGMEXEC
97969 + vma_m = pax_find_mirror_vma(vma);
97970 +#endif
97971 +
97972 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97973 if (!new)
97974 goto out_err;
97975
97976 +#ifdef CONFIG_PAX_SEGMEXEC
97977 + if (vma_m) {
97978 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97979 + if (!new_m) {
97980 + kmem_cache_free(vm_area_cachep, new);
97981 + goto out_err;
97982 + }
97983 + }
97984 +#endif
97985 +
97986 /* most fields are the same, copy all, and then fixup */
97987 *new = *vma;
97988
97989 @@ -2471,6 +2859,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97990 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97991 }
97992
97993 +#ifdef CONFIG_PAX_SEGMEXEC
97994 + if (vma_m) {
97995 + *new_m = *vma_m;
97996 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
97997 + new_m->vm_mirror = new;
97998 + new->vm_mirror = new_m;
97999 +
98000 + if (new_below)
98001 + new_m->vm_end = addr_m;
98002 + else {
98003 + new_m->vm_start = addr_m;
98004 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
98005 + }
98006 + }
98007 +#endif
98008 +
98009 err = vma_dup_policy(vma, new);
98010 if (err)
98011 goto out_free_vma;
98012 @@ -2491,6 +2895,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98013 else
98014 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
98015
98016 +#ifdef CONFIG_PAX_SEGMEXEC
98017 + if (!err && vma_m) {
98018 + struct mempolicy *pol = vma_policy(new);
98019 +
98020 + if (anon_vma_clone(new_m, vma_m))
98021 + goto out_free_mpol;
98022 +
98023 + mpol_get(pol);
98024 + set_vma_policy(new_m, pol);
98025 +
98026 + if (new_m->vm_file)
98027 + get_file(new_m->vm_file);
98028 +
98029 + if (new_m->vm_ops && new_m->vm_ops->open)
98030 + new_m->vm_ops->open(new_m);
98031 +
98032 + if (new_below)
98033 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
98034 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98035 + else
98036 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98037 +
98038 + if (err) {
98039 + if (new_m->vm_ops && new_m->vm_ops->close)
98040 + new_m->vm_ops->close(new_m);
98041 + if (new_m->vm_file)
98042 + fput(new_m->vm_file);
98043 + mpol_put(pol);
98044 + }
98045 + }
98046 +#endif
98047 +
98048 /* Success. */
98049 if (!err)
98050 return 0;
98051 @@ -2500,10 +2936,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98052 new->vm_ops->close(new);
98053 if (new->vm_file)
98054 fput(new->vm_file);
98055 - unlink_anon_vmas(new);
98056 out_free_mpol:
98057 mpol_put(vma_policy(new));
98058 out_free_vma:
98059 +
98060 +#ifdef CONFIG_PAX_SEGMEXEC
98061 + if (new_m) {
98062 + unlink_anon_vmas(new_m);
98063 + kmem_cache_free(vm_area_cachep, new_m);
98064 + }
98065 +#endif
98066 +
98067 + unlink_anon_vmas(new);
98068 kmem_cache_free(vm_area_cachep, new);
98069 out_err:
98070 return err;
98071 @@ -2516,6 +2960,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98072 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98073 unsigned long addr, int new_below)
98074 {
98075 +
98076 +#ifdef CONFIG_PAX_SEGMEXEC
98077 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98078 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98079 + if (mm->map_count >= sysctl_max_map_count-1)
98080 + return -ENOMEM;
98081 + } else
98082 +#endif
98083 +
98084 if (mm->map_count >= sysctl_max_map_count)
98085 return -ENOMEM;
98086
98087 @@ -2527,11 +2980,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98088 * work. This now handles partial unmappings.
98089 * Jeremy Fitzhardinge <jeremy@goop.org>
98090 */
98091 +#ifdef CONFIG_PAX_SEGMEXEC
98092 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98093 {
98094 + int ret = __do_munmap(mm, start, len);
98095 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98096 + return ret;
98097 +
98098 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98099 +}
98100 +
98101 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98102 +#else
98103 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98104 +#endif
98105 +{
98106 unsigned long end;
98107 struct vm_area_struct *vma, *prev, *last;
98108
98109 + /*
98110 + * mm->mmap_sem is required to protect against another thread
98111 + * changing the mappings in case we sleep.
98112 + */
98113 + verify_mm_writelocked(mm);
98114 +
98115 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98116 return -EINVAL;
98117
98118 @@ -2607,6 +3079,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98119 /* Fix up all other VM information */
98120 remove_vma_list(mm, vma);
98121
98122 + track_exec_limit(mm, start, end, 0UL);
98123 +
98124 return 0;
98125 }
98126
98127 @@ -2615,6 +3089,13 @@ int vm_munmap(unsigned long start, size_t len)
98128 int ret;
98129 struct mm_struct *mm = current->mm;
98130
98131 +
98132 +#ifdef CONFIG_PAX_SEGMEXEC
98133 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98134 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98135 + return -EINVAL;
98136 +#endif
98137 +
98138 down_write(&mm->mmap_sem);
98139 ret = do_munmap(mm, start, len);
98140 up_write(&mm->mmap_sem);
98141 @@ -2628,16 +3109,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98142 return vm_munmap(addr, len);
98143 }
98144
98145 -static inline void verify_mm_writelocked(struct mm_struct *mm)
98146 -{
98147 -#ifdef CONFIG_DEBUG_VM
98148 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98149 - WARN_ON(1);
98150 - up_read(&mm->mmap_sem);
98151 - }
98152 -#endif
98153 -}
98154 -
98155 /*
98156 * this is really a simplified "do_mmap". it only handles
98157 * anonymous maps. eventually we may be able to do some
98158 @@ -2651,6 +3122,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98159 struct rb_node **rb_link, *rb_parent;
98160 pgoff_t pgoff = addr >> PAGE_SHIFT;
98161 int error;
98162 + unsigned long charged;
98163
98164 len = PAGE_ALIGN(len);
98165 if (!len)
98166 @@ -2658,10 +3130,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98167
98168 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98169
98170 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98171 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98172 + flags &= ~VM_EXEC;
98173 +
98174 +#ifdef CONFIG_PAX_MPROTECT
98175 + if (mm->pax_flags & MF_PAX_MPROTECT)
98176 + flags &= ~VM_MAYEXEC;
98177 +#endif
98178 +
98179 + }
98180 +#endif
98181 +
98182 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98183 if (error & ~PAGE_MASK)
98184 return error;
98185
98186 + charged = len >> PAGE_SHIFT;
98187 +
98188 error = mlock_future_check(mm, mm->def_flags, len);
98189 if (error)
98190 return error;
98191 @@ -2675,21 +3161,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98192 /*
98193 * Clear old maps. this also does some error checking for us
98194 */
98195 - munmap_back:
98196 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98197 if (do_munmap(mm, addr, len))
98198 return -ENOMEM;
98199 - goto munmap_back;
98200 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98201 }
98202
98203 /* Check against address space limits *after* clearing old maps... */
98204 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98205 + if (!may_expand_vm(mm, charged))
98206 return -ENOMEM;
98207
98208 if (mm->map_count > sysctl_max_map_count)
98209 return -ENOMEM;
98210
98211 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98212 + if (security_vm_enough_memory_mm(mm, charged))
98213 return -ENOMEM;
98214
98215 /* Can we just expand an old private anonymous mapping? */
98216 @@ -2703,7 +3188,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98217 */
98218 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98219 if (!vma) {
98220 - vm_unacct_memory(len >> PAGE_SHIFT);
98221 + vm_unacct_memory(charged);
98222 return -ENOMEM;
98223 }
98224
98225 @@ -2717,10 +3202,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98226 vma_link(mm, vma, prev, rb_link, rb_parent);
98227 out:
98228 perf_event_mmap(vma);
98229 - mm->total_vm += len >> PAGE_SHIFT;
98230 + mm->total_vm += charged;
98231 if (flags & VM_LOCKED)
98232 - mm->locked_vm += (len >> PAGE_SHIFT);
98233 + mm->locked_vm += charged;
98234 vma->vm_flags |= VM_SOFTDIRTY;
98235 + track_exec_limit(mm, addr, addr + len, flags);
98236 return addr;
98237 }
98238
98239 @@ -2782,6 +3268,7 @@ void exit_mmap(struct mm_struct *mm)
98240 while (vma) {
98241 if (vma->vm_flags & VM_ACCOUNT)
98242 nr_accounted += vma_pages(vma);
98243 + vma->vm_mirror = NULL;
98244 vma = remove_vma(vma);
98245 }
98246 vm_unacct_memory(nr_accounted);
98247 @@ -2799,6 +3286,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98248 struct vm_area_struct *prev;
98249 struct rb_node **rb_link, *rb_parent;
98250
98251 +#ifdef CONFIG_PAX_SEGMEXEC
98252 + struct vm_area_struct *vma_m = NULL;
98253 +#endif
98254 +
98255 + if (security_mmap_addr(vma->vm_start))
98256 + return -EPERM;
98257 +
98258 /*
98259 * The vm_pgoff of a purely anonymous vma should be irrelevant
98260 * until its first write fault, when page's anon_vma and index
98261 @@ -2822,7 +3316,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98262 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98263 return -ENOMEM;
98264
98265 +#ifdef CONFIG_PAX_SEGMEXEC
98266 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98267 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98268 + if (!vma_m)
98269 + return -ENOMEM;
98270 + }
98271 +#endif
98272 +
98273 vma_link(mm, vma, prev, rb_link, rb_parent);
98274 +
98275 +#ifdef CONFIG_PAX_SEGMEXEC
98276 + if (vma_m)
98277 + BUG_ON(pax_mirror_vma(vma_m, vma));
98278 +#endif
98279 +
98280 return 0;
98281 }
98282
98283 @@ -2841,6 +3349,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98284 struct rb_node **rb_link, *rb_parent;
98285 bool faulted_in_anon_vma = true;
98286
98287 + BUG_ON(vma->vm_mirror);
98288 +
98289 /*
98290 * If anonymous vma has not yet been faulted, update new pgoff
98291 * to match new location, to increase its chance of merging.
98292 @@ -2905,6 +3415,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98293 return NULL;
98294 }
98295
98296 +#ifdef CONFIG_PAX_SEGMEXEC
98297 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98298 +{
98299 + struct vm_area_struct *prev_m;
98300 + struct rb_node **rb_link_m, *rb_parent_m;
98301 + struct mempolicy *pol_m;
98302 +
98303 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98304 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98305 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98306 + *vma_m = *vma;
98307 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98308 + if (anon_vma_clone(vma_m, vma))
98309 + return -ENOMEM;
98310 + pol_m = vma_policy(vma_m);
98311 + mpol_get(pol_m);
98312 + set_vma_policy(vma_m, pol_m);
98313 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98314 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98315 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98316 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98317 + if (vma_m->vm_file)
98318 + get_file(vma_m->vm_file);
98319 + if (vma_m->vm_ops && vma_m->vm_ops->open)
98320 + vma_m->vm_ops->open(vma_m);
98321 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98322 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98323 + vma_m->vm_mirror = vma;
98324 + vma->vm_mirror = vma_m;
98325 + return 0;
98326 +}
98327 +#endif
98328 +
98329 /*
98330 * Return true if the calling process may expand its vm space by the passed
98331 * number of pages
98332 @@ -2916,6 +3459,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98333
98334 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98335
98336 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98337 if (cur + npages > lim)
98338 return 0;
98339 return 1;
98340 @@ -2998,6 +3542,22 @@ static struct vm_area_struct *__install_special_mapping(
98341 vma->vm_start = addr;
98342 vma->vm_end = addr + len;
98343
98344 +#ifdef CONFIG_PAX_MPROTECT
98345 + if (mm->pax_flags & MF_PAX_MPROTECT) {
98346 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
98347 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98348 + return ERR_PTR(-EPERM);
98349 + if (!(vm_flags & VM_EXEC))
98350 + vm_flags &= ~VM_MAYEXEC;
98351 +#else
98352 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98353 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98354 +#endif
98355 + else
98356 + vm_flags &= ~VM_MAYWRITE;
98357 + }
98358 +#endif
98359 +
98360 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98361 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98362
98363 diff --git a/mm/mprotect.c b/mm/mprotect.c
98364 index ace9345..63320dc 100644
98365 --- a/mm/mprotect.c
98366 +++ b/mm/mprotect.c
98367 @@ -24,10 +24,18 @@
98368 #include <linux/migrate.h>
98369 #include <linux/perf_event.h>
98370 #include <linux/ksm.h>
98371 +#include <linux/sched/sysctl.h>
98372 +
98373 +#ifdef CONFIG_PAX_MPROTECT
98374 +#include <linux/elf.h>
98375 +#include <linux/binfmts.h>
98376 +#endif
98377 +
98378 #include <asm/uaccess.h>
98379 #include <asm/pgtable.h>
98380 #include <asm/cacheflush.h>
98381 #include <asm/tlbflush.h>
98382 +#include <asm/mmu_context.h>
98383
98384 /*
98385 * For a prot_numa update we only hold mmap_sem for read so there is a
98386 @@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98387 return pages;
98388 }
98389
98390 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98391 +/* called while holding the mmap semaphor for writing except stack expansion */
98392 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98393 +{
98394 + unsigned long oldlimit, newlimit = 0UL;
98395 +
98396 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98397 + return;
98398 +
98399 + spin_lock(&mm->page_table_lock);
98400 + oldlimit = mm->context.user_cs_limit;
98401 + if ((prot & VM_EXEC) && oldlimit < end)
98402 + /* USER_CS limit moved up */
98403 + newlimit = end;
98404 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98405 + /* USER_CS limit moved down */
98406 + newlimit = start;
98407 +
98408 + if (newlimit) {
98409 + mm->context.user_cs_limit = newlimit;
98410 +
98411 +#ifdef CONFIG_SMP
98412 + wmb();
98413 + cpus_clear(mm->context.cpu_user_cs_mask);
98414 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98415 +#endif
98416 +
98417 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98418 + }
98419 + spin_unlock(&mm->page_table_lock);
98420 + if (newlimit == end) {
98421 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
98422 +
98423 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
98424 + if (is_vm_hugetlb_page(vma))
98425 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98426 + else
98427 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98428 + }
98429 +}
98430 +#endif
98431 +
98432 int
98433 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98434 unsigned long start, unsigned long end, unsigned long newflags)
98435 @@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98436 int error;
98437 int dirty_accountable = 0;
98438
98439 +#ifdef CONFIG_PAX_SEGMEXEC
98440 + struct vm_area_struct *vma_m = NULL;
98441 + unsigned long start_m, end_m;
98442 +
98443 + start_m = start + SEGMEXEC_TASK_SIZE;
98444 + end_m = end + SEGMEXEC_TASK_SIZE;
98445 +#endif
98446 +
98447 if (newflags == oldflags) {
98448 *pprev = vma;
98449 return 0;
98450 }
98451
98452 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98453 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98454 +
98455 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98456 + return -ENOMEM;
98457 +
98458 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98459 + return -ENOMEM;
98460 + }
98461 +
98462 /*
98463 * If we make a private mapping writable we increase our commit;
98464 * but (without finer accounting) cannot reduce our commit if we
98465 @@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98466 }
98467 }
98468
98469 +#ifdef CONFIG_PAX_SEGMEXEC
98470 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98471 + if (start != vma->vm_start) {
98472 + error = split_vma(mm, vma, start, 1);
98473 + if (error)
98474 + goto fail;
98475 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98476 + *pprev = (*pprev)->vm_next;
98477 + }
98478 +
98479 + if (end != vma->vm_end) {
98480 + error = split_vma(mm, vma, end, 0);
98481 + if (error)
98482 + goto fail;
98483 + }
98484 +
98485 + if (pax_find_mirror_vma(vma)) {
98486 + error = __do_munmap(mm, start_m, end_m - start_m);
98487 + if (error)
98488 + goto fail;
98489 + } else {
98490 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98491 + if (!vma_m) {
98492 + error = -ENOMEM;
98493 + goto fail;
98494 + }
98495 + vma->vm_flags = newflags;
98496 + error = pax_mirror_vma(vma_m, vma);
98497 + if (error) {
98498 + vma->vm_flags = oldflags;
98499 + goto fail;
98500 + }
98501 + }
98502 + }
98503 +#endif
98504 +
98505 /*
98506 * First try to merge with previous and/or next vma.
98507 */
98508 @@ -314,7 +418,19 @@ success:
98509 * vm_flags and vm_page_prot are protected by the mmap_sem
98510 * held in write mode.
98511 */
98512 +
98513 +#ifdef CONFIG_PAX_SEGMEXEC
98514 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98515 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98516 +#endif
98517 +
98518 vma->vm_flags = newflags;
98519 +
98520 +#ifdef CONFIG_PAX_MPROTECT
98521 + if (mm->binfmt && mm->binfmt->handle_mprotect)
98522 + mm->binfmt->handle_mprotect(vma, newflags);
98523 +#endif
98524 +
98525 dirty_accountable = vma_wants_writenotify(vma);
98526 vma_set_page_prot(vma);
98527
98528 @@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98529 end = start + len;
98530 if (end <= start)
98531 return -ENOMEM;
98532 +
98533 +#ifdef CONFIG_PAX_SEGMEXEC
98534 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98535 + if (end > SEGMEXEC_TASK_SIZE)
98536 + return -EINVAL;
98537 + } else
98538 +#endif
98539 +
98540 + if (end > TASK_SIZE)
98541 + return -EINVAL;
98542 +
98543 if (!arch_validate_prot(prot))
98544 return -EINVAL;
98545
98546 @@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98547 /*
98548 * Does the application expect PROT_READ to imply PROT_EXEC:
98549 */
98550 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98551 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98552 prot |= PROT_EXEC;
98553
98554 vm_flags = calc_vm_prot_bits(prot);
98555 @@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98556 if (start > vma->vm_start)
98557 prev = vma;
98558
98559 +#ifdef CONFIG_PAX_MPROTECT
98560 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98561 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
98562 +#endif
98563 +
98564 for (nstart = start ; ; ) {
98565 unsigned long newflags;
98566
98567 @@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98568
98569 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98570 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98571 + if (prot & (PROT_WRITE | PROT_EXEC))
98572 + gr_log_rwxmprotect(vma);
98573 +
98574 + error = -EACCES;
98575 + goto out;
98576 + }
98577 +
98578 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98579 error = -EACCES;
98580 goto out;
98581 }
98582 @@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98583 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98584 if (error)
98585 goto out;
98586 +
98587 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
98588 +
98589 nstart = tmp;
98590
98591 if (nstart < prev->vm_end)
98592 diff --git a/mm/mremap.c b/mm/mremap.c
98593 index b147f66..98a695ab 100644
98594 --- a/mm/mremap.c
98595 +++ b/mm/mremap.c
98596 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98597 continue;
98598 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98599 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98600 +
98601 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98602 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98603 + pte = pte_exprotect(pte);
98604 +#endif
98605 +
98606 pte = move_soft_dirty_pte(pte);
98607 set_pte_at(mm, new_addr, new_pte, pte);
98608 }
98609 @@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98610 if (is_vm_hugetlb_page(vma))
98611 goto Einval;
98612
98613 +#ifdef CONFIG_PAX_SEGMEXEC
98614 + if (pax_find_mirror_vma(vma))
98615 + goto Einval;
98616 +#endif
98617 +
98618 /* We can't remap across vm area boundaries */
98619 if (old_len > vma->vm_end - addr)
98620 goto Efault;
98621 @@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98622 unsigned long ret = -EINVAL;
98623 unsigned long charged = 0;
98624 unsigned long map_flags;
98625 + unsigned long pax_task_size = TASK_SIZE;
98626
98627 if (new_addr & ~PAGE_MASK)
98628 goto out;
98629
98630 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98631 +#ifdef CONFIG_PAX_SEGMEXEC
98632 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98633 + pax_task_size = SEGMEXEC_TASK_SIZE;
98634 +#endif
98635 +
98636 + pax_task_size -= PAGE_SIZE;
98637 +
98638 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98639 goto out;
98640
98641 /* Check if the location we're moving into overlaps the
98642 * old location at all, and fail if it does.
98643 */
98644 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
98645 - goto out;
98646 -
98647 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
98648 + if (addr + old_len > new_addr && new_addr + new_len > addr)
98649 goto out;
98650
98651 ret = do_munmap(mm, new_addr, new_len);
98652 @@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98653 unsigned long ret = -EINVAL;
98654 unsigned long charged = 0;
98655 bool locked = false;
98656 + unsigned long pax_task_size = TASK_SIZE;
98657
98658 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98659 return ret;
98660 @@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98661 if (!new_len)
98662 return ret;
98663
98664 +#ifdef CONFIG_PAX_SEGMEXEC
98665 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
98666 + pax_task_size = SEGMEXEC_TASK_SIZE;
98667 +#endif
98668 +
98669 + pax_task_size -= PAGE_SIZE;
98670 +
98671 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98672 + old_len > pax_task_size || addr > pax_task_size-old_len)
98673 + return ret;
98674 +
98675 down_write(&current->mm->mmap_sem);
98676
98677 if (flags & MREMAP_FIXED) {
98678 @@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98679 new_addr = addr;
98680 }
98681 ret = addr;
98682 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98683 goto out;
98684 }
98685 }
98686 @@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98687 goto out;
98688 }
98689
98690 + map_flags = vma->vm_flags;
98691 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98692 + if (!(ret & ~PAGE_MASK)) {
98693 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98694 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98695 + }
98696 }
98697 out:
98698 if (ret & ~PAGE_MASK)
98699 diff --git a/mm/nommu.c b/mm/nommu.c
98700 index bd1808e..22cbc6a 100644
98701 --- a/mm/nommu.c
98702 +++ b/mm/nommu.c
98703 @@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98704 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98705 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98706 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98707 -int heap_stack_gap = 0;
98708
98709 atomic_long_t mmap_pages_allocated;
98710
98711 @@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98712 EXPORT_SYMBOL(find_vma);
98713
98714 /*
98715 - * find a VMA
98716 - * - we don't extend stack VMAs under NOMMU conditions
98717 - */
98718 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98719 -{
98720 - return find_vma(mm, addr);
98721 -}
98722 -
98723 -/*
98724 * expand a stack to a given address
98725 * - not supported under NOMMU conditions
98726 */
98727 @@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98728
98729 /* most fields are the same, copy all, and then fixup */
98730 *new = *vma;
98731 + INIT_LIST_HEAD(&new->anon_vma_chain);
98732 *region = *vma->vm_region;
98733 new->vm_region = region;
98734
98735 @@ -1905,7 +1896,7 @@ EXPORT_SYMBOL(unmap_mapping_range);
98736 */
98737 int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98738 {
98739 - unsigned long free, allowed, reserve;
98740 + long free, allowed, reserve;
98741
98742 vm_acct_memory(pages);
98743
98744 @@ -1969,7 +1960,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
98745 */
98746 if (mm) {
98747 reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
98748 - allowed -= min(mm->total_vm / 32, reserve);
98749 + allowed -= min_t(long, mm->total_vm / 32, reserve);
98750 }
98751
98752 if (percpu_counter_read_positive(&vm_committed_as) < allowed)
98753 @@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98754 }
98755 EXPORT_SYMBOL(generic_file_remap_pages);
98756
98757 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98758 - unsigned long addr, void *buf, int len, int write)
98759 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98760 + unsigned long addr, void *buf, size_t len, int write)
98761 {
98762 struct vm_area_struct *vma;
98763
98764 @@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98765 *
98766 * The caller must hold a reference on @mm.
98767 */
98768 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98769 - void *buf, int len, int write)
98770 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98771 + void *buf, size_t len, int write)
98772 {
98773 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98774 }
98775 @@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98776 * Access another process' address space.
98777 * - source/target buffer must be kernel space
98778 */
98779 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98780 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98781 {
98782 struct mm_struct *mm;
98783
98784 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98785 index 437174a..8b86707 100644
98786 --- a/mm/page-writeback.c
98787 +++ b/mm/page-writeback.c
98788 @@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98789 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98790 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98791 */
98792 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98793 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98794 unsigned long thresh,
98795 unsigned long bg_thresh,
98796 unsigned long dirty,
98797 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98798 index 616a2c9..0e755f6 100644
98799 --- a/mm/page_alloc.c
98800 +++ b/mm/page_alloc.c
98801 @@ -59,6 +59,7 @@
98802 #include <linux/page-debug-flags.h>
98803 #include <linux/hugetlb.h>
98804 #include <linux/sched/rt.h>
98805 +#include <linux/random.h>
98806
98807 #include <asm/sections.h>
98808 #include <asm/tlbflush.h>
98809 @@ -356,7 +357,7 @@ out:
98810 * This usage means that zero-order pages may not be compound.
98811 */
98812
98813 -static void free_compound_page(struct page *page)
98814 +void free_compound_page(struct page *page)
98815 {
98816 __free_pages_ok(page, compound_order(page));
98817 }
98818 @@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98819 int i;
98820 int bad = 0;
98821
98822 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98823 + unsigned long index = 1UL << order;
98824 +#endif
98825 +
98826 trace_mm_page_free(page, order);
98827 kmemcheck_free_shadow(page, order);
98828
98829 @@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98830 debug_check_no_obj_freed(page_address(page),
98831 PAGE_SIZE << order);
98832 }
98833 +
98834 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
98835 + for (; index; --index)
98836 + sanitize_highpage(page + index - 1);
98837 +#endif
98838 +
98839 arch_free_page(page, order);
98840 kernel_map_pages(page, 1 << order, 0);
98841
98842 @@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98843 local_irq_restore(flags);
98844 }
98845
98846 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98847 +bool __meminitdata extra_latent_entropy;
98848 +
98849 +static int __init setup_pax_extra_latent_entropy(char *str)
98850 +{
98851 + extra_latent_entropy = true;
98852 + return 0;
98853 +}
98854 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98855 +
98856 +volatile u64 latent_entropy __latent_entropy;
98857 +EXPORT_SYMBOL(latent_entropy);
98858 +#endif
98859 +
98860 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98861 {
98862 unsigned int nr_pages = 1 << order;
98863 @@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98864 __ClearPageReserved(p);
98865 set_page_count(p, 0);
98866
98867 +#ifdef CONFIG_PAX_LATENT_ENTROPY
98868 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98869 + u64 hash = 0;
98870 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98871 + const u64 *data = lowmem_page_address(page);
98872 +
98873 + for (index = 0; index < end; index++)
98874 + hash ^= hash + data[index];
98875 + latent_entropy ^= hash;
98876 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98877 + }
98878 +#endif
98879 +
98880 page_zone(page)->managed_pages += nr_pages;
98881 set_page_refcounted(page);
98882 __free_pages(page, order);
98883 @@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98884 arch_alloc_page(page, order);
98885 kernel_map_pages(page, 1 << order, 1);
98886
98887 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
98888 if (gfp_flags & __GFP_ZERO)
98889 prep_zero_page(page, order, gfp_flags);
98890 +#endif
98891
98892 if (order && (gfp_flags & __GFP_COMP))
98893 prep_compound_page(page, order);
98894 @@ -1602,7 +1642,7 @@ again:
98895 }
98896
98897 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98898 - if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98899 + if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98900 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98901 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98902
98903 @@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98904 do {
98905 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98906 high_wmark_pages(zone) - low_wmark_pages(zone) -
98907 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98908 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98909 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98910 } while (zone++ != preferred_zone);
98911 }
98912 @@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98913
98914 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98915 high_wmark_pages(zone) - low_wmark_pages(zone) -
98916 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98917 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98918
98919 setup_zone_migrate_reserve(zone);
98920 spin_unlock_irqrestore(&zone->lock, flags);
98921 diff --git a/mm/percpu.c b/mm/percpu.c
98922 index 014bab6..db5a76f 100644
98923 --- a/mm/percpu.c
98924 +++ b/mm/percpu.c
98925 @@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98926 static unsigned int pcpu_high_unit_cpu __read_mostly;
98927
98928 /* the address of the first chunk which starts with the kernel static area */
98929 -void *pcpu_base_addr __read_mostly;
98930 +void *pcpu_base_addr __read_only;
98931 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98932
98933 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98934 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98935 index 5077afc..846c9ef 100644
98936 --- a/mm/process_vm_access.c
98937 +++ b/mm/process_vm_access.c
98938 @@ -13,6 +13,7 @@
98939 #include <linux/uio.h>
98940 #include <linux/sched.h>
98941 #include <linux/highmem.h>
98942 +#include <linux/security.h>
98943 #include <linux/ptrace.h>
98944 #include <linux/slab.h>
98945 #include <linux/syscalls.h>
98946 @@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98947 ssize_t iov_len;
98948 size_t total_len = iov_iter_count(iter);
98949
98950 + return -ENOSYS; // PaX: until properly audited
98951 +
98952 /*
98953 * Work out how many pages of struct pages we're going to need
98954 * when eventually calling get_user_pages
98955 */
98956 for (i = 0; i < riovcnt; i++) {
98957 iov_len = rvec[i].iov_len;
98958 - if (iov_len > 0) {
98959 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
98960 - + iov_len)
98961 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98962 - / PAGE_SIZE + 1;
98963 - nr_pages = max(nr_pages, nr_pages_iov);
98964 - }
98965 + if (iov_len <= 0)
98966 + continue;
98967 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98968 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98969 + nr_pages = max(nr_pages, nr_pages_iov);
98970 }
98971
98972 if (nr_pages == 0)
98973 @@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98974 goto free_proc_pages;
98975 }
98976
98977 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98978 + rc = -EPERM;
98979 + goto put_task_struct;
98980 + }
98981 +
98982 mm = mm_access(task, PTRACE_MODE_ATTACH);
98983 if (!mm || IS_ERR(mm)) {
98984 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98985 diff --git a/mm/rmap.c b/mm/rmap.c
98986 index 3e4c721..a5e3e39 100644
98987 --- a/mm/rmap.c
98988 +++ b/mm/rmap.c
98989 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98990 struct anon_vma *anon_vma = vma->anon_vma;
98991 struct anon_vma_chain *avc;
98992
98993 +#ifdef CONFIG_PAX_SEGMEXEC
98994 + struct anon_vma_chain *avc_m = NULL;
98995 +#endif
98996 +
98997 might_sleep();
98998 if (unlikely(!anon_vma)) {
98999 struct mm_struct *mm = vma->vm_mm;
99000 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99001 if (!avc)
99002 goto out_enomem;
99003
99004 +#ifdef CONFIG_PAX_SEGMEXEC
99005 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
99006 + if (!avc_m)
99007 + goto out_enomem_free_avc;
99008 +#endif
99009 +
99010 anon_vma = find_mergeable_anon_vma(vma);
99011 allocated = NULL;
99012 if (!anon_vma) {
99013 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99014 /* page_table_lock to protect against threads */
99015 spin_lock(&mm->page_table_lock);
99016 if (likely(!vma->anon_vma)) {
99017 +
99018 +#ifdef CONFIG_PAX_SEGMEXEC
99019 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
99020 +
99021 + if (vma_m) {
99022 + BUG_ON(vma_m->anon_vma);
99023 + vma_m->anon_vma = anon_vma;
99024 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
99025 + avc_m = NULL;
99026 + }
99027 +#endif
99028 +
99029 vma->anon_vma = anon_vma;
99030 anon_vma_chain_link(vma, avc, anon_vma);
99031 allocated = NULL;
99032 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99033
99034 if (unlikely(allocated))
99035 put_anon_vma(allocated);
99036 +
99037 +#ifdef CONFIG_PAX_SEGMEXEC
99038 + if (unlikely(avc_m))
99039 + anon_vma_chain_free(avc_m);
99040 +#endif
99041 +
99042 if (unlikely(avc))
99043 anon_vma_chain_free(avc);
99044 }
99045 return 0;
99046
99047 out_enomem_free_avc:
99048 +
99049 +#ifdef CONFIG_PAX_SEGMEXEC
99050 + if (avc_m)
99051 + anon_vma_chain_free(avc_m);
99052 +#endif
99053 +
99054 anon_vma_chain_free(avc);
99055 out_enomem:
99056 return -ENOMEM;
99057 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99058 * Attach the anon_vmas from src to dst.
99059 * Returns 0 on success, -ENOMEM on failure.
99060 */
99061 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99062 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99063 {
99064 struct anon_vma_chain *avc, *pavc;
99065 struct anon_vma *root = NULL;
99066 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99067 * the corresponding VMA in the parent process is attached to.
99068 * Returns 0 on success, non-zero on failure.
99069 */
99070 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99071 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99072 {
99073 struct anon_vma_chain *avc;
99074 struct anon_vma *anon_vma;
99075 @@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
99076 void __init anon_vma_init(void)
99077 {
99078 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99079 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99080 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99081 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99082 + anon_vma_ctor);
99083 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99084 + SLAB_PANIC|SLAB_NO_SANITIZE);
99085 }
99086
99087 /*
99088 diff --git a/mm/shmem.c b/mm/shmem.c
99089 index 0b4ba55..bcef4ae 100644
99090 --- a/mm/shmem.c
99091 +++ b/mm/shmem.c
99092 @@ -33,7 +33,7 @@
99093 #include <linux/swap.h>
99094 #include <linux/aio.h>
99095
99096 -static struct vfsmount *shm_mnt;
99097 +struct vfsmount *shm_mnt;
99098
99099 #ifdef CONFIG_SHMEM
99100 /*
99101 @@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99102 #define BOGO_DIRENT_SIZE 20
99103
99104 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99105 -#define SHORT_SYMLINK_LEN 128
99106 +#define SHORT_SYMLINK_LEN 64
99107
99108 /*
99109 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99110 @@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99111 static int shmem_xattr_validate(const char *name)
99112 {
99113 struct { const char *prefix; size_t len; } arr[] = {
99114 +
99115 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99116 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99117 +#endif
99118 +
99119 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99120 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99121 };
99122 @@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99123 if (err)
99124 return err;
99125
99126 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99127 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99128 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99129 + return -EOPNOTSUPP;
99130 + if (size > 8)
99131 + return -EINVAL;
99132 + }
99133 +#endif
99134 +
99135 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99136 }
99137
99138 @@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99139 int err = -ENOMEM;
99140
99141 /* Round up to L1_CACHE_BYTES to resist false sharing */
99142 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99143 - L1_CACHE_BYTES), GFP_KERNEL);
99144 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99145 if (!sbinfo)
99146 return -ENOMEM;
99147
99148 diff --git a/mm/slab.c b/mm/slab.c
99149 index f34e053..78a3839 100644
99150 --- a/mm/slab.c
99151 +++ b/mm/slab.c
99152 @@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99153 if ((x)->max_freeable < i) \
99154 (x)->max_freeable = i; \
99155 } while (0)
99156 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99157 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99158 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99159 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99160 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99161 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99162 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99163 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99164 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99165 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99166 #else
99167 #define STATS_INC_ACTIVE(x) do { } while (0)
99168 #define STATS_DEC_ACTIVE(x) do { } while (0)
99169 @@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99170 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99171 #define STATS_INC_FREEHIT(x) do { } while (0)
99172 #define STATS_INC_FREEMISS(x) do { } while (0)
99173 +#define STATS_INC_SANITIZED(x) do { } while (0)
99174 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99175 #endif
99176
99177 #if DEBUG
99178 @@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99179 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99180 */
99181 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99182 - const struct page *page, void *obj)
99183 + const struct page *page, const void *obj)
99184 {
99185 u32 offset = (obj - page->s_mem);
99186 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99187 @@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
99188 * structures first. Without this, further allocations will bug.
99189 */
99190 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
99191 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99192 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99193 slab_state = PARTIAL_NODE;
99194
99195 slab_early_init = 0;
99196 @@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99197
99198 cachep = find_mergeable(size, align, flags, name, ctor);
99199 if (cachep) {
99200 - cachep->refcount++;
99201 + atomic_inc(&cachep->refcount);
99202
99203 /*
99204 * Adjust the object sizes so that we clear
99205 @@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99206 struct array_cache *ac = cpu_cache_get(cachep);
99207
99208 check_irq_off();
99209 +
99210 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99211 + if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99212 + STATS_INC_NOT_SANITIZED(cachep);
99213 + else {
99214 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99215 +
99216 + if (cachep->ctor)
99217 + cachep->ctor(objp);
99218 +
99219 + STATS_INC_SANITIZED(cachep);
99220 + }
99221 +#endif
99222 +
99223 kmemleak_free_recursive(objp, cachep->flags);
99224 objp = cache_free_debugcheck(cachep, objp, caller);
99225
99226 @@ -3557,6 +3575,7 @@ void kfree(const void *objp)
99227
99228 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99229 return;
99230 + VM_BUG_ON(!virt_addr_valid(objp));
99231 local_irq_save(flags);
99232 kfree_debugcheck(objp);
99233 c = virt_to_cache(objp);
99234 @@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99235 }
99236 /* cpu stats */
99237 {
99238 - unsigned long allochit = atomic_read(&cachep->allochit);
99239 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99240 - unsigned long freehit = atomic_read(&cachep->freehit);
99241 - unsigned long freemiss = atomic_read(&cachep->freemiss);
99242 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99243 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99244 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99245 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99246
99247 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99248 allochit, allocmiss, freehit, freemiss);
99249 }
99250 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99251 + {
99252 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99253 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99254 +
99255 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99256 + }
99257 +#endif
99258 #endif
99259 }
99260
99261 @@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
99262 static int __init slab_proc_init(void)
99263 {
99264 #ifdef CONFIG_DEBUG_SLAB_LEAK
99265 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99266 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99267 #endif
99268 return 0;
99269 }
99270 module_init(slab_proc_init);
99271 #endif
99272
99273 +bool is_usercopy_object(const void *ptr)
99274 +{
99275 + struct page *page;
99276 + struct kmem_cache *cachep;
99277 +
99278 + if (ZERO_OR_NULL_PTR(ptr))
99279 + return false;
99280 +
99281 + if (!slab_is_available())
99282 + return false;
99283 +
99284 + if (!virt_addr_valid(ptr))
99285 + return false;
99286 +
99287 + page = virt_to_head_page(ptr);
99288 +
99289 + if (!PageSlab(page))
99290 + return false;
99291 +
99292 + cachep = page->slab_cache;
99293 + return cachep->flags & SLAB_USERCOPY;
99294 +}
99295 +
99296 +#ifdef CONFIG_PAX_USERCOPY
99297 +const char *check_heap_object(const void *ptr, unsigned long n)
99298 +{
99299 + struct page *page;
99300 + struct kmem_cache *cachep;
99301 + unsigned int objnr;
99302 + unsigned long offset;
99303 +
99304 + if (ZERO_OR_NULL_PTR(ptr))
99305 + return "<null>";
99306 +
99307 + if (!virt_addr_valid(ptr))
99308 + return NULL;
99309 +
99310 + page = virt_to_head_page(ptr);
99311 +
99312 + if (!PageSlab(page))
99313 + return NULL;
99314 +
99315 + cachep = page->slab_cache;
99316 + if (!(cachep->flags & SLAB_USERCOPY))
99317 + return cachep->name;
99318 +
99319 + objnr = obj_to_index(cachep, page, ptr);
99320 + BUG_ON(objnr >= cachep->num);
99321 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99322 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99323 + return NULL;
99324 +
99325 + return cachep->name;
99326 +}
99327 +#endif
99328 +
99329 /**
99330 * ksize - get the actual amount of memory allocated for a given object
99331 * @objp: Pointer to the object
99332 diff --git a/mm/slab.h b/mm/slab.h
99333 index ab019e6..fbcac34 100644
99334 --- a/mm/slab.h
99335 +++ b/mm/slab.h
99336 @@ -22,7 +22,7 @@ struct kmem_cache {
99337 unsigned int align; /* Alignment as calculated */
99338 unsigned long flags; /* Active flags on the slab */
99339 const char *name; /* Slab name for sysfs */
99340 - int refcount; /* Use counter */
99341 + atomic_t refcount; /* Use counter */
99342 void (*ctor)(void *); /* Called on object slot creation */
99343 struct list_head list; /* List of all slab caches on the system */
99344 };
99345 @@ -66,6 +66,20 @@ extern struct list_head slab_caches;
99346 /* The slab cache that manages slab cache information */
99347 extern struct kmem_cache *kmem_cache;
99348
99349 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99350 +#ifdef CONFIG_X86_64
99351 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99352 +#else
99353 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99354 +#endif
99355 +enum pax_sanitize_mode {
99356 + PAX_SANITIZE_SLAB_OFF = 0,
99357 + PAX_SANITIZE_SLAB_FAST,
99358 + PAX_SANITIZE_SLAB_FULL,
99359 +};
99360 +extern enum pax_sanitize_mode pax_sanitize_slab;
99361 +#endif
99362 +
99363 unsigned long calculate_alignment(unsigned long flags,
99364 unsigned long align, unsigned long size);
99365
99366 @@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
99367
99368 /* Legal flag mask for kmem_cache_create(), for various configurations */
99369 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99370 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99371 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99372 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
99373
99374 #if defined(CONFIG_DEBUG_SLAB)
99375 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99376 @@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99377 return s;
99378
99379 page = virt_to_head_page(x);
99380 +
99381 + BUG_ON(!PageSlab(page));
99382 +
99383 cachep = page->slab_cache;
99384 if (slab_equal_or_root(cachep, s))
99385 return cachep;
99386 diff --git a/mm/slab_common.c b/mm/slab_common.c
99387 index dcdab81..3576646 100644
99388 --- a/mm/slab_common.c
99389 +++ b/mm/slab_common.c
99390 @@ -25,11 +25,35 @@
99391
99392 #include "slab.h"
99393
99394 -enum slab_state slab_state;
99395 +enum slab_state slab_state __read_only;
99396 LIST_HEAD(slab_caches);
99397 DEFINE_MUTEX(slab_mutex);
99398 struct kmem_cache *kmem_cache;
99399
99400 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99401 +enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99402 +static int __init pax_sanitize_slab_setup(char *str)
99403 +{
99404 + if (!str)
99405 + return 0;
99406 +
99407 + if (!strcmp(str, "0") || !strcmp(str, "off")) {
99408 + pr_info("PaX slab sanitization: %s\n", "disabled");
99409 + pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99410 + } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99411 + pr_info("PaX slab sanitization: %s\n", "fast");
99412 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99413 + } else if (!strcmp(str, "full")) {
99414 + pr_info("PaX slab sanitization: %s\n", "full");
99415 + pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99416 + } else
99417 + pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99418 +
99419 + return 0;
99420 +}
99421 +early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99422 +#endif
99423 +
99424 /*
99425 * Set of flags that will prevent slab merging
99426 */
99427 @@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
99428 * Merge control. If this is set then no merging of slab caches will occur.
99429 * (Could be removed. This was introduced to pacify the merge skeptics.)
99430 */
99431 -static int slab_nomerge;
99432 +static int slab_nomerge = 1;
99433
99434 static int __init setup_slab_nomerge(char *str)
99435 {
99436 @@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
99437 /*
99438 * We may have set a slab to be unmergeable during bootstrap.
99439 */
99440 - if (s->refcount < 0)
99441 + if (atomic_read(&s->refcount) < 0)
99442 return 1;
99443
99444 return 0;
99445 @@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99446 if (err)
99447 goto out_free_cache;
99448
99449 - s->refcount = 1;
99450 + atomic_set(&s->refcount, 1);
99451 list_add(&s->list, &slab_caches);
99452 out:
99453 if (err)
99454 @@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99455 */
99456 flags &= CACHE_CREATE_MASK;
99457
99458 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99459 + if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99460 + flags |= SLAB_NO_SANITIZE;
99461 + else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99462 + flags &= ~SLAB_NO_SANITIZE;
99463 +#endif
99464 +
99465 s = __kmem_cache_alias(name, size, align, flags, ctor);
99466 if (s)
99467 goto out_unlock;
99468 @@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99469
99470 mutex_lock(&slab_mutex);
99471
99472 - s->refcount--;
99473 - if (s->refcount)
99474 + if (!atomic_dec_and_test(&s->refcount))
99475 goto out_unlock;
99476
99477 if (memcg_cleanup_cache_params(s) != 0)
99478 @@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99479 rcu_barrier();
99480
99481 memcg_free_cache_params(s);
99482 -#ifdef SLAB_SUPPORTS_SYSFS
99483 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99484 sysfs_slab_remove(s);
99485 #else
99486 slab_kmem_cache_release(s);
99487 @@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99488 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99489 name, size, err);
99490
99491 - s->refcount = -1; /* Exempt from merging for now */
99492 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99493 }
99494
99495 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99496 @@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99497
99498 create_boot_cache(s, name, size, flags);
99499 list_add(&s->list, &slab_caches);
99500 - s->refcount = 1;
99501 + atomic_set(&s->refcount, 1);
99502 return s;
99503 }
99504
99505 @@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99506 EXPORT_SYMBOL(kmalloc_dma_caches);
99507 #endif
99508
99509 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99510 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99511 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
99512 +#endif
99513 +
99514 /*
99515 * Conversion table for small slabs sizes / 8 to the index in the
99516 * kmalloc array. This is necessary for slabs < 192 since we have non power
99517 @@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99518 return kmalloc_dma_caches[index];
99519
99520 #endif
99521 +
99522 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99523 + if (unlikely((flags & GFP_USERCOPY)))
99524 + return kmalloc_usercopy_caches[index];
99525 +
99526 +#endif
99527 +
99528 return kmalloc_caches[index];
99529 }
99530
99531 @@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99532 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99533 if (!kmalloc_caches[i]) {
99534 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99535 - 1 << i, flags);
99536 + 1 << i, SLAB_USERCOPY | flags);
99537 }
99538
99539 /*
99540 @@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99541 * earlier power of two caches
99542 */
99543 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99544 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99545 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99546
99547 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99548 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99549 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99550 }
99551
99552 /* Kmalloc array is now usable */
99553 @@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99554 }
99555 }
99556 #endif
99557 +
99558 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99559 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99560 + struct kmem_cache *s = kmalloc_caches[i];
99561 +
99562 + if (s) {
99563 + int size = kmalloc_size(i);
99564 + char *n = kasprintf(GFP_NOWAIT,
99565 + "usercopy-kmalloc-%d", size);
99566 +
99567 + BUG_ON(!n);
99568 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99569 + size, SLAB_USERCOPY | flags);
99570 + }
99571 + }
99572 +#endif
99573 +
99574 }
99575 #endif /* !CONFIG_SLOB */
99576
99577 @@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99578 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99579 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99580 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99581 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99582 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
99583 +#endif
99584 #endif
99585 seq_putc(m, '\n');
99586 }
99587 diff --git a/mm/slob.c b/mm/slob.c
99588 index 96a8620..3e7e663 100644
99589 --- a/mm/slob.c
99590 +++ b/mm/slob.c
99591 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99592 /*
99593 * Return the size of a slob block.
99594 */
99595 -static slobidx_t slob_units(slob_t *s)
99596 +static slobidx_t slob_units(const slob_t *s)
99597 {
99598 if (s->units > 0)
99599 return s->units;
99600 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99601 /*
99602 * Return the next free slob block pointer after this one.
99603 */
99604 -static slob_t *slob_next(slob_t *s)
99605 +static slob_t *slob_next(const slob_t *s)
99606 {
99607 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99608 slobidx_t next;
99609 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99610 /*
99611 * Returns true if s is the last free block in its page.
99612 */
99613 -static int slob_last(slob_t *s)
99614 +static int slob_last(const slob_t *s)
99615 {
99616 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99617 }
99618
99619 -static void *slob_new_pages(gfp_t gfp, int order, int node)
99620 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99621 {
99622 - void *page;
99623 + struct page *page;
99624
99625 #ifdef CONFIG_NUMA
99626 if (node != NUMA_NO_NODE)
99627 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99628 if (!page)
99629 return NULL;
99630
99631 - return page_address(page);
99632 + __SetPageSlab(page);
99633 + return page;
99634 }
99635
99636 -static void slob_free_pages(void *b, int order)
99637 +static void slob_free_pages(struct page *sp, int order)
99638 {
99639 if (current->reclaim_state)
99640 current->reclaim_state->reclaimed_slab += 1 << order;
99641 - free_pages((unsigned long)b, order);
99642 + __ClearPageSlab(sp);
99643 + page_mapcount_reset(sp);
99644 + sp->private = 0;
99645 + __free_pages(sp, order);
99646 }
99647
99648 /*
99649 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99650
99651 /* Not enough space: must allocate a new page */
99652 if (!b) {
99653 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99654 - if (!b)
99655 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99656 + if (!sp)
99657 return NULL;
99658 - sp = virt_to_page(b);
99659 - __SetPageSlab(sp);
99660 + b = page_address(sp);
99661
99662 spin_lock_irqsave(&slob_lock, flags);
99663 sp->units = SLOB_UNITS(PAGE_SIZE);
99664 sp->freelist = b;
99665 + sp->private = 0;
99666 INIT_LIST_HEAD(&sp->lru);
99667 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99668 set_slob_page_free(sp, slob_list);
99669 @@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99670 /*
99671 * slob_free: entry point into the slob allocator.
99672 */
99673 -static void slob_free(void *block, int size)
99674 +static void slob_free(struct kmem_cache *c, void *block, int size)
99675 {
99676 struct page *sp;
99677 slob_t *prev, *next, *b = (slob_t *)block;
99678 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99679 if (slob_page_free(sp))
99680 clear_slob_page_free(sp);
99681 spin_unlock_irqrestore(&slob_lock, flags);
99682 - __ClearPageSlab(sp);
99683 - page_mapcount_reset(sp);
99684 - slob_free_pages(b, 0);
99685 + slob_free_pages(sp, 0);
99686 return;
99687 }
99688
99689 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
99690 + if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99691 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99692 +#endif
99693 +
99694 if (!slob_page_free(sp)) {
99695 /* This slob page is about to become partially free. Easy! */
99696 sp->units = units;
99697 @@ -424,11 +431,10 @@ out:
99698 */
99699
99700 static __always_inline void *
99701 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99702 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99703 {
99704 - unsigned int *m;
99705 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99706 - void *ret;
99707 + slob_t *m;
99708 + void *ret = NULL;
99709
99710 gfp &= gfp_allowed_mask;
99711
99712 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99713
99714 if (!m)
99715 return NULL;
99716 - *m = size;
99717 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99718 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99719 + m[0].units = size;
99720 + m[1].units = align;
99721 ret = (void *)m + align;
99722
99723 trace_kmalloc_node(caller, ret,
99724 size, size + align, gfp, node);
99725 } else {
99726 unsigned int order = get_order(size);
99727 + struct page *page;
99728
99729 if (likely(order))
99730 gfp |= __GFP_COMP;
99731 - ret = slob_new_pages(gfp, order, node);
99732 + page = slob_new_pages(gfp, order, node);
99733 + if (page) {
99734 + ret = page_address(page);
99735 + page->private = size;
99736 + }
99737
99738 trace_kmalloc_node(caller, ret,
99739 size, PAGE_SIZE << order, gfp, node);
99740 }
99741
99742 - kmemleak_alloc(ret, size, 1, gfp);
99743 + return ret;
99744 +}
99745 +
99746 +static __always_inline void *
99747 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99748 +{
99749 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99750 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99751 +
99752 + if (!ZERO_OR_NULL_PTR(ret))
99753 + kmemleak_alloc(ret, size, 1, gfp);
99754 return ret;
99755 }
99756
99757 @@ -491,34 +515,112 @@ void kfree(const void *block)
99758 return;
99759 kmemleak_free(block);
99760
99761 + VM_BUG_ON(!virt_addr_valid(block));
99762 sp = virt_to_page(block);
99763 - if (PageSlab(sp)) {
99764 + VM_BUG_ON(!PageSlab(sp));
99765 + if (!sp->private) {
99766 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99767 - unsigned int *m = (unsigned int *)(block - align);
99768 - slob_free(m, *m + align);
99769 - } else
99770 + slob_t *m = (slob_t *)(block - align);
99771 + slob_free(NULL, m, m[0].units + align);
99772 + } else {
99773 + __ClearPageSlab(sp);
99774 + page_mapcount_reset(sp);
99775 + sp->private = 0;
99776 __free_pages(sp, compound_order(sp));
99777 + }
99778 }
99779 EXPORT_SYMBOL(kfree);
99780
99781 +bool is_usercopy_object(const void *ptr)
99782 +{
99783 + if (!slab_is_available())
99784 + return false;
99785 +
99786 + // PAX: TODO
99787 +
99788 + return false;
99789 +}
99790 +
99791 +#ifdef CONFIG_PAX_USERCOPY
99792 +const char *check_heap_object(const void *ptr, unsigned long n)
99793 +{
99794 + struct page *page;
99795 + const slob_t *free;
99796 + const void *base;
99797 + unsigned long flags;
99798 +
99799 + if (ZERO_OR_NULL_PTR(ptr))
99800 + return "<null>";
99801 +
99802 + if (!virt_addr_valid(ptr))
99803 + return NULL;
99804 +
99805 + page = virt_to_head_page(ptr);
99806 + if (!PageSlab(page))
99807 + return NULL;
99808 +
99809 + if (page->private) {
99810 + base = page;
99811 + if (base <= ptr && n <= page->private - (ptr - base))
99812 + return NULL;
99813 + return "<slob>";
99814 + }
99815 +
99816 + /* some tricky double walking to find the chunk */
99817 + spin_lock_irqsave(&slob_lock, flags);
99818 + base = (void *)((unsigned long)ptr & PAGE_MASK);
99819 + free = page->freelist;
99820 +
99821 + while (!slob_last(free) && (void *)free <= ptr) {
99822 + base = free + slob_units(free);
99823 + free = slob_next(free);
99824 + }
99825 +
99826 + while (base < (void *)free) {
99827 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99828 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
99829 + int offset;
99830 +
99831 + if (ptr < base + align)
99832 + break;
99833 +
99834 + offset = ptr - base - align;
99835 + if (offset >= m) {
99836 + base += size;
99837 + continue;
99838 + }
99839 +
99840 + if (n > m - offset)
99841 + break;
99842 +
99843 + spin_unlock_irqrestore(&slob_lock, flags);
99844 + return NULL;
99845 + }
99846 +
99847 + spin_unlock_irqrestore(&slob_lock, flags);
99848 + return "<slob>";
99849 +}
99850 +#endif
99851 +
99852 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99853 size_t ksize(const void *block)
99854 {
99855 struct page *sp;
99856 int align;
99857 - unsigned int *m;
99858 + slob_t *m;
99859
99860 BUG_ON(!block);
99861 if (unlikely(block == ZERO_SIZE_PTR))
99862 return 0;
99863
99864 sp = virt_to_page(block);
99865 - if (unlikely(!PageSlab(sp)))
99866 - return PAGE_SIZE << compound_order(sp);
99867 + VM_BUG_ON(!PageSlab(sp));
99868 + if (sp->private)
99869 + return sp->private;
99870
99871 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99872 - m = (unsigned int *)(block - align);
99873 - return SLOB_UNITS(*m) * SLOB_UNIT;
99874 + m = (slob_t *)(block - align);
99875 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99876 }
99877 EXPORT_SYMBOL(ksize);
99878
99879 @@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99880
99881 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99882 {
99883 - void *b;
99884 + void *b = NULL;
99885
99886 flags &= gfp_allowed_mask;
99887
99888 lockdep_trace_alloc(flags);
99889
99890 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99891 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99892 +#else
99893 if (c->size < PAGE_SIZE) {
99894 b = slob_alloc(c->size, flags, c->align, node);
99895 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99896 SLOB_UNITS(c->size) * SLOB_UNIT,
99897 flags, node);
99898 } else {
99899 - b = slob_new_pages(flags, get_order(c->size), node);
99900 + struct page *sp;
99901 +
99902 + sp = slob_new_pages(flags, get_order(c->size), node);
99903 + if (sp) {
99904 + b = page_address(sp);
99905 + sp->private = c->size;
99906 + }
99907 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99908 PAGE_SIZE << get_order(c->size),
99909 flags, node);
99910 }
99911 +#endif
99912
99913 if (b && c->ctor)
99914 c->ctor(b);
99915 @@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99916 EXPORT_SYMBOL(kmem_cache_alloc_node);
99917 #endif
99918
99919 -static void __kmem_cache_free(void *b, int size)
99920 +static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99921 {
99922 - if (size < PAGE_SIZE)
99923 - slob_free(b, size);
99924 + struct page *sp;
99925 +
99926 + sp = virt_to_page(b);
99927 + BUG_ON(!PageSlab(sp));
99928 + if (!sp->private)
99929 + slob_free(c, b, size);
99930 else
99931 - slob_free_pages(b, get_order(size));
99932 + slob_free_pages(sp, get_order(size));
99933 }
99934
99935 static void kmem_rcu_free(struct rcu_head *head)
99936 @@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99937 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99938 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99939
99940 - __kmem_cache_free(b, slob_rcu->size);
99941 + __kmem_cache_free(NULL, b, slob_rcu->size);
99942 }
99943
99944 void kmem_cache_free(struct kmem_cache *c, void *b)
99945 {
99946 + int size = c->size;
99947 +
99948 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99949 + if (size + c->align < PAGE_SIZE) {
99950 + size += c->align;
99951 + b -= c->align;
99952 + }
99953 +#endif
99954 +
99955 kmemleak_free_recursive(b, c->flags);
99956 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99957 struct slob_rcu *slob_rcu;
99958 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99959 - slob_rcu->size = c->size;
99960 + slob_rcu = b + (size - sizeof(struct slob_rcu));
99961 + slob_rcu->size = size;
99962 call_rcu(&slob_rcu->head, kmem_rcu_free);
99963 } else {
99964 - __kmem_cache_free(b, c->size);
99965 + __kmem_cache_free(c, b, size);
99966 }
99967
99968 +#ifdef CONFIG_PAX_USERCOPY_SLABS
99969 + trace_kfree(_RET_IP_, b);
99970 +#else
99971 trace_kmem_cache_free(_RET_IP_, b);
99972 +#endif
99973 +
99974 }
99975 EXPORT_SYMBOL(kmem_cache_free);
99976
99977 diff --git a/mm/slub.c b/mm/slub.c
99978 index ae7b9f1..7b3fdbe 100644
99979 --- a/mm/slub.c
99980 +++ b/mm/slub.c
99981 @@ -197,7 +197,7 @@ struct track {
99982
99983 enum track_item { TRACK_ALLOC, TRACK_FREE };
99984
99985 -#ifdef CONFIG_SYSFS
99986 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99987 static int sysfs_slab_add(struct kmem_cache *);
99988 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99989 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99990 @@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99991 if (!t->addr)
99992 return;
99993
99994 - pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99995 + pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99996 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99997 #ifdef CONFIG_STACKTRACE
99998 {
99999 @@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
100000
100001 slab_free_hook(s, x);
100002
100003 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100004 + if (!(s->flags & SLAB_NO_SANITIZE)) {
100005 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
100006 + if (s->ctor)
100007 + s->ctor(x);
100008 + }
100009 +#endif
100010 +
100011 redo:
100012 /*
100013 * Determine the currently cpus per cpu slab.
100014 @@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
100015 s->inuse = size;
100016
100017 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
100018 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100019 + (!(flags & SLAB_NO_SANITIZE)) ||
100020 +#endif
100021 s->ctor)) {
100022 /*
100023 * Relocate free pointer after the object if it is not
100024 @@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
100025 EXPORT_SYMBOL(__kmalloc_node);
100026 #endif
100027
100028 +bool is_usercopy_object(const void *ptr)
100029 +{
100030 + struct page *page;
100031 + struct kmem_cache *s;
100032 +
100033 + if (ZERO_OR_NULL_PTR(ptr))
100034 + return false;
100035 +
100036 + if (!slab_is_available())
100037 + return false;
100038 +
100039 + if (!virt_addr_valid(ptr))
100040 + return false;
100041 +
100042 + page = virt_to_head_page(ptr);
100043 +
100044 + if (!PageSlab(page))
100045 + return false;
100046 +
100047 + s = page->slab_cache;
100048 + return s->flags & SLAB_USERCOPY;
100049 +}
100050 +
100051 +#ifdef CONFIG_PAX_USERCOPY
100052 +const char *check_heap_object(const void *ptr, unsigned long n)
100053 +{
100054 + struct page *page;
100055 + struct kmem_cache *s;
100056 + unsigned long offset;
100057 +
100058 + if (ZERO_OR_NULL_PTR(ptr))
100059 + return "<null>";
100060 +
100061 + if (!virt_addr_valid(ptr))
100062 + return NULL;
100063 +
100064 + page = virt_to_head_page(ptr);
100065 +
100066 + if (!PageSlab(page))
100067 + return NULL;
100068 +
100069 + s = page->slab_cache;
100070 + if (!(s->flags & SLAB_USERCOPY))
100071 + return s->name;
100072 +
100073 + offset = (ptr - page_address(page)) % s->size;
100074 + if (offset <= s->object_size && n <= s->object_size - offset)
100075 + return NULL;
100076 +
100077 + return s->name;
100078 +}
100079 +#endif
100080 +
100081 size_t ksize(const void *object)
100082 {
100083 struct page *page;
100084 @@ -3329,6 +3393,7 @@ void kfree(const void *x)
100085 if (unlikely(ZERO_OR_NULL_PTR(x)))
100086 return;
100087
100088 + VM_BUG_ON(!virt_addr_valid(x));
100089 page = virt_to_head_page(x);
100090 if (unlikely(!PageSlab(page))) {
100091 BUG_ON(!PageCompound(page));
100092 @@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100093 int i;
100094 struct kmem_cache *c;
100095
100096 - s->refcount++;
100097 + atomic_inc(&s->refcount);
100098
100099 /*
100100 * Adjust the object sizes so that we clear
100101 @@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100102 }
100103
100104 if (sysfs_slab_alias(s, name)) {
100105 - s->refcount--;
100106 + atomic_dec(&s->refcount);
100107 s = NULL;
100108 }
100109 }
100110 @@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100111 }
100112 #endif
100113
100114 -#ifdef CONFIG_SYSFS
100115 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100116 static int count_inuse(struct page *page)
100117 {
100118 return page->inuse;
100119 @@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100120 len += sprintf(buf + len, "%7ld ", l->count);
100121
100122 if (l->addr)
100123 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100124 + len += sprintf(buf + len, "%pS", NULL);
100125 +#else
100126 len += sprintf(buf + len, "%pS", (void *)l->addr);
100127 +#endif
100128 else
100129 len += sprintf(buf + len, "<not-available>");
100130
100131 @@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
100132 validate_slab_cache(kmalloc_caches[9]);
100133 }
100134 #else
100135 -#ifdef CONFIG_SYSFS
100136 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100137 static void resiliency_test(void) {};
100138 #endif
100139 #endif
100140
100141 -#ifdef CONFIG_SYSFS
100142 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100143 enum slab_stat_type {
100144 SL_ALL, /* All slabs */
100145 SL_PARTIAL, /* Only partially allocated slabs */
100146 @@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100147 {
100148 if (!s->ctor)
100149 return 0;
100150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100151 + return sprintf(buf, "%pS\n", NULL);
100152 +#else
100153 return sprintf(buf, "%pS\n", s->ctor);
100154 +#endif
100155 }
100156 SLAB_ATTR_RO(ctor);
100157
100158 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100159 {
100160 - return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100161 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100162 }
100163 SLAB_ATTR_RO(aliases);
100164
100165 @@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100166 SLAB_ATTR_RO(cache_dma);
100167 #endif
100168
100169 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100170 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100171 +{
100172 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100173 +}
100174 +SLAB_ATTR_RO(usercopy);
100175 +#endif
100176 +
100177 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100178 +static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100179 +{
100180 + return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100181 +}
100182 +SLAB_ATTR_RO(sanitize);
100183 +#endif
100184 +
100185 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100186 {
100187 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100188 @@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
100189 * as well as cause other issues like converting a mergeable
100190 * cache into an umergeable one.
100191 */
100192 - if (s->refcount > 1)
100193 + if (atomic_read(&s->refcount) > 1)
100194 return -EINVAL;
100195
100196 s->flags &= ~SLAB_TRACE;
100197 @@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
100198 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
100199 size_t length)
100200 {
100201 - if (s->refcount > 1)
100202 + if (atomic_read(&s->refcount) > 1)
100203 return -EINVAL;
100204
100205 s->flags &= ~SLAB_FAILSLAB;
100206 @@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
100207 #ifdef CONFIG_ZONE_DMA
100208 &cache_dma_attr.attr,
100209 #endif
100210 +#ifdef CONFIG_PAX_USERCOPY_SLABS
100211 + &usercopy_attr.attr,
100212 +#endif
100213 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
100214 + &sanitize_attr.attr,
100215 +#endif
100216 #ifdef CONFIG_NUMA
100217 &remote_node_defrag_ratio_attr.attr,
100218 #endif
100219 @@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
100220 return name;
100221 }
100222
100223 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100224 static int sysfs_slab_add(struct kmem_cache *s)
100225 {
100226 int err;
100227 @@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100228 kobject_del(&s->kobj);
100229 kobject_put(&s->kobj);
100230 }
100231 +#endif
100232
100233 /*
100234 * Need to buffer aliases during bootup until sysfs becomes
100235 @@ -5154,6 +5251,7 @@ struct saved_alias {
100236
100237 static struct saved_alias *alias_list;
100238
100239 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100240 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100241 {
100242 struct saved_alias *al;
100243 @@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100244 alias_list = al;
100245 return 0;
100246 }
100247 +#endif
100248
100249 static int __init slab_sysfs_init(void)
100250 {
100251 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100252 index 4cba9c2..b4f9fcc 100644
100253 --- a/mm/sparse-vmemmap.c
100254 +++ b/mm/sparse-vmemmap.c
100255 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100256 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100257 if (!p)
100258 return NULL;
100259 - pud_populate(&init_mm, pud, p);
100260 + pud_populate_kernel(&init_mm, pud, p);
100261 }
100262 return pud;
100263 }
100264 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100265 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100266 if (!p)
100267 return NULL;
100268 - pgd_populate(&init_mm, pgd, p);
100269 + pgd_populate_kernel(&init_mm, pgd, p);
100270 }
100271 return pgd;
100272 }
100273 diff --git a/mm/sparse.c b/mm/sparse.c
100274 index d1b48b6..6e8590e 100644
100275 --- a/mm/sparse.c
100276 +++ b/mm/sparse.c
100277 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100278
100279 for (i = 0; i < PAGES_PER_SECTION; i++) {
100280 if (PageHWPoison(&memmap[i])) {
100281 - atomic_long_sub(1, &num_poisoned_pages);
100282 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
100283 ClearPageHWPoison(&memmap[i]);
100284 }
100285 }
100286 diff --git a/mm/swap.c b/mm/swap.c
100287 index 8a12b33..7068e78 100644
100288 --- a/mm/swap.c
100289 +++ b/mm/swap.c
100290 @@ -31,6 +31,7 @@
100291 #include <linux/memcontrol.h>
100292 #include <linux/gfp.h>
100293 #include <linux/uio.h>
100294 +#include <linux/hugetlb.h>
100295
100296 #include "internal.h"
100297
100298 @@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100299
100300 __page_cache_release(page);
100301 dtor = get_compound_page_dtor(page);
100302 + if (!PageHuge(page))
100303 + BUG_ON(dtor != free_compound_page);
100304 (*dtor)(page);
100305 }
100306
100307 diff --git a/mm/swapfile.c b/mm/swapfile.c
100308 index 8798b2e..348f9dd 100644
100309 --- a/mm/swapfile.c
100310 +++ b/mm/swapfile.c
100311 @@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100312
100313 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100314 /* Activity counter to indicate that a swapon or swapoff has occurred */
100315 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
100316 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100317
100318 static inline unsigned char swap_count(unsigned char ent)
100319 {
100320 @@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100321 spin_unlock(&swap_lock);
100322
100323 err = 0;
100324 - atomic_inc(&proc_poll_event);
100325 + atomic_inc_unchecked(&proc_poll_event);
100326 wake_up_interruptible(&proc_poll_wait);
100327
100328 out_dput:
100329 @@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100330
100331 poll_wait(file, &proc_poll_wait, wait);
100332
100333 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
100334 - seq->poll_event = atomic_read(&proc_poll_event);
100335 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100336 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100337 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100338 }
100339
100340 @@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100341 return ret;
100342
100343 seq = file->private_data;
100344 - seq->poll_event = atomic_read(&proc_poll_event);
100345 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100346 return 0;
100347 }
100348
100349 @@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100350 (frontswap_map) ? "FS" : "");
100351
100352 mutex_unlock(&swapon_mutex);
100353 - atomic_inc(&proc_poll_event);
100354 + atomic_inc_unchecked(&proc_poll_event);
100355 wake_up_interruptible(&proc_poll_wait);
100356
100357 if (S_ISREG(inode->i_mode))
100358 diff --git a/mm/util.c b/mm/util.c
100359 index fec39d4..3e60325 100644
100360 --- a/mm/util.c
100361 +++ b/mm/util.c
100362 @@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
100363 void arch_pick_mmap_layout(struct mm_struct *mm)
100364 {
100365 mm->mmap_base = TASK_UNMAPPED_BASE;
100366 +
100367 +#ifdef CONFIG_PAX_RANDMMAP
100368 + if (mm->pax_flags & MF_PAX_RANDMMAP)
100369 + mm->mmap_base += mm->delta_mmap;
100370 +#endif
100371 +
100372 mm->get_unmapped_area = arch_get_unmapped_area;
100373 }
100374 #endif
100375 @@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100376 if (!mm->arg_end)
100377 goto out_mm; /* Shh! No looking before we're done */
100378
100379 + if (gr_acl_handle_procpidmem(task))
100380 + goto out_mm;
100381 +
100382 len = mm->arg_end - mm->arg_start;
100383
100384 if (len > buflen)
100385 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100386 index 90520af..24231aa 100644
100387 --- a/mm/vmalloc.c
100388 +++ b/mm/vmalloc.c
100389 @@ -40,6 +40,21 @@ struct vfree_deferred {
100390 };
100391 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100392
100393 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100394 +struct stack_deferred_llist {
100395 + struct llist_head list;
100396 + void *stack;
100397 + void *lowmem_stack;
100398 +};
100399 +
100400 +struct stack_deferred {
100401 + struct stack_deferred_llist list;
100402 + struct work_struct wq;
100403 +};
100404 +
100405 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100406 +#endif
100407 +
100408 static void __vunmap(const void *, int);
100409
100410 static void free_work(struct work_struct *w)
100411 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100412 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100413 struct llist_node *llnode = llist_del_all(&p->list);
100414 while (llnode) {
100415 - void *p = llnode;
100416 + void *x = llnode;
100417 llnode = llist_next(llnode);
100418 - __vunmap(p, 1);
100419 + __vunmap(x, 1);
100420 }
100421 }
100422
100423 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100424 +static void unmap_work(struct work_struct *w)
100425 +{
100426 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100427 + struct llist_node *llnode = llist_del_all(&p->list.list);
100428 + while (llnode) {
100429 + struct stack_deferred_llist *x =
100430 + llist_entry((struct llist_head *)llnode,
100431 + struct stack_deferred_llist, list);
100432 + void *stack = ACCESS_ONCE(x->stack);
100433 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100434 + llnode = llist_next(llnode);
100435 + __vunmap(stack, 0);
100436 + free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100437 + }
100438 +}
100439 +#endif
100440 +
100441 /*** Page table manipulation functions ***/
100442
100443 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100444 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100445
100446 pte = pte_offset_kernel(pmd, addr);
100447 do {
100448 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100449 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100450 +
100451 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100452 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100453 + BUG_ON(!pte_exec(*pte));
100454 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100455 + continue;
100456 + }
100457 +#endif
100458 +
100459 + {
100460 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100461 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100462 + }
100463 } while (pte++, addr += PAGE_SIZE, addr != end);
100464 }
100465
100466 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100467 pte = pte_alloc_kernel(pmd, addr);
100468 if (!pte)
100469 return -ENOMEM;
100470 +
100471 + pax_open_kernel();
100472 do {
100473 struct page *page = pages[*nr];
100474
100475 - if (WARN_ON(!pte_none(*pte)))
100476 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100477 + if (pgprot_val(prot) & _PAGE_NX)
100478 +#endif
100479 +
100480 + if (!pte_none(*pte)) {
100481 + pax_close_kernel();
100482 + WARN_ON(1);
100483 return -EBUSY;
100484 - if (WARN_ON(!page))
100485 + }
100486 + if (!page) {
100487 + pax_close_kernel();
100488 + WARN_ON(1);
100489 return -ENOMEM;
100490 + }
100491 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100492 (*nr)++;
100493 } while (pte++, addr += PAGE_SIZE, addr != end);
100494 + pax_close_kernel();
100495 return 0;
100496 }
100497
100498 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100499 pmd_t *pmd;
100500 unsigned long next;
100501
100502 - pmd = pmd_alloc(&init_mm, pud, addr);
100503 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100504 if (!pmd)
100505 return -ENOMEM;
100506 do {
100507 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100508 pud_t *pud;
100509 unsigned long next;
100510
100511 - pud = pud_alloc(&init_mm, pgd, addr);
100512 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
100513 if (!pud)
100514 return -ENOMEM;
100515 do {
100516 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100517 if (addr >= MODULES_VADDR && addr < MODULES_END)
100518 return 1;
100519 #endif
100520 +
100521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100522 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100523 + return 1;
100524 +#endif
100525 +
100526 return is_vmalloc_addr(x);
100527 }
100528
100529 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100530
100531 if (!pgd_none(*pgd)) {
100532 pud_t *pud = pud_offset(pgd, addr);
100533 +#ifdef CONFIG_X86
100534 + if (!pud_large(*pud))
100535 +#endif
100536 if (!pud_none(*pud)) {
100537 pmd_t *pmd = pmd_offset(pud, addr);
100538 +#ifdef CONFIG_X86
100539 + if (!pmd_large(*pmd))
100540 +#endif
100541 if (!pmd_none(*pmd)) {
100542 pte_t *ptep, pte;
100543
100544 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100545 for_each_possible_cpu(i) {
100546 struct vmap_block_queue *vbq;
100547 struct vfree_deferred *p;
100548 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100549 + struct stack_deferred *p2;
100550 +#endif
100551
100552 vbq = &per_cpu(vmap_block_queue, i);
100553 spin_lock_init(&vbq->lock);
100554 INIT_LIST_HEAD(&vbq->free);
100555 +
100556 p = &per_cpu(vfree_deferred, i);
100557 init_llist_head(&p->list);
100558 INIT_WORK(&p->wq, free_work);
100559 +
100560 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100561 + p2 = &per_cpu(stack_deferred, i);
100562 + init_llist_head(&p2->list.list);
100563 + INIT_WORK(&p2->wq, unmap_work);
100564 +#endif
100565 }
100566
100567 /* Import existing vmlist entries. */
100568 @@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100569 struct vm_struct *area;
100570
100571 BUG_ON(in_interrupt());
100572 +
100573 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100574 + if (flags & VM_KERNEXEC) {
100575 + if (start != VMALLOC_START || end != VMALLOC_END)
100576 + return NULL;
100577 + start = (unsigned long)MODULES_EXEC_VADDR;
100578 + end = (unsigned long)MODULES_EXEC_END;
100579 + }
100580 +#endif
100581 +
100582 if (flags & VM_IOREMAP)
100583 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100584
100585 @@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100586 }
100587 EXPORT_SYMBOL(vunmap);
100588
100589 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100590 +void unmap_process_stacks(struct task_struct *task)
100591 +{
100592 + if (unlikely(in_interrupt())) {
100593 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100594 + struct stack_deferred_llist *list = task->stack;
100595 + list->stack = task->stack;
100596 + list->lowmem_stack = task->lowmem_stack;
100597 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
100598 + schedule_work(&p->wq);
100599 + } else {
100600 + __vunmap(task->stack, 0);
100601 + free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100602 + }
100603 +}
100604 +#endif
100605 +
100606 /**
100607 * vmap - map an array of pages into virtually contiguous space
100608 * @pages: array of page pointers
100609 @@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100610 if (count > totalram_pages)
100611 return NULL;
100612
100613 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100614 + if (!(pgprot_val(prot) & _PAGE_NX))
100615 + flags |= VM_KERNEXEC;
100616 +#endif
100617 +
100618 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100619 __builtin_return_address(0));
100620 if (!area)
100621 @@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100622 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100623 goto fail;
100624
100625 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100626 + if (!(pgprot_val(prot) & _PAGE_NX))
100627 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100628 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100629 + else
100630 +#endif
100631 +
100632 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100633 start, end, node, gfp_mask, caller);
100634 if (!area)
100635 @@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100636 * For tight control over page level allocator and protection flags
100637 * use __vmalloc() instead.
100638 */
100639 -
100640 void *vmalloc_exec(unsigned long size)
100641 {
100642 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100643 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100644 NUMA_NO_NODE, __builtin_return_address(0));
100645 }
100646
100647 @@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100648 {
100649 struct vm_struct *area;
100650
100651 + BUG_ON(vma->vm_mirror);
100652 +
100653 size = PAGE_ALIGN(size);
100654
100655 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100656 @@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100657 v->addr, v->addr + v->size, v->size);
100658
100659 if (v->caller)
100660 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100661 + seq_printf(m, " %pK", v->caller);
100662 +#else
100663 seq_printf(m, " %pS", v->caller);
100664 +#endif
100665
100666 if (v->nr_pages)
100667 seq_printf(m, " pages=%d", v->nr_pages);
100668 diff --git a/mm/vmstat.c b/mm/vmstat.c
100669 index 1b12d39..57b29b2 100644
100670 --- a/mm/vmstat.c
100671 +++ b/mm/vmstat.c
100672 @@ -22,6 +22,7 @@
100673 #include <linux/writeback.h>
100674 #include <linux/compaction.h>
100675 #include <linux/mm_inline.h>
100676 +#include <linux/grsecurity.h>
100677
100678 #include "internal.h"
100679
100680 @@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100681 *
100682 * vm_stat contains the global counters
100683 */
100684 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100685 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100686 EXPORT_SYMBOL(vm_stat);
100687
100688 #ifdef CONFIG_SMP
100689 @@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100690
100691 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100692 if (diff[i]) {
100693 - atomic_long_add(diff[i], &vm_stat[i]);
100694 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100695 changes++;
100696 }
100697 return changes;
100698 @@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100699 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100700 if (v) {
100701
100702 - atomic_long_add(v, &zone->vm_stat[i]);
100703 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100704 global_diff[i] += v;
100705 #ifdef CONFIG_NUMA
100706 /* 3 seconds idle till flush */
100707 @@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100708
100709 v = p->vm_stat_diff[i];
100710 p->vm_stat_diff[i] = 0;
100711 - atomic_long_add(v, &zone->vm_stat[i]);
100712 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100713 global_diff[i] += v;
100714 }
100715 }
100716 @@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100717 if (pset->vm_stat_diff[i]) {
100718 int v = pset->vm_stat_diff[i];
100719 pset->vm_stat_diff[i] = 0;
100720 - atomic_long_add(v, &zone->vm_stat[i]);
100721 - atomic_long_add(v, &vm_stat[i]);
100722 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100723 + atomic_long_add_unchecked(v, &vm_stat[i]);
100724 }
100725 }
100726 #endif
100727 @@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100728 stat_items_size += sizeof(struct vm_event_state);
100729 #endif
100730
100731 - v = kmalloc(stat_items_size, GFP_KERNEL);
100732 + v = kzalloc(stat_items_size, GFP_KERNEL);
100733 m->private = v;
100734 if (!v)
100735 return ERR_PTR(-ENOMEM);
100736 +
100737 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100738 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100739 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100740 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100741 + && !in_group_p(grsec_proc_gid)
100742 +#endif
100743 + )
100744 + return (unsigned long *)m->private + *pos;
100745 +#endif
100746 +#endif
100747 +
100748 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100749 v[i] = global_page_state(i);
100750 v += NR_VM_ZONE_STAT_ITEMS;
100751 @@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100752 cpu_notifier_register_done();
100753 #endif
100754 #ifdef CONFIG_PROC_FS
100755 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100756 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100757 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100758 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100759 + {
100760 + mode_t gr_mode = S_IRUGO;
100761 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
100762 + gr_mode = S_IRUSR;
100763 +#endif
100764 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100765 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100766 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100767 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100768 + }
100769 #endif
100770 return 0;
100771 }
100772 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100773 index 64c6bed..b79a5de 100644
100774 --- a/net/8021q/vlan.c
100775 +++ b/net/8021q/vlan.c
100776 @@ -481,7 +481,7 @@ out:
100777 return NOTIFY_DONE;
100778 }
100779
100780 -static struct notifier_block vlan_notifier_block __read_mostly = {
100781 +static struct notifier_block vlan_notifier_block = {
100782 .notifier_call = vlan_device_event,
100783 };
100784
100785 @@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100786 err = -EPERM;
100787 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100788 break;
100789 - if ((args.u.name_type >= 0) &&
100790 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100791 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100792 struct vlan_net *vn;
100793
100794 vn = net_generic(net, vlan_net_id);
100795 diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100796 index 8ac8a5c..991defc 100644
100797 --- a/net/8021q/vlan_netlink.c
100798 +++ b/net/8021q/vlan_netlink.c
100799 @@ -238,7 +238,7 @@ nla_put_failure:
100800 return -EMSGSIZE;
100801 }
100802
100803 -struct rtnl_link_ops vlan_link_ops __read_mostly = {
100804 +struct rtnl_link_ops vlan_link_ops = {
100805 .kind = "vlan",
100806 .maxtype = IFLA_VLAN_MAX,
100807 .policy = vlan_policy,
100808 diff --git a/net/9p/client.c b/net/9p/client.c
100809 index e86a9bea..e91f70e 100644
100810 --- a/net/9p/client.c
100811 +++ b/net/9p/client.c
100812 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100813 len - inline_len);
100814 } else {
100815 err = copy_from_user(ename + inline_len,
100816 - uidata, len - inline_len);
100817 + (char __force_user *)uidata, len - inline_len);
100818 if (err) {
100819 err = -EFAULT;
100820 goto out_err;
100821 @@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100822 kernel_buf = 1;
100823 indata = data;
100824 } else
100825 - indata = (__force char *)udata;
100826 + indata = (__force_kernel char *)udata;
100827 /*
100828 * response header len is 11
100829 * PDU Header(7) + IO Size (4)
100830 @@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100831 kernel_buf = 1;
100832 odata = data;
100833 } else
100834 - odata = (char *)udata;
100835 + odata = (char __force_kernel *)udata;
100836 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100837 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100838 fid->fid, offset, rsize);
100839 diff --git a/net/9p/mod.c b/net/9p/mod.c
100840 index 6ab36ae..6f1841b 100644
100841 --- a/net/9p/mod.c
100842 +++ b/net/9p/mod.c
100843 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100844 void v9fs_register_trans(struct p9_trans_module *m)
100845 {
100846 spin_lock(&v9fs_trans_lock);
100847 - list_add_tail(&m->list, &v9fs_trans_list);
100848 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100849 spin_unlock(&v9fs_trans_lock);
100850 }
100851 EXPORT_SYMBOL(v9fs_register_trans);
100852 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100853 void v9fs_unregister_trans(struct p9_trans_module *m)
100854 {
100855 spin_lock(&v9fs_trans_lock);
100856 - list_del_init(&m->list);
100857 + pax_list_del_init((struct list_head *)&m->list);
100858 spin_unlock(&v9fs_trans_lock);
100859 }
100860 EXPORT_SYMBOL(v9fs_unregister_trans);
100861 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100862 index 80d08f6..de63fd1 100644
100863 --- a/net/9p/trans_fd.c
100864 +++ b/net/9p/trans_fd.c
100865 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100866 oldfs = get_fs();
100867 set_fs(get_ds());
100868 /* The cast to a user pointer is valid due to the set_fs() */
100869 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100870 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100871 set_fs(oldfs);
100872
100873 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100874 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100875 index af46bc4..f9adfcd 100644
100876 --- a/net/appletalk/atalk_proc.c
100877 +++ b/net/appletalk/atalk_proc.c
100878 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100879 struct proc_dir_entry *p;
100880 int rc = -ENOMEM;
100881
100882 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100883 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100884 if (!atalk_proc_dir)
100885 goto out;
100886
100887 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100888 index 876fbe8..8bbea9f 100644
100889 --- a/net/atm/atm_misc.c
100890 +++ b/net/atm/atm_misc.c
100891 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100892 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100893 return 1;
100894 atm_return(vcc, truesize);
100895 - atomic_inc(&vcc->stats->rx_drop);
100896 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100897 return 0;
100898 }
100899 EXPORT_SYMBOL(atm_charge);
100900 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100901 }
100902 }
100903 atm_return(vcc, guess);
100904 - atomic_inc(&vcc->stats->rx_drop);
100905 + atomic_inc_unchecked(&vcc->stats->rx_drop);
100906 return NULL;
100907 }
100908 EXPORT_SYMBOL(atm_alloc_charge);
100909 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100910
100911 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100912 {
100913 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100914 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100915 __SONET_ITEMS
100916 #undef __HANDLE_ITEM
100917 }
100918 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100919
100920 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100921 {
100922 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100923 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100924 __SONET_ITEMS
100925 #undef __HANDLE_ITEM
100926 }
100927 diff --git a/net/atm/lec.c b/net/atm/lec.c
100928 index 4b98f89..5a2f6cb 100644
100929 --- a/net/atm/lec.c
100930 +++ b/net/atm/lec.c
100931 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100932 }
100933
100934 static struct lane2_ops lane2_ops = {
100935 - lane2_resolve, /* resolve, spec 3.1.3 */
100936 - lane2_associate_req, /* associate_req, spec 3.1.4 */
100937 - NULL /* associate indicator, spec 3.1.5 */
100938 + .resolve = lane2_resolve,
100939 + .associate_req = lane2_associate_req,
100940 + .associate_indicator = NULL
100941 };
100942
100943 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100944 diff --git a/net/atm/lec.h b/net/atm/lec.h
100945 index 4149db1..f2ab682 100644
100946 --- a/net/atm/lec.h
100947 +++ b/net/atm/lec.h
100948 @@ -48,7 +48,7 @@ struct lane2_ops {
100949 const u8 *tlvs, u32 sizeoftlvs);
100950 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100951 const u8 *tlvs, u32 sizeoftlvs);
100952 -};
100953 +} __no_const;
100954
100955 /*
100956 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100957 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100958 index d1b2d9a..d549f7f 100644
100959 --- a/net/atm/mpoa_caches.c
100960 +++ b/net/atm/mpoa_caches.c
100961 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100962
100963
100964 static struct in_cache_ops ingress_ops = {
100965 - in_cache_add_entry, /* add_entry */
100966 - in_cache_get, /* get */
100967 - in_cache_get_with_mask, /* get_with_mask */
100968 - in_cache_get_by_vcc, /* get_by_vcc */
100969 - in_cache_put, /* put */
100970 - in_cache_remove_entry, /* remove_entry */
100971 - cache_hit, /* cache_hit */
100972 - clear_count_and_expired, /* clear_count */
100973 - check_resolving_entries, /* check_resolving */
100974 - refresh_entries, /* refresh */
100975 - in_destroy_cache /* destroy_cache */
100976 + .add_entry = in_cache_add_entry,
100977 + .get = in_cache_get,
100978 + .get_with_mask = in_cache_get_with_mask,
100979 + .get_by_vcc = in_cache_get_by_vcc,
100980 + .put = in_cache_put,
100981 + .remove_entry = in_cache_remove_entry,
100982 + .cache_hit = cache_hit,
100983 + .clear_count = clear_count_and_expired,
100984 + .check_resolving = check_resolving_entries,
100985 + .refresh = refresh_entries,
100986 + .destroy_cache = in_destroy_cache
100987 };
100988
100989 static struct eg_cache_ops egress_ops = {
100990 - eg_cache_add_entry, /* add_entry */
100991 - eg_cache_get_by_cache_id, /* get_by_cache_id */
100992 - eg_cache_get_by_tag, /* get_by_tag */
100993 - eg_cache_get_by_vcc, /* get_by_vcc */
100994 - eg_cache_get_by_src_ip, /* get_by_src_ip */
100995 - eg_cache_put, /* put */
100996 - eg_cache_remove_entry, /* remove_entry */
100997 - update_eg_cache_entry, /* update */
100998 - clear_expired, /* clear_expired */
100999 - eg_destroy_cache /* destroy_cache */
101000 + .add_entry = eg_cache_add_entry,
101001 + .get_by_cache_id = eg_cache_get_by_cache_id,
101002 + .get_by_tag = eg_cache_get_by_tag,
101003 + .get_by_vcc = eg_cache_get_by_vcc,
101004 + .get_by_src_ip = eg_cache_get_by_src_ip,
101005 + .put = eg_cache_put,
101006 + .remove_entry = eg_cache_remove_entry,
101007 + .update = update_eg_cache_entry,
101008 + .clear_expired = clear_expired,
101009 + .destroy_cache = eg_destroy_cache
101010 };
101011
101012
101013 diff --git a/net/atm/proc.c b/net/atm/proc.c
101014 index bbb6461..cf04016 100644
101015 --- a/net/atm/proc.c
101016 +++ b/net/atm/proc.c
101017 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
101018 const struct k_atm_aal_stats *stats)
101019 {
101020 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
101021 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
101022 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
101023 - atomic_read(&stats->rx_drop));
101024 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
101025 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
101026 + atomic_read_unchecked(&stats->rx_drop));
101027 }
101028
101029 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
101030 diff --git a/net/atm/resources.c b/net/atm/resources.c
101031 index 0447d5d..3cf4728 100644
101032 --- a/net/atm/resources.c
101033 +++ b/net/atm/resources.c
101034 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
101035 static void copy_aal_stats(struct k_atm_aal_stats *from,
101036 struct atm_aal_stats *to)
101037 {
101038 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101039 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101040 __AAL_STAT_ITEMS
101041 #undef __HANDLE_ITEM
101042 }
101043 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
101044 static void subtract_aal_stats(struct k_atm_aal_stats *from,
101045 struct atm_aal_stats *to)
101046 {
101047 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101048 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
101049 __AAL_STAT_ITEMS
101050 #undef __HANDLE_ITEM
101051 }
101052 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
101053 index 919a5ce..cc6b444 100644
101054 --- a/net/ax25/sysctl_net_ax25.c
101055 +++ b/net/ax25/sysctl_net_ax25.c
101056 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
101057 {
101058 char path[sizeof("net/ax25/") + IFNAMSIZ];
101059 int k;
101060 - struct ctl_table *table;
101061 + ctl_table_no_const *table;
101062
101063 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
101064 if (!table)
101065 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
101066 index 1e80539..676c37a 100644
101067 --- a/net/batman-adv/bat_iv_ogm.c
101068 +++ b/net/batman-adv/bat_iv_ogm.c
101069 @@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
101070
101071 /* randomize initial seqno to avoid collision */
101072 get_random_bytes(&random_seqno, sizeof(random_seqno));
101073 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101074 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101075
101076 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
101077 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
101078 @@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
101079 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
101080
101081 /* change sequence number to network order */
101082 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
101083 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
101084 batadv_ogm_packet->seqno = htonl(seqno);
101085 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
101086 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
101087
101088 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
101089
101090 @@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
101091 return;
101092
101093 /* could be changed by schedule_own_packet() */
101094 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
101095 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
101096
101097 if (ogm_packet->flags & BATADV_DIRECTLINK)
101098 has_directlink_flag = true;
101099 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
101100 index 00f9e14..e1c7203 100644
101101 --- a/net/batman-adv/fragmentation.c
101102 +++ b/net/batman-adv/fragmentation.c
101103 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101104 frag_header.packet_type = BATADV_UNICAST_FRAG;
101105 frag_header.version = BATADV_COMPAT_VERSION;
101106 frag_header.ttl = BATADV_TTL;
101107 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101108 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101109 frag_header.reserved = 0;
101110 frag_header.no = 0;
101111 frag_header.total_size = htons(skb->len);
101112 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101113 index 5467955..75ad4e3 100644
101114 --- a/net/batman-adv/soft-interface.c
101115 +++ b/net/batman-adv/soft-interface.c
101116 @@ -296,7 +296,7 @@ send:
101117 primary_if->net_dev->dev_addr);
101118
101119 /* set broadcast sequence number */
101120 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101121 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101122 bcast_packet->seqno = htonl(seqno);
101123
101124 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101125 @@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101126 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101127
101128 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101129 - atomic_set(&bat_priv->bcast_seqno, 1);
101130 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101131 atomic_set(&bat_priv->tt.vn, 0);
101132 atomic_set(&bat_priv->tt.local_changes, 0);
101133 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101134 @@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101135
101136 /* randomize initial seqno to avoid collision */
101137 get_random_bytes(&random_seqno, sizeof(random_seqno));
101138 - atomic_set(&bat_priv->frag_seqno, random_seqno);
101139 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101140
101141 bat_priv->primary_if = NULL;
101142 bat_priv->num_ifaces = 0;
101143 @@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
101144 return 0;
101145 }
101146
101147 -struct rtnl_link_ops batadv_link_ops __read_mostly = {
101148 +struct rtnl_link_ops batadv_link_ops = {
101149 .kind = "batadv",
101150 .priv_size = sizeof(struct batadv_priv),
101151 .setup = batadv_softif_init_early,
101152 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101153 index 8854c05..ee5d5497 100644
101154 --- a/net/batman-adv/types.h
101155 +++ b/net/batman-adv/types.h
101156 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101157 struct batadv_hard_iface_bat_iv {
101158 unsigned char *ogm_buff;
101159 int ogm_buff_len;
101160 - atomic_t ogm_seqno;
101161 + atomic_unchecked_t ogm_seqno;
101162 };
101163
101164 /**
101165 @@ -768,7 +768,7 @@ struct batadv_priv {
101166 atomic_t bonding;
101167 atomic_t fragmentation;
101168 atomic_t packet_size_max;
101169 - atomic_t frag_seqno;
101170 + atomic_unchecked_t frag_seqno;
101171 #ifdef CONFIG_BATMAN_ADV_BLA
101172 atomic_t bridge_loop_avoidance;
101173 #endif
101174 @@ -787,7 +787,7 @@ struct batadv_priv {
101175 #endif
101176 uint32_t isolation_mark;
101177 uint32_t isolation_mark_mask;
101178 - atomic_t bcast_seqno;
101179 + atomic_unchecked_t bcast_seqno;
101180 atomic_t bcast_queue_left;
101181 atomic_t batman_queue_left;
101182 char num_ifaces;
101183 diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
101184 index cfbb39e..0bbfc9d 100644
101185 --- a/net/bluetooth/6lowpan.c
101186 +++ b/net/bluetooth/6lowpan.c
101187 @@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
101188
101189 drop:
101190 dev->stats.rx_dropped++;
101191 - kfree_skb(skb);
101192 return NET_RX_DROP;
101193 }
101194
101195 diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
101196 index 85bcc21..ce82722d 100644
101197 --- a/net/bluetooth/bnep/core.c
101198 +++ b/net/bluetooth/bnep/core.c
101199 @@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
101200
101201 BT_DBG("");
101202
101203 + if (!l2cap_is_socket(sock))
101204 + return -EBADFD;
101205 +
101206 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
101207 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
101208
101209 diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
101210 index 67fe5e8..278a194 100644
101211 --- a/net/bluetooth/cmtp/core.c
101212 +++ b/net/bluetooth/cmtp/core.c
101213 @@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
101214
101215 BT_DBG("");
101216
101217 + if (!l2cap_is_socket(sock))
101218 + return -EBADFD;
101219 +
101220 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
101221 if (!session)
101222 return -ENOMEM;
101223 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101224 index 115f149..f0ba286 100644
101225 --- a/net/bluetooth/hci_sock.c
101226 +++ b/net/bluetooth/hci_sock.c
101227 @@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101228 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101229 }
101230
101231 - len = min_t(unsigned int, len, sizeof(uf));
101232 + len = min((size_t)len, sizeof(uf));
101233 if (copy_from_user(&uf, optval, len)) {
101234 err = -EFAULT;
101235 break;
101236 diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
101237 index 1b7d605..02ebd10 100644
101238 --- a/net/bluetooth/hidp/core.c
101239 +++ b/net/bluetooth/hidp/core.c
101240 @@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
101241 {
101242 struct hidp_session *session;
101243 struct l2cap_conn *conn;
101244 - struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
101245 + struct l2cap_chan *chan;
101246 int ret;
101247
101248 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
101249 if (ret)
101250 return ret;
101251
101252 + chan = l2cap_pi(ctrl_sock->sk)->chan;
101253 conn = NULL;
101254 l2cap_chan_lock(chan);
101255 if (chan->conn)
101256 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101257 index b6f9777..36d3039 100644
101258 --- a/net/bluetooth/l2cap_core.c
101259 +++ b/net/bluetooth/l2cap_core.c
101260 @@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101261 break;
101262
101263 case L2CAP_CONF_RFC:
101264 - if (olen == sizeof(rfc))
101265 - memcpy(&rfc, (void *)val, olen);
101266 + if (olen != sizeof(rfc))
101267 + break;
101268 +
101269 + memcpy(&rfc, (void *)val, olen);
101270
101271 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101272 rfc.mode != chan->mode)
101273 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101274 index 31f106e..323f606 100644
101275 --- a/net/bluetooth/l2cap_sock.c
101276 +++ b/net/bluetooth/l2cap_sock.c
101277 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101278 struct sock *sk = sock->sk;
101279 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101280 struct l2cap_options opts;
101281 - int len, err = 0;
101282 + int err = 0;
101283 + size_t len = optlen;
101284 u32 opt;
101285
101286 BT_DBG("sk %p", sk);
101287 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101288 opts.max_tx = chan->max_tx;
101289 opts.txwin_size = chan->tx_win;
101290
101291 - len = min_t(unsigned int, sizeof(opts), optlen);
101292 + len = min(sizeof(opts), len);
101293 if (copy_from_user((char *) &opts, optval, len)) {
101294 err = -EFAULT;
101295 break;
101296 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101297 struct bt_security sec;
101298 struct bt_power pwr;
101299 struct l2cap_conn *conn;
101300 - int len, err = 0;
101301 + int err = 0;
101302 + size_t len = optlen;
101303 u32 opt;
101304
101305 BT_DBG("sk %p", sk);
101306 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101307
101308 sec.level = BT_SECURITY_LOW;
101309
101310 - len = min_t(unsigned int, sizeof(sec), optlen);
101311 + len = min(sizeof(sec), len);
101312 if (copy_from_user((char *) &sec, optval, len)) {
101313 err = -EFAULT;
101314 break;
101315 @@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101316
101317 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101318
101319 - len = min_t(unsigned int, sizeof(pwr), optlen);
101320 + len = min(sizeof(pwr), len);
101321 if (copy_from_user((char *) &pwr, optval, len)) {
101322 err = -EFAULT;
101323 break;
101324 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101325 index 8bbbb5e..6fc0950 100644
101326 --- a/net/bluetooth/rfcomm/sock.c
101327 +++ b/net/bluetooth/rfcomm/sock.c
101328 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101329 struct sock *sk = sock->sk;
101330 struct bt_security sec;
101331 int err = 0;
101332 - size_t len;
101333 + size_t len = optlen;
101334 u32 opt;
101335
101336 BT_DBG("sk %p", sk);
101337 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101338
101339 sec.level = BT_SECURITY_LOW;
101340
101341 - len = min_t(unsigned int, sizeof(sec), optlen);
101342 + len = min(sizeof(sec), len);
101343 if (copy_from_user((char *) &sec, optval, len)) {
101344 err = -EFAULT;
101345 break;
101346 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101347 index 8e385a0..a5bdd8e 100644
101348 --- a/net/bluetooth/rfcomm/tty.c
101349 +++ b/net/bluetooth/rfcomm/tty.c
101350 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101351 BT_DBG("tty %p id %d", tty, tty->index);
101352
101353 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101354 - dev->channel, dev->port.count);
101355 + dev->channel, atomic_read(&dev->port.count));
101356
101357 err = tty_port_open(&dev->port, tty, filp);
101358 if (err)
101359 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101360 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101361
101362 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101363 - dev->port.count);
101364 + atomic_read(&dev->port.count));
101365
101366 tty_port_close(&dev->port, tty, filp);
101367 }
101368 diff --git a/net/bridge/br.c b/net/bridge/br.c
101369 index 44425af..4ee730e 100644
101370 --- a/net/bridge/br.c
101371 +++ b/net/bridge/br.c
101372 @@ -147,6 +147,8 @@ static int __init br_init(void)
101373 {
101374 int err;
101375
101376 + BUILD_BUG_ON(sizeof(struct br_input_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb));
101377 +
101378 err = stp_proto_register(&br_stp_proto);
101379 if (err < 0) {
101380 pr_err("bridge: can't register sap for STP\n");
101381 diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101382 index e5ec470..cbfabd1 100644
101383 --- a/net/bridge/br_netlink.c
101384 +++ b/net/bridge/br_netlink.c
101385 @@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
101386 .get_link_af_size = br_get_link_af_size,
101387 };
101388
101389 -struct rtnl_link_ops br_link_ops __read_mostly = {
101390 +struct rtnl_link_ops br_link_ops = {
101391 .kind = "bridge",
101392 .priv_size = sizeof(struct net_bridge),
101393 .setup = br_dev_setup,
101394 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101395 index d9a8c05..8dadc6c6 100644
101396 --- a/net/bridge/netfilter/ebtables.c
101397 +++ b/net/bridge/netfilter/ebtables.c
101398 @@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101399 tmp.valid_hooks = t->table->valid_hooks;
101400 }
101401 mutex_unlock(&ebt_mutex);
101402 - if (copy_to_user(user, &tmp, *len) != 0) {
101403 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101404 BUGPRINT("c2u Didn't work\n");
101405 ret = -EFAULT;
101406 break;
101407 @@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101408 goto out;
101409 tmp.valid_hooks = t->valid_hooks;
101410
101411 - if (copy_to_user(user, &tmp, *len) != 0) {
101412 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101413 ret = -EFAULT;
101414 break;
101415 }
101416 @@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101417 tmp.entries_size = t->table->entries_size;
101418 tmp.valid_hooks = t->table->valid_hooks;
101419
101420 - if (copy_to_user(user, &tmp, *len) != 0) {
101421 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101422 ret = -EFAULT;
101423 break;
101424 }
101425 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101426 index f5afda1..dcf770a 100644
101427 --- a/net/caif/cfctrl.c
101428 +++ b/net/caif/cfctrl.c
101429 @@ -10,6 +10,7 @@
101430 #include <linux/spinlock.h>
101431 #include <linux/slab.h>
101432 #include <linux/pkt_sched.h>
101433 +#include <linux/sched.h>
101434 #include <net/caif/caif_layer.h>
101435 #include <net/caif/cfpkt.h>
101436 #include <net/caif/cfctrl.h>
101437 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101438 memset(&dev_info, 0, sizeof(dev_info));
101439 dev_info.id = 0xff;
101440 cfsrvl_init(&this->serv, 0, &dev_info, false);
101441 - atomic_set(&this->req_seq_no, 1);
101442 - atomic_set(&this->rsp_seq_no, 1);
101443 + atomic_set_unchecked(&this->req_seq_no, 1);
101444 + atomic_set_unchecked(&this->rsp_seq_no, 1);
101445 this->serv.layer.receive = cfctrl_recv;
101446 sprintf(this->serv.layer.name, "ctrl");
101447 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101448 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101449 struct cfctrl_request_info *req)
101450 {
101451 spin_lock_bh(&ctrl->info_list_lock);
101452 - atomic_inc(&ctrl->req_seq_no);
101453 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
101454 + atomic_inc_unchecked(&ctrl->req_seq_no);
101455 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101456 list_add_tail(&req->list, &ctrl->list);
101457 spin_unlock_bh(&ctrl->info_list_lock);
101458 }
101459 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101460 if (p != first)
101461 pr_warn("Requests are not received in order\n");
101462
101463 - atomic_set(&ctrl->rsp_seq_no,
101464 + atomic_set_unchecked(&ctrl->rsp_seq_no,
101465 p->sequence_no);
101466 list_del(&p->list);
101467 goto out;
101468 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101469 index 4589ff67..46d6b8f 100644
101470 --- a/net/caif/chnl_net.c
101471 +++ b/net/caif/chnl_net.c
101472 @@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101473 };
101474
101475
101476 -static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101477 +static struct rtnl_link_ops ipcaif_link_ops = {
101478 .kind = "caif",
101479 .priv_size = sizeof(struct chnl_net),
101480 .setup = ipcaif_net_setup,
101481 diff --git a/net/can/af_can.c b/net/can/af_can.c
101482 index ce82337..5d17b4d 100644
101483 --- a/net/can/af_can.c
101484 +++ b/net/can/af_can.c
101485 @@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101486 };
101487
101488 /* notifier block for netdevice event */
101489 -static struct notifier_block can_netdev_notifier __read_mostly = {
101490 +static struct notifier_block can_netdev_notifier = {
101491 .notifier_call = can_notifier,
101492 };
101493
101494 diff --git a/net/can/bcm.c b/net/can/bcm.c
101495 index dcb75c0..24b1b43 100644
101496 --- a/net/can/bcm.c
101497 +++ b/net/can/bcm.c
101498 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101499 }
101500
101501 /* create /proc/net/can-bcm directory */
101502 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101503 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101504 return 0;
101505 }
101506
101507 diff --git a/net/can/gw.c b/net/can/gw.c
101508 index 050a211..bb9fe33 100644
101509 --- a/net/can/gw.c
101510 +++ b/net/can/gw.c
101511 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101512 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101513
101514 static HLIST_HEAD(cgw_list);
101515 -static struct notifier_block notifier;
101516
101517 static struct kmem_cache *cgw_cache __read_mostly;
101518
101519 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101520 return err;
101521 }
101522
101523 +static struct notifier_block notifier = {
101524 + .notifier_call = cgw_notifier
101525 +};
101526 +
101527 static __init int cgw_module_init(void)
101528 {
101529 /* sanitize given module parameter */
101530 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101531 return -ENOMEM;
101532
101533 /* set notifier */
101534 - notifier.notifier_call = cgw_notifier;
101535 register_netdevice_notifier(&notifier);
101536
101537 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101538 diff --git a/net/can/proc.c b/net/can/proc.c
101539 index 1a19b98..df2b4ec 100644
101540 --- a/net/can/proc.c
101541 +++ b/net/can/proc.c
101542 @@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101543 void can_init_proc(void)
101544 {
101545 /* create /proc/net/can directory */
101546 - can_dir = proc_mkdir("can", init_net.proc_net);
101547 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101548
101549 if (!can_dir) {
101550 printk(KERN_INFO "can: failed to create /proc/net/can . "
101551 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101552 index 8d1653c..77ad145 100644
101553 --- a/net/ceph/messenger.c
101554 +++ b/net/ceph/messenger.c
101555 @@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101556 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101557
101558 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101559 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
101560 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101561
101562 static struct page *zero_page; /* used in certain error cases */
101563
101564 @@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101565 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101566 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101567
101568 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101569 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101570 s = addr_str[i];
101571
101572 switch (ss->ss_family) {
101573 diff --git a/net/compat.c b/net/compat.c
101574 index bc8aeef..f9c070c 100644
101575 --- a/net/compat.c
101576 +++ b/net/compat.c
101577 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101578 return -EFAULT;
101579 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101580 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101581 - kmsg->msg_name = compat_ptr(tmp1);
101582 - kmsg->msg_iov = compat_ptr(tmp2);
101583 - kmsg->msg_control = compat_ptr(tmp3);
101584 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101585 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101586 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101587 return 0;
101588 }
101589
101590 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101591
101592 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101593 if (mode == VERIFY_READ) {
101594 - int err = move_addr_to_kernel(kern_msg->msg_name,
101595 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101596 kern_msg->msg_namelen,
101597 kern_address);
101598 if (err < 0)
101599 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101600 }
101601
101602 tot_len = iov_from_user_compat_to_kern(kern_iov,
101603 - (struct compat_iovec __user *)kern_msg->msg_iov,
101604 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
101605 kern_msg->msg_iovlen);
101606 if (tot_len >= 0)
101607 kern_msg->msg_iov = kern_iov;
101608 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101609
101610 #define CMSG_COMPAT_FIRSTHDR(msg) \
101611 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101612 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101613 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101614 (struct compat_cmsghdr __user *)NULL)
101615
101616 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101617 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101618 (ucmlen) <= (unsigned long) \
101619 ((mhdr)->msg_controllen - \
101620 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101621 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101622
101623 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101624 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101625 {
101626 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101627 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101628 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101629 msg->msg_controllen)
101630 return NULL;
101631 return (struct compat_cmsghdr __user *)ptr;
101632 @@ -223,7 +223,7 @@ Efault:
101633
101634 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101635 {
101636 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101637 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101638 struct compat_cmsghdr cmhdr;
101639 struct compat_timeval ctv;
101640 struct compat_timespec cts[3];
101641 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101642
101643 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101644 {
101645 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101646 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101647 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101648 int fdnum = scm->fp->count;
101649 struct file **fp = scm->fp->fp;
101650 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101651 return -EFAULT;
101652 old_fs = get_fs();
101653 set_fs(KERNEL_DS);
101654 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101655 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101656 set_fs(old_fs);
101657
101658 return err;
101659 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101660 len = sizeof(ktime);
101661 old_fs = get_fs();
101662 set_fs(KERNEL_DS);
101663 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101664 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101665 set_fs(old_fs);
101666
101667 if (!err) {
101668 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101669 case MCAST_JOIN_GROUP:
101670 case MCAST_LEAVE_GROUP:
101671 {
101672 - struct compat_group_req __user *gr32 = (void *)optval;
101673 + struct compat_group_req __user *gr32 = (void __user *)optval;
101674 struct group_req __user *kgr =
101675 compat_alloc_user_space(sizeof(struct group_req));
101676 u32 interface;
101677 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101678 case MCAST_BLOCK_SOURCE:
101679 case MCAST_UNBLOCK_SOURCE:
101680 {
101681 - struct compat_group_source_req __user *gsr32 = (void *)optval;
101682 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101683 struct group_source_req __user *kgsr = compat_alloc_user_space(
101684 sizeof(struct group_source_req));
101685 u32 interface;
101686 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101687 }
101688 case MCAST_MSFILTER:
101689 {
101690 - struct compat_group_filter __user *gf32 = (void *)optval;
101691 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101692 struct group_filter __user *kgf;
101693 u32 interface, fmode, numsrc;
101694
101695 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101696 char __user *optval, int __user *optlen,
101697 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101698 {
101699 - struct compat_group_filter __user *gf32 = (void *)optval;
101700 + struct compat_group_filter __user *gf32 = (void __user *)optval;
101701 struct group_filter __user *kgf;
101702 int __user *koptlen;
101703 u32 interface, fmode, numsrc;
101704 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101705
101706 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101707 return -EINVAL;
101708 - if (copy_from_user(a, args, nas[call]))
101709 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101710 return -EFAULT;
101711 a0 = a[0];
101712 a1 = a[1];
101713 diff --git a/net/core/datagram.c b/net/core/datagram.c
101714 index fdbc9a8..cd6972c 100644
101715 --- a/net/core/datagram.c
101716 +++ b/net/core/datagram.c
101717 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101718 }
101719
101720 kfree_skb(skb);
101721 - atomic_inc(&sk->sk_drops);
101722 + atomic_inc_unchecked(&sk->sk_drops);
101723 sk_mem_reclaim_partial(sk);
101724
101725 return err;
101726 diff --git a/net/core/dev.c b/net/core/dev.c
101727 index 9704a5c..1f363d0d 100644
101728 --- a/net/core/dev.c
101729 +++ b/net/core/dev.c
101730 @@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101731 {
101732 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101733 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101734 - atomic_long_inc(&dev->rx_dropped);
101735 + atomic_long_inc_unchecked(&dev->rx_dropped);
101736 kfree_skb(skb);
101737 return NET_RX_DROP;
101738 }
101739 }
101740
101741 if (unlikely(!is_skb_forwardable(dev, skb))) {
101742 - atomic_long_inc(&dev->rx_dropped);
101743 + atomic_long_inc_unchecked(&dev->rx_dropped);
101744 kfree_skb(skb);
101745 return NET_RX_DROP;
101746 }
101747 @@ -2994,7 +2994,7 @@ recursion_alert:
101748 drop:
101749 rcu_read_unlock_bh();
101750
101751 - atomic_long_inc(&dev->tx_dropped);
101752 + atomic_long_inc_unchecked(&dev->tx_dropped);
101753 kfree_skb_list(skb);
101754 return rc;
101755 out:
101756 @@ -3337,7 +3337,7 @@ enqueue:
101757
101758 local_irq_restore(flags);
101759
101760 - atomic_long_inc(&skb->dev->rx_dropped);
101761 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101762 kfree_skb(skb);
101763 return NET_RX_DROP;
101764 }
101765 @@ -3414,7 +3414,7 @@ int netif_rx_ni(struct sk_buff *skb)
101766 }
101767 EXPORT_SYMBOL(netif_rx_ni);
101768
101769 -static void net_tx_action(struct softirq_action *h)
101770 +static __latent_entropy void net_tx_action(void)
101771 {
101772 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101773
101774 @@ -3747,7 +3747,7 @@ ncls:
101775 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101776 } else {
101777 drop:
101778 - atomic_long_inc(&skb->dev->rx_dropped);
101779 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101780 kfree_skb(skb);
101781 /* Jamal, now you will not able to escape explaining
101782 * me how you were going to use this. :-)
101783 @@ -4511,7 +4511,7 @@ void netif_napi_del(struct napi_struct *napi)
101784 }
101785 EXPORT_SYMBOL(netif_napi_del);
101786
101787 -static void net_rx_action(struct softirq_action *h)
101788 +static __latent_entropy void net_rx_action(void)
101789 {
101790 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101791 unsigned long time_limit = jiffies + 2;
101792 @@ -5247,7 +5247,7 @@ void netdev_upper_dev_unlink(struct net_device *dev,
101793 }
101794 EXPORT_SYMBOL(netdev_upper_dev_unlink);
101795
101796 -void netdev_adjacent_add_links(struct net_device *dev)
101797 +static void netdev_adjacent_add_links(struct net_device *dev)
101798 {
101799 struct netdev_adjacent *iter;
101800
101801 @@ -5272,7 +5272,7 @@ void netdev_adjacent_add_links(struct net_device *dev)
101802 }
101803 }
101804
101805 -void netdev_adjacent_del_links(struct net_device *dev)
101806 +static void netdev_adjacent_del_links(struct net_device *dev)
101807 {
101808 struct netdev_adjacent *iter;
101809
101810 @@ -6557,8 +6557,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101811 } else {
101812 netdev_stats_to_stats64(storage, &dev->stats);
101813 }
101814 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101815 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101816 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101817 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101818 return storage;
101819 }
101820 EXPORT_SYMBOL(dev_get_stats);
101821 @@ -6574,7 +6574,7 @@ struct netdev_queue *dev_ingress_queue_create(struct net_device *dev)
101822 if (!queue)
101823 return NULL;
101824 netdev_init_one_queue(dev, queue, NULL);
101825 - queue->qdisc = &noop_qdisc;
101826 + RCU_INIT_POINTER(queue->qdisc, &noop_qdisc);
101827 queue->qdisc_sleeping = &noop_qdisc;
101828 rcu_assign_pointer(dev->ingress_queue, queue);
101829 #endif
101830 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101831 index 72e899a..79a9409 100644
101832 --- a/net/core/dev_ioctl.c
101833 +++ b/net/core/dev_ioctl.c
101834 @@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101835 no_module = !dev;
101836 if (no_module && capable(CAP_NET_ADMIN))
101837 no_module = request_module("netdev-%s", name);
101838 - if (no_module && capable(CAP_SYS_MODULE))
101839 + if (no_module && capable(CAP_SYS_MODULE)) {
101840 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
101841 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
101842 +#else
101843 request_module("%s", name);
101844 +#endif
101845 + }
101846 }
101847 EXPORT_SYMBOL(dev_load);
101848
101849 diff --git a/net/core/filter.c b/net/core/filter.c
101850 index 647b122..18a7ff6 100644
101851 --- a/net/core/filter.c
101852 +++ b/net/core/filter.c
101853 @@ -532,7 +532,11 @@ do_pass:
101854
101855 /* Unkown instruction. */
101856 default:
101857 - goto err;
101858 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101859 + fp->code, fp->jt, fp->jf, fp->k);
101860 + kfree(addrs);
101861 + BUG();
101862 + return -EINVAL;
101863 }
101864
101865 insn++;
101866 @@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101867 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101868 int pc, ret = 0;
101869
101870 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
101871 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
101872
101873 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101874 if (!masks)
101875 @@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101876 if (!fp)
101877 return -ENOMEM;
101878
101879 - memcpy(fp->insns, fprog->filter, fsize);
101880 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101881
101882 fp->len = fprog->len;
101883 /* Since unattached filters are not copied back to user
101884 diff --git a/net/core/flow.c b/net/core/flow.c
101885 index a0348fd..340f65d 100644
101886 --- a/net/core/flow.c
101887 +++ b/net/core/flow.c
101888 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101889 static int flow_entry_valid(struct flow_cache_entry *fle,
101890 struct netns_xfrm *xfrm)
101891 {
101892 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101893 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101894 return 0;
101895 if (fle->object && !fle->object->ops->check(fle->object))
101896 return 0;
101897 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101898 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101899 fcp->hash_count++;
101900 }
101901 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101902 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101903 flo = fle->object;
101904 if (!flo)
101905 goto ret_object;
101906 @@ -263,7 +263,7 @@ nocache:
101907 }
101908 flo = resolver(net, key, family, dir, flo, ctx);
101909 if (fle) {
101910 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101911 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101912 if (!IS_ERR(flo))
101913 fle->object = flo;
101914 else
101915 @@ -379,7 +379,7 @@ done:
101916 static void flow_cache_flush_task(struct work_struct *work)
101917 {
101918 struct netns_xfrm *xfrm = container_of(work, struct netns_xfrm,
101919 - flow_cache_gc_work);
101920 + flow_cache_flush_work);
101921 struct net *net = container_of(xfrm, struct net, xfrm);
101922
101923 flow_cache_flush(net);
101924 diff --git a/net/core/iovec.c b/net/core/iovec.c
101925 index e1ec45a..e5c6f16 100644
101926 --- a/net/core/iovec.c
101927 +++ b/net/core/iovec.c
101928 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101929 if (m->msg_name && m->msg_namelen) {
101930 if (mode == VERIFY_READ) {
101931 void __user *namep;
101932 - namep = (void __user __force *) m->msg_name;
101933 + namep = (void __force_user *) m->msg_name;
101934 err = move_addr_to_kernel(namep, m->msg_namelen,
101935 address);
101936 if (err < 0)
101937 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101938 }
101939
101940 size = m->msg_iovlen * sizeof(struct iovec);
101941 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101942 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101943 return -EFAULT;
101944
101945 m->msg_iov = iov;
101946 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101947 index ef31fef..8be66d9 100644
101948 --- a/net/core/neighbour.c
101949 +++ b/net/core/neighbour.c
101950 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101951 void __user *buffer, size_t *lenp, loff_t *ppos)
101952 {
101953 int size, ret;
101954 - struct ctl_table tmp = *ctl;
101955 + ctl_table_no_const tmp = *ctl;
101956
101957 tmp.extra1 = &zero;
101958 tmp.extra2 = &unres_qlen_max;
101959 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101960 void __user *buffer,
101961 size_t *lenp, loff_t *ppos)
101962 {
101963 - struct ctl_table tmp = *ctl;
101964 + ctl_table_no_const tmp = *ctl;
101965 int ret;
101966
101967 tmp.extra1 = &zero;
101968 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101969 index 2bf8329..2eb1423 100644
101970 --- a/net/core/net-procfs.c
101971 +++ b/net/core/net-procfs.c
101972 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101973 struct rtnl_link_stats64 temp;
101974 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101975
101976 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101977 + if (gr_proc_is_restricted())
101978 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101979 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101980 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101981 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101982 + else
101983 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101984 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101985 dev->name, stats->rx_bytes, stats->rx_packets,
101986 stats->rx_errors,
101987 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101988 return 0;
101989 }
101990
101991 -static const struct seq_operations dev_seq_ops = {
101992 +const struct seq_operations dev_seq_ops = {
101993 .start = dev_seq_start,
101994 .next = dev_seq_next,
101995 .stop = dev_seq_stop,
101996 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101997
101998 static int softnet_seq_open(struct inode *inode, struct file *file)
101999 {
102000 - return seq_open(file, &softnet_seq_ops);
102001 + return seq_open_restrict(file, &softnet_seq_ops);
102002 }
102003
102004 static const struct file_operations softnet_seq_fops = {
102005 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
102006 else
102007 seq_printf(seq, "%04x", ntohs(pt->type));
102008
102009 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102010 + seq_printf(seq, " %-8s %pf\n",
102011 + pt->dev ? pt->dev->name : "", NULL);
102012 +#else
102013 seq_printf(seq, " %-8s %pf\n",
102014 pt->dev ? pt->dev->name : "", pt->func);
102015 +#endif
102016 }
102017
102018 return 0;
102019 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
102020 index 9dd0669..c52fb1b 100644
102021 --- a/net/core/net-sysfs.c
102022 +++ b/net/core/net-sysfs.c
102023 @@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
102024 {
102025 struct net_device *netdev = to_net_dev(dev);
102026 return sprintf(buf, fmt_dec,
102027 - atomic_read(&netdev->carrier_changes));
102028 + atomic_read_unchecked(&netdev->carrier_changes));
102029 }
102030 static DEVICE_ATTR_RO(carrier_changes);
102031
102032 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
102033 index 7f15517..f7d65c0 100644
102034 --- a/net/core/net_namespace.c
102035 +++ b/net/core/net_namespace.c
102036 @@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
102037 int error;
102038 LIST_HEAD(net_exit_list);
102039
102040 - list_add_tail(&ops->list, list);
102041 + pax_list_add_tail((struct list_head *)&ops->list, list);
102042 if (ops->init || (ops->id && ops->size)) {
102043 for_each_net(net) {
102044 error = ops_init(ops, net);
102045 @@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
102046
102047 out_undo:
102048 /* If I have an error cleanup all namespaces I initialized */
102049 - list_del(&ops->list);
102050 + pax_list_del((struct list_head *)&ops->list);
102051 ops_exit_list(ops, &net_exit_list);
102052 ops_free_list(ops, &net_exit_list);
102053 return error;
102054 @@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102055 struct net *net;
102056 LIST_HEAD(net_exit_list);
102057
102058 - list_del(&ops->list);
102059 + pax_list_del((struct list_head *)&ops->list);
102060 for_each_net(net)
102061 list_add_tail(&net->exit_list, &net_exit_list);
102062 ops_exit_list(ops, &net_exit_list);
102063 @@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102064 mutex_lock(&net_mutex);
102065 error = register_pernet_operations(&pernet_list, ops);
102066 if (!error && (first_device == &pernet_list))
102067 - first_device = &ops->list;
102068 + first_device = (struct list_head *)&ops->list;
102069 mutex_unlock(&net_mutex);
102070 return error;
102071 }
102072 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102073 index e6645b4..43e1af9 100644
102074 --- a/net/core/netpoll.c
102075 +++ b/net/core/netpoll.c
102076 @@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102077 struct udphdr *udph;
102078 struct iphdr *iph;
102079 struct ethhdr *eth;
102080 - static atomic_t ip_ident;
102081 + static atomic_unchecked_t ip_ident;
102082 struct ipv6hdr *ip6h;
102083
102084 udp_len = len + sizeof(*udph);
102085 @@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102086 put_unaligned(0x45, (unsigned char *)iph);
102087 iph->tos = 0;
102088 put_unaligned(htons(ip_len), &(iph->tot_len));
102089 - iph->id = htons(atomic_inc_return(&ip_ident));
102090 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102091 iph->frag_off = 0;
102092 iph->ttl = 64;
102093 iph->protocol = IPPROTO_UDP;
102094 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102095 index 443256b..bbff424 100644
102096 --- a/net/core/pktgen.c
102097 +++ b/net/core/pktgen.c
102098 @@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
102099 pn->net = net;
102100 INIT_LIST_HEAD(&pn->pktgen_threads);
102101 pn->pktgen_exiting = false;
102102 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102103 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102104 if (!pn->proc_dir) {
102105 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102106 return -ENODEV;
102107 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102108 index ca82629..f168c36 100644
102109 --- a/net/core/rtnetlink.c
102110 +++ b/net/core/rtnetlink.c
102111 @@ -58,7 +58,7 @@ struct rtnl_link {
102112 rtnl_doit_func doit;
102113 rtnl_dumpit_func dumpit;
102114 rtnl_calcit_func calcit;
102115 -};
102116 +} __no_const;
102117
102118 static DEFINE_MUTEX(rtnl_mutex);
102119
102120 @@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102121 * to use the ops for creating device. So do not
102122 * fill up dellink as well. That disables rtnl_dellink.
102123 */
102124 - if (ops->setup && !ops->dellink)
102125 - ops->dellink = unregister_netdevice_queue;
102126 + if (ops->setup && !ops->dellink) {
102127 + pax_open_kernel();
102128 + *(void **)&ops->dellink = unregister_netdevice_queue;
102129 + pax_close_kernel();
102130 + }
102131
102132 - list_add_tail(&ops->list, &link_ops);
102133 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102134 return 0;
102135 }
102136 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102137 @@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102138 for_each_net(net) {
102139 __rtnl_kill_links(net, ops);
102140 }
102141 - list_del(&ops->list);
102142 + pax_list_del((struct list_head *)&ops->list);
102143 }
102144 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102145
102146 @@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102147 (dev->ifalias &&
102148 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102149 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102150 - atomic_read(&dev->carrier_changes)))
102151 + atomic_read_unchecked(&dev->carrier_changes)))
102152 goto nla_put_failure;
102153
102154 if (1) {
102155 @@ -2077,6 +2080,10 @@ replay:
102156 if (IS_ERR(dest_net))
102157 return PTR_ERR(dest_net);
102158
102159 + err = -EPERM;
102160 + if (!netlink_ns_capable(skb, dest_net->user_ns, CAP_NET_ADMIN))
102161 + goto out;
102162 +
102163 dev = rtnl_create_link(dest_net, ifname, name_assign_type, ops, tb);
102164 if (IS_ERR(dev)) {
102165 err = PTR_ERR(dev);
102166 diff --git a/net/core/scm.c b/net/core/scm.c
102167 index b442e7e..6f5b5a2 100644
102168 --- a/net/core/scm.c
102169 +++ b/net/core/scm.c
102170 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102171 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102172 {
102173 struct cmsghdr __user *cm
102174 - = (__force struct cmsghdr __user *)msg->msg_control;
102175 + = (struct cmsghdr __force_user *)msg->msg_control;
102176 struct cmsghdr cmhdr;
102177 int cmlen = CMSG_LEN(len);
102178 int err;
102179 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102180 err = -EFAULT;
102181 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102182 goto out;
102183 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102184 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102185 goto out;
102186 cmlen = CMSG_SPACE(len);
102187 if (msg->msg_controllen < cmlen)
102188 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102189 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102190 {
102191 struct cmsghdr __user *cm
102192 - = (__force struct cmsghdr __user*)msg->msg_control;
102193 + = (struct cmsghdr __force_user *)msg->msg_control;
102194
102195 int fdmax = 0;
102196 int fdnum = scm->fp->count;
102197 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102198 if (fdnum < fdmax)
102199 fdmax = fdnum;
102200
102201 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102202 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102203 i++, cmfptr++)
102204 {
102205 struct socket *sock;
102206 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102207 index d7543d0..ff96aec 100644
102208 --- a/net/core/skbuff.c
102209 +++ b/net/core/skbuff.c
102210 @@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
102211 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102212 int len, __wsum csum)
102213 {
102214 - const struct skb_checksum_ops ops = {
102215 + static const struct skb_checksum_ops ops = {
102216 .update = csum_partial_ext,
102217 .combine = csum_block_add_ext,
102218 };
102219 @@ -3255,12 +3255,14 @@ void __init skb_init(void)
102220 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102221 sizeof(struct sk_buff),
102222 0,
102223 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102224 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102225 + SLAB_NO_SANITIZE,
102226 NULL);
102227 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102228 sizeof(struct sk_buff_fclones),
102229 0,
102230 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102231 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102232 + SLAB_NO_SANITIZE,
102233 NULL);
102234 }
102235
102236 diff --git a/net/core/sock.c b/net/core/sock.c
102237 index 15e0c67..0310f4a 100644
102238 --- a/net/core/sock.c
102239 +++ b/net/core/sock.c
102240 @@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102241 struct sk_buff_head *list = &sk->sk_receive_queue;
102242
102243 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102244 - atomic_inc(&sk->sk_drops);
102245 + atomic_inc_unchecked(&sk->sk_drops);
102246 trace_sock_rcvqueue_full(sk, skb);
102247 return -ENOMEM;
102248 }
102249 @@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102250 return err;
102251
102252 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102253 - atomic_inc(&sk->sk_drops);
102254 + atomic_inc_unchecked(&sk->sk_drops);
102255 return -ENOBUFS;
102256 }
102257
102258 @@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102259 skb_dst_force(skb);
102260
102261 spin_lock_irqsave(&list->lock, flags);
102262 - skb->dropcount = atomic_read(&sk->sk_drops);
102263 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102264 __skb_queue_tail(list, skb);
102265 spin_unlock_irqrestore(&list->lock, flags);
102266
102267 @@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102268 skb->dev = NULL;
102269
102270 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102271 - atomic_inc(&sk->sk_drops);
102272 + atomic_inc_unchecked(&sk->sk_drops);
102273 goto discard_and_relse;
102274 }
102275 if (nested)
102276 @@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102277 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102278 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102279 bh_unlock_sock(sk);
102280 - atomic_inc(&sk->sk_drops);
102281 + atomic_inc_unchecked(&sk->sk_drops);
102282 goto discard_and_relse;
102283 }
102284
102285 @@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102286 struct timeval tm;
102287 } v;
102288
102289 - int lv = sizeof(int);
102290 - int len;
102291 + unsigned int lv = sizeof(int);
102292 + unsigned int len;
102293
102294 if (get_user(len, optlen))
102295 return -EFAULT;
102296 - if (len < 0)
102297 + if (len > INT_MAX)
102298 return -EINVAL;
102299
102300 memset(&v, 0, sizeof(v));
102301 @@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102302
102303 case SO_PEERNAME:
102304 {
102305 - char address[128];
102306 + char address[_K_SS_MAXSIZE];
102307
102308 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102309 return -ENOTCONN;
102310 - if (lv < len)
102311 + if (lv < len || sizeof address < len)
102312 return -EINVAL;
102313 if (copy_to_user(optval, address, len))
102314 return -EFAULT;
102315 @@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102316
102317 if (len > lv)
102318 len = lv;
102319 - if (copy_to_user(optval, &v, len))
102320 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
102321 return -EFAULT;
102322 lenout:
102323 if (put_user(len, optlen))
102324 @@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102325 */
102326 smp_wmb();
102327 atomic_set(&sk->sk_refcnt, 1);
102328 - atomic_set(&sk->sk_drops, 0);
102329 + atomic_set_unchecked(&sk->sk_drops, 0);
102330 }
102331 EXPORT_SYMBOL(sock_init_data);
102332
102333 @@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102334 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102335 int level, int type)
102336 {
102337 + struct sock_extended_err ee;
102338 struct sock_exterr_skb *serr;
102339 struct sk_buff *skb;
102340 int copied, err;
102341 @@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102342 sock_recv_timestamp(msg, sk, skb);
102343
102344 serr = SKB_EXT_ERR(skb);
102345 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102346 + ee = serr->ee;
102347 + put_cmsg(msg, level, type, sizeof ee, &ee);
102348
102349 msg->msg_flags |= MSG_ERRQUEUE;
102350 err = copied;
102351 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102352 index ad704c7..ca48aff 100644
102353 --- a/net/core/sock_diag.c
102354 +++ b/net/core/sock_diag.c
102355 @@ -9,26 +9,33 @@
102356 #include <linux/inet_diag.h>
102357 #include <linux/sock_diag.h>
102358
102359 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102360 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102361 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102362 static DEFINE_MUTEX(sock_diag_table_mutex);
102363
102364 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102365 {
102366 +#ifndef CONFIG_GRKERNSEC_HIDESYM
102367 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102368 cookie[1] != INET_DIAG_NOCOOKIE) &&
102369 ((u32)(unsigned long)sk != cookie[0] ||
102370 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102371 return -ESTALE;
102372 else
102373 +#endif
102374 return 0;
102375 }
102376 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102377
102378 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102379 {
102380 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102381 + cookie[0] = 0;
102382 + cookie[1] = 0;
102383 +#else
102384 cookie[0] = (u32)(unsigned long)sk;
102385 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102386 +#endif
102387 }
102388 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102389
102390 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102391 mutex_lock(&sock_diag_table_mutex);
102392 if (sock_diag_handlers[hndl->family])
102393 err = -EBUSY;
102394 - else
102395 + else {
102396 + pax_open_kernel();
102397 sock_diag_handlers[hndl->family] = hndl;
102398 + pax_close_kernel();
102399 + }
102400 mutex_unlock(&sock_diag_table_mutex);
102401
102402 return err;
102403 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102404
102405 mutex_lock(&sock_diag_table_mutex);
102406 BUG_ON(sock_diag_handlers[family] != hnld);
102407 + pax_open_kernel();
102408 sock_diag_handlers[family] = NULL;
102409 + pax_close_kernel();
102410 mutex_unlock(&sock_diag_table_mutex);
102411 }
102412 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102413 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102414 index cf9cd13..50683950 100644
102415 --- a/net/core/sysctl_net_core.c
102416 +++ b/net/core/sysctl_net_core.c
102417 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102418 {
102419 unsigned int orig_size, size;
102420 int ret, i;
102421 - struct ctl_table tmp = {
102422 + ctl_table_no_const tmp = {
102423 .data = &size,
102424 .maxlen = sizeof(size),
102425 .mode = table->mode
102426 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102427 void __user *buffer, size_t *lenp, loff_t *ppos)
102428 {
102429 char id[IFNAMSIZ];
102430 - struct ctl_table tbl = {
102431 + ctl_table_no_const tbl = {
102432 .data = id,
102433 .maxlen = IFNAMSIZ,
102434 };
102435 @@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102436 .mode = 0644,
102437 .proc_handler = proc_dointvec
102438 },
102439 -#ifdef CONFIG_BPF_JIT
102440 +#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102441 {
102442 .procname = "bpf_jit_enable",
102443 .data = &bpf_jit_enable,
102444 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102445
102446 static __net_init int sysctl_core_net_init(struct net *net)
102447 {
102448 - struct ctl_table *tbl;
102449 + ctl_table_no_const *tbl = NULL;
102450
102451 net->core.sysctl_somaxconn = SOMAXCONN;
102452
102453 - tbl = netns_core_table;
102454 if (!net_eq(net, &init_net)) {
102455 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102456 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102457 if (tbl == NULL)
102458 goto err_dup;
102459
102460 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102461 if (net->user_ns != &init_user_ns) {
102462 tbl[0].procname = NULL;
102463 }
102464 - }
102465 -
102466 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102467 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102468 + } else
102469 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102470 if (net->core.sysctl_hdr == NULL)
102471 goto err_reg;
102472
102473 return 0;
102474
102475 err_reg:
102476 - if (tbl != netns_core_table)
102477 - kfree(tbl);
102478 + kfree(tbl);
102479 err_dup:
102480 return -ENOMEM;
102481 }
102482 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102483 kfree(tbl);
102484 }
102485
102486 -static __net_initdata struct pernet_operations sysctl_core_ops = {
102487 +static __net_initconst struct pernet_operations sysctl_core_ops = {
102488 .init = sysctl_core_net_init,
102489 .exit = sysctl_core_net_exit,
102490 };
102491 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102492 index 25733d5..b9360f0 100644
102493 --- a/net/decnet/af_decnet.c
102494 +++ b/net/decnet/af_decnet.c
102495 @@ -466,6 +466,7 @@ static struct proto dn_proto = {
102496 .sysctl_rmem = sysctl_decnet_rmem,
102497 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102498 .obj_size = sizeof(struct dn_sock),
102499 + .slab_flags = SLAB_USERCOPY,
102500 };
102501
102502 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102503 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102504 index 4400da7..3429972 100644
102505 --- a/net/decnet/dn_dev.c
102506 +++ b/net/decnet/dn_dev.c
102507 @@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
102508 .extra1 = &min_t3,
102509 .extra2 = &max_t3
102510 },
102511 - {0}
102512 + { }
102513 },
102514 };
102515
102516 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102517 index 5325b54..a0d4d69 100644
102518 --- a/net/decnet/sysctl_net_decnet.c
102519 +++ b/net/decnet/sysctl_net_decnet.c
102520 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102521
102522 if (len > *lenp) len = *lenp;
102523
102524 - if (copy_to_user(buffer, addr, len))
102525 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
102526 return -EFAULT;
102527
102528 *lenp = len;
102529 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102530
102531 if (len > *lenp) len = *lenp;
102532
102533 - if (copy_to_user(buffer, devname, len))
102534 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
102535 return -EFAULT;
102536
102537 *lenp = len;
102538 diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102539 index a2c7e4c..3dc9f67 100644
102540 --- a/net/hsr/hsr_netlink.c
102541 +++ b/net/hsr/hsr_netlink.c
102542 @@ -102,7 +102,7 @@ nla_put_failure:
102543 return -EMSGSIZE;
102544 }
102545
102546 -static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102547 +static struct rtnl_link_ops hsr_link_ops = {
102548 .kind = "hsr",
102549 .maxtype = IFLA_HSR_MAX,
102550 .policy = hsr_policy,
102551 diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102552 index 4413629..dea596a 100644
102553 --- a/net/ieee802154/6lowpan_rtnl.c
102554 +++ b/net/ieee802154/6lowpan_rtnl.c
102555 @@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102556 dev_put(real_dev);
102557 }
102558
102559 -static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102560 +static struct rtnl_link_ops lowpan_link_ops = {
102561 .kind = "lowpan",
102562 .priv_size = sizeof(struct lowpan_dev_info),
102563 .setup = lowpan_setup,
102564 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102565 index 7cfcd68..84ca5b7 100644
102566 --- a/net/ieee802154/reassembly.c
102567 +++ b/net/ieee802154/reassembly.c
102568 @@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102569
102570 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102571 {
102572 - struct ctl_table *table;
102573 + ctl_table_no_const *table = NULL;
102574 struct ctl_table_header *hdr;
102575 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102576 net_ieee802154_lowpan(net);
102577
102578 - table = lowpan_frags_ns_ctl_table;
102579 if (!net_eq(net, &init_net)) {
102580 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102581 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102582 GFP_KERNEL);
102583 if (table == NULL)
102584 goto err_alloc;
102585 @@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102586 /* Don't export sysctls to unprivileged users */
102587 if (net->user_ns != &init_user_ns)
102588 table[0].procname = NULL;
102589 - }
102590 -
102591 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102592 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102593 + } else
102594 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102595 if (hdr == NULL)
102596 goto err_reg;
102597
102598 @@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102599 return 0;
102600
102601 err_reg:
102602 - if (!net_eq(net, &init_net))
102603 - kfree(table);
102604 + kfree(table);
102605 err_alloc:
102606 return -ENOMEM;
102607 }
102608 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102609 index e67da4e..da217942 100644
102610 --- a/net/ipv4/af_inet.c
102611 +++ b/net/ipv4/af_inet.c
102612 @@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102613 return ip_recv_error(sk, msg, len, addr_len);
102614 #if IS_ENABLED(CONFIG_IPV6)
102615 if (sk->sk_family == AF_INET6)
102616 - return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102617 + return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102618 #endif
102619 return -EINVAL;
102620 }
102621 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102622 index 214882e..ec032f6 100644
102623 --- a/net/ipv4/devinet.c
102624 +++ b/net/ipv4/devinet.c
102625 @@ -69,7 +69,8 @@
102626
102627 static struct ipv4_devconf ipv4_devconf = {
102628 .data = {
102629 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102630 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102631 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102632 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102633 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102634 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102635 @@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102636
102637 static struct ipv4_devconf ipv4_devconf_dflt = {
102638 .data = {
102639 - [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102640 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102641 + [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102642 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102643 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102644 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102645 @@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102646 idx = 0;
102647 head = &net->dev_index_head[h];
102648 rcu_read_lock();
102649 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102650 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102651 net->dev_base_seq;
102652 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102653 if (idx < s_idx)
102654 @@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102655 idx = 0;
102656 head = &net->dev_index_head[h];
102657 rcu_read_lock();
102658 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102659 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102660 net->dev_base_seq;
102661 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102662 if (idx < s_idx)
102663 @@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102664 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102665 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102666
102667 -static struct devinet_sysctl_table {
102668 +static const struct devinet_sysctl_table {
102669 struct ctl_table_header *sysctl_header;
102670 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102671 } devinet_sysctl = {
102672 @@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102673 int err;
102674 struct ipv4_devconf *all, *dflt;
102675 #ifdef CONFIG_SYSCTL
102676 - struct ctl_table *tbl = ctl_forward_entry;
102677 + ctl_table_no_const *tbl = NULL;
102678 struct ctl_table_header *forw_hdr;
102679 #endif
102680
102681 @@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102682 goto err_alloc_dflt;
102683
102684 #ifdef CONFIG_SYSCTL
102685 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102686 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102687 if (tbl == NULL)
102688 goto err_alloc_ctl;
102689
102690 @@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102691 goto err_reg_dflt;
102692
102693 err = -ENOMEM;
102694 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102695 + if (!net_eq(net, &init_net))
102696 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102697 + else
102698 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102699 if (forw_hdr == NULL)
102700 goto err_reg_ctl;
102701 net->ipv4.forw_hdr = forw_hdr;
102702 @@ -2287,8 +2292,7 @@ err_reg_ctl:
102703 err_reg_dflt:
102704 __devinet_sysctl_unregister(all);
102705 err_reg_all:
102706 - if (tbl != ctl_forward_entry)
102707 - kfree(tbl);
102708 + kfree(tbl);
102709 err_alloc_ctl:
102710 #endif
102711 if (dflt != &ipv4_devconf_dflt)
102712 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102713 index 23104a3..9f5570b 100644
102714 --- a/net/ipv4/fib_frontend.c
102715 +++ b/net/ipv4/fib_frontend.c
102716 @@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102717 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102718 fib_sync_up(dev);
102719 #endif
102720 - atomic_inc(&net->ipv4.dev_addr_genid);
102721 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102722 rt_cache_flush(dev_net(dev));
102723 break;
102724 case NETDEV_DOWN:
102725 fib_del_ifaddr(ifa, NULL);
102726 - atomic_inc(&net->ipv4.dev_addr_genid);
102727 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102728 if (ifa->ifa_dev->ifa_list == NULL) {
102729 /* Last address was deleted from this interface.
102730 * Disable IP.
102731 @@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102732 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102733 fib_sync_up(dev);
102734 #endif
102735 - atomic_inc(&net->ipv4.dev_addr_genid);
102736 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102737 rt_cache_flush(net);
102738 break;
102739 case NETDEV_DOWN:
102740 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102741 index f99f41b..1879da9 100644
102742 --- a/net/ipv4/fib_semantics.c
102743 +++ b/net/ipv4/fib_semantics.c
102744 @@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102745 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102746 nh->nh_gw,
102747 nh->nh_parent->fib_scope);
102748 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102749 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102750
102751 return nh->nh_saddr;
102752 }
102753 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102754 index 9111a4e..3576905 100644
102755 --- a/net/ipv4/inet_hashtables.c
102756 +++ b/net/ipv4/inet_hashtables.c
102757 @@ -18,6 +18,7 @@
102758 #include <linux/sched.h>
102759 #include <linux/slab.h>
102760 #include <linux/wait.h>
102761 +#include <linux/security.h>
102762
102763 #include <net/inet_connection_sock.h>
102764 #include <net/inet_hashtables.h>
102765 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102766 return inet_ehashfn(net, laddr, lport, faddr, fport);
102767 }
102768
102769 +extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102770 +
102771 /*
102772 * Allocate and initialize a new local port bind bucket.
102773 * The bindhash mutex for snum's hash chain must be held here.
102774 @@ -554,6 +557,8 @@ ok:
102775 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102776 spin_unlock(&head->lock);
102777
102778 + gr_update_task_in_ip_table(inet_sk(sk));
102779 +
102780 if (tw) {
102781 inet_twsk_deschedule(tw, death_row);
102782 while (twrefcnt) {
102783 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102784 index 241afd7..31b95d5 100644
102785 --- a/net/ipv4/inetpeer.c
102786 +++ b/net/ipv4/inetpeer.c
102787 @@ -461,7 +461,7 @@ relookup:
102788 if (p) {
102789 p->daddr = *daddr;
102790 atomic_set(&p->refcnt, 1);
102791 - atomic_set(&p->rid, 0);
102792 + atomic_set_unchecked(&p->rid, 0);
102793 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102794 p->rate_tokens = 0;
102795 /* 60*HZ is arbitrary, but chosen enough high so that the first
102796 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102797 index 2811cc1..ad5a534 100644
102798 --- a/net/ipv4/ip_fragment.c
102799 +++ b/net/ipv4/ip_fragment.c
102800 @@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102801 return 0;
102802
102803 start = qp->rid;
102804 - end = atomic_inc_return(&peer->rid);
102805 + end = atomic_inc_return_unchecked(&peer->rid);
102806 qp->rid = end;
102807
102808 rc = qp->q.fragments && (end - start) > max;
102809 @@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102810
102811 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102812 {
102813 - struct ctl_table *table;
102814 + ctl_table_no_const *table = NULL;
102815 struct ctl_table_header *hdr;
102816
102817 - table = ip4_frags_ns_ctl_table;
102818 if (!net_eq(net, &init_net)) {
102819 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102820 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102821 if (table == NULL)
102822 goto err_alloc;
102823
102824 @@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102825 /* Don't export sysctls to unprivileged users */
102826 if (net->user_ns != &init_user_ns)
102827 table[0].procname = NULL;
102828 - }
102829 + hdr = register_net_sysctl(net, "net/ipv4", table);
102830 + } else
102831 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102832
102833 - hdr = register_net_sysctl(net, "net/ipv4", table);
102834 if (hdr == NULL)
102835 goto err_reg;
102836
102837 @@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102838 return 0;
102839
102840 err_reg:
102841 - if (!net_eq(net, &init_net))
102842 - kfree(table);
102843 + kfree(table);
102844 err_alloc:
102845 return -ENOMEM;
102846 }
102847 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102848 index 69aaf0a..8298c029 100644
102849 --- a/net/ipv4/ip_gre.c
102850 +++ b/net/ipv4/ip_gre.c
102851 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102852 module_param(log_ecn_error, bool, 0644);
102853 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102854
102855 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102856 +static struct rtnl_link_ops ipgre_link_ops;
102857 static int ipgre_tunnel_init(struct net_device *dev);
102858
102859 static int ipgre_net_id __read_mostly;
102860 @@ -816,7 +816,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102861 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102862 };
102863
102864 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102865 +static struct rtnl_link_ops ipgre_link_ops = {
102866 .kind = "gre",
102867 .maxtype = IFLA_GRE_MAX,
102868 .policy = ipgre_policy,
102869 @@ -830,7 +830,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102870 .fill_info = ipgre_fill_info,
102871 };
102872
102873 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102874 +static struct rtnl_link_ops ipgre_tap_ops = {
102875 .kind = "gretap",
102876 .maxtype = IFLA_GRE_MAX,
102877 .policy = ipgre_policy,
102878 diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102879 index 3d4da2c..40f9c29 100644
102880 --- a/net/ipv4/ip_input.c
102881 +++ b/net/ipv4/ip_input.c
102882 @@ -147,6 +147,10 @@
102883 #include <linux/mroute.h>
102884 #include <linux/netlink.h>
102885
102886 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102887 +extern int grsec_enable_blackhole;
102888 +#endif
102889 +
102890 /*
102891 * Process Router Attention IP option (RFC 2113)
102892 */
102893 @@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102894 if (!raw) {
102895 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102896 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102897 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102898 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102899 +#endif
102900 icmp_send(skb, ICMP_DEST_UNREACH,
102901 ICMP_PROT_UNREACH, 0);
102902 }
102903 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102904 index 046fce0..4b28126 100644
102905 --- a/net/ipv4/ip_sockglue.c
102906 +++ b/net/ipv4/ip_sockglue.c
102907 @@ -1173,7 +1173,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102908 len = min_t(unsigned int, len, opt->optlen);
102909 if (put_user(len, optlen))
102910 return -EFAULT;
102911 - if (copy_to_user(optval, opt->__data, len))
102912 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102913 + copy_to_user(optval, opt->__data, len))
102914 return -EFAULT;
102915 return 0;
102916 }
102917 @@ -1304,7 +1305,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102918 if (sk->sk_type != SOCK_STREAM)
102919 return -ENOPROTOOPT;
102920
102921 - msg.msg_control = (__force void *) optval;
102922 + msg.msg_control = (__force_kernel void *) optval;
102923 msg.msg_controllen = len;
102924 msg.msg_flags = flags;
102925
102926 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102927 index 1a7e979..fd05aa4 100644
102928 --- a/net/ipv4/ip_vti.c
102929 +++ b/net/ipv4/ip_vti.c
102930 @@ -45,7 +45,7 @@
102931 #include <net/net_namespace.h>
102932 #include <net/netns/generic.h>
102933
102934 -static struct rtnl_link_ops vti_link_ops __read_mostly;
102935 +static struct rtnl_link_ops vti_link_ops;
102936
102937 static int vti_net_id __read_mostly;
102938 static int vti_tunnel_init(struct net_device *dev);
102939 @@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102940 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102941 };
102942
102943 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
102944 +static struct rtnl_link_ops vti_link_ops = {
102945 .kind = "vti",
102946 .maxtype = IFLA_VTI_MAX,
102947 .policy = vti_policy,
102948 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102949 index 648fa14..97864d0 100644
102950 --- a/net/ipv4/ipconfig.c
102951 +++ b/net/ipv4/ipconfig.c
102952 @@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102953
102954 mm_segment_t oldfs = get_fs();
102955 set_fs(get_ds());
102956 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102957 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102958 set_fs(oldfs);
102959 return res;
102960 }
102961 @@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102962
102963 mm_segment_t oldfs = get_fs();
102964 set_fs(get_ds());
102965 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102966 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102967 set_fs(oldfs);
102968 return res;
102969 }
102970 @@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102971
102972 mm_segment_t oldfs = get_fs();
102973 set_fs(get_ds());
102974 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102975 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102976 set_fs(oldfs);
102977 return res;
102978 }
102979 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102980 index 37096d6..86abb03 100644
102981 --- a/net/ipv4/ipip.c
102982 +++ b/net/ipv4/ipip.c
102983 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102984 static int ipip_net_id __read_mostly;
102985
102986 static int ipip_tunnel_init(struct net_device *dev);
102987 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
102988 +static struct rtnl_link_ops ipip_link_ops;
102989
102990 static int ipip_err(struct sk_buff *skb, u32 info)
102991 {
102992 @@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102993 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102994 };
102995
102996 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102997 +static struct rtnl_link_ops ipip_link_ops = {
102998 .kind = "ipip",
102999 .maxtype = IFLA_IPTUN_MAX,
103000 .policy = ipip_policy,
103001 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
103002 index f95b6f9..2ee2097 100644
103003 --- a/net/ipv4/netfilter/arp_tables.c
103004 +++ b/net/ipv4/netfilter/arp_tables.c
103005 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
103006 #endif
103007
103008 static int get_info(struct net *net, void __user *user,
103009 - const int *len, int compat)
103010 + int len, int compat)
103011 {
103012 char name[XT_TABLE_MAXNAMELEN];
103013 struct xt_table *t;
103014 int ret;
103015
103016 - if (*len != sizeof(struct arpt_getinfo)) {
103017 - duprintf("length %u != %Zu\n", *len,
103018 + if (len != sizeof(struct arpt_getinfo)) {
103019 + duprintf("length %u != %Zu\n", len,
103020 sizeof(struct arpt_getinfo));
103021 return -EINVAL;
103022 }
103023 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
103024 info.size = private->size;
103025 strcpy(info.name, name);
103026
103027 - if (copy_to_user(user, &info, *len) != 0)
103028 + if (copy_to_user(user, &info, len) != 0)
103029 ret = -EFAULT;
103030 else
103031 ret = 0;
103032 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
103033
103034 switch (cmd) {
103035 case ARPT_SO_GET_INFO:
103036 - ret = get_info(sock_net(sk), user, len, 1);
103037 + ret = get_info(sock_net(sk), user, *len, 1);
103038 break;
103039 case ARPT_SO_GET_ENTRIES:
103040 ret = compat_get_entries(sock_net(sk), user, len);
103041 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
103042
103043 switch (cmd) {
103044 case ARPT_SO_GET_INFO:
103045 - ret = get_info(sock_net(sk), user, len, 0);
103046 + ret = get_info(sock_net(sk), user, *len, 0);
103047 break;
103048
103049 case ARPT_SO_GET_ENTRIES:
103050 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
103051 index 99e810f..3711b81 100644
103052 --- a/net/ipv4/netfilter/ip_tables.c
103053 +++ b/net/ipv4/netfilter/ip_tables.c
103054 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
103055 #endif
103056
103057 static int get_info(struct net *net, void __user *user,
103058 - const int *len, int compat)
103059 + int len, int compat)
103060 {
103061 char name[XT_TABLE_MAXNAMELEN];
103062 struct xt_table *t;
103063 int ret;
103064
103065 - if (*len != sizeof(struct ipt_getinfo)) {
103066 - duprintf("length %u != %zu\n", *len,
103067 + if (len != sizeof(struct ipt_getinfo)) {
103068 + duprintf("length %u != %zu\n", len,
103069 sizeof(struct ipt_getinfo));
103070 return -EINVAL;
103071 }
103072 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103073 info.size = private->size;
103074 strcpy(info.name, name);
103075
103076 - if (copy_to_user(user, &info, *len) != 0)
103077 + if (copy_to_user(user, &info, len) != 0)
103078 ret = -EFAULT;
103079 else
103080 ret = 0;
103081 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103082
103083 switch (cmd) {
103084 case IPT_SO_GET_INFO:
103085 - ret = get_info(sock_net(sk), user, len, 1);
103086 + ret = get_info(sock_net(sk), user, *len, 1);
103087 break;
103088 case IPT_SO_GET_ENTRIES:
103089 ret = compat_get_entries(sock_net(sk), user, len);
103090 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103091
103092 switch (cmd) {
103093 case IPT_SO_GET_INFO:
103094 - ret = get_info(sock_net(sk), user, len, 0);
103095 + ret = get_info(sock_net(sk), user, *len, 0);
103096 break;
103097
103098 case IPT_SO_GET_ENTRIES:
103099 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103100 index e90f83a..3e6acca 100644
103101 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103102 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103103 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103104 spin_lock_init(&cn->lock);
103105
103106 #ifdef CONFIG_PROC_FS
103107 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103108 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103109 if (!cn->procdir) {
103110 pr_err("Unable to proc dir entry\n");
103111 return -ENOMEM;
103112 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103113 index 5638b17..dec7fa3 100644
103114 --- a/net/ipv4/ping.c
103115 +++ b/net/ipv4/ping.c
103116 @@ -59,7 +59,7 @@ struct ping_table {
103117 };
103118
103119 static struct ping_table ping_table;
103120 -struct pingv6_ops pingv6_ops;
103121 +struct pingv6_ops *pingv6_ops;
103122 EXPORT_SYMBOL_GPL(pingv6_ops);
103123
103124 static u16 ping_port_rover;
103125 @@ -259,6 +259,9 @@ int ping_init_sock(struct sock *sk)
103126 kgid_t low, high;
103127 int ret = 0;
103128
103129 + if (sk->sk_family == AF_INET6)
103130 + sk->sk_ipv6only = 1;
103131 +
103132 inet_get_ping_group_range_net(net, &low, &high);
103133 if (gid_lte(low, group) && gid_lte(group, high))
103134 return 0;
103135 @@ -305,6 +308,11 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103136 if (addr_len < sizeof(*addr))
103137 return -EINVAL;
103138
103139 + if (addr->sin_family != AF_INET &&
103140 + !(addr->sin_family == AF_UNSPEC &&
103141 + addr->sin_addr.s_addr == htonl(INADDR_ANY)))
103142 + return -EAFNOSUPPORT;
103143 +
103144 pr_debug("ping_check_bind_addr(sk=%p,addr=%pI4,port=%d)\n",
103145 sk, &addr->sin_addr.s_addr, ntohs(addr->sin_port));
103146
103147 @@ -330,7 +338,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103148 return -EINVAL;
103149
103150 if (addr->sin6_family != AF_INET6)
103151 - return -EINVAL;
103152 + return -EAFNOSUPPORT;
103153
103154 pr_debug("ping_check_bind_addr(sk=%p,addr=%pI6c,port=%d)\n",
103155 sk, addr->sin6_addr.s6_addr, ntohs(addr->sin6_port));
103156 @@ -350,7 +358,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103157 return -ENODEV;
103158 }
103159 }
103160 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103161 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103162 scoped);
103163 rcu_read_unlock();
103164
103165 @@ -558,7 +566,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103166 }
103167 #if IS_ENABLED(CONFIG_IPV6)
103168 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103169 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103170 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103171 #endif
103172 }
103173
103174 @@ -576,7 +584,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103175 info, (u8 *)icmph);
103176 #if IS_ENABLED(CONFIG_IPV6)
103177 } else if (family == AF_INET6) {
103178 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103179 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103180 info, (u8 *)icmph);
103181 #endif
103182 }
103183 @@ -716,7 +724,7 @@ static int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
103184 if (msg->msg_namelen < sizeof(*usin))
103185 return -EINVAL;
103186 if (usin->sin_family != AF_INET)
103187 - return -EINVAL;
103188 + return -EAFNOSUPPORT;
103189 daddr = usin->sin_addr.s_addr;
103190 /* no remote port */
103191 } else {
103192 @@ -910,10 +918,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103193 }
103194
103195 if (inet6_sk(sk)->rxopt.all)
103196 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103197 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103198 if (skb->protocol == htons(ETH_P_IPV6) &&
103199 inet6_sk(sk)->rxopt.all)
103200 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103201 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103202 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103203 ip_cmsg_recv(msg, skb);
103204 #endif
103205 @@ -1108,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103206 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103207 0, sock_i_ino(sp),
103208 atomic_read(&sp->sk_refcnt), sp,
103209 - atomic_read(&sp->sk_drops));
103210 + atomic_read_unchecked(&sp->sk_drops));
103211 }
103212
103213 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103214 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103215 index 739db31..74f0210 100644
103216 --- a/net/ipv4/raw.c
103217 +++ b/net/ipv4/raw.c
103218 @@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103219 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103220 {
103221 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103222 - atomic_inc(&sk->sk_drops);
103223 + atomic_inc_unchecked(&sk->sk_drops);
103224 kfree_skb(skb);
103225 return NET_RX_DROP;
103226 }
103227 @@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103228
103229 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103230 {
103231 + struct icmp_filter filter;
103232 +
103233 if (optlen > sizeof(struct icmp_filter))
103234 optlen = sizeof(struct icmp_filter);
103235 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103236 + if (copy_from_user(&filter, optval, optlen))
103237 return -EFAULT;
103238 + raw_sk(sk)->filter = filter;
103239 return 0;
103240 }
103241
103242 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103243 {
103244 int len, ret = -EFAULT;
103245 + struct icmp_filter filter;
103246
103247 if (get_user(len, optlen))
103248 goto out;
103249 @@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103250 if (len > sizeof(struct icmp_filter))
103251 len = sizeof(struct icmp_filter);
103252 ret = -EFAULT;
103253 - if (put_user(len, optlen) ||
103254 - copy_to_user(optval, &raw_sk(sk)->filter, len))
103255 + filter = raw_sk(sk)->filter;
103256 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103257 goto out;
103258 ret = 0;
103259 out: return ret;
103260 @@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103261 0, 0L, 0,
103262 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103263 0, sock_i_ino(sp),
103264 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103265 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103266 }
103267
103268 static int raw_seq_show(struct seq_file *seq, void *v)
103269 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103270 index d58dd0e..47de388 100644
103271 --- a/net/ipv4/route.c
103272 +++ b/net/ipv4/route.c
103273 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103274
103275 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103276 {
103277 - return seq_open(file, &rt_cache_seq_ops);
103278 + return seq_open_restrict(file, &rt_cache_seq_ops);
103279 }
103280
103281 static const struct file_operations rt_cache_seq_fops = {
103282 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103283
103284 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103285 {
103286 - return seq_open(file, &rt_cpu_seq_ops);
103287 + return seq_open_restrict(file, &rt_cpu_seq_ops);
103288 }
103289
103290 static const struct file_operations rt_cpu_seq_fops = {
103291 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103292
103293 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103294 {
103295 - return single_open(file, rt_acct_proc_show, NULL);
103296 + return single_open_restrict(file, rt_acct_proc_show, NULL);
103297 }
103298
103299 static const struct file_operations rt_acct_proc_fops = {
103300 @@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103301
103302 #define IP_IDENTS_SZ 2048u
103303 struct ip_ident_bucket {
103304 - atomic_t id;
103305 + atomic_unchecked_t id;
103306 u32 stamp32;
103307 };
103308
103309 -static struct ip_ident_bucket *ip_idents __read_mostly;
103310 +static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103311
103312 /* In order to protect privacy, we add a perturbation to identifiers
103313 * if one generator is seldom used. This makes hard for an attacker
103314 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103315 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103316 delta = prandom_u32_max(now - old);
103317
103318 - return atomic_add_return(segs + delta, &bucket->id) - segs;
103319 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103320 }
103321 EXPORT_SYMBOL(ip_idents_reserve);
103322
103323 @@ -2625,34 +2625,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103324 .maxlen = sizeof(int),
103325 .mode = 0200,
103326 .proc_handler = ipv4_sysctl_rtcache_flush,
103327 + .extra1 = &init_net,
103328 },
103329 { },
103330 };
103331
103332 static __net_init int sysctl_route_net_init(struct net *net)
103333 {
103334 - struct ctl_table *tbl;
103335 + ctl_table_no_const *tbl = NULL;
103336
103337 - tbl = ipv4_route_flush_table;
103338 if (!net_eq(net, &init_net)) {
103339 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103340 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103341 if (tbl == NULL)
103342 goto err_dup;
103343
103344 /* Don't export sysctls to unprivileged users */
103345 if (net->user_ns != &init_user_ns)
103346 tbl[0].procname = NULL;
103347 - }
103348 - tbl[0].extra1 = net;
103349 + tbl[0].extra1 = net;
103350 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103351 + } else
103352 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103353
103354 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103355 if (net->ipv4.route_hdr == NULL)
103356 goto err_reg;
103357 return 0;
103358
103359 err_reg:
103360 - if (tbl != ipv4_route_flush_table)
103361 - kfree(tbl);
103362 + kfree(tbl);
103363 err_dup:
103364 return -ENOMEM;
103365 }
103366 @@ -2675,8 +2675,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103367
103368 static __net_init int rt_genid_init(struct net *net)
103369 {
103370 - atomic_set(&net->ipv4.rt_genid, 0);
103371 - atomic_set(&net->fnhe_genid, 0);
103372 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103373 + atomic_set_unchecked(&net->fnhe_genid, 0);
103374 get_random_bytes(&net->ipv4.dev_addr_genid,
103375 sizeof(net->ipv4.dev_addr_genid));
103376 return 0;
103377 @@ -2719,11 +2719,7 @@ int __init ip_rt_init(void)
103378 {
103379 int rc = 0;
103380
103381 - ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103382 - if (!ip_idents)
103383 - panic("IP: failed to allocate ip_idents\n");
103384 -
103385 - prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103386 + prandom_bytes(ip_idents, sizeof(ip_idents));
103387
103388 #ifdef CONFIG_IP_ROUTE_CLASSID
103389 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103390 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103391 index b3c53c8..35cc18d 100644
103392 --- a/net/ipv4/sysctl_net_ipv4.c
103393 +++ b/net/ipv4/sysctl_net_ipv4.c
103394 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103395 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103396 int ret;
103397 int range[2];
103398 - struct ctl_table tmp = {
103399 + ctl_table_no_const tmp = {
103400 .data = &range,
103401 .maxlen = sizeof(range),
103402 .mode = table->mode,
103403 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103404 int ret;
103405 gid_t urange[2];
103406 kgid_t low, high;
103407 - struct ctl_table tmp = {
103408 + ctl_table_no_const tmp = {
103409 .data = &urange,
103410 .maxlen = sizeof(urange),
103411 .mode = table->mode,
103412 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103413 void __user *buffer, size_t *lenp, loff_t *ppos)
103414 {
103415 char val[TCP_CA_NAME_MAX];
103416 - struct ctl_table tbl = {
103417 + ctl_table_no_const tbl = {
103418 .data = val,
103419 .maxlen = TCP_CA_NAME_MAX,
103420 };
103421 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103422 void __user *buffer, size_t *lenp,
103423 loff_t *ppos)
103424 {
103425 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103426 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103427 int ret;
103428
103429 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103430 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103431 void __user *buffer, size_t *lenp,
103432 loff_t *ppos)
103433 {
103434 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103435 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103436 int ret;
103437
103438 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103439 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103440 void __user *buffer, size_t *lenp,
103441 loff_t *ppos)
103442 {
103443 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103444 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103445 struct tcp_fastopen_context *ctxt;
103446 int ret;
103447 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103448 @@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
103449
103450 static __net_init int ipv4_sysctl_init_net(struct net *net)
103451 {
103452 - struct ctl_table *table;
103453 + ctl_table_no_const *table = NULL;
103454
103455 - table = ipv4_net_table;
103456 if (!net_eq(net, &init_net)) {
103457 int i;
103458
103459 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103460 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103461 if (table == NULL)
103462 goto err_alloc;
103463
103464 @@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103465 table[i].data += (void *)net - (void *)&init_net;
103466 }
103467
103468 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103469 + if (!net_eq(net, &init_net))
103470 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103471 + else
103472 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103473 if (net->ipv4.ipv4_hdr == NULL)
103474 goto err_reg;
103475
103476 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103477 index d107ee2..bcebf11 100644
103478 --- a/net/ipv4/tcp_input.c
103479 +++ b/net/ipv4/tcp_input.c
103480 @@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103481 * without any lock. We want to make sure compiler wont store
103482 * intermediate values in this location.
103483 */
103484 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103485 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103486 sk->sk_max_pacing_rate);
103487 }
103488
103489 @@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103490 * simplifies code)
103491 */
103492 static void
103493 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103494 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103495 struct sk_buff *head, struct sk_buff *tail,
103496 u32 start, u32 end)
103497 {
103498 @@ -5506,6 +5506,7 @@ discard:
103499 tcp_paws_reject(&tp->rx_opt, 0))
103500 goto discard_and_undo;
103501
103502 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103503 if (th->syn) {
103504 /* We see SYN without ACK. It is attempt of
103505 * simultaneous connect with crossed SYNs.
103506 @@ -5556,6 +5557,7 @@ discard:
103507 goto discard;
103508 #endif
103509 }
103510 +#endif
103511 /* "fifth, if neither of the SYN or RST bits is set then
103512 * drop the segment and return."
103513 */
103514 @@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103515 goto discard;
103516
103517 if (th->syn) {
103518 - if (th->fin)
103519 + if (th->fin || th->urg || th->psh)
103520 goto discard;
103521 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103522 return 1;
103523 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103524 index 944ce5e..5b83585 100644
103525 --- a/net/ipv4/tcp_ipv4.c
103526 +++ b/net/ipv4/tcp_ipv4.c
103527 @@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
103528 int sysctl_tcp_low_latency __read_mostly;
103529 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103530
103531 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103532 +extern int grsec_enable_blackhole;
103533 +#endif
103534 +
103535 #ifdef CONFIG_TCP_MD5SIG
103536 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103537 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103538 @@ -1471,6 +1475,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103539 return 0;
103540
103541 reset:
103542 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103543 + if (!grsec_enable_blackhole)
103544 +#endif
103545 tcp_v4_send_reset(rsk, skb);
103546 discard:
103547 kfree_skb(skb);
103548 @@ -1635,12 +1642,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103549 TCP_SKB_CB(skb)->sacked = 0;
103550
103551 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103552 - if (!sk)
103553 + if (!sk) {
103554 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103555 + ret = 1;
103556 +#endif
103557 goto no_tcp_socket;
103558 -
103559 + }
103560 process:
103561 - if (sk->sk_state == TCP_TIME_WAIT)
103562 + if (sk->sk_state == TCP_TIME_WAIT) {
103563 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103564 + ret = 2;
103565 +#endif
103566 goto do_time_wait;
103567 + }
103568
103569 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103570 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103571 @@ -1696,6 +1710,10 @@ csum_error:
103572 bad_packet:
103573 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103574 } else {
103575 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103576 + if (!grsec_enable_blackhole || (ret == 1 &&
103577 + (skb->dev->flags & IFF_LOOPBACK)))
103578 +#endif
103579 tcp_v4_send_reset(NULL, skb);
103580 }
103581
103582 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103583 index 63d2680..2db9d6b 100644
103584 --- a/net/ipv4/tcp_minisocks.c
103585 +++ b/net/ipv4/tcp_minisocks.c
103586 @@ -27,6 +27,10 @@
103587 #include <net/inet_common.h>
103588 #include <net/xfrm.h>
103589
103590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103591 +extern int grsec_enable_blackhole;
103592 +#endif
103593 +
103594 int sysctl_tcp_syncookies __read_mostly = 1;
103595 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103596
103597 @@ -739,7 +743,10 @@ embryonic_reset:
103598 * avoid becoming vulnerable to outside attack aiming at
103599 * resetting legit local connections.
103600 */
103601 - req->rsk_ops->send_reset(sk, skb);
103602 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103603 + if (!grsec_enable_blackhole)
103604 +#endif
103605 + req->rsk_ops->send_reset(sk, skb);
103606 } else if (fastopen) { /* received a valid RST pkt */
103607 reqsk_fastopen_remove(sk, req, true);
103608 tcp_reset(sk);
103609 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103610 index ebf5ff5..4d1ff32 100644
103611 --- a/net/ipv4/tcp_probe.c
103612 +++ b/net/ipv4/tcp_probe.c
103613 @@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103614 if (cnt + width >= len)
103615 break;
103616
103617 - if (copy_to_user(buf + cnt, tbuf, width))
103618 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103619 return -EFAULT;
103620 cnt += width;
103621 }
103622 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103623 index 9b21ae8..4eb67df 100644
103624 --- a/net/ipv4/tcp_timer.c
103625 +++ b/net/ipv4/tcp_timer.c
103626 @@ -22,6 +22,10 @@
103627 #include <linux/gfp.h>
103628 #include <net/tcp.h>
103629
103630 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103631 +extern int grsec_lastack_retries;
103632 +#endif
103633 +
103634 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103635 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103636 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103637 @@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103638 }
103639 }
103640
103641 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103642 + if ((sk->sk_state == TCP_LAST_ACK) &&
103643 + (grsec_lastack_retries > 0) &&
103644 + (grsec_lastack_retries < retry_until))
103645 + retry_until = grsec_lastack_retries;
103646 +#endif
103647 +
103648 if (retransmits_timed_out(sk, retry_until,
103649 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103650 /* Has it gone just too far? */
103651 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103652 index cd0db54..93a6518 100644
103653 --- a/net/ipv4/udp.c
103654 +++ b/net/ipv4/udp.c
103655 @@ -87,6 +87,7 @@
103656 #include <linux/types.h>
103657 #include <linux/fcntl.h>
103658 #include <linux/module.h>
103659 +#include <linux/security.h>
103660 #include <linux/socket.h>
103661 #include <linux/sockios.h>
103662 #include <linux/igmp.h>
103663 @@ -114,6 +115,10 @@
103664 #include <net/busy_poll.h>
103665 #include "udp_impl.h"
103666
103667 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103668 +extern int grsec_enable_blackhole;
103669 +#endif
103670 +
103671 struct udp_table udp_table __read_mostly;
103672 EXPORT_SYMBOL(udp_table);
103673
103674 @@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103675 return true;
103676 }
103677
103678 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103679 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103680 +
103681 /*
103682 * This routine is called by the ICMP module when it gets some
103683 * sort of error condition. If err < 0 then the socket should
103684 @@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103685 dport = usin->sin_port;
103686 if (dport == 0)
103687 return -EINVAL;
103688 +
103689 + err = gr_search_udp_sendmsg(sk, usin);
103690 + if (err)
103691 + return err;
103692 } else {
103693 if (sk->sk_state != TCP_ESTABLISHED)
103694 return -EDESTADDRREQ;
103695 +
103696 + err = gr_search_udp_sendmsg(sk, NULL);
103697 + if (err)
103698 + return err;
103699 +
103700 daddr = inet->inet_daddr;
103701 dport = inet->inet_dport;
103702 /* Open fast path for connected socket.
103703 @@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103704 IS_UDPLITE(sk));
103705 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103706 IS_UDPLITE(sk));
103707 - atomic_inc(&sk->sk_drops);
103708 + atomic_inc_unchecked(&sk->sk_drops);
103709 __skb_unlink(skb, rcvq);
103710 __skb_queue_tail(&list_kill, skb);
103711 }
103712 @@ -1262,6 +1279,10 @@ try_again:
103713 if (!skb)
103714 goto out;
103715
103716 + err = gr_search_udp_recvmsg(sk, skb);
103717 + if (err)
103718 + goto out_free;
103719 +
103720 ulen = skb->len - sizeof(struct udphdr);
103721 copied = len;
103722 if (copied > ulen)
103723 @@ -1295,7 +1316,7 @@ try_again:
103724 if (unlikely(err)) {
103725 trace_kfree_skb(skb, udp_recvmsg);
103726 if (!peeked) {
103727 - atomic_inc(&sk->sk_drops);
103728 + atomic_inc_unchecked(&sk->sk_drops);
103729 UDP_INC_STATS_USER(sock_net(sk),
103730 UDP_MIB_INERRORS, is_udplite);
103731 }
103732 @@ -1592,7 +1613,7 @@ csum_error:
103733 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103734 drop:
103735 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103736 - atomic_inc(&sk->sk_drops);
103737 + atomic_inc_unchecked(&sk->sk_drops);
103738 kfree_skb(skb);
103739 return -1;
103740 }
103741 @@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103742 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103743
103744 if (!skb1) {
103745 - atomic_inc(&sk->sk_drops);
103746 + atomic_inc_unchecked(&sk->sk_drops);
103747 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103748 IS_UDPLITE(sk));
103749 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103750 @@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103751 goto csum_error;
103752
103753 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103754 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103755 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103756 +#endif
103757 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103758
103759 /*
103760 @@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103761 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103762 0, sock_i_ino(sp),
103763 atomic_read(&sp->sk_refcnt), sp,
103764 - atomic_read(&sp->sk_drops));
103765 + atomic_read_unchecked(&sp->sk_drops));
103766 }
103767
103768 int udp4_seq_show(struct seq_file *seq, void *v)
103769 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103770 index 6156f68..d6ab46d 100644
103771 --- a/net/ipv4/xfrm4_policy.c
103772 +++ b/net/ipv4/xfrm4_policy.c
103773 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103774 fl4->flowi4_tos = iph->tos;
103775 }
103776
103777 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103778 +static int xfrm4_garbage_collect(struct dst_ops *ops)
103779 {
103780 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103781
103782 - xfrm4_policy_afinfo.garbage_collect(net);
103783 + xfrm_garbage_collect_deferred(net);
103784 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103785 }
103786
103787 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103788
103789 static int __net_init xfrm4_net_init(struct net *net)
103790 {
103791 - struct ctl_table *table;
103792 + ctl_table_no_const *table = NULL;
103793 struct ctl_table_header *hdr;
103794
103795 - table = xfrm4_policy_table;
103796 if (!net_eq(net, &init_net)) {
103797 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103798 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103799 if (!table)
103800 goto err_alloc;
103801
103802 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103803 - }
103804 -
103805 - hdr = register_net_sysctl(net, "net/ipv4", table);
103806 + hdr = register_net_sysctl(net, "net/ipv4", table);
103807 + } else
103808 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103809 if (!hdr)
103810 goto err_reg;
103811
103812 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103813 return 0;
103814
103815 err_reg:
103816 - if (!net_eq(net, &init_net))
103817 - kfree(table);
103818 + kfree(table);
103819 err_alloc:
103820 return -ENOMEM;
103821 }
103822 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103823 index 0169ccf..6f14338 100644
103824 --- a/net/ipv6/addrconf.c
103825 +++ b/net/ipv6/addrconf.c
103826 @@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103827 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103828 .mtu6 = IPV6_MIN_MTU,
103829 .accept_ra = 1,
103830 - .accept_redirects = 1,
103831 + .accept_redirects = 0,
103832 .autoconf = 1,
103833 .force_mld_version = 0,
103834 .mldv1_unsolicited_report_interval = 10 * HZ,
103835 @@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103836 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103837 .mtu6 = IPV6_MIN_MTU,
103838 .accept_ra = 1,
103839 - .accept_redirects = 1,
103840 + .accept_redirects = 0,
103841 .autoconf = 1,
103842 .force_mld_version = 0,
103843 .mldv1_unsolicited_report_interval = 10 * HZ,
103844 @@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103845 idx = 0;
103846 head = &net->dev_index_head[h];
103847 rcu_read_lock();
103848 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103849 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103850 net->dev_base_seq;
103851 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103852 if (idx < s_idx)
103853 @@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103854 p.iph.ihl = 5;
103855 p.iph.protocol = IPPROTO_IPV6;
103856 p.iph.ttl = 64;
103857 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103858 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103859
103860 if (ops->ndo_do_ioctl) {
103861 mm_segment_t oldfs = get_fs();
103862 @@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103863 .release = seq_release_net,
103864 };
103865
103866 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103867 +extern void unregister_ipv6_seq_ops_addr(void);
103868 +
103869 static int __net_init if6_proc_net_init(struct net *net)
103870 {
103871 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103872 + register_ipv6_seq_ops_addr(&if6_seq_ops);
103873 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103874 + unregister_ipv6_seq_ops_addr();
103875 return -ENOMEM;
103876 + }
103877 return 0;
103878 }
103879
103880 static void __net_exit if6_proc_net_exit(struct net *net)
103881 {
103882 remove_proc_entry("if_inet6", net->proc_net);
103883 + unregister_ipv6_seq_ops_addr();
103884 }
103885
103886 static struct pernet_operations if6_proc_net_ops = {
103887 @@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103888 s_ip_idx = ip_idx = cb->args[2];
103889
103890 rcu_read_lock();
103891 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103892 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103893 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103894 idx = 0;
103895 head = &net->dev_index_head[h];
103896 @@ -4536,6 +4543,22 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
103897 return 0;
103898 }
103899
103900 +static const struct nla_policy inet6_af_policy[IFLA_INET6_MAX + 1] = {
103901 + [IFLA_INET6_ADDR_GEN_MODE] = { .type = NLA_U8 },
103902 + [IFLA_INET6_TOKEN] = { .len = sizeof(struct in6_addr) },
103903 +};
103904 +
103905 +static int inet6_validate_link_af(const struct net_device *dev,
103906 + const struct nlattr *nla)
103907 +{
103908 + struct nlattr *tb[IFLA_INET6_MAX + 1];
103909 +
103910 + if (dev && !__in6_dev_get(dev))
103911 + return -EAFNOSUPPORT;
103912 +
103913 + return nla_parse_nested(tb, IFLA_INET6_MAX, nla, inet6_af_policy);
103914 +}
103915 +
103916 static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
103917 {
103918 int err = -EINVAL;
103919 @@ -4788,7 +4811,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103920 rt_genid_bump_ipv6(net);
103921 break;
103922 }
103923 - atomic_inc(&net->ipv6.dev_addr_genid);
103924 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103925 }
103926
103927 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103928 @@ -4808,7 +4831,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103929 int *valp = ctl->data;
103930 int val = *valp;
103931 loff_t pos = *ppos;
103932 - struct ctl_table lctl;
103933 + ctl_table_no_const lctl;
103934 int ret;
103935
103936 /*
103937 @@ -4893,7 +4916,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103938 int *valp = ctl->data;
103939 int val = *valp;
103940 loff_t pos = *ppos;
103941 - struct ctl_table lctl;
103942 + ctl_table_no_const lctl;
103943 int ret;
103944
103945 /*
103946 @@ -5351,6 +5374,7 @@ static struct rtnl_af_ops inet6_ops = {
103947 .family = AF_INET6,
103948 .fill_link_af = inet6_fill_link_af,
103949 .get_link_af_size = inet6_get_link_af_size,
103950 + .validate_link_af = inet6_validate_link_af,
103951 .set_link_af = inet6_set_link_af,
103952 };
103953
103954 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103955 index e8c4400..a4cd5da 100644
103956 --- a/net/ipv6/af_inet6.c
103957 +++ b/net/ipv6/af_inet6.c
103958 @@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103959 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103960 net->ipv6.sysctl.flowlabel_consistency = 1;
103961 net->ipv6.sysctl.auto_flowlabels = 0;
103962 - atomic_set(&net->ipv6.fib6_sernum, 1);
103963 + atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103964
103965 err = ipv6_init_mibs(net);
103966 if (err)
103967 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103968 index 11e3945..4f1b785 100644
103969 --- a/net/ipv6/datagram.c
103970 +++ b/net/ipv6/datagram.c
103971 @@ -924,5 +924,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103972 0,
103973 sock_i_ino(sp),
103974 atomic_read(&sp->sk_refcnt), sp,
103975 - atomic_read(&sp->sk_drops));
103976 + atomic_read_unchecked(&sp->sk_drops));
103977 }
103978 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103979 index 97ae700..18dcae0 100644
103980 --- a/net/ipv6/icmp.c
103981 +++ b/net/ipv6/icmp.c
103982 @@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103983
103984 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103985 {
103986 - struct ctl_table *table;
103987 + ctl_table_no_const *table;
103988
103989 table = kmemdup(ipv6_icmp_table_template,
103990 sizeof(ipv6_icmp_table_template),
103991 diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103992 index f1c6d5e..faabef6 100644
103993 --- a/net/ipv6/ip6_fib.c
103994 +++ b/net/ipv6/ip6_fib.c
103995 @@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103996 int new, old;
103997
103998 do {
103999 - old = atomic_read(&net->ipv6.fib6_sernum);
104000 + old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
104001 new = old < INT_MAX ? old + 1 : 1;
104002 - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
104003 + } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
104004 old, new) != old);
104005 return new;
104006 }
104007 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
104008 index 0e32d2e..dd45cdc 100644
104009 --- a/net/ipv6/ip6_gre.c
104010 +++ b/net/ipv6/ip6_gre.c
104011 @@ -71,8 +71,8 @@ struct ip6gre_net {
104012 struct net_device *fb_tunnel_dev;
104013 };
104014
104015 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
104016 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
104017 +static struct rtnl_link_ops ip6gre_link_ops;
104018 +static struct rtnl_link_ops ip6gre_tap_ops;
104019 static int ip6gre_tunnel_init(struct net_device *dev);
104020 static void ip6gre_tunnel_setup(struct net_device *dev);
104021 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
104022 @@ -417,7 +417,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
104023 if (code == ICMPV6_HDR_FIELD)
104024 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
104025
104026 - if (teli && teli == info - 2) {
104027 + if (teli && teli == be32_to_cpu(info) - 2) {
104028 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
104029 if (tel->encap_limit == 0) {
104030 net_warn_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
104031 @@ -429,7 +429,7 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
104032 }
104033 break;
104034 case ICMPV6_PKT_TOOBIG:
104035 - mtu = info - offset;
104036 + mtu = be32_to_cpu(info) - offset;
104037 if (mtu < IPV6_MIN_MTU)
104038 mtu = IPV6_MIN_MTU;
104039 t->dev->mtu = mtu;
104040 @@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
104041 }
104042
104043
104044 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
104045 +static struct inet6_protocol ip6gre_protocol = {
104046 .handler = ip6gre_rcv,
104047 .err_handler = ip6gre_err,
104048 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
104049 @@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
104050 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
104051 };
104052
104053 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104054 +static struct rtnl_link_ops ip6gre_link_ops = {
104055 .kind = "ip6gre",
104056 .maxtype = IFLA_GRE_MAX,
104057 .policy = ip6gre_policy,
104058 @@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104059 .fill_info = ip6gre_fill_info,
104060 };
104061
104062 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
104063 +static struct rtnl_link_ops ip6gre_tap_ops = {
104064 .kind = "ip6gretap",
104065 .maxtype = IFLA_GRE_MAX,
104066 .policy = ip6gre_policy,
104067 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
104068 index 9cb94cf..5678108 100644
104069 --- a/net/ipv6/ip6_tunnel.c
104070 +++ b/net/ipv6/ip6_tunnel.c
104071 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104072
104073 static int ip6_tnl_dev_init(struct net_device *dev);
104074 static void ip6_tnl_dev_setup(struct net_device *dev);
104075 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
104076 +static struct rtnl_link_ops ip6_link_ops;
104077
104078 static int ip6_tnl_net_id __read_mostly;
104079 struct ip6_tnl_net {
104080 @@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
104081 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
104082 };
104083
104084 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
104085 +static struct rtnl_link_ops ip6_link_ops = {
104086 .kind = "ip6tnl",
104087 .maxtype = IFLA_IPTUN_MAX,
104088 .policy = ip6_tnl_policy,
104089 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
104090 index bcda14d..49378c9 100644
104091 --- a/net/ipv6/ip6_vti.c
104092 +++ b/net/ipv6/ip6_vti.c
104093 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104094
104095 static int vti6_dev_init(struct net_device *dev);
104096 static void vti6_dev_setup(struct net_device *dev);
104097 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
104098 +static struct rtnl_link_ops vti6_link_ops;
104099
104100 static int vti6_net_id __read_mostly;
104101 struct vti6_net {
104102 @@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
104103 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
104104 };
104105
104106 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
104107 +static struct rtnl_link_ops vti6_link_ops = {
104108 .kind = "vti6",
104109 .maxtype = IFLA_VTI_MAX,
104110 .policy = vti6_policy,
104111 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
104112 index e1a9583..7dd8f4d 100644
104113 --- a/net/ipv6/ipv6_sockglue.c
104114 +++ b/net/ipv6/ipv6_sockglue.c
104115 @@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104116 if (sk->sk_type != SOCK_STREAM)
104117 return -ENOPROTOOPT;
104118
104119 - msg.msg_control = optval;
104120 + msg.msg_control = (void __force_kernel *)optval;
104121 msg.msg_controllen = len;
104122 msg.msg_flags = flags;
104123
104124 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104125 index e080fbb..412b3cf 100644
104126 --- a/net/ipv6/netfilter/ip6_tables.c
104127 +++ b/net/ipv6/netfilter/ip6_tables.c
104128 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104129 #endif
104130
104131 static int get_info(struct net *net, void __user *user,
104132 - const int *len, int compat)
104133 + int len, int compat)
104134 {
104135 char name[XT_TABLE_MAXNAMELEN];
104136 struct xt_table *t;
104137 int ret;
104138
104139 - if (*len != sizeof(struct ip6t_getinfo)) {
104140 - duprintf("length %u != %zu\n", *len,
104141 + if (len != sizeof(struct ip6t_getinfo)) {
104142 + duprintf("length %u != %zu\n", len,
104143 sizeof(struct ip6t_getinfo));
104144 return -EINVAL;
104145 }
104146 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104147 info.size = private->size;
104148 strcpy(info.name, name);
104149
104150 - if (copy_to_user(user, &info, *len) != 0)
104151 + if (copy_to_user(user, &info, len) != 0)
104152 ret = -EFAULT;
104153 else
104154 ret = 0;
104155 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104156
104157 switch (cmd) {
104158 case IP6T_SO_GET_INFO:
104159 - ret = get_info(sock_net(sk), user, len, 1);
104160 + ret = get_info(sock_net(sk), user, *len, 1);
104161 break;
104162 case IP6T_SO_GET_ENTRIES:
104163 ret = compat_get_entries(sock_net(sk), user, len);
104164 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104165
104166 switch (cmd) {
104167 case IP6T_SO_GET_INFO:
104168 - ret = get_info(sock_net(sk), user, len, 0);
104169 + ret = get_info(sock_net(sk), user, *len, 0);
104170 break;
104171
104172 case IP6T_SO_GET_ENTRIES:
104173 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104174 index 6f187c8..34b367f 100644
104175 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104176 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104177 @@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104178
104179 static int nf_ct_frag6_sysctl_register(struct net *net)
104180 {
104181 - struct ctl_table *table;
104182 + ctl_table_no_const *table = NULL;
104183 struct ctl_table_header *hdr;
104184
104185 - table = nf_ct_frag6_sysctl_table;
104186 if (!net_eq(net, &init_net)) {
104187 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104188 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104189 GFP_KERNEL);
104190 if (table == NULL)
104191 goto err_alloc;
104192 @@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104193 table[2].data = &net->nf_frag.frags.high_thresh;
104194 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104195 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104196 - }
104197 -
104198 - hdr = register_net_sysctl(net, "net/netfilter", table);
104199 + hdr = register_net_sysctl(net, "net/netfilter", table);
104200 + } else
104201 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104202 if (hdr == NULL)
104203 goto err_reg;
104204
104205 @@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104206 return 0;
104207
104208 err_reg:
104209 - if (!net_eq(net, &init_net))
104210 - kfree(table);
104211 + kfree(table);
104212 err_alloc:
104213 return -ENOMEM;
104214 }
104215 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104216 index 5b7a1ed..83e96de 100644
104217 --- a/net/ipv6/ping.c
104218 +++ b/net/ipv6/ping.c
104219 @@ -102,9 +102,10 @@ int ping_v6_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
104220
104221 if (msg->msg_name) {
104222 DECLARE_SOCKADDR(struct sockaddr_in6 *, u, msg->msg_name);
104223 - if (msg->msg_namelen < sizeof(struct sockaddr_in6) ||
104224 - u->sin6_family != AF_INET6) {
104225 + if (msg->msg_namelen < sizeof(*u))
104226 return -EINVAL;
104227 + if (u->sin6_family != AF_INET6) {
104228 + return -EAFNOSUPPORT;
104229 }
104230 if (sk->sk_bound_dev_if &&
104231 sk->sk_bound_dev_if != u->sin6_scope_id) {
104232 @@ -240,6 +241,24 @@ static struct pernet_operations ping_v6_net_ops = {
104233 };
104234 #endif
104235
104236 +static struct pingv6_ops real_pingv6_ops = {
104237 + .ipv6_recv_error = ipv6_recv_error,
104238 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104239 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104240 + .icmpv6_err_convert = icmpv6_err_convert,
104241 + .ipv6_icmp_error = ipv6_icmp_error,
104242 + .ipv6_chk_addr = ipv6_chk_addr,
104243 +};
104244 +
104245 +static struct pingv6_ops dummy_pingv6_ops = {
104246 + .ipv6_recv_error = dummy_ipv6_recv_error,
104247 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104248 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104249 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
104250 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
104251 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
104252 +};
104253 +
104254 int __init pingv6_init(void)
104255 {
104256 #ifdef CONFIG_PROC_FS
104257 @@ -247,13 +266,7 @@ int __init pingv6_init(void)
104258 if (ret)
104259 return ret;
104260 #endif
104261 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104262 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104263 - pingv6_ops.ip6_datagram_recv_specific_ctl =
104264 - ip6_datagram_recv_specific_ctl;
104265 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104266 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104267 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104268 + pingv6_ops = &real_pingv6_ops;
104269 return inet6_register_protosw(&pingv6_protosw);
104270 }
104271
104272 @@ -262,14 +275,9 @@ int __init pingv6_init(void)
104273 */
104274 void pingv6_exit(void)
104275 {
104276 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104277 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104278 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104279 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104280 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104281 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104282 #ifdef CONFIG_PROC_FS
104283 unregister_pernet_subsys(&ping_v6_net_ops);
104284 #endif
104285 + pingv6_ops = &dummy_pingv6_ops;
104286 inet6_unregister_protosw(&pingv6_protosw);
104287 }
104288 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104289 index 1752cd0..3c6af41 100644
104290 --- a/net/ipv6/proc.c
104291 +++ b/net/ipv6/proc.c
104292 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104293 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104294 goto proc_snmp6_fail;
104295
104296 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104297 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104298 if (!net->mib.proc_net_devsnmp6)
104299 goto proc_dev_snmp6_fail;
104300 return 0;
104301 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104302 index 896af88..6e2ba628 100644
104303 --- a/net/ipv6/raw.c
104304 +++ b/net/ipv6/raw.c
104305 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104306 {
104307 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104308 skb_checksum_complete(skb)) {
104309 - atomic_inc(&sk->sk_drops);
104310 + atomic_inc_unchecked(&sk->sk_drops);
104311 kfree_skb(skb);
104312 return NET_RX_DROP;
104313 }
104314 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104315 struct raw6_sock *rp = raw6_sk(sk);
104316
104317 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104318 - atomic_inc(&sk->sk_drops);
104319 + atomic_inc_unchecked(&sk->sk_drops);
104320 kfree_skb(skb);
104321 return NET_RX_DROP;
104322 }
104323 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104324
104325 if (inet->hdrincl) {
104326 if (skb_checksum_complete(skb)) {
104327 - atomic_inc(&sk->sk_drops);
104328 + atomic_inc_unchecked(&sk->sk_drops);
104329 kfree_skb(skb);
104330 return NET_RX_DROP;
104331 }
104332 @@ -608,7 +608,7 @@ out:
104333 return err;
104334 }
104335
104336 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104337 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104338 struct flowi6 *fl6, struct dst_entry **dstp,
104339 unsigned int flags)
104340 {
104341 @@ -914,12 +914,15 @@ do_confirm:
104342 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104343 char __user *optval, int optlen)
104344 {
104345 + struct icmp6_filter filter;
104346 +
104347 switch (optname) {
104348 case ICMPV6_FILTER:
104349 if (optlen > sizeof(struct icmp6_filter))
104350 optlen = sizeof(struct icmp6_filter);
104351 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104352 + if (copy_from_user(&filter, optval, optlen))
104353 return -EFAULT;
104354 + raw6_sk(sk)->filter = filter;
104355 return 0;
104356 default:
104357 return -ENOPROTOOPT;
104358 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104359 char __user *optval, int __user *optlen)
104360 {
104361 int len;
104362 + struct icmp6_filter filter;
104363
104364 switch (optname) {
104365 case ICMPV6_FILTER:
104366 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104367 len = sizeof(struct icmp6_filter);
104368 if (put_user(len, optlen))
104369 return -EFAULT;
104370 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104371 + filter = raw6_sk(sk)->filter;
104372 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
104373 return -EFAULT;
104374 return 0;
104375 default:
104376 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104377 index 1a157ca..9fc05f4 100644
104378 --- a/net/ipv6/reassembly.c
104379 +++ b/net/ipv6/reassembly.c
104380 @@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104381
104382 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104383 {
104384 - struct ctl_table *table;
104385 + ctl_table_no_const *table = NULL;
104386 struct ctl_table_header *hdr;
104387
104388 - table = ip6_frags_ns_ctl_table;
104389 if (!net_eq(net, &init_net)) {
104390 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104391 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104392 if (table == NULL)
104393 goto err_alloc;
104394
104395 @@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104396 /* Don't export sysctls to unprivileged users */
104397 if (net->user_ns != &init_user_ns)
104398 table[0].procname = NULL;
104399 - }
104400 + hdr = register_net_sysctl(net, "net/ipv6", table);
104401 + } else
104402 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104403
104404 - hdr = register_net_sysctl(net, "net/ipv6", table);
104405 if (hdr == NULL)
104406 goto err_reg;
104407
104408 @@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104409 return 0;
104410
104411 err_reg:
104412 - if (!net_eq(net, &init_net))
104413 - kfree(table);
104414 + kfree(table);
104415 err_alloc:
104416 return -ENOMEM;
104417 }
104418 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104419 index d02ee01..42a612c 100644
104420 --- a/net/ipv6/route.c
104421 +++ b/net/ipv6/route.c
104422 @@ -2962,7 +2962,7 @@ struct ctl_table ipv6_route_table_template[] = {
104423
104424 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104425 {
104426 - struct ctl_table *table;
104427 + ctl_table_no_const *table;
104428
104429 table = kmemdup(ipv6_route_table_template,
104430 sizeof(ipv6_route_table_template),
104431 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104432 index a24557a..ade77d3 100644
104433 --- a/net/ipv6/sit.c
104434 +++ b/net/ipv6/sit.c
104435 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104436 static void ipip6_dev_free(struct net_device *dev);
104437 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104438 __be32 *v4dst);
104439 -static struct rtnl_link_ops sit_link_ops __read_mostly;
104440 +static struct rtnl_link_ops sit_link_ops;
104441
104442 static int sit_net_id __read_mostly;
104443 struct sit_net {
104444 @@ -1505,12 +1505,12 @@ static bool ipip6_netlink_encap_parms(struct nlattr *data[],
104445
104446 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
104447 ret = true;
104448 - ipencap->sport = nla_get_u16(data[IFLA_IPTUN_ENCAP_SPORT]);
104449 + ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
104450 }
104451
104452 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
104453 ret = true;
104454 - ipencap->dport = nla_get_u16(data[IFLA_IPTUN_ENCAP_DPORT]);
104455 + ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
104456 }
104457
104458 return ret;
104459 @@ -1706,9 +1706,9 @@ static int ipip6_fill_info(struct sk_buff *skb, const struct net_device *dev)
104460
104461 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE,
104462 tunnel->encap.type) ||
104463 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_SPORT,
104464 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT,
104465 tunnel->encap.sport) ||
104466 - nla_put_u16(skb, IFLA_IPTUN_ENCAP_DPORT,
104467 + nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT,
104468 tunnel->encap.dport) ||
104469 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS,
104470 tunnel->encap.dport))
104471 @@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104472 unregister_netdevice_queue(dev, head);
104473 }
104474
104475 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
104476 +static struct rtnl_link_ops sit_link_ops = {
104477 .kind = "sit",
104478 .maxtype = IFLA_IPTUN_MAX,
104479 .policy = ipip6_policy,
104480 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104481 index c5c10fa..2577d51 100644
104482 --- a/net/ipv6/sysctl_net_ipv6.c
104483 +++ b/net/ipv6/sysctl_net_ipv6.c
104484 @@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
104485
104486 static int __net_init ipv6_sysctl_net_init(struct net *net)
104487 {
104488 - struct ctl_table *ipv6_table;
104489 + ctl_table_no_const *ipv6_table;
104490 struct ctl_table *ipv6_route_table;
104491 struct ctl_table *ipv6_icmp_table;
104492 int err;
104493 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104494 index c113602..0cccb46 100644
104495 --- a/net/ipv6/tcp_ipv6.c
104496 +++ b/net/ipv6/tcp_ipv6.c
104497 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104498 }
104499 }
104500
104501 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104502 +extern int grsec_enable_blackhole;
104503 +#endif
104504 +
104505 static void tcp_v6_hash(struct sock *sk)
104506 {
104507 if (sk->sk_state != TCP_CLOSE) {
104508 @@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104509 return 0;
104510
104511 reset:
104512 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104513 + if (!grsec_enable_blackhole)
104514 +#endif
104515 tcp_v6_send_reset(sk, skb);
104516 discard:
104517 if (opt_skb)
104518 @@ -1441,12 +1448,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104519
104520 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
104521 inet6_iif(skb));
104522 - if (!sk)
104523 + if (!sk) {
104524 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104525 + ret = 1;
104526 +#endif
104527 goto no_tcp_socket;
104528 + }
104529
104530 process:
104531 - if (sk->sk_state == TCP_TIME_WAIT)
104532 + if (sk->sk_state == TCP_TIME_WAIT) {
104533 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104534 + ret = 2;
104535 +#endif
104536 goto do_time_wait;
104537 + }
104538
104539 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104540 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104541 @@ -1497,6 +1512,10 @@ csum_error:
104542 bad_packet:
104543 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104544 } else {
104545 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104546 + if (!grsec_enable_blackhole || (ret == 1 &&
104547 + (skb->dev->flags & IFF_LOOPBACK)))
104548 +#endif
104549 tcp_v6_send_reset(NULL, skb);
104550 }
104551
104552 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104553 index f6ba535..b41033f 100644
104554 --- a/net/ipv6/udp.c
104555 +++ b/net/ipv6/udp.c
104556 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104557 udp_ipv6_hash_secret + net_hash_mix(net));
104558 }
104559
104560 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104561 +extern int grsec_enable_blackhole;
104562 +#endif
104563 +
104564 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104565 {
104566 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104567 @@ -434,7 +438,7 @@ try_again:
104568 if (unlikely(err)) {
104569 trace_kfree_skb(skb, udpv6_recvmsg);
104570 if (!peeked) {
104571 - atomic_inc(&sk->sk_drops);
104572 + atomic_inc_unchecked(&sk->sk_drops);
104573 if (is_udp4)
104574 UDP_INC_STATS_USER(sock_net(sk),
104575 UDP_MIB_INERRORS,
104576 @@ -701,7 +705,7 @@ csum_error:
104577 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104578 drop:
104579 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104580 - atomic_inc(&sk->sk_drops);
104581 + atomic_inc_unchecked(&sk->sk_drops);
104582 kfree_skb(skb);
104583 return -1;
104584 }
104585 @@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104586 if (likely(skb1 == NULL))
104587 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104588 if (!skb1) {
104589 - atomic_inc(&sk->sk_drops);
104590 + atomic_inc_unchecked(&sk->sk_drops);
104591 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104592 IS_UDPLITE(sk));
104593 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104594 @@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104595 goto csum_error;
104596
104597 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104599 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104600 +#endif
104601 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104602
104603 kfree_skb(skb);
104604 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104605 index 5f98364..691985a 100644
104606 --- a/net/ipv6/xfrm6_policy.c
104607 +++ b/net/ipv6/xfrm6_policy.c
104608 @@ -130,12 +130,18 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104609 {
104610 struct flowi6 *fl6 = &fl->u.ip6;
104611 int onlyproto = 0;
104612 - u16 offset = skb_network_header_len(skb);
104613 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104614 + u16 offset = sizeof(*hdr);
104615 struct ipv6_opt_hdr *exthdr;
104616 const unsigned char *nh = skb_network_header(skb);
104617 - u8 nexthdr = nh[IP6CB(skb)->nhoff];
104618 + u16 nhoff = IP6CB(skb)->nhoff;
104619 int oif = 0;
104620 + u8 nexthdr;
104621 +
104622 + if (!nhoff)
104623 + nhoff = offsetof(struct ipv6hdr, nexthdr);
104624 +
104625 + nexthdr = nh[nhoff];
104626
104627 if (skb_dst(skb))
104628 oif = skb_dst(skb)->dev->ifindex;
104629 @@ -217,11 +223,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104630 }
104631 }
104632
104633 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104634 +static int xfrm6_garbage_collect(struct dst_ops *ops)
104635 {
104636 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104637
104638 - xfrm6_policy_afinfo.garbage_collect(net);
104639 + xfrm_garbage_collect_deferred(net);
104640 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104641 }
104642
104643 @@ -334,19 +340,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104644
104645 static int __net_init xfrm6_net_init(struct net *net)
104646 {
104647 - struct ctl_table *table;
104648 + ctl_table_no_const *table = NULL;
104649 struct ctl_table_header *hdr;
104650
104651 - table = xfrm6_policy_table;
104652 if (!net_eq(net, &init_net)) {
104653 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104654 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104655 if (!table)
104656 goto err_alloc;
104657
104658 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104659 - }
104660 + hdr = register_net_sysctl(net, "net/ipv6", table);
104661 + } else
104662 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104663
104664 - hdr = register_net_sysctl(net, "net/ipv6", table);
104665 if (!hdr)
104666 goto err_reg;
104667
104668 @@ -354,8 +360,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104669 return 0;
104670
104671 err_reg:
104672 - if (!net_eq(net, &init_net))
104673 - kfree(table);
104674 + kfree(table);
104675 err_alloc:
104676 return -ENOMEM;
104677 }
104678 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104679 index e15c16a..7cf07aa 100644
104680 --- a/net/ipx/ipx_proc.c
104681 +++ b/net/ipx/ipx_proc.c
104682 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104683 struct proc_dir_entry *p;
104684 int rc = -ENOMEM;
104685
104686 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104687 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104688
104689 if (!ipx_proc_dir)
104690 goto out;
104691 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104692 index 61ceb4c..e788eb8 100644
104693 --- a/net/irda/ircomm/ircomm_tty.c
104694 +++ b/net/irda/ircomm/ircomm_tty.c
104695 @@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104696 add_wait_queue(&port->open_wait, &wait);
104697
104698 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104699 - __FILE__, __LINE__, tty->driver->name, port->count);
104700 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104701
104702 spin_lock_irqsave(&port->lock, flags);
104703 - port->count--;
104704 + atomic_dec(&port->count);
104705 port->blocked_open++;
104706 spin_unlock_irqrestore(&port->lock, flags);
104707
104708 @@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104709 }
104710
104711 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104712 - __FILE__, __LINE__, tty->driver->name, port->count);
104713 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104714
104715 schedule();
104716 }
104717 @@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104718
104719 spin_lock_irqsave(&port->lock, flags);
104720 if (!tty_hung_up_p(filp))
104721 - port->count++;
104722 + atomic_inc(&port->count);
104723 port->blocked_open--;
104724 spin_unlock_irqrestore(&port->lock, flags);
104725
104726 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104727 - __FILE__, __LINE__, tty->driver->name, port->count);
104728 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104729
104730 if (!retval)
104731 port->flags |= ASYNC_NORMAL_ACTIVE;
104732 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104733
104734 /* ++ is not atomic, so this should be protected - Jean II */
104735 spin_lock_irqsave(&self->port.lock, flags);
104736 - self->port.count++;
104737 + atomic_inc(&self->port.count);
104738 spin_unlock_irqrestore(&self->port.lock, flags);
104739 tty_port_tty_set(&self->port, tty);
104740
104741 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104742 - self->line, self->port.count);
104743 + self->line, atomic_read(&self->port.count));
104744
104745 /* Not really used by us, but lets do it anyway */
104746 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104747 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104748 tty_kref_put(port->tty);
104749 }
104750 port->tty = NULL;
104751 - port->count = 0;
104752 + atomic_set(&port->count, 0);
104753 spin_unlock_irqrestore(&port->lock, flags);
104754
104755 wake_up_interruptible(&port->open_wait);
104756 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104757 seq_putc(m, '\n');
104758
104759 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104760 - seq_printf(m, "Open count: %d\n", self->port.count);
104761 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104762 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104763 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104764
104765 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104766 index b9ac598..f88cc56 100644
104767 --- a/net/irda/irproc.c
104768 +++ b/net/irda/irproc.c
104769 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104770 {
104771 int i;
104772
104773 - proc_irda = proc_mkdir("irda", init_net.proc_net);
104774 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104775 if (proc_irda == NULL)
104776 return;
104777
104778 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104779 index a089b6b..3ca3b60 100644
104780 --- a/net/iucv/af_iucv.c
104781 +++ b/net/iucv/af_iucv.c
104782 @@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104783 {
104784 char name[12];
104785
104786 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104787 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104788 while (__iucv_get_sock_by_name(name)) {
104789 sprintf(name, "%08x",
104790 - atomic_inc_return(&iucv_sk_list.autobind_name));
104791 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104792 }
104793 memcpy(iucv->src_name, name, 8);
104794 }
104795 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104796 index 2a6a1fd..6c112b0 100644
104797 --- a/net/iucv/iucv.c
104798 +++ b/net/iucv/iucv.c
104799 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104800 return NOTIFY_OK;
104801 }
104802
104803 -static struct notifier_block __refdata iucv_cpu_notifier = {
104804 +static struct notifier_block iucv_cpu_notifier = {
104805 .notifier_call = iucv_cpu_notify,
104806 };
104807
104808 diff --git a/net/key/af_key.c b/net/key/af_key.c
104809 index 1847ec4..26ef732 100644
104810 --- a/net/key/af_key.c
104811 +++ b/net/key/af_key.c
104812 @@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104813 static u32 get_acqseq(void)
104814 {
104815 u32 res;
104816 - static atomic_t acqseq;
104817 + static atomic_unchecked_t acqseq;
104818
104819 do {
104820 - res = atomic_inc_return(&acqseq);
104821 + res = atomic_inc_return_unchecked(&acqseq);
104822 } while (!res);
104823 return res;
104824 }
104825 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104826 index edb78e6..8dc654a 100644
104827 --- a/net/l2tp/l2tp_eth.c
104828 +++ b/net/l2tp/l2tp_eth.c
104829 @@ -42,12 +42,12 @@ struct l2tp_eth {
104830 struct sock *tunnel_sock;
104831 struct l2tp_session *session;
104832 struct list_head list;
104833 - atomic_long_t tx_bytes;
104834 - atomic_long_t tx_packets;
104835 - atomic_long_t tx_dropped;
104836 - atomic_long_t rx_bytes;
104837 - atomic_long_t rx_packets;
104838 - atomic_long_t rx_errors;
104839 + atomic_long_unchecked_t tx_bytes;
104840 + atomic_long_unchecked_t tx_packets;
104841 + atomic_long_unchecked_t tx_dropped;
104842 + atomic_long_unchecked_t rx_bytes;
104843 + atomic_long_unchecked_t rx_packets;
104844 + atomic_long_unchecked_t rx_errors;
104845 };
104846
104847 /* via l2tp_session_priv() */
104848 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104849 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104850
104851 if (likely(ret == NET_XMIT_SUCCESS)) {
104852 - atomic_long_add(len, &priv->tx_bytes);
104853 - atomic_long_inc(&priv->tx_packets);
104854 + atomic_long_add_unchecked(len, &priv->tx_bytes);
104855 + atomic_long_inc_unchecked(&priv->tx_packets);
104856 } else {
104857 - atomic_long_inc(&priv->tx_dropped);
104858 + atomic_long_inc_unchecked(&priv->tx_dropped);
104859 }
104860 return NETDEV_TX_OK;
104861 }
104862 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104863 {
104864 struct l2tp_eth *priv = netdev_priv(dev);
104865
104866 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104867 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
104868 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104869 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104870 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
104871 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
104872 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104873 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104874 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104875 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104876 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104877 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104878 return stats;
104879 }
104880
104881 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104882 nf_reset(skb);
104883
104884 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104885 - atomic_long_inc(&priv->rx_packets);
104886 - atomic_long_add(data_len, &priv->rx_bytes);
104887 + atomic_long_inc_unchecked(&priv->rx_packets);
104888 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104889 } else {
104890 - atomic_long_inc(&priv->rx_errors);
104891 + atomic_long_inc_unchecked(&priv->rx_errors);
104892 }
104893 return;
104894
104895 error:
104896 - atomic_long_inc(&priv->rx_errors);
104897 + atomic_long_inc_unchecked(&priv->rx_errors);
104898 kfree_skb(skb);
104899 }
104900
104901 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104902 index 1a3c7e0..80f8b0c 100644
104903 --- a/net/llc/llc_proc.c
104904 +++ b/net/llc/llc_proc.c
104905 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104906 int rc = -ENOMEM;
104907 struct proc_dir_entry *p;
104908
104909 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104910 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104911 if (!llc_proc_dir)
104912 goto out;
104913
104914 diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c
104915 index 612a5dd..799bafc 100644
104916 --- a/net/llc/sysctl_net_llc.c
104917 +++ b/net/llc/sysctl_net_llc.c
104918 @@ -18,28 +18,28 @@ static struct ctl_table llc2_timeout_table[] = {
104919 {
104920 .procname = "ack",
104921 .data = &sysctl_llc2_ack_timeout,
104922 - .maxlen = sizeof(long),
104923 + .maxlen = sizeof(sysctl_llc2_ack_timeout),
104924 .mode = 0644,
104925 .proc_handler = proc_dointvec_jiffies,
104926 },
104927 {
104928 .procname = "busy",
104929 .data = &sysctl_llc2_busy_timeout,
104930 - .maxlen = sizeof(long),
104931 + .maxlen = sizeof(sysctl_llc2_busy_timeout),
104932 .mode = 0644,
104933 .proc_handler = proc_dointvec_jiffies,
104934 },
104935 {
104936 .procname = "p",
104937 .data = &sysctl_llc2_p_timeout,
104938 - .maxlen = sizeof(long),
104939 + .maxlen = sizeof(sysctl_llc2_p_timeout),
104940 .mode = 0644,
104941 .proc_handler = proc_dointvec_jiffies,
104942 },
104943 {
104944 .procname = "rej",
104945 .data = &sysctl_llc2_rej_timeout,
104946 - .maxlen = sizeof(long),
104947 + .maxlen = sizeof(sysctl_llc2_rej_timeout),
104948 .mode = 0644,
104949 .proc_handler = proc_dointvec_jiffies,
104950 },
104951 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104952 index 343da1e..509873f 100644
104953 --- a/net/mac80211/cfg.c
104954 +++ b/net/mac80211/cfg.c
104955 @@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104956 ret = ieee80211_vif_use_channel(sdata, chandef,
104957 IEEE80211_CHANCTX_EXCLUSIVE);
104958 }
104959 - } else if (local->open_count == local->monitors) {
104960 + } else if (local_read(&local->open_count) == local->monitors) {
104961 local->_oper_chandef = *chandef;
104962 ieee80211_hw_config(local, 0);
104963 }
104964 @@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104965 else
104966 local->probe_req_reg--;
104967
104968 - if (!local->open_count)
104969 + if (!local_read(&local->open_count))
104970 break;
104971
104972 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104973 @@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104974 if (chanctx_conf) {
104975 *chandef = sdata->vif.bss_conf.chandef;
104976 ret = 0;
104977 - } else if (local->open_count > 0 &&
104978 - local->open_count == local->monitors &&
104979 + } else if (local_read(&local->open_count) > 0 &&
104980 + local_read(&local->open_count) == local->monitors &&
104981 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104982 if (local->use_chanctx)
104983 *chandef = local->monitor_chandef;
104984 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104985 index 8c68da3..0695016 100644
104986 --- a/net/mac80211/ieee80211_i.h
104987 +++ b/net/mac80211/ieee80211_i.h
104988 @@ -29,6 +29,7 @@
104989 #include <net/ieee80211_radiotap.h>
104990 #include <net/cfg80211.h>
104991 #include <net/mac80211.h>
104992 +#include <asm/local.h>
104993 #include "key.h"
104994 #include "sta_info.h"
104995 #include "debug.h"
104996 @@ -1057,7 +1058,7 @@ struct ieee80211_local {
104997 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104998 spinlock_t queue_stop_reason_lock;
104999
105000 - int open_count;
105001 + local_t open_count;
105002 int monitors, cooked_mntrs;
105003 /* number of interfaces with corresponding FIF_ flags */
105004 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
105005 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
105006 index eeae0ab..0f24585 100644
105007 --- a/net/mac80211/iface.c
105008 +++ b/net/mac80211/iface.c
105009 @@ -533,7 +533,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105010 break;
105011 }
105012
105013 - if (local->open_count == 0) {
105014 + if (local_read(&local->open_count) == 0) {
105015 res = drv_start(local);
105016 if (res)
105017 goto err_del_bss;
105018 @@ -580,7 +580,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105019 res = drv_add_interface(local, sdata);
105020 if (res)
105021 goto err_stop;
105022 - } else if (local->monitors == 0 && local->open_count == 0) {
105023 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
105024 res = ieee80211_add_virtual_monitor(local);
105025 if (res)
105026 goto err_stop;
105027 @@ -689,7 +689,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105028 atomic_inc(&local->iff_promiscs);
105029
105030 if (coming_up)
105031 - local->open_count++;
105032 + local_inc(&local->open_count);
105033
105034 if (hw_reconf_flags)
105035 ieee80211_hw_config(local, hw_reconf_flags);
105036 @@ -727,7 +727,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105037 err_del_interface:
105038 drv_remove_interface(local, sdata);
105039 err_stop:
105040 - if (!local->open_count)
105041 + if (!local_read(&local->open_count))
105042 drv_stop(local);
105043 err_del_bss:
105044 sdata->bss = NULL;
105045 @@ -893,7 +893,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105046 }
105047
105048 if (going_down)
105049 - local->open_count--;
105050 + local_dec(&local->open_count);
105051
105052 switch (sdata->vif.type) {
105053 case NL80211_IFTYPE_AP_VLAN:
105054 @@ -955,7 +955,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105055 }
105056 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
105057
105058 - if (local->open_count == 0)
105059 + if (local_read(&local->open_count) == 0)
105060 ieee80211_clear_tx_pending(local);
105061
105062 /*
105063 @@ -998,7 +998,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105064 if (cancel_scan)
105065 flush_delayed_work(&local->scan_work);
105066
105067 - if (local->open_count == 0) {
105068 + if (local_read(&local->open_count) == 0) {
105069 ieee80211_stop_device(local);
105070
105071 /* no reconfiguring after stop! */
105072 @@ -1009,7 +1009,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105073 ieee80211_configure_filter(local);
105074 ieee80211_hw_config(local, hw_reconf_flags);
105075
105076 - if (local->monitors == local->open_count)
105077 + if (local->monitors == local_read(&local->open_count))
105078 ieee80211_add_virtual_monitor(local);
105079 }
105080
105081 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
105082 index 0de7c93..884b2ca 100644
105083 --- a/net/mac80211/main.c
105084 +++ b/net/mac80211/main.c
105085 @@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
105086 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
105087 IEEE80211_CONF_CHANGE_POWER);
105088
105089 - if (changed && local->open_count) {
105090 + if (changed && local_read(&local->open_count)) {
105091 ret = drv_config(local, changed);
105092 /*
105093 * Goal:
105094 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
105095 index 4a95fe3..0bfd713 100644
105096 --- a/net/mac80211/pm.c
105097 +++ b/net/mac80211/pm.c
105098 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105099 struct ieee80211_sub_if_data *sdata;
105100 struct sta_info *sta;
105101
105102 - if (!local->open_count)
105103 + if (!local_read(&local->open_count))
105104 goto suspend;
105105
105106 ieee80211_scan_cancel(local);
105107 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105108 cancel_work_sync(&local->dynamic_ps_enable_work);
105109 del_timer_sync(&local->dynamic_ps_timer);
105110
105111 - local->wowlan = wowlan && local->open_count;
105112 + local->wowlan = wowlan && local_read(&local->open_count);
105113 if (local->wowlan) {
105114 int err = drv_suspend(local, wowlan);
105115 if (err < 0) {
105116 @@ -126,7 +126,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105117 WARN_ON(!list_empty(&local->chanctx_list));
105118
105119 /* stop hardware - this must stop RX */
105120 - if (local->open_count)
105121 + if (local_read(&local->open_count))
105122 ieee80211_stop_device(local);
105123
105124 suspend:
105125 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
105126 index 6081329..ab23834 100644
105127 --- a/net/mac80211/rate.c
105128 +++ b/net/mac80211/rate.c
105129 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
105130
105131 ASSERT_RTNL();
105132
105133 - if (local->open_count)
105134 + if (local_read(&local->open_count))
105135 return -EBUSY;
105136
105137 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
105138 diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
105139 index 900632a2..80ce44f 100644
105140 --- a/net/mac80211/tx.c
105141 +++ b/net/mac80211/tx.c
105142 @@ -563,6 +563,7 @@ ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
105143 if (tx->sdata->control_port_no_encrypt)
105144 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
105145 info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
105146 + info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
105147 }
105148
105149 return TX_CONTINUE;
105150 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
105151 index 3c61060..7bed2e3 100644
105152 --- a/net/mac80211/util.c
105153 +++ b/net/mac80211/util.c
105154 @@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105155 }
105156 #endif
105157 /* everything else happens only if HW was up & running */
105158 - if (!local->open_count)
105159 + if (!local_read(&local->open_count))
105160 goto wake_up;
105161
105162 /*
105163 @@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105164 local->in_reconfig = false;
105165 barrier();
105166
105167 - if (local->monitors == local->open_count && local->monitors > 0)
105168 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105169 ieee80211_add_virtual_monitor(local);
105170
105171 /*
105172 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105173 index ae5096ab..e5aa70a 100644
105174 --- a/net/netfilter/Kconfig
105175 +++ b/net/netfilter/Kconfig
105176 @@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
105177
105178 To compile it as a module, choose M here. If unsure, say N.
105179
105180 +config NETFILTER_XT_MATCH_GRADM
105181 + tristate '"gradm" match support'
105182 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105183 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105184 + ---help---
105185 + The gradm match allows to match on grsecurity RBAC being enabled.
105186 + It is useful when iptables rules are applied early on bootup to
105187 + prevent connections to the machine (except from a trusted host)
105188 + while the RBAC system is disabled.
105189 +
105190 config NETFILTER_XT_MATCH_HASHLIMIT
105191 tristate '"hashlimit" match support'
105192 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105193 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105194 index a9571be..c59e173 100644
105195 --- a/net/netfilter/Makefile
105196 +++ b/net/netfilter/Makefile
105197 @@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105198 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105199 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105200 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105201 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105202 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105203 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105204 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105205 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105206 index d259da3..6a32b2c 100644
105207 --- a/net/netfilter/ipset/ip_set_core.c
105208 +++ b/net/netfilter/ipset/ip_set_core.c
105209 @@ -1952,7 +1952,7 @@ done:
105210 return ret;
105211 }
105212
105213 -static struct nf_sockopt_ops so_set __read_mostly = {
105214 +static struct nf_sockopt_ops so_set = {
105215 .pf = PF_INET,
105216 .get_optmin = SO_IP_SET,
105217 .get_optmax = SO_IP_SET + 1,
105218 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105219 index b0f7b62..0541842 100644
105220 --- a/net/netfilter/ipvs/ip_vs_conn.c
105221 +++ b/net/netfilter/ipvs/ip_vs_conn.c
105222 @@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105223 /* Increase the refcnt counter of the dest */
105224 ip_vs_dest_hold(dest);
105225
105226 - conn_flags = atomic_read(&dest->conn_flags);
105227 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
105228 if (cp->protocol != IPPROTO_UDP)
105229 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105230 flags = cp->flags;
105231 @@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
105232
105233 cp->control = NULL;
105234 atomic_set(&cp->n_control, 0);
105235 - atomic_set(&cp->in_pkts, 0);
105236 + atomic_set_unchecked(&cp->in_pkts, 0);
105237
105238 cp->packet_xmit = NULL;
105239 cp->app = NULL;
105240 @@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105241
105242 /* Don't drop the entry if its number of incoming packets is not
105243 located in [0, 8] */
105244 - i = atomic_read(&cp->in_pkts);
105245 + i = atomic_read_unchecked(&cp->in_pkts);
105246 if (i > 8 || i < 0) return 0;
105247
105248 if (!todrop_rate[i]) return 0;
105249 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105250 index 990decb..5075248 100644
105251 --- a/net/netfilter/ipvs/ip_vs_core.c
105252 +++ b/net/netfilter/ipvs/ip_vs_core.c
105253 @@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105254 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105255 /* do not touch skb anymore */
105256
105257 - atomic_inc(&cp->in_pkts);
105258 + atomic_inc_unchecked(&cp->in_pkts);
105259 ip_vs_conn_put(cp);
105260 return ret;
105261 }
105262 @@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105263 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105264 pkts = sysctl_sync_threshold(ipvs);
105265 else
105266 - pkts = atomic_add_return(1, &cp->in_pkts);
105267 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105268
105269 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105270 ip_vs_sync_conn(net, cp, pkts);
105271 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105272 index ac7ba68..9735acb9 100644
105273 --- a/net/netfilter/ipvs/ip_vs_ctl.c
105274 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
105275 @@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105276 */
105277 ip_vs_rs_hash(ipvs, dest);
105278 }
105279 - atomic_set(&dest->conn_flags, conn_flags);
105280 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
105281
105282 /* bind the service */
105283 old_svc = rcu_dereference_protected(dest->svc, 1);
105284 @@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105285 * align with netns init in ip_vs_control_net_init()
105286 */
105287
105288 -static struct ctl_table vs_vars[] = {
105289 +static ctl_table_no_const vs_vars[] __read_only = {
105290 {
105291 .procname = "amemthresh",
105292 .maxlen = sizeof(int),
105293 @@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105294 " %-7s %-6d %-10d %-10d\n",
105295 &dest->addr.in6,
105296 ntohs(dest->port),
105297 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105298 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105299 atomic_read(&dest->weight),
105300 atomic_read(&dest->activeconns),
105301 atomic_read(&dest->inactconns));
105302 @@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105303 "%-7s %-6d %-10d %-10d\n",
105304 ntohl(dest->addr.ip),
105305 ntohs(dest->port),
105306 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105307 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105308 atomic_read(&dest->weight),
105309 atomic_read(&dest->activeconns),
105310 atomic_read(&dest->inactconns));
105311 @@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105312
105313 entry.addr = dest->addr.ip;
105314 entry.port = dest->port;
105315 - entry.conn_flags = atomic_read(&dest->conn_flags);
105316 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105317 entry.weight = atomic_read(&dest->weight);
105318 entry.u_threshold = dest->u_threshold;
105319 entry.l_threshold = dest->l_threshold;
105320 @@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105321 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105322 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105323 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105324 - (atomic_read(&dest->conn_flags) &
105325 + (atomic_read_unchecked(&dest->conn_flags) &
105326 IP_VS_CONN_F_FWD_MASK)) ||
105327 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105328 atomic_read(&dest->weight)) ||
105329 @@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105330 {
105331 int idx;
105332 struct netns_ipvs *ipvs = net_ipvs(net);
105333 - struct ctl_table *tbl;
105334 + ctl_table_no_const *tbl;
105335
105336 atomic_set(&ipvs->dropentry, 0);
105337 spin_lock_init(&ipvs->dropentry_lock);
105338 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105339 index 127f140..553d652 100644
105340 --- a/net/netfilter/ipvs/ip_vs_lblc.c
105341 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
105342 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105343 * IPVS LBLC sysctl table
105344 */
105345 #ifdef CONFIG_SYSCTL
105346 -static struct ctl_table vs_vars_table[] = {
105347 +static ctl_table_no_const vs_vars_table[] __read_only = {
105348 {
105349 .procname = "lblc_expiration",
105350 .data = NULL,
105351 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105352 index 2229d2d..b32b785 100644
105353 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
105354 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105355 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105356 * IPVS LBLCR sysctl table
105357 */
105358
105359 -static struct ctl_table vs_vars_table[] = {
105360 +static ctl_table_no_const vs_vars_table[] __read_only = {
105361 {
105362 .procname = "lblcr_expiration",
105363 .data = NULL,
105364 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105365 index 7162c86..9eeb60e 100644
105366 --- a/net/netfilter/ipvs/ip_vs_sync.c
105367 +++ b/net/netfilter/ipvs/ip_vs_sync.c
105368 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105369 cp = cp->control;
105370 if (cp) {
105371 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105372 - pkts = atomic_add_return(1, &cp->in_pkts);
105373 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105374 else
105375 pkts = sysctl_sync_threshold(ipvs);
105376 ip_vs_sync_conn(net, cp->control, pkts);
105377 @@ -771,7 +771,7 @@ control:
105378 if (!cp)
105379 return;
105380 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105381 - pkts = atomic_add_return(1, &cp->in_pkts);
105382 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105383 else
105384 pkts = sysctl_sync_threshold(ipvs);
105385 goto sloop;
105386 @@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105387
105388 if (opt)
105389 memcpy(&cp->in_seq, opt, sizeof(*opt));
105390 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105391 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105392 cp->state = state;
105393 cp->old_state = cp->state;
105394 /*
105395 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105396 index bd90bf8..816a020d 100644
105397 --- a/net/netfilter/ipvs/ip_vs_xmit.c
105398 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
105399 @@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105400 else
105401 rc = NF_ACCEPT;
105402 /* do not touch skb anymore */
105403 - atomic_inc(&cp->in_pkts);
105404 + atomic_inc_unchecked(&cp->in_pkts);
105405 goto out;
105406 }
105407
105408 @@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105409 else
105410 rc = NF_ACCEPT;
105411 /* do not touch skb anymore */
105412 - atomic_inc(&cp->in_pkts);
105413 + atomic_inc_unchecked(&cp->in_pkts);
105414 goto out;
105415 }
105416
105417 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105418 index a4b5e2a..13b1de3 100644
105419 --- a/net/netfilter/nf_conntrack_acct.c
105420 +++ b/net/netfilter/nf_conntrack_acct.c
105421 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105422 #ifdef CONFIG_SYSCTL
105423 static int nf_conntrack_acct_init_sysctl(struct net *net)
105424 {
105425 - struct ctl_table *table;
105426 + ctl_table_no_const *table;
105427
105428 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105429 GFP_KERNEL);
105430 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105431 index c588012..b0d4ef8 100644
105432 --- a/net/netfilter/nf_conntrack_core.c
105433 +++ b/net/netfilter/nf_conntrack_core.c
105434 @@ -1737,6 +1737,10 @@ void nf_conntrack_init_end(void)
105435 #define DYING_NULLS_VAL ((1<<30)+1)
105436 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105437
105438 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105439 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105440 +#endif
105441 +
105442 int nf_conntrack_init_net(struct net *net)
105443 {
105444 int ret = -ENOMEM;
105445 @@ -1762,7 +1766,11 @@ int nf_conntrack_init_net(struct net *net)
105446 if (!net->ct.stat)
105447 goto err_pcpu_lists;
105448
105449 +#ifdef CONFIG_GRKERNSEC_HIDESYM
105450 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105451 +#else
105452 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105453 +#endif
105454 if (!net->ct.slabname)
105455 goto err_slabname;
105456
105457 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105458 index 4e78c57..ec8fb74 100644
105459 --- a/net/netfilter/nf_conntrack_ecache.c
105460 +++ b/net/netfilter/nf_conntrack_ecache.c
105461 @@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105462 #ifdef CONFIG_SYSCTL
105463 static int nf_conntrack_event_init_sysctl(struct net *net)
105464 {
105465 - struct ctl_table *table;
105466 + ctl_table_no_const *table;
105467
105468 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105469 GFP_KERNEL);
105470 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105471 index 5b3eae7..dd4b8fe 100644
105472 --- a/net/netfilter/nf_conntrack_helper.c
105473 +++ b/net/netfilter/nf_conntrack_helper.c
105474 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105475
105476 static int nf_conntrack_helper_init_sysctl(struct net *net)
105477 {
105478 - struct ctl_table *table;
105479 + ctl_table_no_const *table;
105480
105481 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105482 GFP_KERNEL);
105483 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105484 index b65d586..beec902 100644
105485 --- a/net/netfilter/nf_conntrack_proto.c
105486 +++ b/net/netfilter/nf_conntrack_proto.c
105487 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105488
105489 static void
105490 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105491 - struct ctl_table **table,
105492 + ctl_table_no_const **table,
105493 unsigned int users)
105494 {
105495 if (users > 0)
105496 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105497 index cf65a1e..2f291e9 100644
105498 --- a/net/netfilter/nf_conntrack_standalone.c
105499 +++ b/net/netfilter/nf_conntrack_standalone.c
105500 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105501
105502 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105503 {
105504 - struct ctl_table *table;
105505 + ctl_table_no_const *table;
105506
105507 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105508 GFP_KERNEL);
105509 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105510 index 7a394df..bd91a8a 100644
105511 --- a/net/netfilter/nf_conntrack_timestamp.c
105512 +++ b/net/netfilter/nf_conntrack_timestamp.c
105513 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105514 #ifdef CONFIG_SYSCTL
105515 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105516 {
105517 - struct ctl_table *table;
105518 + ctl_table_no_const *table;
105519
105520 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105521 GFP_KERNEL);
105522 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105523 index d719764..311bc60 100644
105524 --- a/net/netfilter/nf_log.c
105525 +++ b/net/netfilter/nf_log.c
105526 @@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105527
105528 #ifdef CONFIG_SYSCTL
105529 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105530 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105531 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105532
105533 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105534 void __user *buffer, size_t *lenp, loff_t *ppos)
105535 @@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105536 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105537 mutex_unlock(&nf_log_mutex);
105538 } else {
105539 + ctl_table_no_const nf_log_table = *table;
105540 +
105541 mutex_lock(&nf_log_mutex);
105542 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105543 lockdep_is_held(&nf_log_mutex));
105544 if (!logger)
105545 - table->data = "NONE";
105546 + nf_log_table.data = "NONE";
105547 else
105548 - table->data = logger->name;
105549 - r = proc_dostring(table, write, buffer, lenp, ppos);
105550 + nf_log_table.data = logger->name;
105551 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105552 mutex_unlock(&nf_log_mutex);
105553 }
105554
105555 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105556 index c68c1e5..8b5d670 100644
105557 --- a/net/netfilter/nf_sockopt.c
105558 +++ b/net/netfilter/nf_sockopt.c
105559 @@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105560 }
105561 }
105562
105563 - list_add(&reg->list, &nf_sockopts);
105564 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105565 out:
105566 mutex_unlock(&nf_sockopt_mutex);
105567 return ret;
105568 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105569 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105570 {
105571 mutex_lock(&nf_sockopt_mutex);
105572 - list_del(&reg->list);
105573 + pax_list_del((struct list_head *)&reg->list);
105574 mutex_unlock(&nf_sockopt_mutex);
105575 }
105576 EXPORT_SYMBOL(nf_unregister_sockopt);
105577 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
105578 index 71b574c..d319e8b 100644
105579 --- a/net/netfilter/nf_tables_api.c
105580 +++ b/net/netfilter/nf_tables_api.c
105581 @@ -1134,9 +1134,11 @@ static struct nft_stats __percpu *nft_stats_alloc(const struct nlattr *attr)
105582 /* Restore old counters on this cpu, no problem. Per-cpu statistics
105583 * are not exposed to userspace.
105584 */
105585 + preempt_disable();
105586 stats = this_cpu_ptr(newstats);
105587 stats->bytes = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES]));
105588 stats->pkts = be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS]));
105589 + preempt_enable();
105590
105591 return newstats;
105592 }
105593 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105594 index 5f1be5b..2cba8cd 100644
105595 --- a/net/netfilter/nfnetlink_log.c
105596 +++ b/net/netfilter/nfnetlink_log.c
105597 @@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105598 struct nfnl_log_net {
105599 spinlock_t instances_lock;
105600 struct hlist_head instance_table[INSTANCE_BUCKETS];
105601 - atomic_t global_seq;
105602 + atomic_unchecked_t global_seq;
105603 };
105604
105605 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105606 @@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105607 /* global sequence number */
105608 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105609 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105610 - htonl(atomic_inc_return(&log->global_seq))))
105611 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
105612 goto nla_put_failure;
105613
105614 if (data_len) {
105615 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105616 new file mode 100644
105617 index 0000000..c566332
105618 --- /dev/null
105619 +++ b/net/netfilter/xt_gradm.c
105620 @@ -0,0 +1,51 @@
105621 +/*
105622 + * gradm match for netfilter
105623 + * Copyright © Zbigniew Krzystolik, 2010
105624 + *
105625 + * This program is free software; you can redistribute it and/or modify
105626 + * it under the terms of the GNU General Public License; either version
105627 + * 2 or 3 as published by the Free Software Foundation.
105628 + */
105629 +#include <linux/module.h>
105630 +#include <linux/moduleparam.h>
105631 +#include <linux/skbuff.h>
105632 +#include <linux/netfilter/x_tables.h>
105633 +#include <linux/grsecurity.h>
105634 +#include <linux/netfilter/xt_gradm.h>
105635 +
105636 +static bool
105637 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
105638 +{
105639 + const struct xt_gradm_mtinfo *info = par->matchinfo;
105640 + bool retval = false;
105641 + if (gr_acl_is_enabled())
105642 + retval = true;
105643 + return retval ^ info->invflags;
105644 +}
105645 +
105646 +static struct xt_match gradm_mt_reg __read_mostly = {
105647 + .name = "gradm",
105648 + .revision = 0,
105649 + .family = NFPROTO_UNSPEC,
105650 + .match = gradm_mt,
105651 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
105652 + .me = THIS_MODULE,
105653 +};
105654 +
105655 +static int __init gradm_mt_init(void)
105656 +{
105657 + return xt_register_match(&gradm_mt_reg);
105658 +}
105659 +
105660 +static void __exit gradm_mt_exit(void)
105661 +{
105662 + xt_unregister_match(&gradm_mt_reg);
105663 +}
105664 +
105665 +module_init(gradm_mt_init);
105666 +module_exit(gradm_mt_exit);
105667 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
105668 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
105669 +MODULE_LICENSE("GPL");
105670 +MODULE_ALIAS("ipt_gradm");
105671 +MODULE_ALIAS("ip6t_gradm");
105672 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
105673 index 05fbc2a..4424b5c 100644
105674 --- a/net/netfilter/xt_hashlimit.c
105675 +++ b/net/netfilter/xt_hashlimit.c
105676 @@ -871,11 +871,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
105677 {
105678 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
105679
105680 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
105681 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
105682 if (!hashlimit_net->ipt_hashlimit)
105683 return -ENOMEM;
105684 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
105685 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
105686 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
105687 if (!hashlimit_net->ip6t_hashlimit) {
105688 remove_proc_entry("ipt_hashlimit", net->proc_net);
105689 return -ENOMEM;
105690 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
105691 index a9faae8..1ea30e0 100644
105692 --- a/net/netfilter/xt_recent.c
105693 +++ b/net/netfilter/xt_recent.c
105694 @@ -615,7 +615,7 @@ static int __net_init recent_proc_net_init(struct net *net)
105695 {
105696 struct recent_net *recent_net = recent_pernet(net);
105697
105698 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
105699 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
105700 if (!recent_net->xt_recent)
105701 return -ENOMEM;
105702 return 0;
105703 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
105704 index 11de55e..f25e448 100644
105705 --- a/net/netfilter/xt_statistic.c
105706 +++ b/net/netfilter/xt_statistic.c
105707 @@ -19,7 +19,7 @@
105708 #include <linux/module.h>
105709
105710 struct xt_statistic_priv {
105711 - atomic_t count;
105712 + atomic_unchecked_t count;
105713 } ____cacheline_aligned_in_smp;
105714
105715 MODULE_LICENSE("GPL");
105716 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
105717 break;
105718 case XT_STATISTIC_MODE_NTH:
105719 do {
105720 - oval = atomic_read(&info->master->count);
105721 + oval = atomic_read_unchecked(&info->master->count);
105722 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
105723 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
105724 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
105725 if (nval == 0)
105726 ret = !ret;
105727 break;
105728 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
105729 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
105730 if (info->master == NULL)
105731 return -ENOMEM;
105732 - atomic_set(&info->master->count, info->u.nth.count);
105733 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
105734
105735 return 0;
105736 }
105737 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
105738 index 79c965a..ee2b76d 100644
105739 --- a/net/netlink/af_netlink.c
105740 +++ b/net/netlink/af_netlink.c
105741 @@ -273,7 +273,7 @@ static void netlink_overrun(struct sock *sk)
105742 sk->sk_error_report(sk);
105743 }
105744 }
105745 - atomic_inc(&sk->sk_drops);
105746 + atomic_inc_unchecked(&sk->sk_drops);
105747 }
105748
105749 static void netlink_rcv_wake(struct sock *sk)
105750 @@ -2990,7 +2990,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
105751 sk_wmem_alloc_get(s),
105752 nlk->cb_running,
105753 atomic_read(&s->sk_refcnt),
105754 - atomic_read(&s->sk_drops),
105755 + atomic_read_unchecked(&s->sk_drops),
105756 sock_i_ino(s)
105757 );
105758
105759 diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
105760 index 8451612..c8872bc 100644
105761 --- a/net/openvswitch/vport-internal_dev.c
105762 +++ b/net/openvswitch/vport-internal_dev.c
105763 @@ -122,7 +122,7 @@ static const struct net_device_ops internal_dev_netdev_ops = {
105764 .ndo_get_stats64 = internal_dev_get_stats,
105765 };
105766
105767 -static struct rtnl_link_ops internal_dev_link_ops __read_mostly = {
105768 +static struct rtnl_link_ops internal_dev_link_ops = {
105769 .kind = "openvswitch",
105770 };
105771
105772 diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
105773 index 6015802..e81e8bf 100644
105774 --- a/net/openvswitch/vport.c
105775 +++ b/net/openvswitch/vport.c
105776 @@ -269,10 +269,10 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats)
105777 * netdev-stats can be directly read over netlink-ioctl.
105778 */
105779
105780 - stats->rx_errors = atomic_long_read(&vport->err_stats.rx_errors);
105781 - stats->tx_errors = atomic_long_read(&vport->err_stats.tx_errors);
105782 - stats->tx_dropped = atomic_long_read(&vport->err_stats.tx_dropped);
105783 - stats->rx_dropped = atomic_long_read(&vport->err_stats.rx_dropped);
105784 + stats->rx_errors = atomic_long_read_unchecked(&vport->err_stats.rx_errors);
105785 + stats->tx_errors = atomic_long_read_unchecked(&vport->err_stats.tx_errors);
105786 + stats->tx_dropped = atomic_long_read_unchecked(&vport->err_stats.tx_dropped);
105787 + stats->rx_dropped = atomic_long_read_unchecked(&vport->err_stats.rx_dropped);
105788
105789 for_each_possible_cpu(i) {
105790 const struct pcpu_sw_netstats *percpu_stats;
105791 @@ -503,19 +503,19 @@ static void ovs_vport_record_error(struct vport *vport,
105792 {
105793 switch (err_type) {
105794 case VPORT_E_RX_DROPPED:
105795 - atomic_long_inc(&vport->err_stats.rx_dropped);
105796 + atomic_long_inc_unchecked(&vport->err_stats.rx_dropped);
105797 break;
105798
105799 case VPORT_E_RX_ERROR:
105800 - atomic_long_inc(&vport->err_stats.rx_errors);
105801 + atomic_long_inc_unchecked(&vport->err_stats.rx_errors);
105802 break;
105803
105804 case VPORT_E_TX_DROPPED:
105805 - atomic_long_inc(&vport->err_stats.tx_dropped);
105806 + atomic_long_inc_unchecked(&vport->err_stats.tx_dropped);
105807 break;
105808
105809 case VPORT_E_TX_ERROR:
105810 - atomic_long_inc(&vport->err_stats.tx_errors);
105811 + atomic_long_inc_unchecked(&vport->err_stats.tx_errors);
105812 break;
105813 }
105814
105815 diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
105816 index 8942125..03ed887 100644
105817 --- a/net/openvswitch/vport.h
105818 +++ b/net/openvswitch/vport.h
105819 @@ -61,10 +61,10 @@ int ovs_vport_send(struct vport *, struct sk_buff *);
105820 /* The following definitions are for implementers of vport devices: */
105821
105822 struct vport_err_stats {
105823 - atomic_long_t rx_dropped;
105824 - atomic_long_t rx_errors;
105825 - atomic_long_t tx_dropped;
105826 - atomic_long_t tx_errors;
105827 + atomic_long_unchecked_t rx_dropped;
105828 + atomic_long_unchecked_t rx_errors;
105829 + atomic_long_unchecked_t tx_dropped;
105830 + atomic_long_unchecked_t tx_errors;
105831 };
105832 /**
105833 * struct vport_portids - array of netlink portids of a vport.
105834 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
105835 index 07c04a8..3ca11eb 100644
105836 --- a/net/packet/af_packet.c
105837 +++ b/net/packet/af_packet.c
105838 @@ -269,7 +269,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
105839
105840 return ret;
105841 drop:
105842 - atomic_long_inc(&dev->tx_dropped);
105843 + atomic_long_inc_unchecked(&dev->tx_dropped);
105844 kfree_skb(skb);
105845 return NET_XMIT_DROP;
105846 }
105847 @@ -1836,7 +1836,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105848
105849 spin_lock(&sk->sk_receive_queue.lock);
105850 po->stats.stats1.tp_packets++;
105851 - skb->dropcount = atomic_read(&sk->sk_drops);
105852 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
105853 __skb_queue_tail(&sk->sk_receive_queue, skb);
105854 spin_unlock(&sk->sk_receive_queue.lock);
105855 sk->sk_data_ready(sk);
105856 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
105857 drop_n_acct:
105858 spin_lock(&sk->sk_receive_queue.lock);
105859 po->stats.stats1.tp_drops++;
105860 - atomic_inc(&sk->sk_drops);
105861 + atomic_inc_unchecked(&sk->sk_drops);
105862 spin_unlock(&sk->sk_receive_queue.lock);
105863
105864 drop_n_restore:
105865 @@ -3460,7 +3460,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105866 case PACKET_HDRLEN:
105867 if (len > sizeof(int))
105868 len = sizeof(int);
105869 - if (copy_from_user(&val, optval, len))
105870 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
105871 return -EFAULT;
105872 switch (val) {
105873 case TPACKET_V1:
105874 @@ -3506,7 +3506,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
105875 len = lv;
105876 if (put_user(len, optlen))
105877 return -EFAULT;
105878 - if (copy_to_user(optval, data, len))
105879 + if (len > sizeof(st) || copy_to_user(optval, data, len))
105880 return -EFAULT;
105881 return 0;
105882 }
105883 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
105884 index 70a547e..23477fe 100644
105885 --- a/net/phonet/pep.c
105886 +++ b/net/phonet/pep.c
105887 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105888
105889 case PNS_PEP_CTRL_REQ:
105890 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
105891 - atomic_inc(&sk->sk_drops);
105892 + atomic_inc_unchecked(&sk->sk_drops);
105893 break;
105894 }
105895 __skb_pull(skb, 4);
105896 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
105897 }
105898
105899 if (pn->rx_credits == 0) {
105900 - atomic_inc(&sk->sk_drops);
105901 + atomic_inc_unchecked(&sk->sk_drops);
105902 err = -ENOBUFS;
105903 break;
105904 }
105905 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
105906 }
105907
105908 if (pn->rx_credits == 0) {
105909 - atomic_inc(&sk->sk_drops);
105910 + atomic_inc_unchecked(&sk->sk_drops);
105911 err = NET_RX_DROP;
105912 break;
105913 }
105914 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
105915 index 008214a..bb68240 100644
105916 --- a/net/phonet/socket.c
105917 +++ b/net/phonet/socket.c
105918 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
105919 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
105920 sock_i_ino(sk),
105921 atomic_read(&sk->sk_refcnt), sk,
105922 - atomic_read(&sk->sk_drops));
105923 + atomic_read_unchecked(&sk->sk_drops));
105924 }
105925 seq_pad(seq, '\n');
105926 return 0;
105927 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
105928 index c02a8c4..3c5b600 100644
105929 --- a/net/phonet/sysctl.c
105930 +++ b/net/phonet/sysctl.c
105931 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
105932 {
105933 int ret;
105934 int range[2] = {local_port_range[0], local_port_range[1]};
105935 - struct ctl_table tmp = {
105936 + ctl_table_no_const tmp = {
105937 .data = &range,
105938 .maxlen = sizeof(range),
105939 .mode = table->mode,
105940 diff --git a/net/rds/cong.c b/net/rds/cong.c
105941 index e5b65ac..f3b6fb7 100644
105942 --- a/net/rds/cong.c
105943 +++ b/net/rds/cong.c
105944 @@ -78,7 +78,7 @@
105945 * finds that the saved generation number is smaller than the global generation
105946 * number, it wakes up the process.
105947 */
105948 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
105949 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
105950
105951 /*
105952 * Congestion monitoring
105953 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
105954 rdsdebug("waking map %p for %pI4\n",
105955 map, &map->m_addr);
105956 rds_stats_inc(s_cong_update_received);
105957 - atomic_inc(&rds_cong_generation);
105958 + atomic_inc_unchecked(&rds_cong_generation);
105959 if (waitqueue_active(&map->m_waitq))
105960 wake_up(&map->m_waitq);
105961 if (waitqueue_active(&rds_poll_waitq))
105962 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
105963
105964 int rds_cong_updated_since(unsigned long *recent)
105965 {
105966 - unsigned long gen = atomic_read(&rds_cong_generation);
105967 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
105968
105969 if (likely(*recent == gen))
105970 return 0;
105971 diff --git a/net/rds/ib.h b/net/rds/ib.h
105972 index 7280ab8..e04f4ea 100644
105973 --- a/net/rds/ib.h
105974 +++ b/net/rds/ib.h
105975 @@ -128,7 +128,7 @@ struct rds_ib_connection {
105976 /* sending acks */
105977 unsigned long i_ack_flags;
105978 #ifdef KERNEL_HAS_ATOMIC64
105979 - atomic64_t i_ack_next; /* next ACK to send */
105980 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
105981 #else
105982 spinlock_t i_ack_lock; /* protect i_ack_next */
105983 u64 i_ack_next; /* next ACK to send */
105984 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
105985 index 31b74f5..dc1fbfa 100644
105986 --- a/net/rds/ib_cm.c
105987 +++ b/net/rds/ib_cm.c
105988 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
105989 /* Clear the ACK state */
105990 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
105991 #ifdef KERNEL_HAS_ATOMIC64
105992 - atomic64_set(&ic->i_ack_next, 0);
105993 + atomic64_set_unchecked(&ic->i_ack_next, 0);
105994 #else
105995 ic->i_ack_next = 0;
105996 #endif
105997 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
105998 index d67de45..73dbf51 100644
105999 --- a/net/rds/ib_recv.c
106000 +++ b/net/rds/ib_recv.c
106001 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
106002 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
106003 int ack_required)
106004 {
106005 - atomic64_set(&ic->i_ack_next, seq);
106006 + atomic64_set_unchecked(&ic->i_ack_next, seq);
106007 if (ack_required) {
106008 smp_mb__before_atomic();
106009 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106010 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
106011 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106012 smp_mb__after_atomic();
106013
106014 - return atomic64_read(&ic->i_ack_next);
106015 + return atomic64_read_unchecked(&ic->i_ack_next);
106016 }
106017 #endif
106018
106019 diff --git a/net/rds/iw.h b/net/rds/iw.h
106020 index 04ce3b1..48119a6 100644
106021 --- a/net/rds/iw.h
106022 +++ b/net/rds/iw.h
106023 @@ -134,7 +134,7 @@ struct rds_iw_connection {
106024 /* sending acks */
106025 unsigned long i_ack_flags;
106026 #ifdef KERNEL_HAS_ATOMIC64
106027 - atomic64_t i_ack_next; /* next ACK to send */
106028 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
106029 #else
106030 spinlock_t i_ack_lock; /* protect i_ack_next */
106031 u64 i_ack_next; /* next ACK to send */
106032 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
106033 index a91e1db..cf3053f 100644
106034 --- a/net/rds/iw_cm.c
106035 +++ b/net/rds/iw_cm.c
106036 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
106037 /* Clear the ACK state */
106038 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
106039 #ifdef KERNEL_HAS_ATOMIC64
106040 - atomic64_set(&ic->i_ack_next, 0);
106041 + atomic64_set_unchecked(&ic->i_ack_next, 0);
106042 #else
106043 ic->i_ack_next = 0;
106044 #endif
106045 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
106046 index aa8bf67..b70133c 100644
106047 --- a/net/rds/iw_recv.c
106048 +++ b/net/rds/iw_recv.c
106049 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
106050 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
106051 int ack_required)
106052 {
106053 - atomic64_set(&ic->i_ack_next, seq);
106054 + atomic64_set_unchecked(&ic->i_ack_next, seq);
106055 if (ack_required) {
106056 smp_mb__before_atomic();
106057 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106058 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
106059 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
106060 smp_mb__after_atomic();
106061
106062 - return atomic64_read(&ic->i_ack_next);
106063 + return atomic64_read_unchecked(&ic->i_ack_next);
106064 }
106065 #endif
106066
106067 diff --git a/net/rds/rds.h b/net/rds/rds.h
106068 index 48f8ffc..0ef3eec 100644
106069 --- a/net/rds/rds.h
106070 +++ b/net/rds/rds.h
106071 @@ -449,7 +449,7 @@ struct rds_transport {
106072 void (*sync_mr)(void *trans_private, int direction);
106073 void (*free_mr)(void *trans_private, int invalidate);
106074 void (*flush_mrs)(void);
106075 -};
106076 +} __do_const;
106077
106078 struct rds_sock {
106079 struct sock rs_sk;
106080 diff --git a/net/rds/sysctl.c b/net/rds/sysctl.c
106081 index c3b0cd4..c173f69 100644
106082 --- a/net/rds/sysctl.c
106083 +++ b/net/rds/sysctl.c
106084 @@ -71,14 +71,14 @@ static struct ctl_table rds_sysctl_rds_table[] = {
106085 {
106086 .procname = "max_unacked_packets",
106087 .data = &rds_sysctl_max_unacked_packets,
106088 - .maxlen = sizeof(unsigned long),
106089 + .maxlen = sizeof(int),
106090 .mode = 0644,
106091 .proc_handler = proc_dointvec,
106092 },
106093 {
106094 .procname = "max_unacked_bytes",
106095 .data = &rds_sysctl_max_unacked_bytes,
106096 - .maxlen = sizeof(unsigned long),
106097 + .maxlen = sizeof(int),
106098 .mode = 0644,
106099 .proc_handler = proc_dointvec,
106100 },
106101 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
106102 index edac9ef..16bcb98 100644
106103 --- a/net/rds/tcp.c
106104 +++ b/net/rds/tcp.c
106105 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
106106 int val = 1;
106107
106108 set_fs(KERNEL_DS);
106109 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
106110 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
106111 sizeof(val));
106112 set_fs(oldfs);
106113 }
106114 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
106115 index 53b17ca..45463e7 100644
106116 --- a/net/rds/tcp_send.c
106117 +++ b/net/rds/tcp_send.c
106118 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
106119
106120 oldfs = get_fs();
106121 set_fs(KERNEL_DS);
106122 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
106123 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
106124 sizeof(val));
106125 set_fs(oldfs);
106126 }
106127 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
106128 index 7b16704..9628ec6 100644
106129 --- a/net/rxrpc/af_rxrpc.c
106130 +++ b/net/rxrpc/af_rxrpc.c
106131 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
106132 __be32 rxrpc_epoch;
106133
106134 /* current debugging ID */
106135 -atomic_t rxrpc_debug_id;
106136 +atomic_unchecked_t rxrpc_debug_id;
106137
106138 /* count of skbs currently in use */
106139 atomic_t rxrpc_n_skbs;
106140 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
106141 index c6be17a..2a6200a 100644
106142 --- a/net/rxrpc/ar-ack.c
106143 +++ b/net/rxrpc/ar-ack.c
106144 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106145
106146 _enter("{%d,%d,%d,%d},",
106147 call->acks_hard, call->acks_unacked,
106148 - atomic_read(&call->sequence),
106149 + atomic_read_unchecked(&call->sequence),
106150 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
106151
106152 stop = 0;
106153 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
106154
106155 /* each Tx packet has a new serial number */
106156 sp->hdr.serial =
106157 - htonl(atomic_inc_return(&call->conn->serial));
106158 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
106159
106160 hdr = (struct rxrpc_header *) txb->head;
106161 hdr->serial = sp->hdr.serial;
106162 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
106163 */
106164 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
106165 {
106166 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
106167 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
106168 }
106169
106170 /*
106171 @@ -677,7 +677,7 @@ process_further:
106172
106173 latest = ntohl(sp->hdr.serial);
106174 hard = ntohl(ack.firstPacket);
106175 - tx = atomic_read(&call->sequence);
106176 + tx = atomic_read_unchecked(&call->sequence);
106177
106178 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106179 latest,
106180 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
106181 goto maybe_reschedule;
106182
106183 send_ACK_with_skew:
106184 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
106185 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
106186 ntohl(ack.serial));
106187 send_ACK:
106188 mtu = call->conn->trans->peer->if_mtu;
106189 @@ -1221,7 +1221,7 @@ send_ACK:
106190 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
106191 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
106192
106193 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106194 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106195 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
106196 ntohl(hdr.serial),
106197 ntohs(ack.maxSkew),
106198 @@ -1239,7 +1239,7 @@ send_ACK:
106199 send_message:
106200 _debug("send message");
106201
106202 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
106203 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
106204 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
106205 send_message_2:
106206
106207 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
106208 index a9e05db..194e793 100644
106209 --- a/net/rxrpc/ar-call.c
106210 +++ b/net/rxrpc/ar-call.c
106211 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
106212 spin_lock_init(&call->lock);
106213 rwlock_init(&call->state_lock);
106214 atomic_set(&call->usage, 1);
106215 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
106216 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106217 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
106218
106219 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
106220 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
106221 index 6631f4f..bfdf056 100644
106222 --- a/net/rxrpc/ar-connection.c
106223 +++ b/net/rxrpc/ar-connection.c
106224 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
106225 rwlock_init(&conn->lock);
106226 spin_lock_init(&conn->state_lock);
106227 atomic_set(&conn->usage, 1);
106228 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
106229 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106230 conn->avail_calls = RXRPC_MAXCALLS;
106231 conn->size_align = 4;
106232 conn->header_size = sizeof(struct rxrpc_header);
106233 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
106234 index e7ed43a..6afa140 100644
106235 --- a/net/rxrpc/ar-connevent.c
106236 +++ b/net/rxrpc/ar-connevent.c
106237 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
106238
106239 len = iov[0].iov_len + iov[1].iov_len;
106240
106241 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106242 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106243 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
106244
106245 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106246 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
106247 index 481f89f..ceeaf8d 100644
106248 --- a/net/rxrpc/ar-input.c
106249 +++ b/net/rxrpc/ar-input.c
106250 @@ -331,9 +331,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
106251 /* track the latest serial number on this connection for ACK packet
106252 * information */
106253 serial = ntohl(sp->hdr.serial);
106254 - hi_serial = atomic_read(&call->conn->hi_serial);
106255 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
106256 while (serial > hi_serial)
106257 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
106258 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
106259 serial);
106260
106261 /* request ACK generation for any ACK or DATA packet that requests
106262 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
106263 index ba9fd36..9bbfe01 100644
106264 --- a/net/rxrpc/ar-internal.h
106265 +++ b/net/rxrpc/ar-internal.h
106266 @@ -272,8 +272,8 @@ struct rxrpc_connection {
106267 int error; /* error code for local abort */
106268 int debug_id; /* debug ID for printks */
106269 unsigned int call_counter; /* call ID counter */
106270 - atomic_t serial; /* packet serial number counter */
106271 - atomic_t hi_serial; /* highest serial number received */
106272 + atomic_unchecked_t serial; /* packet serial number counter */
106273 + atomic_unchecked_t hi_serial; /* highest serial number received */
106274 u8 avail_calls; /* number of calls available */
106275 u8 size_align; /* data size alignment (for security) */
106276 u8 header_size; /* rxrpc + security header size */
106277 @@ -346,7 +346,7 @@ struct rxrpc_call {
106278 spinlock_t lock;
106279 rwlock_t state_lock; /* lock for state transition */
106280 atomic_t usage;
106281 - atomic_t sequence; /* Tx data packet sequence counter */
106282 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
106283 u32 abort_code; /* local/remote abort code */
106284 enum { /* current state of call */
106285 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
106286 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
106287 */
106288 extern atomic_t rxrpc_n_skbs;
106289 extern __be32 rxrpc_epoch;
106290 -extern atomic_t rxrpc_debug_id;
106291 +extern atomic_unchecked_t rxrpc_debug_id;
106292 extern struct workqueue_struct *rxrpc_workqueue;
106293
106294 /*
106295 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
106296 index 87f7135..74d3703 100644
106297 --- a/net/rxrpc/ar-local.c
106298 +++ b/net/rxrpc/ar-local.c
106299 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
106300 spin_lock_init(&local->lock);
106301 rwlock_init(&local->services_lock);
106302 atomic_set(&local->usage, 1);
106303 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
106304 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106305 memcpy(&local->srx, srx, sizeof(*srx));
106306 }
106307
106308 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
106309 index 0b4b9a7..966ffbb 100644
106310 --- a/net/rxrpc/ar-output.c
106311 +++ b/net/rxrpc/ar-output.c
106312 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
106313 memset(skb_put(skb, pad), 0, pad);
106314 }
106315
106316 - seq = atomic_inc_return(&call->sequence);
106317 + seq = atomic_inc_return_unchecked(&call->sequence);
106318
106319 sp->hdr.epoch = conn->epoch;
106320 sp->hdr.cid = call->cid;
106321 sp->hdr.callNumber = call->call_id;
106322 sp->hdr.seq = htonl(seq);
106323 sp->hdr.serial =
106324 - htonl(atomic_inc_return(&conn->serial));
106325 + htonl(atomic_inc_return_unchecked(&conn->serial));
106326 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
106327 sp->hdr.userStatus = 0;
106328 sp->hdr.securityIndex = conn->security_ix;
106329 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
106330 index bebaa43..2644591 100644
106331 --- a/net/rxrpc/ar-peer.c
106332 +++ b/net/rxrpc/ar-peer.c
106333 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
106334 INIT_LIST_HEAD(&peer->error_targets);
106335 spin_lock_init(&peer->lock);
106336 atomic_set(&peer->usage, 1);
106337 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
106338 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106339 memcpy(&peer->srx, srx, sizeof(*srx));
106340
106341 rxrpc_assess_MTU_size(peer);
106342 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
106343 index 38047f7..9f48511 100644
106344 --- a/net/rxrpc/ar-proc.c
106345 +++ b/net/rxrpc/ar-proc.c
106346 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
106347 atomic_read(&conn->usage),
106348 rxrpc_conn_states[conn->state],
106349 key_serial(conn->key),
106350 - atomic_read(&conn->serial),
106351 - atomic_read(&conn->hi_serial));
106352 + atomic_read_unchecked(&conn->serial),
106353 + atomic_read_unchecked(&conn->hi_serial));
106354
106355 return 0;
106356 }
106357 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
106358 index 1976dec..aa70be5 100644
106359 --- a/net/rxrpc/ar-transport.c
106360 +++ b/net/rxrpc/ar-transport.c
106361 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
106362 spin_lock_init(&trans->client_lock);
106363 rwlock_init(&trans->conn_lock);
106364 atomic_set(&trans->usage, 1);
106365 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
106366 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
106367
106368 if (peer->srx.transport.family == AF_INET) {
106369 switch (peer->srx.transport_type) {
106370 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
106371 index f226709..0e735a8 100644
106372 --- a/net/rxrpc/rxkad.c
106373 +++ b/net/rxrpc/rxkad.c
106374 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
106375
106376 len = iov[0].iov_len + iov[1].iov_len;
106377
106378 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
106379 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106380 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
106381
106382 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
106383 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
106384
106385 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
106386
106387 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
106388 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
106389 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
106390
106391 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
106392 diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
106393 index aad6a67..baef987 100644
106394 --- a/net/sched/cls_api.c
106395 +++ b/net/sched/cls_api.c
106396 @@ -556,8 +556,9 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
106397 }
106398 EXPORT_SYMBOL(tcf_exts_change);
106399
106400 -#define tcf_exts_first_act(ext) \
106401 - list_first_entry(&(exts)->actions, struct tc_action, list)
106402 +#define tcf_exts_first_act(ext) \
106403 + list_first_entry_or_null(&(exts)->actions, \
106404 + struct tc_action, list)
106405
106406 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
106407 {
106408 @@ -603,7 +604,7 @@ int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
106409 {
106410 #ifdef CONFIG_NET_CLS_ACT
106411 struct tc_action *a = tcf_exts_first_act(exts);
106412 - if (tcf_action_copy_stats(skb, a, 1) < 0)
106413 + if (a != NULL && tcf_action_copy_stats(skb, a, 1) < 0)
106414 return -1;
106415 #endif
106416 return 0;
106417 diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
106418 index eed49d1..ce22514 100644
106419 --- a/net/sched/cls_bpf.c
106420 +++ b/net/sched/cls_bpf.c
106421 @@ -191,6 +191,11 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
106422 }
106423
106424 bpf_size = bpf_len * sizeof(*bpf_ops);
106425 + if (bpf_size != nla_len(tb[TCA_BPF_OPS])) {
106426 + ret = -EINVAL;
106427 + goto errout;
106428 + }
106429 +
106430 bpf_ops = kzalloc(bpf_size, GFP_KERNEL);
106431 if (bpf_ops == NULL) {
106432 ret = -ENOMEM;
106433 @@ -226,15 +231,21 @@ static u32 cls_bpf_grab_new_handle(struct tcf_proto *tp,
106434 struct cls_bpf_head *head)
106435 {
106436 unsigned int i = 0x80000000;
106437 + u32 handle;
106438
106439 do {
106440 if (++head->hgen == 0x7FFFFFFF)
106441 head->hgen = 1;
106442 } while (--i > 0 && cls_bpf_get(tp, head->hgen));
106443 - if (i == 0)
106444 +
106445 + if (unlikely(i == 0)) {
106446 pr_err("Insufficient number of handles\n");
106447 + handle = 0;
106448 + } else {
106449 + handle = head->hgen;
106450 + }
106451
106452 - return i;
106453 + return handle;
106454 }
106455
106456 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
106457 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
106458 index 6efca30..1259f82 100644
106459 --- a/net/sched/sch_generic.c
106460 +++ b/net/sched/sch_generic.c
106461 @@ -349,7 +349,7 @@ void netif_carrier_on(struct net_device *dev)
106462 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106463 if (dev->reg_state == NETREG_UNINITIALIZED)
106464 return;
106465 - atomic_inc(&dev->carrier_changes);
106466 + atomic_inc_unchecked(&dev->carrier_changes);
106467 linkwatch_fire_event(dev);
106468 if (netif_running(dev))
106469 __netdev_watchdog_up(dev);
106470 @@ -368,7 +368,7 @@ void netif_carrier_off(struct net_device *dev)
106471 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
106472 if (dev->reg_state == NETREG_UNINITIALIZED)
106473 return;
106474 - atomic_inc(&dev->carrier_changes);
106475 + atomic_inc_unchecked(&dev->carrier_changes);
106476 linkwatch_fire_event(dev);
106477 }
106478 }
106479 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
106480 index 0e4198e..f94193e 100644
106481 --- a/net/sctp/ipv6.c
106482 +++ b/net/sctp/ipv6.c
106483 @@ -972,7 +972,7 @@ static const struct inet6_protocol sctpv6_protocol = {
106484 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
106485 };
106486
106487 -static struct sctp_af sctp_af_inet6 = {
106488 +static struct sctp_af sctp_af_inet6 __read_only = {
106489 .sa_family = AF_INET6,
106490 .sctp_xmit = sctp_v6_xmit,
106491 .setsockopt = ipv6_setsockopt,
106492 @@ -1002,7 +1002,7 @@ static struct sctp_af sctp_af_inet6 = {
106493 #endif
106494 };
106495
106496 -static struct sctp_pf sctp_pf_inet6 = {
106497 +static struct sctp_pf sctp_pf_inet6 __read_only = {
106498 .event_msgname = sctp_inet6_event_msgname,
106499 .skb_msgname = sctp_inet6_skb_msgname,
106500 .af_supported = sctp_inet6_af_supported,
106501 @@ -1029,7 +1029,7 @@ void sctp_v6_pf_init(void)
106502
106503 void sctp_v6_pf_exit(void)
106504 {
106505 - list_del(&sctp_af_inet6.list);
106506 + pax_list_del(&sctp_af_inet6.list);
106507 }
106508
106509 /* Initialize IPv6 support and register with socket layer. */
106510 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
106511 index 8f34b27..b105385 100644
106512 --- a/net/sctp/protocol.c
106513 +++ b/net/sctp/protocol.c
106514 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
106515 return 0;
106516 }
106517
106518 + pax_open_kernel();
106519 INIT_LIST_HEAD(&af->list);
106520 - list_add_tail(&af->list, &sctp_address_families);
106521 + pax_close_kernel();
106522 + pax_list_add_tail(&af->list, &sctp_address_families);
106523 return 1;
106524 }
106525
106526 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
106527
106528 static struct sctp_af sctp_af_inet;
106529
106530 -static struct sctp_pf sctp_pf_inet = {
106531 +static struct sctp_pf sctp_pf_inet __read_only = {
106532 .event_msgname = sctp_inet_event_msgname,
106533 .skb_msgname = sctp_inet_skb_msgname,
106534 .af_supported = sctp_inet_af_supported,
106535 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
106536 };
106537
106538 /* IPv4 address related functions. */
106539 -static struct sctp_af sctp_af_inet = {
106540 +static struct sctp_af sctp_af_inet __read_only = {
106541 .sa_family = AF_INET,
106542 .sctp_xmit = sctp_v4_xmit,
106543 .setsockopt = ip_setsockopt,
106544 @@ -1123,7 +1125,7 @@ static void sctp_v4_pf_init(void)
106545
106546 static void sctp_v4_pf_exit(void)
106547 {
106548 - list_del(&sctp_af_inet.list);
106549 + pax_list_del(&sctp_af_inet.list);
106550 }
106551
106552 static int sctp_v4_protosw_init(void)
106553 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
106554 index fef2acd..c705c4f 100644
106555 --- a/net/sctp/sm_sideeffect.c
106556 +++ b/net/sctp/sm_sideeffect.c
106557 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
106558 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
106559 }
106560
106561 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106562 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
106563 NULL,
106564 sctp_generate_t1_cookie_event,
106565 sctp_generate_t1_init_event,
106566 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
106567 index 634a2ab..dfdaf9b 100644
106568 --- a/net/sctp/socket.c
106569 +++ b/net/sctp/socket.c
106570 @@ -1603,7 +1603,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106571 sctp_assoc_t associd = 0;
106572 sctp_cmsgs_t cmsgs = { NULL };
106573 sctp_scope_t scope;
106574 - bool fill_sinfo_ttl = false;
106575 + bool fill_sinfo_ttl = false, wait_connect = false;
106576 struct sctp_datamsg *datamsg;
106577 int msg_flags = msg->msg_flags;
106578 __u16 sinfo_flags = 0;
106579 @@ -1943,6 +1943,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106580 if (err < 0)
106581 goto out_free;
106582
106583 + wait_connect = true;
106584 pr_debug("%s: we associated primitively\n", __func__);
106585 }
106586
106587 @@ -1980,6 +1981,11 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
106588 sctp_datamsg_put(datamsg);
106589 err = msg_len;
106590
106591 + if (unlikely(wait_connect)) {
106592 + timeo = sock_sndtimeo(sk, msg_flags & MSG_DONTWAIT);
106593 + sctp_wait_for_connect(asoc, &timeo);
106594 + }
106595 +
106596 /* If we are already past ASSOCIATE, the lower
106597 * layers are responsible for association cleanup.
106598 */
106599 @@ -2199,11 +2205,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
106600 {
106601 struct sctp_association *asoc;
106602 struct sctp_ulpevent *event;
106603 + struct sctp_event_subscribe subscribe;
106604
106605 if (optlen > sizeof(struct sctp_event_subscribe))
106606 return -EINVAL;
106607 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
106608 + if (copy_from_user(&subscribe, optval, optlen))
106609 return -EFAULT;
106610 + sctp_sk(sk)->subscribe = subscribe;
106611
106612 if (sctp_sk(sk)->subscribe.sctp_data_io_event)
106613 pr_warn_ratelimited(DEPRECATED "%s (pid %d) "
106614 @@ -4372,13 +4380,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
106615 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106616 int __user *optlen)
106617 {
106618 + struct sctp_event_subscribe subscribe;
106619 +
106620 if (len <= 0)
106621 return -EINVAL;
106622 if (len > sizeof(struct sctp_event_subscribe))
106623 len = sizeof(struct sctp_event_subscribe);
106624 if (put_user(len, optlen))
106625 return -EFAULT;
106626 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
106627 + subscribe = sctp_sk(sk)->subscribe;
106628 + if (copy_to_user(optval, &subscribe, len))
106629 return -EFAULT;
106630 return 0;
106631 }
106632 @@ -4396,6 +4407,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
106633 */
106634 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
106635 {
106636 + __u32 autoclose;
106637 +
106638 /* Applicable to UDP-style socket only */
106639 if (sctp_style(sk, TCP))
106640 return -EOPNOTSUPP;
106641 @@ -4404,7 +4417,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
106642 len = sizeof(int);
106643 if (put_user(len, optlen))
106644 return -EFAULT;
106645 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
106646 + autoclose = sctp_sk(sk)->autoclose;
106647 + if (copy_to_user(optval, &autoclose, sizeof(int)))
106648 return -EFAULT;
106649 return 0;
106650 }
106651 @@ -4778,12 +4792,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
106652 */
106653 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
106654 {
106655 + struct sctp_initmsg initmsg;
106656 +
106657 if (len < sizeof(struct sctp_initmsg))
106658 return -EINVAL;
106659 len = sizeof(struct sctp_initmsg);
106660 if (put_user(len, optlen))
106661 return -EFAULT;
106662 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
106663 + initmsg = sctp_sk(sk)->initmsg;
106664 + if (copy_to_user(optval, &initmsg, len))
106665 return -EFAULT;
106666 return 0;
106667 }
106668 @@ -4824,6 +4841,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
106669 ->addr_to_user(sp, &temp);
106670 if (space_left < addrlen)
106671 return -ENOMEM;
106672 + if (addrlen > sizeof(temp) || addrlen < 0)
106673 + return -EFAULT;
106674 if (copy_to_user(to, &temp, addrlen))
106675 return -EFAULT;
106676 to += addrlen;
106677 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
106678 index 2e9ada1..40f425d 100644
106679 --- a/net/sctp/sysctl.c
106680 +++ b/net/sctp/sysctl.c
106681 @@ -321,7 +321,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
106682 loff_t *ppos)
106683 {
106684 struct net *net = current->nsproxy->net_ns;
106685 - struct ctl_table tbl;
106686 + ctl_table_no_const tbl;
106687 bool changed = false;
106688 char *none = "none";
106689 char tmp[8];
106690 @@ -369,7 +369,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
106691 struct net *net = current->nsproxy->net_ns;
106692 unsigned int min = *(unsigned int *) ctl->extra1;
106693 unsigned int max = *(unsigned int *) ctl->extra2;
106694 - struct ctl_table tbl;
106695 + ctl_table_no_const tbl;
106696 int ret, new_value;
106697
106698 memset(&tbl, 0, sizeof(struct ctl_table));
106699 @@ -398,7 +398,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
106700 struct net *net = current->nsproxy->net_ns;
106701 unsigned int min = *(unsigned int *) ctl->extra1;
106702 unsigned int max = *(unsigned int *) ctl->extra2;
106703 - struct ctl_table tbl;
106704 + ctl_table_no_const tbl;
106705 int ret, new_value;
106706
106707 memset(&tbl, 0, sizeof(struct ctl_table));
106708 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106709 loff_t *ppos)
106710 {
106711 struct net *net = current->nsproxy->net_ns;
106712 - struct ctl_table tbl;
106713 + ctl_table_no_const tbl;
106714 int new_value, ret;
106715
106716 memset(&tbl, 0, sizeof(struct ctl_table));
106717 @@ -463,7 +463,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
106718
106719 int sctp_sysctl_net_register(struct net *net)
106720 {
106721 - struct ctl_table *table;
106722 + ctl_table_no_const *table;
106723 int i;
106724
106725 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
106726 diff --git a/net/socket.c b/net/socket.c
106727 index cf9ebf1..9522714 100644
106728 --- a/net/socket.c
106729 +++ b/net/socket.c
106730 @@ -89,6 +89,7 @@
106731 #include <linux/magic.h>
106732 #include <linux/slab.h>
106733 #include <linux/xattr.h>
106734 +#include <linux/in.h>
106735
106736 #include <asm/uaccess.h>
106737 #include <asm/unistd.h>
106738 @@ -113,6 +114,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
106739 unsigned int sysctl_net_busy_poll __read_mostly;
106740 #endif
106741
106742 +#include <linux/grsock.h>
106743 +
106744 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
106745 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
106746 unsigned long nr_segs, loff_t pos);
106747 @@ -164,7 +167,7 @@ static const struct file_operations socket_file_ops = {
106748 */
106749
106750 static DEFINE_SPINLOCK(net_family_lock);
106751 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106752 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
106753
106754 /*
106755 * Statistics counters of the socket lists
106756 @@ -330,7 +333,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
106757 &sockfs_dentry_operations, SOCKFS_MAGIC);
106758 }
106759
106760 -static struct vfsmount *sock_mnt __read_mostly;
106761 +struct vfsmount *sock_mnt __read_mostly;
106762
106763 static struct file_system_type sock_fs_type = {
106764 .name = "sockfs",
106765 @@ -1260,6 +1263,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106766 return -EAFNOSUPPORT;
106767 if (type < 0 || type >= SOCK_MAX)
106768 return -EINVAL;
106769 + if (protocol < 0)
106770 + return -EINVAL;
106771
106772 /* Compatibility.
106773
106774 @@ -1280,6 +1285,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
106775 if (err)
106776 return err;
106777
106778 + if(!kern && !gr_search_socket(family, type, protocol)) {
106779 + if (rcu_access_pointer(net_families[family]) == NULL)
106780 + return -EAFNOSUPPORT;
106781 + else
106782 + return -EACCES;
106783 + }
106784 +
106785 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
106786 + if (rcu_access_pointer(net_families[family]) == NULL)
106787 + return -EAFNOSUPPORT;
106788 + else
106789 + return -EACCES;
106790 + }
106791 +
106792 /*
106793 * Allocate the socket and allow the family to set things up. if
106794 * the protocol is 0, the family is instructed to select an appropriate
106795 @@ -1531,6 +1550,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106796 if (sock) {
106797 err = move_addr_to_kernel(umyaddr, addrlen, &address);
106798 if (err >= 0) {
106799 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
106800 + err = -EACCES;
106801 + goto error;
106802 + }
106803 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
106804 + if (err)
106805 + goto error;
106806 +
106807 err = security_socket_bind(sock,
106808 (struct sockaddr *)&address,
106809 addrlen);
106810 @@ -1539,6 +1566,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
106811 (struct sockaddr *)
106812 &address, addrlen);
106813 }
106814 +error:
106815 fput_light(sock->file, fput_needed);
106816 }
106817 return err;
106818 @@ -1562,10 +1590,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
106819 if ((unsigned int)backlog > somaxconn)
106820 backlog = somaxconn;
106821
106822 + if (gr_handle_sock_server_other(sock->sk)) {
106823 + err = -EPERM;
106824 + goto error;
106825 + }
106826 +
106827 + err = gr_search_listen(sock);
106828 + if (err)
106829 + goto error;
106830 +
106831 err = security_socket_listen(sock, backlog);
106832 if (!err)
106833 err = sock->ops->listen(sock, backlog);
106834
106835 +error:
106836 fput_light(sock->file, fput_needed);
106837 }
106838 return err;
106839 @@ -1609,6 +1647,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106840 newsock->type = sock->type;
106841 newsock->ops = sock->ops;
106842
106843 + if (gr_handle_sock_server_other(sock->sk)) {
106844 + err = -EPERM;
106845 + sock_release(newsock);
106846 + goto out_put;
106847 + }
106848 +
106849 + err = gr_search_accept(sock);
106850 + if (err) {
106851 + sock_release(newsock);
106852 + goto out_put;
106853 + }
106854 +
106855 /*
106856 * We don't need try_module_get here, as the listening socket (sock)
106857 * has the protocol module (sock->ops->owner) held.
106858 @@ -1654,6 +1704,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
106859 fd_install(newfd, newfile);
106860 err = newfd;
106861
106862 + gr_attach_curr_ip(newsock->sk);
106863 +
106864 out_put:
106865 fput_light(sock->file, fput_needed);
106866 out:
106867 @@ -1686,6 +1738,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106868 int, addrlen)
106869 {
106870 struct socket *sock;
106871 + struct sockaddr *sck;
106872 struct sockaddr_storage address;
106873 int err, fput_needed;
106874
106875 @@ -1696,6 +1749,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
106876 if (err < 0)
106877 goto out_put;
106878
106879 + sck = (struct sockaddr *)&address;
106880 +
106881 + if (gr_handle_sock_client(sck)) {
106882 + err = -EACCES;
106883 + goto out_put;
106884 + }
106885 +
106886 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
106887 + if (err)
106888 + goto out_put;
106889 +
106890 err =
106891 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
106892 if (err)
106893 @@ -1777,6 +1841,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
106894 * the protocol.
106895 */
106896
106897 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
106898 +
106899 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
106900 unsigned int, flags, struct sockaddr __user *, addr,
106901 int, addr_len)
106902 @@ -1843,7 +1909,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
106903 struct socket *sock;
106904 struct iovec iov;
106905 struct msghdr msg;
106906 - struct sockaddr_storage address;
106907 + struct sockaddr_storage address = { };
106908 int err, err2;
106909 int fput_needed;
106910
106911 @@ -2072,7 +2138,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
106912 * checking falls down on this.
106913 */
106914 if (copy_from_user(ctl_buf,
106915 - (void __user __force *)msg_sys->msg_control,
106916 + (void __force_user *)msg_sys->msg_control,
106917 ctl_len))
106918 goto out_freectl;
106919 msg_sys->msg_control = ctl_buf;
106920 @@ -2223,7 +2289,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106921 int err, total_len, len;
106922
106923 /* kernel mode address */
106924 - struct sockaddr_storage addr;
106925 + struct sockaddr_storage addr = { };
106926
106927 /* user mode address pointers */
106928 struct sockaddr __user *uaddr;
106929 @@ -2252,7 +2318,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
106930 /* Save the user-mode address (verify_iovec will change the
106931 * kernel msghdr to use the kernel address space)
106932 */
106933 - uaddr = (__force void __user *)msg_sys->msg_name;
106934 + uaddr = (void __force_user *)msg_sys->msg_name;
106935 uaddr_len = COMPAT_NAMELEN(msg);
106936 if (MSG_CMSG_COMPAT & flags)
106937 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
106938 @@ -2893,7 +2959,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
106939 ifr = compat_alloc_user_space(buf_size);
106940 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
106941
106942 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
106943 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
106944 return -EFAULT;
106945
106946 if (put_user(convert_in ? rxnfc : compat_ptr(data),
106947 @@ -3004,7 +3070,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
106948 old_fs = get_fs();
106949 set_fs(KERNEL_DS);
106950 err = dev_ioctl(net, cmd,
106951 - (struct ifreq __user __force *) &kifr);
106952 + (struct ifreq __force_user *) &kifr);
106953 set_fs(old_fs);
106954
106955 return err;
106956 @@ -3097,7 +3163,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
106957
106958 old_fs = get_fs();
106959 set_fs(KERNEL_DS);
106960 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
106961 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
106962 set_fs(old_fs);
106963
106964 if (cmd == SIOCGIFMAP && !err) {
106965 @@ -3181,7 +3247,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
106966 ret |= get_user(rtdev, &(ur4->rt_dev));
106967 if (rtdev) {
106968 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
106969 - r4.rt_dev = (char __user __force *)devname;
106970 + r4.rt_dev = (char __force_user *)devname;
106971 devname[15] = 0;
106972 } else
106973 r4.rt_dev = NULL;
106974 @@ -3408,8 +3474,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
106975 int __user *uoptlen;
106976 int err;
106977
106978 - uoptval = (char __user __force *) optval;
106979 - uoptlen = (int __user __force *) optlen;
106980 + uoptval = (char __force_user *) optval;
106981 + uoptlen = (int __force_user *) optlen;
106982
106983 set_fs(KERNEL_DS);
106984 if (level == SOL_SOCKET)
106985 @@ -3429,7 +3495,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
106986 char __user *uoptval;
106987 int err;
106988
106989 - uoptval = (char __user __force *) optval;
106990 + uoptval = (char __force_user *) optval;
106991
106992 set_fs(KERNEL_DS);
106993 if (level == SOL_SOCKET)
106994 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
106995 index c548ab2..4e1b68b 100644
106996 --- a/net/sunrpc/auth_gss/svcauth_gss.c
106997 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
106998 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
106999 uint64_t *handle)
107000 {
107001 struct rsc rsci, *rscp = NULL;
107002 - static atomic64_t ctxhctr;
107003 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
107004 long long ctxh;
107005 struct gss_api_mech *gm = NULL;
107006 time_t expiry;
107007 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
107008 status = -ENOMEM;
107009 /* the handle needs to be just a unique id,
107010 * use a static counter */
107011 - ctxh = atomic64_inc_return(&ctxhctr);
107012 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
107013
107014 /* make a copy for the caller */
107015 *handle = ctxh;
107016 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
107017 index 0663621..c4928d4 100644
107018 --- a/net/sunrpc/cache.c
107019 +++ b/net/sunrpc/cache.c
107020 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
107021 struct sunrpc_net *sn;
107022
107023 sn = net_generic(net, sunrpc_net_id);
107024 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
107025 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
107026 if (cd->u.procfs.proc_ent == NULL)
107027 goto out_nomem;
107028 cd->u.procfs.channel_ent = NULL;
107029 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
107030 index ae46f01..d337da8 100644
107031 --- a/net/sunrpc/clnt.c
107032 +++ b/net/sunrpc/clnt.c
107033 @@ -1430,7 +1430,9 @@ call_start(struct rpc_task *task)
107034 (RPC_IS_ASYNC(task) ? "async" : "sync"));
107035
107036 /* Increment call count */
107037 - task->tk_msg.rpc_proc->p_count++;
107038 + pax_open_kernel();
107039 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
107040 + pax_close_kernel();
107041 clnt->cl_stats->rpccnt++;
107042 task->tk_action = call_reserve;
107043 }
107044 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
107045 index fe3441a..922c29e 100644
107046 --- a/net/sunrpc/sched.c
107047 +++ b/net/sunrpc/sched.c
107048 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(struct wait_bit_key *key)
107049 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
107050 static void rpc_task_set_debuginfo(struct rpc_task *task)
107051 {
107052 - static atomic_t rpc_pid;
107053 + static atomic_unchecked_t rpc_pid;
107054
107055 - task->tk_pid = atomic_inc_return(&rpc_pid);
107056 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
107057 }
107058 #else
107059 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
107060 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
107061 index 5453049..465669a 100644
107062 --- a/net/sunrpc/stats.c
107063 +++ b/net/sunrpc/stats.c
107064 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
107065
107066 dprintk("RPC: registering /proc/net/rpc\n");
107067 sn = net_generic(net, sunrpc_net_id);
107068 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
107069 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
107070 if (sn->proc_net_rpc == NULL)
107071 return -ENOMEM;
107072
107073 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
107074 index ca8a795..ddfc41b 100644
107075 --- a/net/sunrpc/svc.c
107076 +++ b/net/sunrpc/svc.c
107077 @@ -1165,7 +1165,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
107078 svc_putnl(resv, RPC_SUCCESS);
107079
107080 /* Bump per-procedure stats counter */
107081 - procp->pc_count++;
107082 + pax_open_kernel();
107083 + (*(unsigned int *)&procp->pc_count)++;
107084 + pax_close_kernel();
107085
107086 /* Initialize storage for argp and resp */
107087 memset(rqstp->rq_argp, 0, procp->pc_argsize);
107088 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
107089 index 621ca7b..59421dd 100644
107090 --- a/net/sunrpc/svcauth_unix.c
107091 +++ b/net/sunrpc/svcauth_unix.c
107092 @@ -414,7 +414,7 @@ struct unix_gid {
107093 struct group_info *gi;
107094 };
107095
107096 -static int unix_gid_hash(kuid_t uid)
107097 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
107098 {
107099 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
107100 }
107101 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
107102 (*bpp)[-1] = '\n';
107103 }
107104
107105 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
107106 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
107107
107108 static int unix_gid_parse(struct cache_detail *cd,
107109 char *mesg, int mlen)
107110 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
107111 index c1b6270..05089c1 100644
107112 --- a/net/sunrpc/xprtrdma/svc_rdma.c
107113 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
107114 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
107115 static unsigned int min_max_inline = 4096;
107116 static unsigned int max_max_inline = 65536;
107117
107118 -atomic_t rdma_stat_recv;
107119 -atomic_t rdma_stat_read;
107120 -atomic_t rdma_stat_write;
107121 -atomic_t rdma_stat_sq_starve;
107122 -atomic_t rdma_stat_rq_starve;
107123 -atomic_t rdma_stat_rq_poll;
107124 -atomic_t rdma_stat_rq_prod;
107125 -atomic_t rdma_stat_sq_poll;
107126 -atomic_t rdma_stat_sq_prod;
107127 +atomic_unchecked_t rdma_stat_recv;
107128 +atomic_unchecked_t rdma_stat_read;
107129 +atomic_unchecked_t rdma_stat_write;
107130 +atomic_unchecked_t rdma_stat_sq_starve;
107131 +atomic_unchecked_t rdma_stat_rq_starve;
107132 +atomic_unchecked_t rdma_stat_rq_poll;
107133 +atomic_unchecked_t rdma_stat_rq_prod;
107134 +atomic_unchecked_t rdma_stat_sq_poll;
107135 +atomic_unchecked_t rdma_stat_sq_prod;
107136
107137 /* Temporary NFS request map and context caches */
107138 struct kmem_cache *svc_rdma_map_cachep;
107139 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
107140 len -= *ppos;
107141 if (len > *lenp)
107142 len = *lenp;
107143 - if (len && copy_to_user(buffer, str_buf, len))
107144 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
107145 return -EFAULT;
107146 *lenp = len;
107147 *ppos += len;
107148 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
107149 {
107150 .procname = "rdma_stat_read",
107151 .data = &rdma_stat_read,
107152 - .maxlen = sizeof(atomic_t),
107153 + .maxlen = sizeof(atomic_unchecked_t),
107154 .mode = 0644,
107155 .proc_handler = read_reset_stat,
107156 },
107157 {
107158 .procname = "rdma_stat_recv",
107159 .data = &rdma_stat_recv,
107160 - .maxlen = sizeof(atomic_t),
107161 + .maxlen = sizeof(atomic_unchecked_t),
107162 .mode = 0644,
107163 .proc_handler = read_reset_stat,
107164 },
107165 {
107166 .procname = "rdma_stat_write",
107167 .data = &rdma_stat_write,
107168 - .maxlen = sizeof(atomic_t),
107169 + .maxlen = sizeof(atomic_unchecked_t),
107170 .mode = 0644,
107171 .proc_handler = read_reset_stat,
107172 },
107173 {
107174 .procname = "rdma_stat_sq_starve",
107175 .data = &rdma_stat_sq_starve,
107176 - .maxlen = sizeof(atomic_t),
107177 + .maxlen = sizeof(atomic_unchecked_t),
107178 .mode = 0644,
107179 .proc_handler = read_reset_stat,
107180 },
107181 {
107182 .procname = "rdma_stat_rq_starve",
107183 .data = &rdma_stat_rq_starve,
107184 - .maxlen = sizeof(atomic_t),
107185 + .maxlen = sizeof(atomic_unchecked_t),
107186 .mode = 0644,
107187 .proc_handler = read_reset_stat,
107188 },
107189 {
107190 .procname = "rdma_stat_rq_poll",
107191 .data = &rdma_stat_rq_poll,
107192 - .maxlen = sizeof(atomic_t),
107193 + .maxlen = sizeof(atomic_unchecked_t),
107194 .mode = 0644,
107195 .proc_handler = read_reset_stat,
107196 },
107197 {
107198 .procname = "rdma_stat_rq_prod",
107199 .data = &rdma_stat_rq_prod,
107200 - .maxlen = sizeof(atomic_t),
107201 + .maxlen = sizeof(atomic_unchecked_t),
107202 .mode = 0644,
107203 .proc_handler = read_reset_stat,
107204 },
107205 {
107206 .procname = "rdma_stat_sq_poll",
107207 .data = &rdma_stat_sq_poll,
107208 - .maxlen = sizeof(atomic_t),
107209 + .maxlen = sizeof(atomic_unchecked_t),
107210 .mode = 0644,
107211 .proc_handler = read_reset_stat,
107212 },
107213 {
107214 .procname = "rdma_stat_sq_prod",
107215 .data = &rdma_stat_sq_prod,
107216 - .maxlen = sizeof(atomic_t),
107217 + .maxlen = sizeof(atomic_unchecked_t),
107218 .mode = 0644,
107219 .proc_handler = read_reset_stat,
107220 },
107221 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107222 index e011027..9d3c4e1 100644
107223 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107224 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
107225 @@ -220,7 +220,7 @@ static int rdma_read_chunk_lcl(struct svcxprt_rdma *xprt,
107226 *page_no = pg_no;
107227 *page_offset = pg_off;
107228 ret = read;
107229 - atomic_inc(&rdma_stat_read);
107230 + atomic_inc_unchecked(&rdma_stat_read);
107231 return ret;
107232 err:
107233 svc_rdma_unmap_dma(ctxt);
107234 @@ -356,7 +356,7 @@ static int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
107235 *page_no = pg_no;
107236 *page_offset = pg_off;
107237 ret = read;
107238 - atomic_inc(&rdma_stat_read);
107239 + atomic_inc_unchecked(&rdma_stat_read);
107240 return ret;
107241 err:
107242 svc_rdma_unmap_dma(ctxt);
107243 @@ -540,7 +540,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107244 dto_q);
107245 list_del_init(&ctxt->dto_q);
107246 } else {
107247 - atomic_inc(&rdma_stat_rq_starve);
107248 + atomic_inc_unchecked(&rdma_stat_rq_starve);
107249 clear_bit(XPT_DATA, &xprt->xpt_flags);
107250 ctxt = NULL;
107251 }
107252 @@ -559,7 +559,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
107253 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
107254 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
107255 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
107256 - atomic_inc(&rdma_stat_recv);
107257 + atomic_inc_unchecked(&rdma_stat_recv);
107258
107259 /* Build up the XDR from the receive buffers. */
107260 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
107261 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107262 index 9f1b506..2e0b321 100644
107263 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107264 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
107265 @@ -208,7 +208,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
107266 write_wr.wr.rdma.remote_addr = to;
107267
107268 /* Post It */
107269 - atomic_inc(&rdma_stat_write);
107270 + atomic_inc_unchecked(&rdma_stat_write);
107271 if (svc_rdma_send(xprt, &write_wr))
107272 goto err;
107273 return write_len - bc;
107274 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107275 index 4e61880..1f0d963 100644
107276 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
107277 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
107278 @@ -295,7 +295,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107279 return;
107280
107281 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
107282 - atomic_inc(&rdma_stat_rq_poll);
107283 + atomic_inc_unchecked(&rdma_stat_rq_poll);
107284
107285 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
107286 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
107287 @@ -317,7 +317,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
107288 }
107289
107290 if (ctxt)
107291 - atomic_inc(&rdma_stat_rq_prod);
107292 + atomic_inc_unchecked(&rdma_stat_rq_prod);
107293
107294 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
107295 /*
107296 @@ -392,7 +392,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107297 return;
107298
107299 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
107300 - atomic_inc(&rdma_stat_sq_poll);
107301 + atomic_inc_unchecked(&rdma_stat_sq_poll);
107302 while ((ret = ib_poll_cq(cq, ARRAY_SIZE(wc_a), wc_a)) > 0) {
107303 int i;
107304
107305 @@ -420,7 +420,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
107306 }
107307
107308 if (ctxt)
107309 - atomic_inc(&rdma_stat_sq_prod);
107310 + atomic_inc_unchecked(&rdma_stat_sq_prod);
107311 }
107312
107313 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
107314 @@ -1264,7 +1264,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
107315 spin_lock_bh(&xprt->sc_lock);
107316 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
107317 spin_unlock_bh(&xprt->sc_lock);
107318 - atomic_inc(&rdma_stat_sq_starve);
107319 + atomic_inc_unchecked(&rdma_stat_sq_starve);
107320
107321 /* See if we can opportunistically reap SQ WR to make room */
107322 sq_cq_reap(xprt);
107323 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
107324 index e7000be..e3b0ba7 100644
107325 --- a/net/sysctl_net.c
107326 +++ b/net/sysctl_net.c
107327 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
107328 kgid_t root_gid = make_kgid(net->user_ns, 0);
107329
107330 /* Allow network administrator to have same access as root. */
107331 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
107332 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
107333 uid_eq(root_uid, current_euid())) {
107334 int mode = (table->mode >> 6) & 7;
107335 return (mode << 6) | (mode << 3) | mode;
107336 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
107337 index 31b5cb2..566ff01 100644
107338 --- a/net/tipc/subscr.c
107339 +++ b/net/tipc/subscr.c
107340 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
107341 struct tipc_subscriber *subscriber = sub->subscriber;
107342 struct kvec msg_sect;
107343
107344 - msg_sect.iov_base = (void *)&sub->evt;
107345 + msg_sect.iov_base = &sub->evt;
107346 msg_sect.iov_len = sizeof(struct tipc_event);
107347 sub->evt.event = htohl(event, sub->swap);
107348 sub->evt.found_lower = htohl(found_lower, sub->swap);
107349 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
107350 index e968843..bc95776 100644
107351 --- a/net/unix/af_unix.c
107352 +++ b/net/unix/af_unix.c
107353 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
107354 err = -ECONNREFUSED;
107355 if (!S_ISSOCK(inode->i_mode))
107356 goto put_fail;
107357 +
107358 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
107359 + err = -EACCES;
107360 + goto put_fail;
107361 + }
107362 +
107363 u = unix_find_socket_byinode(inode);
107364 if (!u)
107365 goto put_fail;
107366 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
107367 if (u) {
107368 struct dentry *dentry;
107369 dentry = unix_sk(u)->path.dentry;
107370 +
107371 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
107372 + err = -EPERM;
107373 + sock_put(u);
107374 + goto fail;
107375 + }
107376 +
107377 if (dentry)
107378 touch_atime(&unix_sk(u)->path);
107379 } else
107380 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
107381 */
107382 err = security_path_mknod(&path, dentry, mode, 0);
107383 if (!err) {
107384 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
107385 + err = -EACCES;
107386 + goto out;
107387 + }
107388 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
107389 if (!err) {
107390 res->mnt = mntget(path.mnt);
107391 res->dentry = dget(dentry);
107392 + gr_handle_create(dentry, path.mnt);
107393 }
107394 }
107395 +out:
107396 done_path_create(&path, dentry);
107397 return err;
107398 }
107399 @@ -2350,9 +2369,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107400 seq_puts(seq, "Num RefCount Protocol Flags Type St "
107401 "Inode Path\n");
107402 else {
107403 - struct sock *s = v;
107404 + struct sock *s = v, *peer;
107405 struct unix_sock *u = unix_sk(s);
107406 unix_state_lock(s);
107407 + peer = unix_peer(s);
107408 + unix_state_unlock(s);
107409 +
107410 + unix_state_double_lock(s, peer);
107411
107412 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
107413 s,
107414 @@ -2379,8 +2402,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
107415 }
107416 for ( ; i < len; i++)
107417 seq_putc(seq, u->addr->name->sun_path[i]);
107418 - }
107419 - unix_state_unlock(s);
107420 + } else if (peer)
107421 + seq_printf(seq, " P%lu", sock_i_ino(peer));
107422 +
107423 + unix_state_double_unlock(s, peer);
107424 seq_putc(seq, '\n');
107425 }
107426
107427 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
107428 index b3d5150..ff3a837 100644
107429 --- a/net/unix/sysctl_net_unix.c
107430 +++ b/net/unix/sysctl_net_unix.c
107431 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
107432
107433 int __net_init unix_sysctl_register(struct net *net)
107434 {
107435 - struct ctl_table *table;
107436 + ctl_table_no_const *table;
107437
107438 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
107439 if (table == NULL)
107440 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
107441 index 9b7f207..2596621 100644
107442 --- a/net/vmw_vsock/vmci_transport_notify.c
107443 +++ b/net/vmw_vsock/vmci_transport_notify.c
107444 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
107445
107446 /* Socket control packet based operations. */
107447 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
107448 - vmci_transport_notify_pkt_socket_init,
107449 - vmci_transport_notify_pkt_socket_destruct,
107450 - vmci_transport_notify_pkt_poll_in,
107451 - vmci_transport_notify_pkt_poll_out,
107452 - vmci_transport_notify_pkt_handle_pkt,
107453 - vmci_transport_notify_pkt_recv_init,
107454 - vmci_transport_notify_pkt_recv_pre_block,
107455 - vmci_transport_notify_pkt_recv_pre_dequeue,
107456 - vmci_transport_notify_pkt_recv_post_dequeue,
107457 - vmci_transport_notify_pkt_send_init,
107458 - vmci_transport_notify_pkt_send_pre_block,
107459 - vmci_transport_notify_pkt_send_pre_enqueue,
107460 - vmci_transport_notify_pkt_send_post_enqueue,
107461 - vmci_transport_notify_pkt_process_request,
107462 - vmci_transport_notify_pkt_process_negotiate,
107463 + .socket_init = vmci_transport_notify_pkt_socket_init,
107464 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107465 + .poll_in = vmci_transport_notify_pkt_poll_in,
107466 + .poll_out = vmci_transport_notify_pkt_poll_out,
107467 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107468 + .recv_init = vmci_transport_notify_pkt_recv_init,
107469 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107470 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107471 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107472 + .send_init = vmci_transport_notify_pkt_send_init,
107473 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107474 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107475 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107476 + .process_request = vmci_transport_notify_pkt_process_request,
107477 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107478 };
107479 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
107480 index dc9c792..3089de0 100644
107481 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
107482 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
107483 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
107484
107485 /* Socket always on control packet based operations. */
107486 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
107487 - vmci_transport_notify_pkt_socket_init,
107488 - vmci_transport_notify_pkt_socket_destruct,
107489 - vmci_transport_notify_pkt_poll_in,
107490 - vmci_transport_notify_pkt_poll_out,
107491 - vmci_transport_notify_pkt_handle_pkt,
107492 - vmci_transport_notify_pkt_recv_init,
107493 - vmci_transport_notify_pkt_recv_pre_block,
107494 - vmci_transport_notify_pkt_recv_pre_dequeue,
107495 - vmci_transport_notify_pkt_recv_post_dequeue,
107496 - vmci_transport_notify_pkt_send_init,
107497 - vmci_transport_notify_pkt_send_pre_block,
107498 - vmci_transport_notify_pkt_send_pre_enqueue,
107499 - vmci_transport_notify_pkt_send_post_enqueue,
107500 - vmci_transport_notify_pkt_process_request,
107501 - vmci_transport_notify_pkt_process_negotiate,
107502 + .socket_init = vmci_transport_notify_pkt_socket_init,
107503 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
107504 + .poll_in = vmci_transport_notify_pkt_poll_in,
107505 + .poll_out = vmci_transport_notify_pkt_poll_out,
107506 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
107507 + .recv_init = vmci_transport_notify_pkt_recv_init,
107508 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
107509 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
107510 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
107511 + .send_init = vmci_transport_notify_pkt_send_init,
107512 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
107513 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
107514 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
107515 + .process_request = vmci_transport_notify_pkt_process_request,
107516 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
107517 };
107518 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
107519 index c8717c1..08539f5 100644
107520 --- a/net/wireless/wext-core.c
107521 +++ b/net/wireless/wext-core.c
107522 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107523 */
107524
107525 /* Support for very large requests */
107526 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
107527 - (user_length > descr->max_tokens)) {
107528 + if (user_length > descr->max_tokens) {
107529 /* Allow userspace to GET more than max so
107530 * we can support any size GET requests.
107531 * There is still a limit : -ENOMEM.
107532 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
107533 }
107534 }
107535
107536 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
107537 - /*
107538 - * If this is a GET, but not NOMAX, it means that the extra
107539 - * data is not bounded by userspace, but by max_tokens. Thus
107540 - * set the length to max_tokens. This matches the extra data
107541 - * allocation.
107542 - * The driver should fill it with the number of tokens it
107543 - * provided, and it may check iwp->length rather than having
107544 - * knowledge of max_tokens. If the driver doesn't change the
107545 - * iwp->length, this ioctl just copies back max_token tokens
107546 - * filled with zeroes. Hopefully the driver isn't claiming
107547 - * them to be valid data.
107548 - */
107549 - iwp->length = descr->max_tokens;
107550 - }
107551 -
107552 err = handler(dev, info, (union iwreq_data *) iwp, extra);
107553
107554 iwp->length += essid_compat;
107555 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
107556 index 4323952..a06dfe1 100644
107557 --- a/net/x25/sysctl_net_x25.c
107558 +++ b/net/x25/sysctl_net_x25.c
107559 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
107560 .mode = 0644,
107561 .proc_handler = proc_dointvec,
107562 },
107563 - { 0, },
107564 + { },
107565 };
107566
107567 void __init x25_register_sysctl(void)
107568 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
107569 index 0917f04..f4e3d8c 100644
107570 --- a/net/x25/x25_proc.c
107571 +++ b/net/x25/x25_proc.c
107572 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
107573
107574 int __init x25_proc_init(void)
107575 {
107576 - if (!proc_mkdir("x25", init_net.proc_net))
107577 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
107578 return -ENOMEM;
107579
107580 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
107581 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
107582 index 88bf289..7b0741b 100644
107583 --- a/net/xfrm/xfrm_policy.c
107584 +++ b/net/xfrm/xfrm_policy.c
107585 @@ -330,7 +330,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
107586 {
107587 policy->walk.dead = 1;
107588
107589 - atomic_inc(&policy->genid);
107590 + atomic_inc_unchecked(&policy->genid);
107591
107592 if (del_timer(&policy->polq.hold_timer))
107593 xfrm_pol_put(policy);
107594 @@ -781,7 +781,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
107595 hlist_add_head(&policy->bydst, chain);
107596 xfrm_pol_hold(policy);
107597 net->xfrm.policy_count[dir]++;
107598 - atomic_inc(&net->xfrm.flow_cache_genid);
107599 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
107600
107601 /* After previous checking, family can either be AF_INET or AF_INET6 */
107602 if (policy->family == AF_INET)
107603 @@ -1871,7 +1871,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
107604
107605 xdst->num_pols = num_pols;
107606 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
107607 - xdst->policy_genid = atomic_read(&pols[0]->genid);
107608 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
107609
107610 return xdst;
107611 }
107612 @@ -2685,10 +2685,11 @@ void xfrm_garbage_collect(struct net *net)
107613 }
107614 EXPORT_SYMBOL(xfrm_garbage_collect);
107615
107616 -static void xfrm_garbage_collect_deferred(struct net *net)
107617 +void xfrm_garbage_collect_deferred(struct net *net)
107618 {
107619 flow_cache_flush_deferred(net);
107620 }
107621 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
107622
107623 static void xfrm_init_pmtu(struct dst_entry *dst)
107624 {
107625 @@ -2738,7 +2739,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
107626 if (xdst->xfrm_genid != dst->xfrm->genid)
107627 return 0;
107628 if (xdst->num_pols > 0 &&
107629 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
107630 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
107631 return 0;
107632
107633 mtu = dst_mtu(dst->child);
107634 @@ -2826,8 +2827,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
107635 dst_ops->link_failure = xfrm_link_failure;
107636 if (likely(dst_ops->neigh_lookup == NULL))
107637 dst_ops->neigh_lookup = xfrm_neigh_lookup;
107638 - if (likely(afinfo->garbage_collect == NULL))
107639 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
107640 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
107641 }
107642 spin_unlock(&xfrm_policy_afinfo_lock);
107643 @@ -2881,7 +2880,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
107644 dst_ops->check = NULL;
107645 dst_ops->negative_advice = NULL;
107646 dst_ops->link_failure = NULL;
107647 - afinfo->garbage_collect = NULL;
107648 }
107649 return err;
107650 }
107651 @@ -3277,7 +3275,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
107652 sizeof(pol->xfrm_vec[i].saddr));
107653 pol->xfrm_vec[i].encap_family = mp->new_family;
107654 /* flush bundles */
107655 - atomic_inc(&pol->genid);
107656 + atomic_inc_unchecked(&pol->genid);
107657 }
107658 }
107659
107660 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
107661 index de971b6..b843409 100644
107662 --- a/net/xfrm/xfrm_state.c
107663 +++ b/net/xfrm/xfrm_state.c
107664 @@ -166,12 +166,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
107665
107666 if (unlikely(afinfo == NULL))
107667 return -EAFNOSUPPORT;
107668 - typemap = afinfo->type_map;
107669 + typemap = (const struct xfrm_type **)afinfo->type_map;
107670 spin_lock_bh(&xfrm_type_lock);
107671
107672 - if (likely(typemap[type->proto] == NULL))
107673 + if (likely(typemap[type->proto] == NULL)) {
107674 + pax_open_kernel();
107675 typemap[type->proto] = type;
107676 - else
107677 + pax_close_kernel();
107678 + } else
107679 err = -EEXIST;
107680 spin_unlock_bh(&xfrm_type_lock);
107681 xfrm_state_put_afinfo(afinfo);
107682 @@ -187,13 +189,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
107683
107684 if (unlikely(afinfo == NULL))
107685 return -EAFNOSUPPORT;
107686 - typemap = afinfo->type_map;
107687 + typemap = (const struct xfrm_type **)afinfo->type_map;
107688 spin_lock_bh(&xfrm_type_lock);
107689
107690 if (unlikely(typemap[type->proto] != type))
107691 err = -ENOENT;
107692 - else
107693 + else {
107694 + pax_open_kernel();
107695 typemap[type->proto] = NULL;
107696 + pax_close_kernel();
107697 + }
107698 spin_unlock_bh(&xfrm_type_lock);
107699 xfrm_state_put_afinfo(afinfo);
107700 return err;
107701 @@ -203,7 +208,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
107702 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
107703 {
107704 struct xfrm_state_afinfo *afinfo;
107705 - const struct xfrm_type **typemap;
107706 const struct xfrm_type *type;
107707 int modload_attempted = 0;
107708
107709 @@ -211,9 +215,8 @@ retry:
107710 afinfo = xfrm_state_get_afinfo(family);
107711 if (unlikely(afinfo == NULL))
107712 return NULL;
107713 - typemap = afinfo->type_map;
107714
107715 - type = typemap[proto];
107716 + type = afinfo->type_map[proto];
107717 if (unlikely(type && !try_module_get(type->owner)))
107718 type = NULL;
107719 if (!type && !modload_attempted) {
107720 @@ -247,7 +250,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107721 return -EAFNOSUPPORT;
107722
107723 err = -EEXIST;
107724 - modemap = afinfo->mode_map;
107725 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107726 spin_lock_bh(&xfrm_mode_lock);
107727 if (modemap[mode->encap])
107728 goto out;
107729 @@ -256,8 +259,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
107730 if (!try_module_get(afinfo->owner))
107731 goto out;
107732
107733 - mode->afinfo = afinfo;
107734 + pax_open_kernel();
107735 + *(const void **)&mode->afinfo = afinfo;
107736 modemap[mode->encap] = mode;
107737 + pax_close_kernel();
107738 err = 0;
107739
107740 out:
107741 @@ -281,10 +286,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
107742 return -EAFNOSUPPORT;
107743
107744 err = -ENOENT;
107745 - modemap = afinfo->mode_map;
107746 + modemap = (struct xfrm_mode **)afinfo->mode_map;
107747 spin_lock_bh(&xfrm_mode_lock);
107748 if (likely(modemap[mode->encap] == mode)) {
107749 + pax_open_kernel();
107750 modemap[mode->encap] = NULL;
107751 + pax_close_kernel();
107752 module_put(mode->afinfo->owner);
107753 err = 0;
107754 }
107755 @@ -1505,10 +1512,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
107756 u32 xfrm_get_acqseq(void)
107757 {
107758 u32 res;
107759 - static atomic_t acqseq;
107760 + static atomic_unchecked_t acqseq;
107761
107762 do {
107763 - res = atomic_inc_return(&acqseq);
107764 + res = atomic_inc_return_unchecked(&acqseq);
107765 } while (!res);
107766
107767 return res;
107768 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
107769 index 05a6e3d..6716ec9 100644
107770 --- a/net/xfrm/xfrm_sysctl.c
107771 +++ b/net/xfrm/xfrm_sysctl.c
107772 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
107773
107774 int __net_init xfrm_sysctl_init(struct net *net)
107775 {
107776 - struct ctl_table *table;
107777 + ctl_table_no_const *table;
107778
107779 __xfrm_sysctl_init(net);
107780
107781 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
107782 index 65e7b08..1b868d5 100644
107783 --- a/scripts/Kbuild.include
107784 +++ b/scripts/Kbuild.include
107785 @@ -144,7 +144,7 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
107786 # cc-ldoption
107787 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
107788 cc-ldoption = $(call try-run,\
107789 - $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107790 + $(CC) $(1) -Wl,-r -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
107791
107792 # ld-option
107793 # Usage: LDFLAGS += $(call ld-option, -X)
107794 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
107795 index 649ce68..f6bc05c 100644
107796 --- a/scripts/Makefile.build
107797 +++ b/scripts/Makefile.build
107798 @@ -60,7 +60,7 @@ endif
107799 endif
107800
107801 # Do not include host rules unless needed
107802 -ifneq ($(hostprogs-y)$(hostprogs-m),)
107803 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
107804 include scripts/Makefile.host
107805 endif
107806
107807 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
107808 index a609552..fde19cd 100644
107809 --- a/scripts/Makefile.clean
107810 +++ b/scripts/Makefile.clean
107811 @@ -41,7 +41,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
107812 __clean-files := $(extra-y) $(extra-m) $(extra-) \
107813 $(always) $(targets) $(clean-files) \
107814 $(host-progs) \
107815 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
107816 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
107817 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
107818
107819 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
107820
107821 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
107822 index 133edfa..c9aa07f 100644
107823 --- a/scripts/Makefile.host
107824 +++ b/scripts/Makefile.host
107825 @@ -20,7 +20,19 @@
107826 # Will compile qconf as a C++ program, and menu as a C program.
107827 # They are linked as C++ code to the executable qconf
107828
107829 +# hostprogs-y := conf
107830 +# conf-objs := conf.o libkconfig.so
107831 +# libkconfig-objs := expr.o type.o
107832 +# Will create a shared library named libkconfig.so that consists of
107833 +# expr.o and type.o (they are both compiled as C code and the object files
107834 +# are made as position independent code).
107835 +# conf.c is compiled as a C program, and conf.o is linked together with
107836 +# libkconfig.so as the executable conf.
107837 +# Note: Shared libraries consisting of C++ files are not supported
107838 +
107839 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
107840 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
107841 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
107842
107843 # C code
107844 # Executables compiled from a single .c file
107845 @@ -42,6 +54,19 @@ host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
107846 # C++ Object (.o) files compiled from .cc files
107847 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
107848
107849 +# Shared libaries (only .c supported)
107850 +# Shared libraries (.so) - all .so files referenced in "xxx-objs"
107851 +host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
107852 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
107853 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
107854 +# Remove .so files from "xxx-objs"
107855 +host-cobjs := $(filter-out %.so,$(host-cobjs))
107856 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
107857 +
107858 +# Object (.o) files used by the shared libaries
107859 +host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
107860 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
107861 +
107862 # output directory for programs/.o files
107863 # hostprogs-y := tools/build may have been specified.
107864 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
107865 @@ -56,6 +81,10 @@ host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
107866 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
107867 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
107868 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
107869 +host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
107870 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
107871 +host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
107872 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
107873 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
107874
107875 obj-dirs += $(host-objdirs)
107876 @@ -124,5 +153,37 @@ quiet_cmd_host-cxxobjs = HOSTCXX $@
107877 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
107878 $(call if_changed_dep,host-cxxobjs)
107879
107880 +# Compile .c file, create position independent .o file
107881 +# host-cshobjs -> .o
107882 +quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
107883 + cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
107884 +$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
107885 + $(call if_changed_dep,host-cshobjs)
107886 +
107887 +# Compile .c file, create position independent .o file
107888 +# host-cxxshobjs -> .o
107889 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
107890 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
107891 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
107892 + $(call if_changed_dep,host-cxxshobjs)
107893 +
107894 +# Link a shared library, based on position independent .o files
107895 +# *.o -> .so shared library (host-cshlib)
107896 +quiet_cmd_host-cshlib = HOSTLLD -shared $@
107897 + cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
107898 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107899 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107900 +$(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
107901 + $(call if_changed,host-cshlib)
107902 +
107903 +# Link a shared library, based on position independent .o files
107904 +# *.o -> .so shared library (host-cxxshlib)
107905 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
107906 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
107907 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
107908 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107909 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
107910 + $(call if_changed,host-cxxshlib)
107911 +
107912 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
107913 - $(host-cxxmulti) $(host-cxxobjs)
107914 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
107915 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
107916 index b304068..462d24e 100644
107917 --- a/scripts/basic/fixdep.c
107918 +++ b/scripts/basic/fixdep.c
107919 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
107920 /*
107921 * Lookup a value in the configuration string.
107922 */
107923 -static int is_defined_config(const char *name, int len, unsigned int hash)
107924 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
107925 {
107926 struct item *aux;
107927
107928 @@ -211,10 +211,10 @@ static void clear_config(void)
107929 /*
107930 * Record the use of a CONFIG_* word.
107931 */
107932 -static void use_config(const char *m, int slen)
107933 +static void use_config(const char *m, unsigned int slen)
107934 {
107935 unsigned int hash = strhash(m, slen);
107936 - int c, i;
107937 + unsigned int c, i;
107938
107939 if (is_defined_config(m, slen, hash))
107940 return;
107941 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
107942
107943 static void parse_config_file(const char *map, size_t len)
107944 {
107945 - const int *end = (const int *) (map + len);
107946 + const unsigned int *end = (const unsigned int *) (map + len);
107947 /* start at +1, so that p can never be < map */
107948 - const int *m = (const int *) map + 1;
107949 + const unsigned int *m = (const unsigned int *) map + 1;
107950 const char *p, *q;
107951
107952 for (; m < end; m++) {
107953 @@ -435,7 +435,7 @@ static void print_deps(void)
107954 static void traps(void)
107955 {
107956 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
107957 - int *p = (int *)test;
107958 + unsigned int *p = (unsigned int *)test;
107959
107960 if (*p != INT_CONF) {
107961 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
107962 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
107963 new file mode 100644
107964 index 0000000..822fa9e
107965 --- /dev/null
107966 +++ b/scripts/gcc-plugin.sh
107967 @@ -0,0 +1,51 @@
107968 +#!/bin/sh
107969 +srctree=$(dirname "$0")
107970 +gccplugins_dir=$($3 -print-file-name=plugin)
107971 +plugincc=$($1 -E - -o /dev/null -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
107972 +#include "gcc-common.h"
107973 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
107974 +#warning $2 CXX
107975 +#else
107976 +#warning $1 CC
107977 +#endif
107978 +EOF
107979 +)
107980 +
107981 +if [ $? -ne 0 ]
107982 +then
107983 + exit 1
107984 +fi
107985 +
107986 +case "$plugincc" in
107987 + *"$1 CC"*)
107988 + echo "$1"
107989 + exit 0
107990 + ;;
107991 +
107992 + *"$2 CXX"*)
107993 + # the c++ compiler needs another test, see below
107994 + ;;
107995 +
107996 + *)
107997 + exit 1
107998 + ;;
107999 +esac
108000 +
108001 +# we need a c++ compiler that supports the designated initializer GNU extension
108002 +plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/../tools/gcc -I"${gccplugins_dir}"/include 2>&1 <<EOF
108003 +#include "gcc-common.h"
108004 +class test {
108005 +public:
108006 + int test;
108007 +} test = {
108008 + .test = 1
108009 +};
108010 +EOF
108011 +)
108012 +
108013 +if [ $? -eq 0 ]
108014 +then
108015 + echo "$2"
108016 + exit 0
108017 +fi
108018 +exit 1
108019 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
108020 index fdebd66..a349e33 100755
108021 --- a/scripts/headers_install.sh
108022 +++ b/scripts/headers_install.sh
108023 @@ -32,6 +32,7 @@ do
108024 FILE="$(basename "$i")"
108025 sed -r \
108026 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
108027 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
108028 -e 's/__attribute_const__([ \t]|$)/\1/g' \
108029 -e 's@^#include <linux/compiler.h>@@' \
108030 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
108031 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
108032 index 86a4fe7..99e91f9 100755
108033 --- a/scripts/link-vmlinux.sh
108034 +++ b/scripts/link-vmlinux.sh
108035 @@ -166,7 +166,7 @@ else
108036 fi;
108037
108038 # final build of init/
108039 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
108040 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
108041
108042 kallsymso=""
108043 kallsyms_vmlinux=""
108044 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
108045 index e614ef6..d9d2b01 100644
108046 --- a/scripts/mod/file2alias.c
108047 +++ b/scripts/mod/file2alias.c
108048 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
108049 unsigned long size, unsigned long id_size,
108050 void *symval)
108051 {
108052 - int i;
108053 + unsigned int i;
108054
108055 if (size % id_size || size < id_size) {
108056 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
108057 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
108058 /* USB is special because the bcdDevice can be matched against a numeric range */
108059 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
108060 static void do_usb_entry(void *symval,
108061 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
108062 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
108063 unsigned char range_lo, unsigned char range_hi,
108064 unsigned char max, struct module *mod)
108065 {
108066 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
108067 {
108068 unsigned int devlo, devhi;
108069 unsigned char chi, clo, max;
108070 - int ndigits;
108071 + unsigned int ndigits;
108072
108073 DEF_FIELD(symval, usb_device_id, match_flags);
108074 DEF_FIELD(symval, usb_device_id, idVendor);
108075 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
108076 for (i = 0; i < count; i++) {
108077 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
108078 char acpi_id[sizeof(*id)];
108079 - int j;
108080 + unsigned int j;
108081
108082 buf_printf(&mod->dev_table_buf,
108083 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
108084 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
108085
108086 for (j = 0; j < PNP_MAX_DEVICES; j++) {
108087 const char *id = (char *)(*devs)[j].id;
108088 - int i2, j2;
108089 + unsigned int i2, j2;
108090 int dup = 0;
108091
108092 if (!id[0])
108093 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
108094 /* add an individual alias for every device entry */
108095 if (!dup) {
108096 char acpi_id[PNP_ID_LEN];
108097 - int k;
108098 + unsigned int k;
108099
108100 buf_printf(&mod->dev_table_buf,
108101 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
108102 @@ -939,7 +939,7 @@ static void dmi_ascii_filter(char *d, const char *s)
108103 static int do_dmi_entry(const char *filename, void *symval,
108104 char *alias)
108105 {
108106 - int i, j;
108107 + unsigned int i, j;
108108 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
108109 sprintf(alias, "dmi*");
108110
108111 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
108112 index d439856..10c1eac 100644
108113 --- a/scripts/mod/modpost.c
108114 +++ b/scripts/mod/modpost.c
108115 @@ -921,6 +921,7 @@ enum mismatch {
108116 ANY_INIT_TO_ANY_EXIT,
108117 ANY_EXIT_TO_ANY_INIT,
108118 EXPORT_TO_INIT_EXIT,
108119 + DATA_TO_TEXT
108120 };
108121
108122 struct sectioncheck {
108123 @@ -1007,6 +1008,12 @@ static const struct sectioncheck sectioncheck[] = {
108124 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
108125 .mismatch = EXPORT_TO_INIT_EXIT,
108126 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
108127 +},
108128 +/* Do not reference code from writable data */
108129 +{
108130 + .fromsec = { DATA_SECTIONS, NULL },
108131 + .tosec = { TEXT_SECTIONS, NULL },
108132 + .mismatch = DATA_TO_TEXT
108133 }
108134 };
108135
108136 @@ -1127,10 +1134,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
108137 continue;
108138 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
108139 continue;
108140 - if (sym->st_value == addr)
108141 - return sym;
108142 /* Find a symbol nearby - addr are maybe negative */
108143 d = sym->st_value - addr;
108144 + if (d == 0)
108145 + return sym;
108146 if (d < 0)
108147 d = addr - sym->st_value;
108148 if (d < distance) {
108149 @@ -1408,6 +1415,14 @@ static void report_sec_mismatch(const char *modname,
108150 tosym, prl_to, prl_to, tosym);
108151 free(prl_to);
108152 break;
108153 + case DATA_TO_TEXT:
108154 +#if 0
108155 + fprintf(stderr,
108156 + "The %s %s:%s references\n"
108157 + "the %s %s:%s%s\n",
108158 + from, fromsec, fromsym, to, tosec, tosym, to_p);
108159 +#endif
108160 + break;
108161 }
108162 fprintf(stderr, "\n");
108163 }
108164 @@ -1659,7 +1674,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
108165 static void check_sec_ref(struct module *mod, const char *modname,
108166 struct elf_info *elf)
108167 {
108168 - int i;
108169 + unsigned int i;
108170 Elf_Shdr *sechdrs = elf->sechdrs;
108171
108172 /* Walk through all sections */
108173 @@ -1790,7 +1805,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
108174 va_end(ap);
108175 }
108176
108177 -void buf_write(struct buffer *buf, const char *s, int len)
108178 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
108179 {
108180 if (buf->size - buf->pos < len) {
108181 buf->size += len + SZ;
108182 @@ -2009,7 +2024,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
108183 if (fstat(fileno(file), &st) < 0)
108184 goto close_write;
108185
108186 - if (st.st_size != b->pos)
108187 + if (st.st_size != (off_t)b->pos)
108188 goto close_write;
108189
108190 tmp = NOFAIL(malloc(b->pos));
108191 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
108192 index 168b43d..77914bf 100644
108193 --- a/scripts/mod/modpost.h
108194 +++ b/scripts/mod/modpost.h
108195 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
108196
108197 struct buffer {
108198 char *p;
108199 - int pos;
108200 - int size;
108201 + unsigned int pos;
108202 + unsigned int size;
108203 };
108204
108205 void __attribute__((format(printf, 2, 3)))
108206 buf_printf(struct buffer *buf, const char *fmt, ...);
108207
108208 void
108209 -buf_write(struct buffer *buf, const char *s, int len);
108210 +buf_write(struct buffer *buf, const char *s, unsigned int len);
108211
108212 struct module {
108213 struct module *next;
108214 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
108215 index 944418d..15291e4 100644
108216 --- a/scripts/mod/sumversion.c
108217 +++ b/scripts/mod/sumversion.c
108218 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
108219 goto out;
108220 }
108221
108222 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
108223 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
108224 warn("writing sum in %s failed: %s\n",
108225 filename, strerror(errno));
108226 goto out;
108227 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
108228 index 0865b3e..7235dd4 100644
108229 --- a/scripts/module-common.lds
108230 +++ b/scripts/module-common.lds
108231 @@ -6,6 +6,10 @@
108232 SECTIONS {
108233 /DISCARD/ : { *(.discard) }
108234
108235 + .rodata : {
108236 + *(.rodata) *(.rodata.*)
108237 + *(.data..read_only)
108238 + }
108239 __ksymtab : { *(SORT(___ksymtab+*)) }
108240 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
108241 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
108242 diff --git a/scripts/package/Makefile b/scripts/package/Makefile
108243 index 99ca6e7..3a1a1a1 100644
108244 --- a/scripts/package/Makefile
108245 +++ b/scripts/package/Makefile
108246 @@ -46,7 +46,7 @@ rpm-pkg rpm: FORCE
108247 ln -sf $(srctree) $(KERNELPATH)
108248 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
108249 $(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
108250 - tar -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108251 + tar --owner=root --group=root -cz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(TAR_CONTENT)
108252 rm $(KERNELPATH)
108253 rm -f $(objtree)/.scmversion
108254 $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version
108255 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
108256 index 5972624..4028795 100755
108257 --- a/scripts/package/builddeb
108258 +++ b/scripts/package/builddeb
108259 @@ -293,6 +293,7 @@ fi
108260 (cd $srctree; find arch/$SRCARCH -name module.lds -o -name Kbuild.platforms -o -name Platform) >> "$objtree/debian/hdrsrcfiles"
108261 (cd $srctree; find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f) >> "$objtree/debian/hdrsrcfiles"
108262 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f) >> "$objtree/debian/hdrobjfiles"
108263 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
108264 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
108265 mkdir -p "$destdir"
108266 (cd $srctree; tar -c -f - -T -) < "$objtree/debian/hdrsrcfiles" | (cd $destdir; tar -xf -)
108267 diff --git a/scripts/package/mkspec b/scripts/package/mkspec
108268 index 1395760..bca2734 100755
108269 --- a/scripts/package/mkspec
108270 +++ b/scripts/package/mkspec
108271 @@ -121,29 +121,40 @@ echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/{build,source}"
108272 echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE"
108273 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\""
108274 echo "tar "'$EXCLUDES'" -cf- . | (cd "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE;tar xvf -)"
108275 -echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE"
108276 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE build"
108277 -echo "ln -sf /usr/src/kernels/$KERNELRELEASE source"
108278
108279 echo ""
108280 echo "%clean"
108281 echo 'rm -rf $RPM_BUILD_ROOT'
108282 echo ""
108283 +echo "%pre"
108284 +echo 'chmod -f 0500 /boot'
108285 +echo 'if [ -d /lib/modules ]; then'
108286 +echo 'chmod -f 0500 /lib/modules'
108287 +echo 'fi'
108288 +echo 'if [ -d /lib32/modules ]; then'
108289 +echo 'chmod -f 0500 /lib32/modules'
108290 +echo 'fi'
108291 +echo 'if [ -d /lib64/modules ]; then'
108292 +echo 'chmod -f 0500 /lib64/modules'
108293 +echo 'fi'
108294 +echo ""
108295 +echo "%post devel"
108296 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/build"
108297 +echo "ln -sf /usr/src/kernels/$KERNELRELEASE /lib/modules/$KERNELRELEASE/source"
108298 +echo ""
108299 echo "%post"
108300 -echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then"
108301 -echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm"
108302 -echo "cp /boot/System.map-$KERNELRELEASE /boot/System.map-$KERNELRELEASE-rpm"
108303 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE"
108304 -echo "/sbin/installkernel $KERNELRELEASE /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108305 -echo "rm -f /boot/vmlinuz-$KERNELRELEASE-rpm /boot/System.map-$KERNELRELEASE-rpm"
108306 +echo "if [ -x /sbin/dracut ]; then"
108307 +echo '/sbin/new-kernel-pkg --dracut --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108308 +echo "else"
108309 +echo '/sbin/new-kernel-pkg --mkinitrd --depmod --install --make-default '"$KERNELRELEASE"' || exit $?'
108310 echo "fi"
108311 echo ""
108312 echo "%files"
108313 -echo '%defattr (-, root, root)'
108314 +echo '%defattr (400, root, root, 500)'
108315 echo "%dir /lib/modules"
108316 -echo "/lib/modules/$KERNELRELEASE"
108317 echo "%exclude /lib/modules/$KERNELRELEASE/build"
108318 echo "%exclude /lib/modules/$KERNELRELEASE/source"
108319 +echo "/lib/modules/$KERNELRELEASE"
108320 echo "/lib/firmware/$KERNELRELEASE"
108321 echo "/boot/*"
108322 echo ""
108323 @@ -152,8 +163,7 @@ echo '%defattr (-, root, root)'
108324 echo "/usr/include"
108325 echo ""
108326 echo "%files devel"
108327 -echo '%defattr (-, root, root)'
108328 +echo '%defattr (400, root, root, 500)'
108329 +echo "%dir /lib/modules/$KERNELRELEASE"
108330 echo "/usr/src/kernels/$KERNELRELEASE"
108331 -echo "/lib/modules/$KERNELRELEASE/build"
108332 -echo "/lib/modules/$KERNELRELEASE/source"
108333 echo ""
108334 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
108335 index 4718d78..9220d58 100644
108336 --- a/scripts/pnmtologo.c
108337 +++ b/scripts/pnmtologo.c
108338 @@ -244,14 +244,14 @@ static void write_header(void)
108339 fprintf(out, " * Linux logo %s\n", logoname);
108340 fputs(" */\n\n", out);
108341 fputs("#include <linux/linux_logo.h>\n\n", out);
108342 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
108343 + fprintf(out, "static unsigned char %s_data[] = {\n",
108344 logoname);
108345 }
108346
108347 static void write_footer(void)
108348 {
108349 fputs("\n};\n\n", out);
108350 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
108351 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
108352 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
108353 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
108354 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
108355 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
108356 fputs("\n};\n\n", out);
108357
108358 /* write logo clut */
108359 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
108360 + fprintf(out, "static unsigned char %s_clut[] = {\n",
108361 logoname);
108362 write_hex_cnt = 0;
108363 for (i = 0; i < logo_clutsize; i++) {
108364 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
108365 index ba87004..3f4852c 100644
108366 --- a/scripts/sortextable.h
108367 +++ b/scripts/sortextable.h
108368 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
108369 const char *secstrtab;
108370 const char *strtab;
108371 char *extab_image;
108372 - int extab_index = 0;
108373 - int i;
108374 - int idx;
108375 + unsigned int extab_index = 0;
108376 + unsigned int i;
108377 + unsigned int idx;
108378 unsigned int num_sections;
108379 unsigned int secindex_strings;
108380
108381 diff --git a/scripts/tags.sh b/scripts/tags.sh
108382 index cdb491d..8d32bfc 100755
108383 --- a/scripts/tags.sh
108384 +++ b/scripts/tags.sh
108385 @@ -26,7 +26,7 @@ else
108386 fi
108387
108388 # ignore userspace tools
108389 -ignore="$ignore ( -path ${tree}tools ) -prune -o"
108390 +ignore="$ignore ( -path \"${tree}tools/[^g]*\" ) -prune -o"
108391
108392 # Find all available archs
108393 find_all_archs()
108394 diff --git a/security/Kconfig b/security/Kconfig
108395 index beb86b5..1a953b1 100644
108396 --- a/security/Kconfig
108397 +++ b/security/Kconfig
108398 @@ -4,6 +4,974 @@
108399
108400 menu "Security options"
108401
108402 +menu "Grsecurity"
108403 +
108404 + config ARCH_TRACK_EXEC_LIMIT
108405 + bool
108406 +
108407 + config PAX_KERNEXEC_PLUGIN
108408 + bool
108409 +
108410 + config PAX_PER_CPU_PGD
108411 + bool
108412 +
108413 + config TASK_SIZE_MAX_SHIFT
108414 + int
108415 + depends on X86_64
108416 + default 47 if !PAX_PER_CPU_PGD
108417 + default 42 if PAX_PER_CPU_PGD
108418 +
108419 + config PAX_ENABLE_PAE
108420 + bool
108421 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
108422 +
108423 + config PAX_USERCOPY_SLABS
108424 + bool
108425 +
108426 +config GRKERNSEC
108427 + bool "Grsecurity"
108428 + select CRYPTO
108429 + select CRYPTO_SHA256
108430 + select PROC_FS
108431 + select STOP_MACHINE
108432 + select TTY
108433 + select DEBUG_KERNEL
108434 + select DEBUG_LIST
108435 + help
108436 + If you say Y here, you will be able to configure many features
108437 + that will enhance the security of your system. It is highly
108438 + recommended that you say Y here and read through the help
108439 + for each option so that you fully understand the features and
108440 + can evaluate their usefulness for your machine.
108441 +
108442 +choice
108443 + prompt "Configuration Method"
108444 + depends on GRKERNSEC
108445 + default GRKERNSEC_CONFIG_CUSTOM
108446 + help
108447 +
108448 +config GRKERNSEC_CONFIG_AUTO
108449 + bool "Automatic"
108450 + help
108451 + If you choose this configuration method, you'll be able to answer a small
108452 + number of simple questions about how you plan to use this kernel.
108453 + The settings of grsecurity and PaX will be automatically configured for
108454 + the highest commonly-used settings within the provided constraints.
108455 +
108456 + If you require additional configuration, custom changes can still be made
108457 + from the "custom configuration" menu.
108458 +
108459 +config GRKERNSEC_CONFIG_CUSTOM
108460 + bool "Custom"
108461 + help
108462 + If you choose this configuration method, you'll be able to configure all
108463 + grsecurity and PaX settings manually. Via this method, no options are
108464 + automatically enabled.
108465 +
108466 +endchoice
108467 +
108468 +choice
108469 + prompt "Usage Type"
108470 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108471 + default GRKERNSEC_CONFIG_SERVER
108472 + help
108473 +
108474 +config GRKERNSEC_CONFIG_SERVER
108475 + bool "Server"
108476 + help
108477 + Choose this option if you plan to use this kernel on a server.
108478 +
108479 +config GRKERNSEC_CONFIG_DESKTOP
108480 + bool "Desktop"
108481 + help
108482 + Choose this option if you plan to use this kernel on a desktop.
108483 +
108484 +endchoice
108485 +
108486 +choice
108487 + prompt "Virtualization Type"
108488 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
108489 + default GRKERNSEC_CONFIG_VIRT_NONE
108490 + help
108491 +
108492 +config GRKERNSEC_CONFIG_VIRT_NONE
108493 + bool "None"
108494 + help
108495 + Choose this option if this kernel will be run on bare metal.
108496 +
108497 +config GRKERNSEC_CONFIG_VIRT_GUEST
108498 + bool "Guest"
108499 + help
108500 + Choose this option if this kernel will be run as a VM guest.
108501 +
108502 +config GRKERNSEC_CONFIG_VIRT_HOST
108503 + bool "Host"
108504 + help
108505 + Choose this option if this kernel will be run as a VM host.
108506 +
108507 +endchoice
108508 +
108509 +choice
108510 + prompt "Virtualization Hardware"
108511 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108512 + help
108513 +
108514 +config GRKERNSEC_CONFIG_VIRT_EPT
108515 + bool "EPT/RVI Processor Support"
108516 + depends on X86
108517 + help
108518 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
108519 + hardware virtualization. This allows for additional kernel hardening protections
108520 + to operate without additional performance impact.
108521 +
108522 + To see if your Intel processor supports EPT, see:
108523 + http://ark.intel.com/Products/VirtualizationTechnology
108524 + (Most Core i3/5/7 support EPT)
108525 +
108526 + To see if your AMD processor supports RVI, see:
108527 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
108528 +
108529 +config GRKERNSEC_CONFIG_VIRT_SOFT
108530 + bool "First-gen/No Hardware Virtualization"
108531 + help
108532 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
108533 + support hardware virtualization or doesn't support the EPT/RVI extensions.
108534 +
108535 +endchoice
108536 +
108537 +choice
108538 + prompt "Virtualization Software"
108539 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
108540 + help
108541 +
108542 +config GRKERNSEC_CONFIG_VIRT_XEN
108543 + bool "Xen"
108544 + help
108545 + Choose this option if this kernel is running as a Xen guest or host.
108546 +
108547 +config GRKERNSEC_CONFIG_VIRT_VMWARE
108548 + bool "VMWare"
108549 + help
108550 + Choose this option if this kernel is running as a VMWare guest or host.
108551 +
108552 +config GRKERNSEC_CONFIG_VIRT_KVM
108553 + bool "KVM"
108554 + help
108555 + Choose this option if this kernel is running as a KVM guest or host.
108556 +
108557 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
108558 + bool "VirtualBox"
108559 + help
108560 + Choose this option if this kernel is running as a VirtualBox guest or host.
108561 +
108562 +config GRKERNSEC_CONFIG_VIRT_HYPERV
108563 + bool "Hyper-V"
108564 + help
108565 + Choose this option if this kernel is running as a Hyper-V guest.
108566 +
108567 +endchoice
108568 +
108569 +choice
108570 + prompt "Required Priorities"
108571 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108572 + default GRKERNSEC_CONFIG_PRIORITY_PERF
108573 + help
108574 +
108575 +config GRKERNSEC_CONFIG_PRIORITY_PERF
108576 + bool "Performance"
108577 + help
108578 + Choose this option if performance is of highest priority for this deployment
108579 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
108580 + clearing of structures intended for userland, and freed memory sanitizing will
108581 + be disabled.
108582 +
108583 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
108584 + bool "Security"
108585 + help
108586 + Choose this option if security is of highest priority for this deployment of
108587 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
108588 + for userland, and freed memory sanitizing will be enabled for this kernel.
108589 + In a worst-case scenario, these features can introduce a 20% performance hit
108590 + (UDEREF on x64 contributing half of this hit).
108591 +
108592 +endchoice
108593 +
108594 +menu "Default Special Groups"
108595 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
108596 +
108597 +config GRKERNSEC_PROC_GID
108598 + int "GID exempted from /proc restrictions"
108599 + default 1001
108600 + help
108601 + Setting this GID determines which group will be exempted from
108602 + grsecurity's /proc restrictions, allowing users of the specified
108603 + group to view network statistics and the existence of other users'
108604 + processes on the system. This GID may also be chosen at boot time
108605 + via "grsec_proc_gid=" on the kernel commandline.
108606 +
108607 +config GRKERNSEC_TPE_UNTRUSTED_GID
108608 + int "GID for TPE-untrusted users"
108609 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
108610 + default 1005
108611 + help
108612 + Setting this GID determines which group untrusted users should
108613 + be added to. These users will be placed under grsecurity's Trusted Path
108614 + Execution mechanism, preventing them from executing their own binaries.
108615 + The users will only be able to execute binaries in directories owned and
108616 + writable only by the root user. If the sysctl option is enabled, a sysctl
108617 + option with name "tpe_gid" is created.
108618 +
108619 +config GRKERNSEC_TPE_TRUSTED_GID
108620 + int "GID for TPE-trusted users"
108621 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
108622 + default 1005
108623 + help
108624 + Setting this GID determines what group TPE restrictions will be
108625 + *disabled* for. If the sysctl option is enabled, a sysctl option
108626 + with name "tpe_gid" is created.
108627 +
108628 +config GRKERNSEC_SYMLINKOWN_GID
108629 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
108630 + depends on GRKERNSEC_CONFIG_SERVER
108631 + default 1006
108632 + help
108633 + Setting this GID determines what group kernel-enforced
108634 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
108635 + is enabled, a sysctl option with name "symlinkown_gid" is created.
108636 +
108637 +
108638 +endmenu
108639 +
108640 +menu "Customize Configuration"
108641 +depends on GRKERNSEC
108642 +
108643 +menu "PaX"
108644 +
108645 +config PAX
108646 + bool "Enable various PaX features"
108647 + default y if GRKERNSEC_CONFIG_AUTO
108648 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
108649 + help
108650 + This allows you to enable various PaX features. PaX adds
108651 + intrusion prevention mechanisms to the kernel that reduce
108652 + the risks posed by exploitable memory corruption bugs.
108653 +
108654 +menu "PaX Control"
108655 + depends on PAX
108656 +
108657 +config PAX_SOFTMODE
108658 + bool 'Support soft mode'
108659 + help
108660 + Enabling this option will allow you to run PaX in soft mode, that
108661 + is, PaX features will not be enforced by default, only on executables
108662 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
108663 + support as they are the only way to mark executables for soft mode use.
108664 +
108665 + Soft mode can be activated by using the "pax_softmode=1" kernel command
108666 + line option on boot. Furthermore you can control various PaX features
108667 + at runtime via the entries in /proc/sys/kernel/pax.
108668 +
108669 +config PAX_EI_PAX
108670 + bool 'Use legacy ELF header marking'
108671 + default y if GRKERNSEC_CONFIG_AUTO
108672 + help
108673 + Enabling this option will allow you to control PaX features on
108674 + a per executable basis via the 'chpax' utility available at
108675 + http://pax.grsecurity.net/. The control flags will be read from
108676 + an otherwise reserved part of the ELF header. This marking has
108677 + numerous drawbacks (no support for soft-mode, toolchain does not
108678 + know about the non-standard use of the ELF header) therefore it
108679 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
108680 + support.
108681 +
108682 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
108683 + support as well, they will override the legacy EI_PAX marks.
108684 +
108685 + If you enable none of the marking options then all applications
108686 + will run with PaX enabled on them by default.
108687 +
108688 +config PAX_PT_PAX_FLAGS
108689 + bool 'Use ELF program header marking'
108690 + default y if GRKERNSEC_CONFIG_AUTO
108691 + help
108692 + Enabling this option will allow you to control PaX features on
108693 + a per executable basis via the 'paxctl' utility available at
108694 + http://pax.grsecurity.net/. The control flags will be read from
108695 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
108696 + has the benefits of supporting both soft mode and being fully
108697 + integrated into the toolchain (the binutils patch is available
108698 + from http://pax.grsecurity.net).
108699 +
108700 + Note that if you enable the legacy EI_PAX marking support as well,
108701 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
108702 +
108703 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108704 + must make sure that the marks are the same if a binary has both marks.
108705 +
108706 + If you enable none of the marking options then all applications
108707 + will run with PaX enabled on them by default.
108708 +
108709 +config PAX_XATTR_PAX_FLAGS
108710 + bool 'Use filesystem extended attributes marking'
108711 + default y if GRKERNSEC_CONFIG_AUTO
108712 + select CIFS_XATTR if CIFS
108713 + select F2FS_FS_XATTR if F2FS_FS
108714 + select EXT2_FS_XATTR if EXT2_FS
108715 + select EXT3_FS_XATTR if EXT3_FS
108716 + select JFFS2_FS_XATTR if JFFS2_FS
108717 + select REISERFS_FS_XATTR if REISERFS_FS
108718 + select SQUASHFS_XATTR if SQUASHFS
108719 + select TMPFS_XATTR if TMPFS
108720 + help
108721 + Enabling this option will allow you to control PaX features on
108722 + a per executable basis via the 'setfattr' utility. The control
108723 + flags will be read from the user.pax.flags extended attribute of
108724 + the file. This marking has the benefit of supporting binary-only
108725 + applications that self-check themselves (e.g., skype) and would
108726 + not tolerate chpax/paxctl changes. The main drawback is that
108727 + extended attributes are not supported by some filesystems (e.g.,
108728 + isofs, udf, vfat) so copying files through such filesystems will
108729 + lose the extended attributes and these PaX markings.
108730 +
108731 + Note that if you enable the legacy EI_PAX marking support as well,
108732 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
108733 +
108734 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
108735 + must make sure that the marks are the same if a binary has both marks.
108736 +
108737 + If you enable none of the marking options then all applications
108738 + will run with PaX enabled on them by default.
108739 +
108740 +choice
108741 + prompt 'MAC system integration'
108742 + default PAX_HAVE_ACL_FLAGS
108743 + help
108744 + Mandatory Access Control systems have the option of controlling
108745 + PaX flags on a per executable basis, choose the method supported
108746 + by your particular system.
108747 +
108748 + - "none": if your MAC system does not interact with PaX,
108749 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
108750 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
108751 +
108752 + NOTE: this option is for developers/integrators only.
108753 +
108754 + config PAX_NO_ACL_FLAGS
108755 + bool 'none'
108756 +
108757 + config PAX_HAVE_ACL_FLAGS
108758 + bool 'direct'
108759 +
108760 + config PAX_HOOK_ACL_FLAGS
108761 + bool 'hook'
108762 +endchoice
108763 +
108764 +endmenu
108765 +
108766 +menu "Non-executable pages"
108767 + depends on PAX
108768 +
108769 +config PAX_NOEXEC
108770 + bool "Enforce non-executable pages"
108771 + default y if GRKERNSEC_CONFIG_AUTO
108772 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
108773 + help
108774 + By design some architectures do not allow for protecting memory
108775 + pages against execution or even if they do, Linux does not make
108776 + use of this feature. In practice this means that if a page is
108777 + readable (such as the stack or heap) it is also executable.
108778 +
108779 + There is a well known exploit technique that makes use of this
108780 + fact and a common programming mistake where an attacker can
108781 + introduce code of his choice somewhere in the attacked program's
108782 + memory (typically the stack or the heap) and then execute it.
108783 +
108784 + If the attacked program was running with different (typically
108785 + higher) privileges than that of the attacker, then he can elevate
108786 + his own privilege level (e.g. get a root shell, write to files for
108787 + which he does not have write access to, etc).
108788 +
108789 + Enabling this option will let you choose from various features
108790 + that prevent the injection and execution of 'foreign' code in
108791 + a program.
108792 +
108793 + This will also break programs that rely on the old behaviour and
108794 + expect that dynamically allocated memory via the malloc() family
108795 + of functions is executable (which it is not). Notable examples
108796 + are the XFree86 4.x server, the java runtime and wine.
108797 +
108798 +config PAX_PAGEEXEC
108799 + bool "Paging based non-executable pages"
108800 + default y if GRKERNSEC_CONFIG_AUTO
108801 + 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)
108802 + select ARCH_TRACK_EXEC_LIMIT if X86_32
108803 + help
108804 + This implementation is based on the paging feature of the CPU.
108805 + On i386 without hardware non-executable bit support there is a
108806 + variable but usually low performance impact, however on Intel's
108807 + P4 core based CPUs it is very high so you should not enable this
108808 + for kernels meant to be used on such CPUs.
108809 +
108810 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
108811 + with hardware non-executable bit support there is no performance
108812 + impact, on ppc the impact is negligible.
108813 +
108814 + Note that several architectures require various emulations due to
108815 + badly designed userland ABIs, this will cause a performance impact
108816 + but will disappear as soon as userland is fixed. For example, ppc
108817 + userland MUST have been built with secure-plt by a recent toolchain.
108818 +
108819 +config PAX_SEGMEXEC
108820 + bool "Segmentation based non-executable pages"
108821 + default y if GRKERNSEC_CONFIG_AUTO
108822 + depends on PAX_NOEXEC && X86_32
108823 + help
108824 + This implementation is based on the segmentation feature of the
108825 + CPU and has a very small performance impact, however applications
108826 + will be limited to a 1.5 GB address space instead of the normal
108827 + 3 GB.
108828 +
108829 +config PAX_EMUTRAMP
108830 + bool "Emulate trampolines"
108831 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
108832 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
108833 + help
108834 + There are some programs and libraries that for one reason or
108835 + another attempt to execute special small code snippets from
108836 + non-executable memory pages. Most notable examples are the
108837 + signal handler return code generated by the kernel itself and
108838 + the GCC trampolines.
108839 +
108840 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
108841 + such programs will no longer work under your kernel.
108842 +
108843 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
108844 + utilities to enable trampoline emulation for the affected programs
108845 + yet still have the protection provided by the non-executable pages.
108846 +
108847 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
108848 + your system will not even boot.
108849 +
108850 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
108851 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
108852 + for the affected files.
108853 +
108854 + NOTE: enabling this feature *may* open up a loophole in the
108855 + protection provided by non-executable pages that an attacker
108856 + could abuse. Therefore the best solution is to not have any
108857 + files on your system that would require this option. This can
108858 + be achieved by not using libc5 (which relies on the kernel
108859 + signal handler return code) and not using or rewriting programs
108860 + that make use of the nested function implementation of GCC.
108861 + Skilled users can just fix GCC itself so that it implements
108862 + nested function calls in a way that does not interfere with PaX.
108863 +
108864 +config PAX_EMUSIGRT
108865 + bool "Automatically emulate sigreturn trampolines"
108866 + depends on PAX_EMUTRAMP && PARISC
108867 + default y
108868 + help
108869 + Enabling this option will have the kernel automatically detect
108870 + and emulate signal return trampolines executing on the stack
108871 + that would otherwise lead to task termination.
108872 +
108873 + This solution is intended as a temporary one for users with
108874 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
108875 + Modula-3 runtime, etc) or executables linked to such, basically
108876 + everything that does not specify its own SA_RESTORER function in
108877 + normal executable memory like glibc 2.1+ does.
108878 +
108879 + On parisc you MUST enable this option, otherwise your system will
108880 + not even boot.
108881 +
108882 + NOTE: this feature cannot be disabled on a per executable basis
108883 + and since it *does* open up a loophole in the protection provided
108884 + by non-executable pages, the best solution is to not have any
108885 + files on your system that would require this option.
108886 +
108887 +config PAX_MPROTECT
108888 + bool "Restrict mprotect()"
108889 + default y if GRKERNSEC_CONFIG_AUTO
108890 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
108891 + help
108892 + Enabling this option will prevent programs from
108893 + - changing the executable status of memory pages that were
108894 + not originally created as executable,
108895 + - making read-only executable pages writable again,
108896 + - creating executable pages from anonymous memory,
108897 + - making read-only-after-relocations (RELRO) data pages writable again.
108898 +
108899 + You should say Y here to complete the protection provided by
108900 + the enforcement of non-executable pages.
108901 +
108902 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
108903 + this feature on a per file basis.
108904 +
108905 +config PAX_MPROTECT_COMPAT
108906 + bool "Use legacy/compat protection demoting (read help)"
108907 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
108908 + depends on PAX_MPROTECT
108909 + help
108910 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
108911 + by sending the proper error code to the application. For some broken
108912 + userland, this can cause problems with Python or other applications. The
108913 + current implementation however allows for applications like clamav to
108914 + detect if JIT compilation/execution is allowed and to fall back gracefully
108915 + to an interpreter-based mode if it does not. While we encourage everyone
108916 + to use the current implementation as-is and push upstream to fix broken
108917 + userland (note that the RWX logging option can assist with this), in some
108918 + environments this may not be possible. Having to disable MPROTECT
108919 + completely on certain binaries reduces the security benefit of PaX,
108920 + so this option is provided for those environments to revert to the old
108921 + behavior.
108922 +
108923 +config PAX_ELFRELOCS
108924 + bool "Allow ELF text relocations (read help)"
108925 + depends on PAX_MPROTECT
108926 + default n
108927 + help
108928 + Non-executable pages and mprotect() restrictions are effective
108929 + in preventing the introduction of new executable code into an
108930 + attacked task's address space. There remain only two venues
108931 + for this kind of attack: if the attacker can execute already
108932 + existing code in the attacked task then he can either have it
108933 + create and mmap() a file containing his code or have it mmap()
108934 + an already existing ELF library that does not have position
108935 + independent code in it and use mprotect() on it to make it
108936 + writable and copy his code there. While protecting against
108937 + the former approach is beyond PaX, the latter can be prevented
108938 + by having only PIC ELF libraries on one's system (which do not
108939 + need to relocate their code). If you are sure this is your case,
108940 + as is the case with all modern Linux distributions, then leave
108941 + this option disabled. You should say 'n' here.
108942 +
108943 +config PAX_ETEXECRELOCS
108944 + bool "Allow ELF ET_EXEC text relocations"
108945 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
108946 + select PAX_ELFRELOCS
108947 + default y
108948 + help
108949 + On some architectures there are incorrectly created applications
108950 + that require text relocations and would not work without enabling
108951 + this option. If you are an alpha, ia64 or parisc user, you should
108952 + enable this option and disable it once you have made sure that
108953 + none of your applications need it.
108954 +
108955 +config PAX_EMUPLT
108956 + bool "Automatically emulate ELF PLT"
108957 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
108958 + default y
108959 + help
108960 + Enabling this option will have the kernel automatically detect
108961 + and emulate the Procedure Linkage Table entries in ELF files.
108962 + On some architectures such entries are in writable memory, and
108963 + become non-executable leading to task termination. Therefore
108964 + it is mandatory that you enable this option on alpha, parisc,
108965 + sparc and sparc64, otherwise your system would not even boot.
108966 +
108967 + NOTE: this feature *does* open up a loophole in the protection
108968 + provided by the non-executable pages, therefore the proper
108969 + solution is to modify the toolchain to produce a PLT that does
108970 + not need to be writable.
108971 +
108972 +config PAX_DLRESOLVE
108973 + bool 'Emulate old glibc resolver stub'
108974 + depends on PAX_EMUPLT && SPARC
108975 + default n
108976 + help
108977 + This option is needed if userland has an old glibc (before 2.4)
108978 + that puts a 'save' instruction into the runtime generated resolver
108979 + stub that needs special emulation.
108980 +
108981 +config PAX_KERNEXEC
108982 + bool "Enforce non-executable kernel pages"
108983 + 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))
108984 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
108985 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
108986 + select PAX_KERNEXEC_PLUGIN if X86_64
108987 + help
108988 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
108989 + that is, enabling this option will make it harder to inject
108990 + and execute 'foreign' code in kernel memory itself.
108991 +
108992 + Note that on amd64, CONFIG_EFI enabled with "efi=old_map" on
108993 + the kernel command-line will result in an RWX physical map.
108994 +
108995 + Likewise, the EFI runtime services are necessarily mapped as
108996 + RWX. If CONFIG_EFI is enabled on an EFI-capable system, it
108997 + is recommended that you boot with "noefi" on the kernel
108998 + command-line if possible to eliminate the mapping.
108999 +
109000 +choice
109001 + prompt "Return Address Instrumentation Method"
109002 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
109003 + depends on PAX_KERNEXEC_PLUGIN
109004 + help
109005 + Select the method used to instrument function pointer dereferences.
109006 + Note that binary modules cannot be instrumented by this approach.
109007 +
109008 + Note that the implementation requires a gcc with plugin support,
109009 + i.e., gcc 4.5 or newer. You may need to install the supporting
109010 + headers explicitly in addition to the normal gcc package.
109011 +
109012 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
109013 + bool "bts"
109014 + help
109015 + This method is compatible with binary only modules but has
109016 + a higher runtime overhead.
109017 +
109018 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
109019 + bool "or"
109020 + depends on !PARAVIRT
109021 + help
109022 + This method is incompatible with binary only modules but has
109023 + a lower runtime overhead.
109024 +endchoice
109025 +
109026 +config PAX_KERNEXEC_PLUGIN_METHOD
109027 + string
109028 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
109029 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
109030 + default ""
109031 +
109032 +config PAX_KERNEXEC_MODULE_TEXT
109033 + int "Minimum amount of memory reserved for module code"
109034 + default "8" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
109035 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
109036 + depends on PAX_KERNEXEC && X86_32
109037 + help
109038 + Due to implementation details the kernel must reserve a fixed
109039 + amount of memory for runtime allocated code (such as modules)
109040 + at compile time that cannot be changed at runtime. Here you
109041 + can specify the minimum amount in MB that will be reserved.
109042 + Due to the same implementation details this size will always
109043 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
109044 + the actually available memory for runtime allocated code will
109045 + usually be more than this minimum.
109046 +
109047 + The default 4 MB should be enough for most users but if you have
109048 + an excessive number of modules (e.g., most distribution configs
109049 + compile many drivers as modules) or use huge modules such as
109050 + nvidia's kernel driver, you will need to adjust this amount.
109051 + A good rule of thumb is to look at your currently loaded kernel
109052 + modules and add up their sizes.
109053 +
109054 +endmenu
109055 +
109056 +menu "Address Space Layout Randomization"
109057 + depends on PAX
109058 +
109059 +config PAX_ASLR
109060 + bool "Address Space Layout Randomization"
109061 + default y if GRKERNSEC_CONFIG_AUTO
109062 + help
109063 + Many if not most exploit techniques rely on the knowledge of
109064 + certain addresses in the attacked program. The following options
109065 + will allow the kernel to apply a certain amount of randomization
109066 + to specific parts of the program thereby forcing an attacker to
109067 + guess them in most cases. Any failed guess will most likely crash
109068 + the attacked program which allows the kernel to detect such attempts
109069 + and react on them. PaX itself provides no reaction mechanisms,
109070 + instead it is strongly encouraged that you make use of grsecurity's
109071 + (http://www.grsecurity.net/) built-in crash detection features or
109072 + develop one yourself.
109073 +
109074 + By saying Y here you can choose to randomize the following areas:
109075 + - top of the task's kernel stack
109076 + - top of the task's userland stack
109077 + - base address for mmap() requests that do not specify one
109078 + (this includes all libraries)
109079 + - base address of the main executable
109080 +
109081 + It is strongly recommended to say Y here as address space layout
109082 + randomization has negligible impact on performance yet it provides
109083 + a very effective protection.
109084 +
109085 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
109086 + this feature on a per file basis.
109087 +
109088 +config PAX_RANDKSTACK
109089 + bool "Randomize kernel stack base"
109090 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
109091 + depends on X86_TSC && X86
109092 + help
109093 + By saying Y here the kernel will randomize every task's kernel
109094 + stack on every system call. This will not only force an attacker
109095 + to guess it but also prevent him from making use of possible
109096 + leaked information about it.
109097 +
109098 + Since the kernel stack is a rather scarce resource, randomization
109099 + may cause unexpected stack overflows, therefore you should very
109100 + carefully test your system. Note that once enabled in the kernel
109101 + configuration, this feature cannot be disabled on a per file basis.
109102 +
109103 +config PAX_RANDUSTACK
109104 + bool
109105 +
109106 +config PAX_RANDMMAP
109107 + bool "Randomize user stack and mmap() bases"
109108 + default y if GRKERNSEC_CONFIG_AUTO
109109 + depends on PAX_ASLR
109110 + select PAX_RANDUSTACK
109111 + help
109112 + By saying Y here the kernel will randomize every task's userland
109113 + stack and use a randomized base address for mmap() requests that
109114 + do not specify one themselves.
109115 +
109116 + The stack randomization is done in two steps where the second
109117 + one may apply a big amount of shift to the top of the stack and
109118 + cause problems for programs that want to use lots of memory (more
109119 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
109120 +
109121 + As a result of mmap randomization all dynamically loaded libraries
109122 + will appear at random addresses and therefore be harder to exploit
109123 + by a technique where an attacker attempts to execute library code
109124 + for his purposes (e.g. spawn a shell from an exploited program that
109125 + is running at an elevated privilege level).
109126 +
109127 + Furthermore, if a program is relinked as a dynamic ELF file, its
109128 + base address will be randomized as well, completing the full
109129 + randomization of the address space layout. Attacking such programs
109130 + becomes a guess game. You can find an example of doing this at
109131 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
109132 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
109133 +
109134 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
109135 + feature on a per file basis.
109136 +
109137 +endmenu
109138 +
109139 +menu "Miscellaneous hardening features"
109140 +
109141 +config PAX_MEMORY_SANITIZE
109142 + bool "Sanitize all freed memory"
109143 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109144 + help
109145 + By saying Y here the kernel will erase memory pages and slab objects
109146 + as soon as they are freed. This in turn reduces the lifetime of data
109147 + stored in them, making it less likely that sensitive information such
109148 + as passwords, cryptographic secrets, etc stay in memory for too long.
109149 +
109150 + This is especially useful for programs whose runtime is short, long
109151 + lived processes and the kernel itself benefit from this as long as
109152 + they ensure timely freeing of memory that may hold sensitive
109153 + information.
109154 +
109155 + A nice side effect of the sanitization of slab objects is the
109156 + reduction of possible info leaks caused by padding bytes within the
109157 + leaky structures. Use-after-free bugs for structures containing
109158 + pointers can also be detected as dereferencing the sanitized pointer
109159 + will generate an access violation.
109160 +
109161 + The tradeoff is performance impact, on a single CPU system kernel
109162 + compilation sees a 3% slowdown, other systems and workloads may vary
109163 + and you are advised to test this feature on your expected workload
109164 + before deploying it.
109165 +
109166 + The slab sanitization feature excludes a few slab caches per default
109167 + for performance reasons. To extend the feature to cover those as
109168 + well, pass "pax_sanitize_slab=full" as kernel command line parameter.
109169 +
109170 + To reduce the performance penalty by sanitizing pages only, albeit
109171 + limiting the effectiveness of this feature at the same time, slab
109172 + sanitization can be disabled with the kernel command line parameter
109173 + "pax_sanitize_slab=off".
109174 +
109175 + Note that this feature does not protect data stored in live pages,
109176 + e.g., process memory swapped to disk may stay there for a long time.
109177 +
109178 +config PAX_MEMORY_STACKLEAK
109179 + bool "Sanitize kernel stack"
109180 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109181 + depends on X86
109182 + help
109183 + By saying Y here the kernel will erase the kernel stack before it
109184 + returns from a system call. This in turn reduces the information
109185 + that a kernel stack leak bug can reveal.
109186 +
109187 + Note that such a bug can still leak information that was put on
109188 + the stack by the current system call (the one eventually triggering
109189 + the bug) but traces of earlier system calls on the kernel stack
109190 + cannot leak anymore.
109191 +
109192 + The tradeoff is performance impact: on a single CPU system kernel
109193 + compilation sees a 1% slowdown, other systems and workloads may vary
109194 + and you are advised to test this feature on your expected workload
109195 + before deploying it.
109196 +
109197 + Note that the full feature requires a gcc with plugin support,
109198 + i.e., gcc 4.5 or newer. You may need to install the supporting
109199 + headers explicitly in addition to the normal gcc package. Using
109200 + older gcc versions means that functions with large enough stack
109201 + frames may leave uninitialized memory behind that may be exposed
109202 + to a later syscall leaking the stack.
109203 +
109204 +config PAX_MEMORY_STRUCTLEAK
109205 + bool "Forcibly initialize local variables copied to userland"
109206 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
109207 + help
109208 + By saying Y here the kernel will zero initialize some local
109209 + variables that are going to be copied to userland. This in
109210 + turn prevents unintended information leakage from the kernel
109211 + stack should later code forget to explicitly set all parts of
109212 + the copied variable.
109213 +
109214 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
109215 + at a much smaller coverage.
109216 +
109217 + Note that the implementation requires a gcc with plugin support,
109218 + i.e., gcc 4.5 or newer. You may need to install the supporting
109219 + headers explicitly in addition to the normal gcc package.
109220 +
109221 +config PAX_MEMORY_UDEREF
109222 + bool "Prevent invalid userland pointer dereference"
109223 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
109224 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
109225 + select PAX_PER_CPU_PGD if X86_64
109226 + help
109227 + By saying Y here the kernel will be prevented from dereferencing
109228 + userland pointers in contexts where the kernel expects only kernel
109229 + pointers. This is both a useful runtime debugging feature and a
109230 + security measure that prevents exploiting a class of kernel bugs.
109231 +
109232 + The tradeoff is that some virtualization solutions may experience
109233 + a huge slowdown and therefore you should not enable this feature
109234 + for kernels meant to run in such environments. Whether a given VM
109235 + solution is affected or not is best determined by simply trying it
109236 + out, the performance impact will be obvious right on boot as this
109237 + mechanism engages from very early on. A good rule of thumb is that
109238 + VMs running on CPUs without hardware virtualization support (i.e.,
109239 + the majority of IA-32 CPUs) will likely experience the slowdown.
109240 +
109241 + On X86_64 the kernel will make use of PCID support when available
109242 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
109243 + or performance impact. Pass pax_weakuderef on the kernel command
109244 + line to choose the latter.
109245 +
109246 +config PAX_REFCOUNT
109247 + bool "Prevent various kernel object reference counter overflows"
109248 + default y if GRKERNSEC_CONFIG_AUTO
109249 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || PPC || SPARC64 || X86)
109250 + help
109251 + By saying Y here the kernel will detect and prevent overflowing
109252 + various (but not all) kinds of object reference counters. Such
109253 + overflows can normally occur due to bugs only and are often, if
109254 + not always, exploitable.
109255 +
109256 + The tradeoff is that data structures protected by an overflowed
109257 + refcount will never be freed and therefore will leak memory. Note
109258 + that this leak also happens even without this protection but in
109259 + that case the overflow can eventually trigger the freeing of the
109260 + data structure while it is still being used elsewhere, resulting
109261 + in the exploitable situation that this feature prevents.
109262 +
109263 + Since this has a negligible performance impact, you should enable
109264 + this feature.
109265 +
109266 +config PAX_CONSTIFY_PLUGIN
109267 + bool "Automatically constify eligible structures"
109268 + default y
109269 + depends on !UML && PAX_KERNEXEC
109270 + help
109271 + By saying Y here the compiler will automatically constify a class
109272 + of types that contain only function pointers. This reduces the
109273 + kernel's attack surface and also produces a better memory layout.
109274 +
109275 + Note that the implementation requires a gcc with plugin support,
109276 + i.e., gcc 4.5 or newer. You may need to install the supporting
109277 + headers explicitly in addition to the normal gcc package.
109278 +
109279 + Note that if some code really has to modify constified variables
109280 + then the source code will have to be patched to allow it. Examples
109281 + can be found in PaX itself (the no_const attribute) and for some
109282 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
109283 +
109284 +config PAX_USERCOPY
109285 + bool "Harden heap object copies between kernel and userland"
109286 + default y if GRKERNSEC_CONFIG_AUTO
109287 + depends on ARM || IA64 || PPC || SPARC || X86
109288 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
109289 + select PAX_USERCOPY_SLABS
109290 + help
109291 + By saying Y here the kernel will enforce the size of heap objects
109292 + when they are copied in either direction between the kernel and
109293 + userland, even if only a part of the heap object is copied.
109294 +
109295 + Specifically, this checking prevents information leaking from the
109296 + kernel heap during kernel to userland copies (if the kernel heap
109297 + object is otherwise fully initialized) and prevents kernel heap
109298 + overflows during userland to kernel copies.
109299 +
109300 + Note that the current implementation provides the strictest bounds
109301 + checks for the SLUB allocator.
109302 +
109303 + Enabling this option also enables per-slab cache protection against
109304 + data in a given cache being copied into/out of via userland
109305 + accessors. Though the whitelist of regions will be reduced over
109306 + time, it notably protects important data structures like task structs.
109307 +
109308 + If frame pointers are enabled on x86, this option will also restrict
109309 + copies into and out of the kernel stack to local variables within a
109310 + single frame.
109311 +
109312 + Since this has a negligible performance impact, you should enable
109313 + this feature.
109314 +
109315 +config PAX_USERCOPY_DEBUG
109316 + bool
109317 + depends on X86 && PAX_USERCOPY
109318 + default n
109319 +
109320 +config PAX_SIZE_OVERFLOW
109321 + bool "Prevent various integer overflows in function size parameters"
109322 + default y if GRKERNSEC_CONFIG_AUTO
109323 + depends on X86
109324 + help
109325 + By saying Y here the kernel recomputes expressions of function
109326 + arguments marked by a size_overflow attribute with double integer
109327 + precision (DImode/TImode for 32/64 bit integer types).
109328 +
109329 + The recomputed argument is checked against TYPE_MAX and an event
109330 + is logged on overflow and the triggering process is killed.
109331 +
109332 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
109333 +
109334 + Note that the implementation requires a gcc with plugin support,
109335 + i.e., gcc 4.5 or newer. You may need to install the supporting
109336 + headers explicitly in addition to the normal gcc package.
109337 +
109338 +config PAX_LATENT_ENTROPY
109339 + bool "Generate some entropy during boot and runtime"
109340 + default y if GRKERNSEC_CONFIG_AUTO
109341 + help
109342 + By saying Y here the kernel will instrument some kernel code to
109343 + extract some entropy from both original and artificially created
109344 + program state. This will help especially embedded systems where
109345 + there is little 'natural' source of entropy normally. The cost
109346 + is some slowdown of the boot process and fork and irq processing.
109347 +
109348 + When pax_extra_latent_entropy is passed on the kernel command line,
109349 + entropy will be extracted from up to the first 4GB of RAM while the
109350 + runtime memory allocator is being initialized. This costs even more
109351 + slowdown of the boot process.
109352 +
109353 + Note that the implementation requires a gcc with plugin support,
109354 + i.e., gcc 4.5 or newer. You may need to install the supporting
109355 + headers explicitly in addition to the normal gcc package.
109356 +
109357 + Note that entropy extracted this way is not cryptographically
109358 + secure!
109359 +
109360 +endmenu
109361 +
109362 +endmenu
109363 +
109364 +source grsecurity/Kconfig
109365 +
109366 +endmenu
109367 +
109368 +endmenu
109369 +
109370 source security/keys/Kconfig
109371
109372 config SECURITY_DMESG_RESTRICT
109373 @@ -103,7 +1071,7 @@ config INTEL_TXT
109374 config LSM_MMAP_MIN_ADDR
109375 int "Low address space for LSM to protect from user allocation"
109376 depends on SECURITY && SECURITY_SELINUX
109377 - default 32768 if ARM || (ARM64 && COMPAT)
109378 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
109379 default 65536
109380 help
109381 This is the portion of low virtual memory which should be protected
109382 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
109383 index fdaa50c..2761dcb 100644
109384 --- a/security/apparmor/file.c
109385 +++ b/security/apparmor/file.c
109386 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
109387 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
109388 struct path *new_dir, struct dentry *new_dentry)
109389 {
109390 - struct path link = { new_dir->mnt, new_dentry };
109391 - struct path target = { new_dir->mnt, old_dentry };
109392 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
109393 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
109394 struct path_cond cond = {
109395 old_dentry->d_inode->i_uid,
109396 old_dentry->d_inode->i_mode
109397 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
109398 index 65ca451..ad6f22d 100644
109399 --- a/security/apparmor/lsm.c
109400 +++ b/security/apparmor/lsm.c
109401 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109402 struct dentry *dentry, u32 mask,
109403 struct path_cond *cond)
109404 {
109405 - struct path path = { dir->mnt, dentry };
109406 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
109407
109408 return common_perm(op, &path, mask, cond);
109409 }
109410 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
109411 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
109412 struct dentry *dentry, u32 mask)
109413 {
109414 - struct path path = { mnt, dentry };
109415 + struct path path = { .mnt = mnt, .dentry = dentry };
109416 struct path_cond cond = { dentry->d_inode->i_uid,
109417 dentry->d_inode->i_mode
109418 };
109419 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
109420
109421 profile = aa_current_profile();
109422 if (!unconfined(profile)) {
109423 - struct path old_path = { old_dir->mnt, old_dentry };
109424 - struct path new_path = { new_dir->mnt, new_dentry };
109425 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
109426 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
109427 struct path_cond cond = { old_dentry->d_inode->i_uid,
109428 old_dentry->d_inode->i_mode
109429 };
109430 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
109431 return error;
109432 }
109433
109434 -static struct security_operations apparmor_ops = {
109435 +static struct security_operations apparmor_ops __read_only = {
109436 .name = "apparmor",
109437
109438 .ptrace_access_check = apparmor_ptrace_access_check,
109439 diff --git a/security/commoncap.c b/security/commoncap.c
109440 index bab0611..f9a0ff5 100644
109441 --- a/security/commoncap.c
109442 +++ b/security/commoncap.c
109443 @@ -427,6 +427,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
109444 return 0;
109445 }
109446
109447 +/* returns:
109448 + 1 for suid privilege
109449 + 2 for sgid privilege
109450 + 3 for fscap privilege
109451 +*/
109452 +int is_privileged_binary(const struct dentry *dentry)
109453 +{
109454 + struct cpu_vfs_cap_data capdata;
109455 + struct inode *inode = dentry->d_inode;
109456 +
109457 + if (!inode || S_ISDIR(inode->i_mode))
109458 + return 0;
109459 +
109460 + if (inode->i_mode & S_ISUID)
109461 + return 1;
109462 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
109463 + return 2;
109464 +
109465 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
109466 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
109467 + return 3;
109468 + }
109469 +
109470 + return 0;
109471 +}
109472 +
109473 /*
109474 * Attempt to get the on-exec apply capability sets for an executable file from
109475 * its xattrs and, if present, apply them to the proposed credentials being
109476 @@ -595,6 +621,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
109477 const struct cred *cred = current_cred();
109478 kuid_t root_uid = make_kuid(cred->user_ns, 0);
109479
109480 + if (gr_acl_enable_at_secure())
109481 + return 1;
109482 +
109483 if (!uid_eq(cred->uid, root_uid)) {
109484 if (bprm->cap_effective)
109485 return 1;
109486 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
109487 index 8ee997d..24c174b 100644
109488 --- a/security/integrity/ima/ima.h
109489 +++ b/security/integrity/ima/ima.h
109490 @@ -116,8 +116,8 @@ int ima_init_template(void);
109491 extern spinlock_t ima_queue_lock;
109492
109493 struct ima_h_table {
109494 - atomic_long_t len; /* number of stored measurements in the list */
109495 - atomic_long_t violations;
109496 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
109497 + atomic_long_unchecked_t violations;
109498 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
109499 };
109500 extern struct ima_h_table ima_htable;
109501 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
109502 index 8688597..9fa80d2 100644
109503 --- a/security/integrity/ima/ima_api.c
109504 +++ b/security/integrity/ima/ima_api.c
109505 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
109506 int result;
109507
109508 /* can overflow, only indicator */
109509 - atomic_long_inc(&ima_htable.violations);
109510 + atomic_long_inc_unchecked(&ima_htable.violations);
109511
109512 result = ima_alloc_init_template(NULL, file, filename,
109513 NULL, 0, &entry);
109514 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
109515 index da92fcc..8a5d390 100644
109516 --- a/security/integrity/ima/ima_fs.c
109517 +++ b/security/integrity/ima/ima_fs.c
109518 @@ -28,12 +28,12 @@
109519 static int valid_policy = 1;
109520 #define TMPBUFLEN 12
109521 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
109522 - loff_t *ppos, atomic_long_t *val)
109523 + loff_t *ppos, atomic_long_unchecked_t *val)
109524 {
109525 char tmpbuf[TMPBUFLEN];
109526 ssize_t len;
109527
109528 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
109529 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
109530 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
109531 }
109532
109533 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
109534 index 552705d..9920f4fb 100644
109535 --- a/security/integrity/ima/ima_queue.c
109536 +++ b/security/integrity/ima/ima_queue.c
109537 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
109538 INIT_LIST_HEAD(&qe->later);
109539 list_add_tail_rcu(&qe->later, &ima_measurements);
109540
109541 - atomic_long_inc(&ima_htable.len);
109542 + atomic_long_inc_unchecked(&ima_htable.len);
109543 key = ima_hash_key(entry->digest);
109544 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
109545 return 0;
109546 diff --git a/security/keys/compat.c b/security/keys/compat.c
109547 index 3478965..ec7bb9e 100644
109548 --- a/security/keys/compat.c
109549 +++ b/security/keys/compat.c
109550 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
109551 if (ret == 0)
109552 goto no_payload_free;
109553
109554 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109555 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109556 err:
109557 if (iov != iovstack)
109558 kfree(iov);
109559 diff --git a/security/keys/internal.h b/security/keys/internal.h
109560 index 200e378..cdc74b5 100644
109561 --- a/security/keys/internal.h
109562 +++ b/security/keys/internal.h
109563 @@ -244,7 +244,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
109564 extern long keyctl_invalidate_key(key_serial_t);
109565
109566 extern long keyctl_instantiate_key_common(key_serial_t,
109567 - const struct iovec *,
109568 + const struct iovec __user *,
109569 unsigned, size_t, key_serial_t);
109570 #ifdef CONFIG_PERSISTENT_KEYRINGS
109571 extern long keyctl_get_persistent(uid_t, key_serial_t);
109572 diff --git a/security/keys/key.c b/security/keys/key.c
109573 index e17ba6a..2cc04a6 100644
109574 --- a/security/keys/key.c
109575 +++ b/security/keys/key.c
109576 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
109577
109578 atomic_set(&key->usage, 1);
109579 init_rwsem(&key->sem);
109580 - lockdep_set_class(&key->sem, &type->lock_class);
109581 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
109582 key->index_key.type = type;
109583 key->user = user;
109584 key->quotalen = quotalen;
109585 @@ -1075,7 +1075,9 @@ int register_key_type(struct key_type *ktype)
109586 struct key_type *p;
109587 int ret;
109588
109589 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
109590 + pax_open_kernel();
109591 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
109592 + pax_close_kernel();
109593
109594 ret = -EEXIST;
109595 down_write(&key_types_sem);
109596 @@ -1087,7 +1089,7 @@ int register_key_type(struct key_type *ktype)
109597 }
109598
109599 /* store the type */
109600 - list_add(&ktype->link, &key_types_list);
109601 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
109602
109603 pr_notice("Key type %s registered\n", ktype->name);
109604 ret = 0;
109605 @@ -1109,7 +1111,7 @@ EXPORT_SYMBOL(register_key_type);
109606 void unregister_key_type(struct key_type *ktype)
109607 {
109608 down_write(&key_types_sem);
109609 - list_del_init(&ktype->link);
109610 + pax_list_del_init((struct list_head *)&ktype->link);
109611 downgrade_write(&key_types_sem);
109612 key_gc_keytype(ktype);
109613 pr_notice("Key type %s unregistered\n", ktype->name);
109614 @@ -1127,10 +1129,10 @@ void __init key_init(void)
109615 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
109616
109617 /* add the special key types */
109618 - list_add_tail(&key_type_keyring.link, &key_types_list);
109619 - list_add_tail(&key_type_dead.link, &key_types_list);
109620 - list_add_tail(&key_type_user.link, &key_types_list);
109621 - list_add_tail(&key_type_logon.link, &key_types_list);
109622 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
109623 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
109624 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
109625 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
109626
109627 /* record the root user tracking */
109628 rb_link_node(&root_key_user.node,
109629 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
109630 index 4743d71..170a185 100644
109631 --- a/security/keys/keyctl.c
109632 +++ b/security/keys/keyctl.c
109633 @@ -1000,7 +1000,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
109634 /*
109635 * Copy the iovec data from userspace
109636 */
109637 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109638 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
109639 unsigned ioc)
109640 {
109641 for (; ioc > 0; ioc--) {
109642 @@ -1022,7 +1022,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
109643 * If successful, 0 will be returned.
109644 */
109645 long keyctl_instantiate_key_common(key_serial_t id,
109646 - const struct iovec *payload_iov,
109647 + const struct iovec __user *payload_iov,
109648 unsigned ioc,
109649 size_t plen,
109650 key_serial_t ringid)
109651 @@ -1117,7 +1117,7 @@ long keyctl_instantiate_key(key_serial_t id,
109652 [0].iov_len = plen
109653 };
109654
109655 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
109656 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
109657 }
109658
109659 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
109660 @@ -1150,7 +1150,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
109661 if (ret == 0)
109662 goto no_payload_free;
109663
109664 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
109665 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
109666 err:
109667 if (iov != iovstack)
109668 kfree(iov);
109669 diff --git a/security/keys/request_key.c b/security/keys/request_key.c
109670 index 0c7aea4..486ef6f 100644
109671 --- a/security/keys/request_key.c
109672 +++ b/security/keys/request_key.c
109673 @@ -414,6 +414,7 @@ link_check_failed:
109674
109675 link_prealloc_failed:
109676 mutex_unlock(&user->cons_lock);
109677 + key_put(key);
109678 kleave(" = %d [prelink]", ret);
109679 return ret;
109680
109681 diff --git a/security/min_addr.c b/security/min_addr.c
109682 index f728728..6457a0c 100644
109683 --- a/security/min_addr.c
109684 +++ b/security/min_addr.c
109685 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
109686 */
109687 static void update_mmap_min_addr(void)
109688 {
109689 +#ifndef SPARC
109690 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
109691 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
109692 mmap_min_addr = dac_mmap_min_addr;
109693 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
109694 #else
109695 mmap_min_addr = dac_mmap_min_addr;
109696 #endif
109697 +#endif
109698 }
109699
109700 /*
109701 diff --git a/security/security.c b/security/security.c
109702 index 18b35c6..c9fbc92 100644
109703 --- a/security/security.c
109704 +++ b/security/security.c
109705 @@ -33,8 +33,8 @@
109706 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
109707 CONFIG_DEFAULT_SECURITY;
109708
109709 -static struct security_operations *security_ops;
109710 -static struct security_operations default_security_ops = {
109711 +struct security_operations *security_ops __read_only;
109712 +struct security_operations default_security_ops __read_only = {
109713 .name = "default",
109714 };
109715
109716 @@ -73,11 +73,6 @@ int __init security_init(void)
109717 return 0;
109718 }
109719
109720 -void reset_security_ops(void)
109721 -{
109722 - security_ops = &default_security_ops;
109723 -}
109724 -
109725 /* Save user chosen LSM */
109726 static int __init choose_lsm(char *str)
109727 {
109728 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
109729 index a18f1fa..c9b9fc4 100644
109730 --- a/security/selinux/avc.c
109731 +++ b/security/selinux/avc.c
109732 @@ -59,7 +59,7 @@ struct avc_node {
109733 struct avc_cache {
109734 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
109735 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
109736 - atomic_t lru_hint; /* LRU hint for reclaim scan */
109737 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
109738 atomic_t active_nodes;
109739 u32 latest_notif; /* latest revocation notification */
109740 };
109741 @@ -167,7 +167,7 @@ void __init avc_init(void)
109742 spin_lock_init(&avc_cache.slots_lock[i]);
109743 }
109744 atomic_set(&avc_cache.active_nodes, 0);
109745 - atomic_set(&avc_cache.lru_hint, 0);
109746 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
109747
109748 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
109749 0, SLAB_PANIC, NULL);
109750 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
109751 spinlock_t *lock;
109752
109753 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
109754 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109755 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
109756 head = &avc_cache.slots[hvalue];
109757 lock = &avc_cache.slots_lock[hvalue];
109758
109759 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
109760 index c603b20..8716ec9 100644
109761 --- a/security/selinux/hooks.c
109762 +++ b/security/selinux/hooks.c
109763 @@ -95,8 +95,6 @@
109764 #include "audit.h"
109765 #include "avc_ss.h"
109766
109767 -extern struct security_operations *security_ops;
109768 -
109769 /* SECMARK reference count */
109770 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
109771
109772 @@ -5809,7 +5807,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
109773
109774 #endif
109775
109776 -static struct security_operations selinux_ops = {
109777 +static struct security_operations selinux_ops __read_only = {
109778 .name = "selinux",
109779
109780 .ptrace_access_check = selinux_ptrace_access_check,
109781 @@ -6150,6 +6148,9 @@ static void selinux_nf_ip_exit(void)
109782 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
109783 static int selinux_disabled;
109784
109785 +extern struct security_operations *security_ops;
109786 +extern struct security_operations default_security_ops;
109787 +
109788 int selinux_disable(void)
109789 {
109790 if (ss_initialized) {
109791 @@ -6167,7 +6168,9 @@ int selinux_disable(void)
109792 selinux_disabled = 1;
109793 selinux_enabled = 0;
109794
109795 - reset_security_ops();
109796 + pax_open_kernel();
109797 + security_ops = &default_security_ops;
109798 + pax_close_kernel();
109799
109800 /* Try to destroy the avc node cache */
109801 avc_disable();
109802 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
109803 index 1450f85..a91e0bc 100644
109804 --- a/security/selinux/include/xfrm.h
109805 +++ b/security/selinux/include/xfrm.h
109806 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
109807
109808 rtnl_lock();
109809 for_each_net(net) {
109810 - atomic_inc(&net->xfrm.flow_cache_genid);
109811 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
109812 rt_genid_bump_all(net);
109813 }
109814 rtnl_unlock();
109815 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
109816 index 9d3c64a..76e336e 100644
109817 --- a/security/smack/smack_lsm.c
109818 +++ b/security/smack/smack_lsm.c
109819 @@ -4081,7 +4081,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
109820 return 0;
109821 }
109822
109823 -struct security_operations smack_ops = {
109824 +struct security_operations smack_ops __read_only = {
109825 .name = "smack",
109826
109827 .ptrace_access_check = smack_ptrace_access_check,
109828 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
109829 index 4003907..13a2b55 100644
109830 --- a/security/tomoyo/file.c
109831 +++ b/security/tomoyo/file.c
109832 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
109833 {
109834 struct tomoyo_request_info r;
109835 struct tomoyo_obj_info obj = {
109836 - .path1 = *path,
109837 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109838 };
109839 int error = -ENOMEM;
109840 struct tomoyo_path_info buf;
109841 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
109842 struct tomoyo_path_info buf;
109843 struct tomoyo_request_info r;
109844 struct tomoyo_obj_info obj = {
109845 - .path1 = *path,
109846 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109847 };
109848 int idx;
109849
109850 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
109851 {
109852 struct tomoyo_request_info r;
109853 struct tomoyo_obj_info obj = {
109854 - .path1 = *path,
109855 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109856 };
109857 int error;
109858 struct tomoyo_path_info buf;
109859 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
109860 {
109861 struct tomoyo_request_info r;
109862 struct tomoyo_obj_info obj = {
109863 - .path1 = *path,
109864 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
109865 };
109866 int error = -ENOMEM;
109867 struct tomoyo_path_info buf;
109868 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
109869 struct tomoyo_path_info buf2;
109870 struct tomoyo_request_info r;
109871 struct tomoyo_obj_info obj = {
109872 - .path1 = *path1,
109873 - .path2 = *path2,
109874 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
109875 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
109876 };
109877 int idx;
109878
109879 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
109880 index 390c646..f2f8db3 100644
109881 --- a/security/tomoyo/mount.c
109882 +++ b/security/tomoyo/mount.c
109883 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
109884 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
109885 need_dev = -1; /* dev_name is a directory */
109886 } else {
109887 + if (!capable(CAP_SYS_ADMIN)) {
109888 + error = -EPERM;
109889 + goto out;
109890 + }
109891 fstype = get_fs_type(type);
109892 if (!fstype) {
109893 error = -ENODEV;
109894 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
109895 index f0b756e..8aa497b 100644
109896 --- a/security/tomoyo/tomoyo.c
109897 +++ b/security/tomoyo/tomoyo.c
109898 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
109899 */
109900 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
109901 {
109902 - struct path path = { mnt, dentry };
109903 + struct path path = { .mnt = mnt, .dentry = dentry };
109904 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
109905 }
109906
109907 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
109908 */
109909 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109910 {
109911 - struct path path = { parent->mnt, dentry };
109912 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109913 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
109914 }
109915
109916 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
109917 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109918 umode_t mode)
109919 {
109920 - struct path path = { parent->mnt, dentry };
109921 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109922 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
109923 mode & S_IALLUGO);
109924 }
109925 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
109926 */
109927 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109928 {
109929 - struct path path = { parent->mnt, dentry };
109930 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109931 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
109932 }
109933
109934 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
109935 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109936 const char *old_name)
109937 {
109938 - struct path path = { parent->mnt, dentry };
109939 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109940 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
109941 }
109942
109943 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
109944 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109945 umode_t mode, unsigned int dev)
109946 {
109947 - struct path path = { parent->mnt, dentry };
109948 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
109949 int type = TOMOYO_TYPE_CREATE;
109950 const unsigned int perm = mode & S_IALLUGO;
109951
109952 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
109953 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
109954 struct dentry *new_dentry)
109955 {
109956 - struct path path1 = { new_dir->mnt, old_dentry };
109957 - struct path path2 = { new_dir->mnt, new_dentry };
109958 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
109959 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
109960 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
109961 }
109962
109963 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
109964 struct path *new_parent,
109965 struct dentry *new_dentry)
109966 {
109967 - struct path path1 = { old_parent->mnt, old_dentry };
109968 - struct path path2 = { new_parent->mnt, new_dentry };
109969 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
109970 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
109971 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
109972 }
109973
109974 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
109975 */
109976 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
109977 {
109978 - struct path path = { mnt, mnt->mnt_root };
109979 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
109980 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
109981 }
109982
109983 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
109984 * tomoyo_security_ops is a "struct security_operations" which is used for
109985 * registering TOMOYO.
109986 */
109987 -static struct security_operations tomoyo_security_ops = {
109988 +static struct security_operations tomoyo_security_ops __read_only = {
109989 .name = "tomoyo",
109990 .cred_alloc_blank = tomoyo_cred_alloc_blank,
109991 .cred_prepare = tomoyo_cred_prepare,
109992 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
109993 index 20ef514..4182bed 100644
109994 --- a/security/yama/Kconfig
109995 +++ b/security/yama/Kconfig
109996 @@ -1,6 +1,6 @@
109997 config SECURITY_YAMA
109998 bool "Yama support"
109999 - depends on SECURITY
110000 + depends on SECURITY && !GRKERNSEC
110001 select SECURITYFS
110002 select SECURITY_PATH
110003 default n
110004 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
110005 index 13c88fbc..f8c115e 100644
110006 --- a/security/yama/yama_lsm.c
110007 +++ b/security/yama/yama_lsm.c
110008 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
110009 }
110010
110011 #ifndef CONFIG_SECURITY_YAMA_STACKED
110012 -static struct security_operations yama_ops = {
110013 +static struct security_operations yama_ops __read_only = {
110014 .name = "yama",
110015
110016 .ptrace_access_check = yama_ptrace_access_check,
110017 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
110018 #endif
110019
110020 #ifdef CONFIG_SYSCTL
110021 +static int zero __read_only;
110022 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
110023 +
110024 static int yama_dointvec_minmax(struct ctl_table *table, int write,
110025 void __user *buffer, size_t *lenp, loff_t *ppos)
110026 {
110027 - int rc;
110028 + ctl_table_no_const yama_table;
110029
110030 if (write && !capable(CAP_SYS_PTRACE))
110031 return -EPERM;
110032
110033 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
110034 - if (rc)
110035 - return rc;
110036 -
110037 + yama_table = *table;
110038 /* Lock the max value if it ever gets set. */
110039 - if (write && *(int *)table->data == *(int *)table->extra2)
110040 - table->extra1 = table->extra2;
110041 -
110042 - return rc;
110043 + if (ptrace_scope == max_scope)
110044 + yama_table.extra1 = &max_scope;
110045 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
110046 }
110047
110048 -static int zero;
110049 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
110050 -
110051 struct ctl_path yama_sysctl_path[] = {
110052 { .procname = "kernel", },
110053 { .procname = "yama", },
110054 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
110055 index 401107b..b9c47c6 100644
110056 --- a/sound/aoa/codecs/onyx.c
110057 +++ b/sound/aoa/codecs/onyx.c
110058 @@ -54,7 +54,7 @@ struct onyx {
110059 spdif_locked:1,
110060 analog_locked:1,
110061 original_mute:2;
110062 - int open_count;
110063 + local_t open_count;
110064 struct codec_info *codec_info;
110065
110066 /* mutex serializes concurrent access to the device
110067 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
110068 struct onyx *onyx = cii->codec_data;
110069
110070 mutex_lock(&onyx->mutex);
110071 - onyx->open_count++;
110072 + local_inc(&onyx->open_count);
110073 mutex_unlock(&onyx->mutex);
110074
110075 return 0;
110076 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
110077 struct onyx *onyx = cii->codec_data;
110078
110079 mutex_lock(&onyx->mutex);
110080 - onyx->open_count--;
110081 - if (!onyx->open_count)
110082 + if (local_dec_and_test(&onyx->open_count))
110083 onyx->spdif_locked = onyx->analog_locked = 0;
110084 mutex_unlock(&onyx->mutex);
110085
110086 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
110087 index ffd2025..df062c9 100644
110088 --- a/sound/aoa/codecs/onyx.h
110089 +++ b/sound/aoa/codecs/onyx.h
110090 @@ -11,6 +11,7 @@
110091 #include <linux/i2c.h>
110092 #include <asm/pmac_low_i2c.h>
110093 #include <asm/prom.h>
110094 +#include <asm/local.h>
110095
110096 /* PCM3052 register definitions */
110097
110098 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
110099 index ada69d7..5f65386 100644
110100 --- a/sound/core/oss/pcm_oss.c
110101 +++ b/sound/core/oss/pcm_oss.c
110102 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
110103 if (in_kernel) {
110104 mm_segment_t fs;
110105 fs = snd_enter_user();
110106 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
110107 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
110108 snd_leave_user(fs);
110109 } else {
110110 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
110111 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
110112 }
110113 if (ret != -EPIPE && ret != -ESTRPIPE)
110114 break;
110115 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
110116 if (in_kernel) {
110117 mm_segment_t fs;
110118 fs = snd_enter_user();
110119 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110120 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110121 snd_leave_user(fs);
110122 } else {
110123 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
110124 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
110125 }
110126 if (ret == -EPIPE) {
110127 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
110128 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
110129 struct snd_pcm_plugin_channel *channels;
110130 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
110131 if (!in_kernel) {
110132 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
110133 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
110134 return -EFAULT;
110135 buf = runtime->oss.buffer;
110136 }
110137 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
110138 }
110139 } else {
110140 tmp = snd_pcm_oss_write2(substream,
110141 - (const char __force *)buf,
110142 + (const char __force_kernel *)buf,
110143 runtime->oss.period_bytes, 0);
110144 if (tmp <= 0)
110145 goto err;
110146 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
110147 struct snd_pcm_runtime *runtime = substream->runtime;
110148 snd_pcm_sframes_t frames, frames1;
110149 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
110150 - char __user *final_dst = (char __force __user *)buf;
110151 + char __user *final_dst = (char __force_user *)buf;
110152 if (runtime->oss.plugin_first) {
110153 struct snd_pcm_plugin_channel *channels;
110154 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
110155 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
110156 xfer += tmp;
110157 runtime->oss.buffer_used -= tmp;
110158 } else {
110159 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
110160 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
110161 runtime->oss.period_bytes, 0);
110162 if (tmp <= 0)
110163 goto err;
110164 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
110165 size1);
110166 size1 /= runtime->channels; /* frames */
110167 fs = snd_enter_user();
110168 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
110169 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
110170 snd_leave_user(fs);
110171 }
110172 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
110173 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
110174 index 2d957ba..fda022c 100644
110175 --- a/sound/core/pcm_compat.c
110176 +++ b/sound/core/pcm_compat.c
110177 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
110178 int err;
110179
110180 fs = snd_enter_user();
110181 - err = snd_pcm_delay(substream, &delay);
110182 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
110183 snd_leave_user(fs);
110184 if (err < 0)
110185 return err;
110186 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
110187 index 166d59c..89e3889 100644
110188 --- a/sound/core/pcm_native.c
110189 +++ b/sound/core/pcm_native.c
110190 @@ -2931,11 +2931,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
110191 switch (substream->stream) {
110192 case SNDRV_PCM_STREAM_PLAYBACK:
110193 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
110194 - (void __user *)arg);
110195 + (void __force_user *)arg);
110196 break;
110197 case SNDRV_PCM_STREAM_CAPTURE:
110198 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
110199 - (void __user *)arg);
110200 + (void __force_user *)arg);
110201 break;
110202 default:
110203 result = -EINVAL;
110204 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
110205 index 16d4267..fe8b49b 100644
110206 --- a/sound/core/seq/oss/seq_oss.c
110207 +++ b/sound/core/seq/oss/seq_oss.c
110208 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
110209 {
110210 int rc;
110211 static struct snd_seq_dev_ops ops = {
110212 - snd_seq_oss_synth_register,
110213 - snd_seq_oss_synth_unregister,
110214 + .init_device = snd_seq_oss_synth_register,
110215 + .free_device = snd_seq_oss_synth_unregister,
110216 };
110217
110218 snd_seq_autoload_lock();
110219 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
110220 index 91a786a..4c07ed4 100644
110221 --- a/sound/core/seq/seq_device.c
110222 +++ b/sound/core/seq/seq_device.c
110223 @@ -64,7 +64,7 @@ struct ops_list {
110224 int argsize; /* argument size */
110225
110226 /* operators */
110227 - struct snd_seq_dev_ops ops;
110228 + struct snd_seq_dev_ops *ops;
110229
110230 /* registered devices */
110231 struct list_head dev_list; /* list of devices */
110232 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
110233
110234 mutex_lock(&ops->reg_mutex);
110235 /* copy driver operators */
110236 - ops->ops = *entry;
110237 + ops->ops = entry;
110238 ops->driver |= DRIVER_LOADED;
110239 ops->argsize = argsize;
110240
110241 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
110242 dev->name, ops->id, ops->argsize, dev->argsize);
110243 return -EINVAL;
110244 }
110245 - if (ops->ops.init_device(dev) >= 0) {
110246 + if (ops->ops->init_device(dev) >= 0) {
110247 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
110248 ops->num_init_devices++;
110249 } else {
110250 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
110251 dev->name, ops->id, ops->argsize, dev->argsize);
110252 return -EINVAL;
110253 }
110254 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
110255 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
110256 dev->status = SNDRV_SEQ_DEVICE_FREE;
110257 dev->driver_data = NULL;
110258 ops->num_init_devices--;
110259 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
110260 index a1fd77a..69cd659 100644
110261 --- a/sound/core/seq/seq_midi.c
110262 +++ b/sound/core/seq/seq_midi.c
110263 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
110264 static int __init alsa_seq_midi_init(void)
110265 {
110266 static struct snd_seq_dev_ops ops = {
110267 - snd_seq_midisynth_register_port,
110268 - snd_seq_midisynth_unregister_port,
110269 + .init_device = snd_seq_midisynth_register_port,
110270 + .free_device = snd_seq_midisynth_unregister_port,
110271 };
110272 memset(&synths, 0, sizeof(synths));
110273 snd_seq_autoload_lock();
110274 diff --git a/sound/core/sound.c b/sound/core/sound.c
110275 index 38ad1a0..5010a40 100644
110276 --- a/sound/core/sound.c
110277 +++ b/sound/core/sound.c
110278 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
110279 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
110280 default: return;
110281 }
110282 - request_module(str);
110283 + request_module("%s", str);
110284 }
110285
110286 #endif /* modular kernel */
110287 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
110288 index f5fd448..6ae276da 100644
110289 --- a/sound/drivers/mts64.c
110290 +++ b/sound/drivers/mts64.c
110291 @@ -29,6 +29,7 @@
110292 #include <sound/initval.h>
110293 #include <sound/rawmidi.h>
110294 #include <sound/control.h>
110295 +#include <asm/local.h>
110296
110297 #define CARD_NAME "Miditerminal 4140"
110298 #define DRIVER_NAME "MTS64"
110299 @@ -67,7 +68,7 @@ struct mts64 {
110300 struct pardevice *pardev;
110301 int pardev_claimed;
110302
110303 - int open_count;
110304 + local_t open_count;
110305 int current_midi_output_port;
110306 int current_midi_input_port;
110307 u8 mode[MTS64_NUM_INPUT_PORTS];
110308 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110309 {
110310 struct mts64 *mts = substream->rmidi->private_data;
110311
110312 - if (mts->open_count == 0) {
110313 + if (local_read(&mts->open_count) == 0) {
110314 /* We don't need a spinlock here, because this is just called
110315 if the device has not been opened before.
110316 So there aren't any IRQs from the device */
110317 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
110318
110319 msleep(50);
110320 }
110321 - ++(mts->open_count);
110322 + local_inc(&mts->open_count);
110323
110324 return 0;
110325 }
110326 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110327 struct mts64 *mts = substream->rmidi->private_data;
110328 unsigned long flags;
110329
110330 - --(mts->open_count);
110331 - if (mts->open_count == 0) {
110332 + if (local_dec_return(&mts->open_count) == 0) {
110333 /* We need the spinlock_irqsave here because we can still
110334 have IRQs at this point */
110335 spin_lock_irqsave(&mts->lock, flags);
110336 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
110337
110338 msleep(500);
110339
110340 - } else if (mts->open_count < 0)
110341 - mts->open_count = 0;
110342 + } else if (local_read(&mts->open_count) < 0)
110343 + local_set(&mts->open_count, 0);
110344
110345 return 0;
110346 }
110347 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
110348 index 6839953..7a0f4b9 100644
110349 --- a/sound/drivers/opl3/opl3_seq.c
110350 +++ b/sound/drivers/opl3/opl3_seq.c
110351 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
110352 {
110353 static struct snd_seq_dev_ops ops =
110354 {
110355 - snd_opl3_seq_new_device,
110356 - snd_opl3_seq_delete_device
110357 + .init_device = snd_opl3_seq_new_device,
110358 + .free_device = snd_opl3_seq_delete_device
110359 };
110360
110361 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
110362 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
110363 index b953fb4..1999c01 100644
110364 --- a/sound/drivers/opl4/opl4_lib.c
110365 +++ b/sound/drivers/opl4/opl4_lib.c
110366 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
110367 MODULE_DESCRIPTION("OPL4 driver");
110368 MODULE_LICENSE("GPL");
110369
110370 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
110371 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
110372 {
110373 int timeout = 10;
110374 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
110375 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
110376 index 9919769..d7de36c 100644
110377 --- a/sound/drivers/opl4/opl4_seq.c
110378 +++ b/sound/drivers/opl4/opl4_seq.c
110379 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
110380 static int __init alsa_opl4_synth_init(void)
110381 {
110382 static struct snd_seq_dev_ops ops = {
110383 - snd_opl4_seq_new_device,
110384 - snd_opl4_seq_delete_device
110385 + .init_device = snd_opl4_seq_new_device,
110386 + .free_device = snd_opl4_seq_delete_device
110387 };
110388
110389 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
110390 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
110391 index 78ccfa4..7a0857b 100644
110392 --- a/sound/drivers/portman2x4.c
110393 +++ b/sound/drivers/portman2x4.c
110394 @@ -48,6 +48,7 @@
110395 #include <sound/initval.h>
110396 #include <sound/rawmidi.h>
110397 #include <sound/control.h>
110398 +#include <asm/local.h>
110399
110400 #define CARD_NAME "Portman 2x4"
110401 #define DRIVER_NAME "portman"
110402 @@ -85,7 +86,7 @@ struct portman {
110403 struct pardevice *pardev;
110404 int pardev_claimed;
110405
110406 - int open_count;
110407 + local_t open_count;
110408 int mode[PORTMAN_NUM_INPUT_PORTS];
110409 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
110410 };
110411 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
110412 index 95fc2eaf..ea5d6a7 100644
110413 --- a/sound/firewire/amdtp.c
110414 +++ b/sound/firewire/amdtp.c
110415 @@ -521,7 +521,7 @@ static void update_pcm_pointers(struct amdtp_stream *s,
110416 ptr = s->pcm_buffer_pointer + frames;
110417 if (ptr >= pcm->runtime->buffer_size)
110418 ptr -= pcm->runtime->buffer_size;
110419 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
110420 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
110421
110422 s->pcm_period_pointer += frames;
110423 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
110424 @@ -961,7 +961,7 @@ EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
110425 */
110426 void amdtp_stream_update(struct amdtp_stream *s)
110427 {
110428 - ACCESS_ONCE(s->source_node_id_field) =
110429 + ACCESS_ONCE_RW(s->source_node_id_field) =
110430 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
110431 }
110432 EXPORT_SYMBOL(amdtp_stream_update);
110433 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
110434 index 4823c08..47a5f7c 100644
110435 --- a/sound/firewire/amdtp.h
110436 +++ b/sound/firewire/amdtp.h
110437 @@ -212,7 +212,7 @@ static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)
110438 static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,
110439 struct snd_pcm_substream *pcm)
110440 {
110441 - ACCESS_ONCE(s->pcm) = pcm;
110442 + ACCESS_ONCE_RW(s->pcm) = pcm;
110443 }
110444
110445 /**
110446 @@ -230,7 +230,7 @@ static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,
110447 struct snd_rawmidi_substream *midi)
110448 {
110449 if (port < s->midi_ports)
110450 - ACCESS_ONCE(s->midi[port]) = midi;
110451 + ACCESS_ONCE_RW(s->midi[port]) = midi;
110452 }
110453
110454 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
110455 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
110456 index 7ac9443..0ec6274 100644
110457 --- a/sound/firewire/isight.c
110458 +++ b/sound/firewire/isight.c
110459 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
110460 ptr += count;
110461 if (ptr >= runtime->buffer_size)
110462 ptr -= runtime->buffer_size;
110463 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
110464 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
110465
110466 isight->period_counter += count;
110467 if (isight->period_counter >= runtime->period_size) {
110468 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
110469 if (err < 0)
110470 return err;
110471
110472 - ACCESS_ONCE(isight->pcm_active) = true;
110473 + ACCESS_ONCE_RW(isight->pcm_active) = true;
110474
110475 return 0;
110476 }
110477 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
110478 {
110479 struct isight *isight = substream->private_data;
110480
110481 - ACCESS_ONCE(isight->pcm_active) = false;
110482 + ACCESS_ONCE_RW(isight->pcm_active) = false;
110483
110484 mutex_lock(&isight->mutex);
110485 isight_stop_streaming(isight);
110486 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
110487
110488 switch (cmd) {
110489 case SNDRV_PCM_TRIGGER_START:
110490 - ACCESS_ONCE(isight->pcm_running) = true;
110491 + ACCESS_ONCE_RW(isight->pcm_running) = true;
110492 break;
110493 case SNDRV_PCM_TRIGGER_STOP:
110494 - ACCESS_ONCE(isight->pcm_running) = false;
110495 + ACCESS_ONCE_RW(isight->pcm_running) = false;
110496 break;
110497 default:
110498 return -EINVAL;
110499 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
110500 index 2dba848..c682aef 100644
110501 --- a/sound/firewire/scs1x.c
110502 +++ b/sound/firewire/scs1x.c
110503 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
110504 {
110505 struct scs *scs = stream->rmidi->private_data;
110506
110507 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
110508 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
110509 if (up) {
110510 scs->output_idle = false;
110511 tasklet_schedule(&scs->tasklet);
110512 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
110513 {
110514 struct scs *scs = stream->rmidi->private_data;
110515
110516 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
110517 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
110518 }
110519
110520 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
110521 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
110522
110523 snd_card_disconnect(scs->card);
110524
110525 - ACCESS_ONCE(scs->output) = NULL;
110526 - ACCESS_ONCE(scs->input) = NULL;
110527 + ACCESS_ONCE_RW(scs->output) = NULL;
110528 + ACCESS_ONCE_RW(scs->input) = NULL;
110529
110530 wait_event(scs->idle_wait, scs->output_idle);
110531
110532 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
110533 index 4e3fcfb..ab45a9d 100644
110534 --- a/sound/isa/sb/emu8000_synth.c
110535 +++ b/sound/isa/sb/emu8000_synth.c
110536 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
110537 {
110538
110539 static struct snd_seq_dev_ops ops = {
110540 - snd_emu8000_new_device,
110541 - snd_emu8000_delete_device,
110542 + .init_device = snd_emu8000_new_device,
110543 + .free_device = snd_emu8000_delete_device,
110544 };
110545 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
110546 sizeof(struct snd_emu8000*));
110547 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
110548 index 048439a..3be9f6f 100644
110549 --- a/sound/oss/sb_audio.c
110550 +++ b/sound/oss/sb_audio.c
110551 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
110552 buf16 = (signed short *)(localbuf + localoffs);
110553 while (c)
110554 {
110555 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110556 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
110557 if (copy_from_user(lbuf8,
110558 userbuf+useroffs + p,
110559 locallen))
110560 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
110561 index a33e8ce..2262303 100644
110562 --- a/sound/oss/swarm_cs4297a.c
110563 +++ b/sound/oss/swarm_cs4297a.c
110564 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
110565 {
110566 struct cs4297a_state *s;
110567 u32 pwr, id;
110568 - mm_segment_t fs;
110569 int rval;
110570 u64 cfg;
110571 int mdio_val;
110572 @@ -2709,22 +2708,23 @@ static int __init cs4297a_init(void)
110573 if (!rval) {
110574 char *sb1250_duart_present;
110575
110576 +#if 0
110577 + mm_segment_t fs;
110578 fs = get_fs();
110579 set_fs(KERNEL_DS);
110580 -#if 0
110581 val = SOUND_MASK_LINE;
110582 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
110583 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
110584 val = initvol[i].vol;
110585 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
110586 }
110587 + set_fs(fs);
110588 // cs4297a_write_ac97(s, 0x18, 0x0808);
110589 #else
110590 // cs4297a_write_ac97(s, 0x5e, 0x180);
110591 cs4297a_write_ac97(s, 0x02, 0x0808);
110592 cs4297a_write_ac97(s, 0x18, 0x0808);
110593 #endif
110594 - set_fs(fs);
110595
110596 list_add(&s->list, &cs4297a_devs);
110597
110598 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
110599 index 4c41c90..37f3631 100644
110600 --- a/sound/pci/emu10k1/emu10k1_synth.c
110601 +++ b/sound/pci/emu10k1/emu10k1_synth.c
110602 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
110603 {
110604
110605 static struct snd_seq_dev_ops ops = {
110606 - snd_emu10k1_synth_new_device,
110607 - snd_emu10k1_synth_delete_device,
110608 + .init_device = snd_emu10k1_synth_new_device,
110609 + .free_device = snd_emu10k1_synth_delete_device,
110610 };
110611 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
110612 sizeof(struct snd_emu10k1_synth_arg));
110613 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
110614 index e708368..764dffe 100644
110615 --- a/sound/pci/hda/hda_codec.c
110616 +++ b/sound/pci/hda/hda_codec.c
110617 @@ -968,14 +968,10 @@ find_codec_preset(struct hda_codec *codec)
110618 mutex_unlock(&preset_mutex);
110619
110620 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
110621 - char name[32];
110622 if (!mod_requested)
110623 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
110624 - codec->vendor_id);
110625 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
110626 else
110627 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
110628 - (codec->vendor_id >> 16) & 0xffff);
110629 - request_module(name);
110630 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
110631 mod_requested++;
110632 goto again;
110633 }
110634 @@ -2802,7 +2798,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
110635 /* FIXME: set_fs() hack for obtaining user-space TLV data */
110636 mm_segment_t fs = get_fs();
110637 set_fs(get_ds());
110638 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
110639 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
110640 tlv = _tlv;
110641 set_fs(fs);
110642 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
110643 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
110644 index 4631a23..001ae57 100644
110645 --- a/sound/pci/ymfpci/ymfpci.h
110646 +++ b/sound/pci/ymfpci/ymfpci.h
110647 @@ -358,7 +358,7 @@ struct snd_ymfpci {
110648 spinlock_t reg_lock;
110649 spinlock_t voice_lock;
110650 wait_queue_head_t interrupt_sleep;
110651 - atomic_t interrupt_sleep_count;
110652 + atomic_unchecked_t interrupt_sleep_count;
110653 struct snd_info_entry *proc_entry;
110654 const struct firmware *dsp_microcode;
110655 const struct firmware *controller_microcode;
110656 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
110657 index 81c916a..516f0bf 100644
110658 --- a/sound/pci/ymfpci/ymfpci_main.c
110659 +++ b/sound/pci/ymfpci/ymfpci_main.c
110660 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
110661 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
110662 break;
110663 }
110664 - if (atomic_read(&chip->interrupt_sleep_count)) {
110665 - atomic_set(&chip->interrupt_sleep_count, 0);
110666 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110667 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110668 wake_up(&chip->interrupt_sleep);
110669 }
110670 __end:
110671 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
110672 continue;
110673 init_waitqueue_entry(&wait, current);
110674 add_wait_queue(&chip->interrupt_sleep, &wait);
110675 - atomic_inc(&chip->interrupt_sleep_count);
110676 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
110677 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
110678 remove_wait_queue(&chip->interrupt_sleep, &wait);
110679 }
110680 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
110681 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
110682 spin_unlock(&chip->reg_lock);
110683
110684 - if (atomic_read(&chip->interrupt_sleep_count)) {
110685 - atomic_set(&chip->interrupt_sleep_count, 0);
110686 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
110687 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110688 wake_up(&chip->interrupt_sleep);
110689 }
110690 }
110691 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
110692 spin_lock_init(&chip->reg_lock);
110693 spin_lock_init(&chip->voice_lock);
110694 init_waitqueue_head(&chip->interrupt_sleep);
110695 - atomic_set(&chip->interrupt_sleep_count, 0);
110696 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
110697 chip->card = card;
110698 chip->pci = pci;
110699 chip->irq = -1;
110700 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
110701 index b60ff56..7307f0f 100644
110702 --- a/sound/soc/soc-core.c
110703 +++ b/sound/soc/soc-core.c
110704 @@ -2132,8 +2132,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
110705 if (ret)
110706 return ret;
110707
110708 - ops->warm_reset = snd_soc_ac97_warm_reset;
110709 - ops->reset = snd_soc_ac97_reset;
110710 + pax_open_kernel();
110711 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
110712 + *(void **)&ops->reset = snd_soc_ac97_reset;
110713 + pax_close_kernel();
110714
110715 snd_ac97_rst_cfg = cfg;
110716 return 0;
110717 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
110718 index 7778b8e..3d619fc 100644
110719 --- a/sound/synth/emux/emux_seq.c
110720 +++ b/sound/synth/emux/emux_seq.c
110721 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
110722 * MIDI emulation operators
110723 */
110724 static struct snd_midi_op emux_ops = {
110725 - snd_emux_note_on,
110726 - snd_emux_note_off,
110727 - snd_emux_key_press,
110728 - snd_emux_terminate_note,
110729 - snd_emux_control,
110730 - snd_emux_nrpn,
110731 - snd_emux_sysex,
110732 + .note_on = snd_emux_note_on,
110733 + .note_off = snd_emux_note_off,
110734 + .key_press = snd_emux_key_press,
110735 + .note_terminate = snd_emux_terminate_note,
110736 + .control = snd_emux_control,
110737 + .nrpn = snd_emux_nrpn,
110738 + .sysex = snd_emux_sysex,
110739 };
110740
110741
110742 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
110743 new file mode 100644
110744 index 0000000..de92ed9
110745 --- /dev/null
110746 +++ b/tools/gcc/.gitignore
110747 @@ -0,0 +1 @@
110748 +randomize_layout_seed.h
110749 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
110750 new file mode 100644
110751 index 0000000..7b8921f
110752 --- /dev/null
110753 +++ b/tools/gcc/Makefile
110754 @@ -0,0 +1,52 @@
110755 +#CC := gcc
110756 +#PLUGIN_SOURCE_FILES := pax_plugin.c
110757 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
110758 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
110759 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
110760 +
110761 +ifeq ($(PLUGINCC),$(HOSTCC))
110762 +HOSTLIBS := hostlibs
110763 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
110764 +export HOST_EXTRACFLAGS
110765 +else
110766 +HOSTLIBS := hostcxxlibs
110767 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
110768 +export HOST_EXTRACXXFLAGS
110769 +endif
110770 +
110771 +export GCCPLUGINS_DIR HOSTLIBS
110772 +
110773 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
110774 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
110775 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
110776 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
110777 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
110778 +$(HOSTLIBS)-y += colorize_plugin.so
110779 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
110780 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
110781 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
110782 +
110783 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
110784 +subdir- += size_overflow_plugin
110785 +
110786 +always := $($(HOSTLIBS)-y)
110787 +
110788 +constify_plugin-objs := constify_plugin.o
110789 +stackleak_plugin-objs := stackleak_plugin.o
110790 +kallocstat_plugin-objs := kallocstat_plugin.o
110791 +kernexec_plugin-objs := kernexec_plugin.o
110792 +checker_plugin-objs := checker_plugin.o
110793 +colorize_plugin-objs := colorize_plugin.o
110794 +latent_entropy_plugin-objs := latent_entropy_plugin.o
110795 +structleak_plugin-objs := structleak_plugin.o
110796 +randomize_layout_plugin-objs := randomize_layout_plugin.o
110797 +
110798 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
110799 +
110800 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
110801 + cmd_create_randomize_layout_seed = \
110802 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
110803 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
110804 + $(call if_changed,create_randomize_layout_seed)
110805 +
110806 +targets += randomize_layout_seed.h randomize_layout_hash.h
110807 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
110808 new file mode 100644
110809 index 0000000..5452feea
110810 --- /dev/null
110811 +++ b/tools/gcc/checker_plugin.c
110812 @@ -0,0 +1,150 @@
110813 +/*
110814 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
110815 + * Licensed under the GPL v2
110816 + *
110817 + * Note: the choice of the license means that the compilation process is
110818 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110819 + * but for the kernel it doesn't matter since it doesn't link against
110820 + * any of the gcc libraries
110821 + *
110822 + * gcc plugin to implement various sparse (source code checker) features
110823 + *
110824 + * TODO:
110825 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
110826 + *
110827 + * BUGS:
110828 + * - none known
110829 + */
110830 +
110831 +#include "gcc-common.h"
110832 +
110833 +extern void c_register_addr_space (const char *str, addr_space_t as);
110834 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
110835 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
110836 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
110837 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
110838 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
110839 +
110840 +int plugin_is_GPL_compatible;
110841 +
110842 +static struct plugin_info checker_plugin_info = {
110843 + .version = "201304082245",
110844 + .help = NULL,
110845 +};
110846 +
110847 +#define ADDR_SPACE_KERNEL 0
110848 +#define ADDR_SPACE_FORCE_KERNEL 1
110849 +#define ADDR_SPACE_USER 2
110850 +#define ADDR_SPACE_FORCE_USER 3
110851 +#define ADDR_SPACE_IOMEM 0
110852 +#define ADDR_SPACE_FORCE_IOMEM 0
110853 +#define ADDR_SPACE_PERCPU 0
110854 +#define ADDR_SPACE_FORCE_PERCPU 0
110855 +#define ADDR_SPACE_RCU 0
110856 +#define ADDR_SPACE_FORCE_RCU 0
110857 +
110858 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
110859 +{
110860 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
110861 +}
110862 +
110863 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
110864 +{
110865 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
110866 +}
110867 +
110868 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
110869 +{
110870 + return default_addr_space_valid_pointer_mode(mode, as);
110871 +}
110872 +
110873 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
110874 +{
110875 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
110876 +}
110877 +
110878 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
110879 +{
110880 + return default_addr_space_legitimize_address(x, oldx, mode, as);
110881 +}
110882 +
110883 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
110884 +{
110885 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
110886 + return true;
110887 +
110888 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
110889 + return true;
110890 +
110891 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
110892 + return true;
110893 +
110894 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
110895 + return true;
110896 +
110897 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
110898 + return true;
110899 +
110900 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
110901 + return true;
110902 +
110903 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
110904 + return true;
110905 +
110906 + return subset == superset;
110907 +}
110908 +
110909 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
110910 +{
110911 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
110912 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
110913 +
110914 + return op;
110915 +}
110916 +
110917 +static void register_checker_address_spaces(void *event_data, void *data)
110918 +{
110919 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
110920 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
110921 + c_register_addr_space("__user", ADDR_SPACE_USER);
110922 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
110923 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
110924 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
110925 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
110926 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
110927 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
110928 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
110929 +
110930 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
110931 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
110932 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
110933 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
110934 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
110935 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
110936 + targetm.addr_space.convert = checker_addr_space_convert;
110937 +}
110938 +
110939 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110940 +{
110941 + const char * const plugin_name = plugin_info->base_name;
110942 + const int argc = plugin_info->argc;
110943 + const struct plugin_argument * const argv = plugin_info->argv;
110944 + int i;
110945 +
110946 + if (!plugin_default_version_check(version, &gcc_version)) {
110947 + error(G_("incompatible gcc/plugin versions"));
110948 + return 1;
110949 + }
110950 +
110951 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
110952 +
110953 + for (i = 0; i < argc; ++i)
110954 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110955 +
110956 + if (TARGET_64BIT == 0)
110957 + return 0;
110958 +
110959 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
110960 +
110961 + return 0;
110962 +}
110963 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
110964 new file mode 100644
110965 index 0000000..54461af
110966 --- /dev/null
110967 +++ b/tools/gcc/colorize_plugin.c
110968 @@ -0,0 +1,210 @@
110969 +/*
110970 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
110971 + * Licensed under the GPL v2
110972 + *
110973 + * Note: the choice of the license means that the compilation process is
110974 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
110975 + * but for the kernel it doesn't matter since it doesn't link against
110976 + * any of the gcc libraries
110977 + *
110978 + * gcc plugin to colorize diagnostic output
110979 + *
110980 + */
110981 +
110982 +#include "gcc-common.h"
110983 +
110984 +int plugin_is_GPL_compatible;
110985 +
110986 +static struct plugin_info colorize_plugin_info = {
110987 + .version = "201404202350",
110988 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
110989 +};
110990 +
110991 +#define GREEN "\033[32m\033[K"
110992 +#define LIGHTGREEN "\033[1;32m\033[K"
110993 +#define YELLOW "\033[33m\033[K"
110994 +#define LIGHTYELLOW "\033[1;33m\033[K"
110995 +#define RED "\033[31m\033[K"
110996 +#define LIGHTRED "\033[1;31m\033[K"
110997 +#define BLUE "\033[34m\033[K"
110998 +#define LIGHTBLUE "\033[1;34m\033[K"
110999 +#define BRIGHT "\033[1;m\033[K"
111000 +#define NORMAL "\033[m\033[K"
111001 +
111002 +static diagnostic_starter_fn old_starter;
111003 +static diagnostic_finalizer_fn old_finalizer;
111004 +
111005 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
111006 +{
111007 + const char *color;
111008 + char *newprefix;
111009 +
111010 + switch (diagnostic->kind) {
111011 + case DK_NOTE:
111012 + color = LIGHTBLUE;
111013 + break;
111014 +
111015 + case DK_PEDWARN:
111016 + case DK_WARNING:
111017 + color = LIGHTYELLOW;
111018 + break;
111019 +
111020 + case DK_ERROR:
111021 + case DK_FATAL:
111022 + case DK_ICE:
111023 + case DK_PERMERROR:
111024 + case DK_SORRY:
111025 + color = LIGHTRED;
111026 + break;
111027 +
111028 + default:
111029 + color = NORMAL;
111030 + }
111031 +
111032 + old_starter(context, diagnostic);
111033 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
111034 + return;
111035 + pp_destroy_prefix(context->printer);
111036 + pp_set_prefix(context->printer, newprefix);
111037 +}
111038 +
111039 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
111040 +{
111041 + old_finalizer(context, diagnostic);
111042 +}
111043 +
111044 +static void colorize_arm(void)
111045 +{
111046 + old_starter = diagnostic_starter(global_dc);
111047 + old_finalizer = diagnostic_finalizer(global_dc);
111048 +
111049 + diagnostic_starter(global_dc) = start_colorize;
111050 + diagnostic_finalizer(global_dc) = finalize_colorize;
111051 +}
111052 +
111053 +static unsigned int execute_colorize_rearm(void)
111054 +{
111055 + if (diagnostic_starter(global_dc) == start_colorize)
111056 + return 0;
111057 +
111058 + colorize_arm();
111059 + return 0;
111060 +}
111061 +
111062 +#if BUILDING_GCC_VERSION >= 4009
111063 +static const struct pass_data colorize_rearm_pass_data = {
111064 +#else
111065 +struct simple_ipa_opt_pass colorize_rearm_pass = {
111066 + .pass = {
111067 +#endif
111068 + .type = SIMPLE_IPA_PASS,
111069 + .name = "colorize_rearm",
111070 +#if BUILDING_GCC_VERSION >= 4008
111071 + .optinfo_flags = OPTGROUP_NONE,
111072 +#endif
111073 +#if BUILDING_GCC_VERSION >= 4009
111074 + .has_gate = false,
111075 + .has_execute = true,
111076 +#else
111077 + .gate = NULL,
111078 + .execute = execute_colorize_rearm,
111079 + .sub = NULL,
111080 + .next = NULL,
111081 + .static_pass_number = 0,
111082 +#endif
111083 + .tv_id = TV_NONE,
111084 + .properties_required = 0,
111085 + .properties_provided = 0,
111086 + .properties_destroyed = 0,
111087 + .todo_flags_start = 0,
111088 + .todo_flags_finish = 0
111089 +#if BUILDING_GCC_VERSION < 4009
111090 + }
111091 +#endif
111092 +};
111093 +
111094 +#if BUILDING_GCC_VERSION >= 4009
111095 +namespace {
111096 +class colorize_rearm_pass : public simple_ipa_opt_pass {
111097 +public:
111098 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
111099 + unsigned int execute() { return execute_colorize_rearm(); }
111100 +};
111101 +}
111102 +
111103 +static opt_pass *make_colorize_rearm_pass(void)
111104 +{
111105 + return new colorize_rearm_pass();
111106 +}
111107 +#else
111108 +static struct opt_pass *make_colorize_rearm_pass(void)
111109 +{
111110 + return &colorize_rearm_pass.pass;
111111 +}
111112 +#endif
111113 +
111114 +static void colorize_start_unit(void *gcc_data, void *user_data)
111115 +{
111116 + colorize_arm();
111117 +}
111118 +
111119 +static bool should_colorize(void)
111120 +{
111121 +#if BUILDING_GCC_VERSION >= 4009
111122 + return false;
111123 +#else
111124 + char const *t = getenv("TERM");
111125 +
111126 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
111127 +#endif
111128 +}
111129 +
111130 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111131 +{
111132 + const char * const plugin_name = plugin_info->base_name;
111133 + const int argc = plugin_info->argc;
111134 + const struct plugin_argument * const argv = plugin_info->argv;
111135 + int i;
111136 + struct register_pass_info colorize_rearm_pass_info;
111137 + bool colorize;
111138 +
111139 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
111140 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
111141 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
111142 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
111143 +
111144 + if (!plugin_default_version_check(version, &gcc_version)) {
111145 + error(G_("incompatible gcc/plugin versions"));
111146 + return 1;
111147 + }
111148 +
111149 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
111150 +
111151 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
111152 +
111153 + for (i = 0; i < argc; ++i) {
111154 + if (!strcmp(argv[i].key, "color")) {
111155 + if (!argv[i].value) {
111156 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111157 + continue;
111158 + }
111159 + if (!strcmp(argv[i].value, "always"))
111160 + colorize = true;
111161 + else if (!strcmp(argv[i].value, "never"))
111162 + colorize = false;
111163 + else if (!strcmp(argv[i].value, "auto"))
111164 + colorize = should_colorize();
111165 + else
111166 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
111167 + continue;
111168 + }
111169 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111170 + }
111171 +
111172 + if (colorize) {
111173 + // TODO: parse GCC_COLORS as used by gcc 4.9+
111174 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
111175 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
111176 + }
111177 + return 0;
111178 +}
111179 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
111180 new file mode 100644
111181 index 0000000..3b5af59
111182 --- /dev/null
111183 +++ b/tools/gcc/constify_plugin.c
111184 @@ -0,0 +1,558 @@
111185 +/*
111186 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
111187 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
111188 + * Licensed under the GPL v2, or (at your option) v3
111189 + *
111190 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
111191 + *
111192 + * Homepage:
111193 + * http://www.grsecurity.net/~ephox/const_plugin/
111194 + *
111195 + * Usage:
111196 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
111197 + * $ gcc -fplugin=constify_plugin.so test.c -O2
111198 + */
111199 +
111200 +#include "gcc-common.h"
111201 +
111202 +// unused C type flag in all versions 4.5-4.9
111203 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
111204 +
111205 +int plugin_is_GPL_compatible;
111206 +
111207 +static struct plugin_info const_plugin_info = {
111208 + .version = "201401270210",
111209 + .help = "no-constify\tturn off constification\n",
111210 +};
111211 +
111212 +typedef struct {
111213 + bool has_fptr_field;
111214 + bool has_writable_field;
111215 + bool has_do_const_field;
111216 + bool has_no_const_field;
111217 +} constify_info;
111218 +
111219 +static const_tree get_field_type(const_tree field)
111220 +{
111221 + return strip_array_types(TREE_TYPE(field));
111222 +}
111223 +
111224 +static bool is_fptr(const_tree field)
111225 +{
111226 + const_tree ptr = get_field_type(field);
111227 +
111228 + if (TREE_CODE(ptr) != POINTER_TYPE)
111229 + return false;
111230 +
111231 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
111232 +}
111233 +
111234 +/*
111235 + * determine whether the given structure type meets the requirements for automatic constification,
111236 + * including the constification attributes on nested structure types
111237 + */
111238 +static void constifiable(const_tree node, constify_info *cinfo)
111239 +{
111240 + const_tree field;
111241 +
111242 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111243 +
111244 + // e.g., pointer to structure fields while still constructing the structure type
111245 + if (TYPE_FIELDS(node) == NULL_TREE)
111246 + return;
111247 +
111248 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
111249 + const_tree type = get_field_type(field);
111250 + enum tree_code code = TREE_CODE(type);
111251 +
111252 + if (node == type)
111253 + continue;
111254 +
111255 + if (is_fptr(field))
111256 + cinfo->has_fptr_field = true;
111257 + else if (!TREE_READONLY(field))
111258 + cinfo->has_writable_field = true;
111259 +
111260 + if (code == RECORD_TYPE || code == UNION_TYPE) {
111261 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111262 + cinfo->has_do_const_field = true;
111263 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
111264 + cinfo->has_no_const_field = true;
111265 + else
111266 + constifiable(type, cinfo);
111267 + }
111268 + }
111269 +}
111270 +
111271 +static bool constified(const_tree node)
111272 +{
111273 + constify_info cinfo = {
111274 + .has_fptr_field = false,
111275 + .has_writable_field = false,
111276 + .has_do_const_field = false,
111277 + .has_no_const_field = false
111278 + };
111279 +
111280 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
111281 +
111282 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
111283 +// gcc_assert(!TYPE_READONLY(node));
111284 + return false;
111285 + }
111286 +
111287 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
111288 + gcc_assert(TYPE_READONLY(node));
111289 + return true;
111290 + }
111291 +
111292 + constifiable(node, &cinfo);
111293 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
111294 + return false;
111295 +
111296 + return TYPE_READONLY(node);
111297 +}
111298 +
111299 +static void deconstify_tree(tree node);
111300 +
111301 +static void deconstify_type(tree type)
111302 +{
111303 + tree field;
111304 +
111305 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
111306 +
111307 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
111308 + const_tree fieldtype = get_field_type(field);
111309 +
111310 + // special case handling of simple ptr-to-same-array-type members
111311 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
111312 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
111313 +
111314 + if (TREE_TYPE(TREE_TYPE(field)) == type)
111315 + continue;
111316 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
111317 + continue;
111318 + if (!constified(ptrtype))
111319 + continue;
111320 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
111321 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
111322 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
111323 + }
111324 + continue;
111325 + }
111326 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
111327 + continue;
111328 + if (!constified(fieldtype))
111329 + continue;
111330 +
111331 + deconstify_tree(field);
111332 + TREE_READONLY(field) = 0;
111333 + }
111334 + TYPE_READONLY(type) = 0;
111335 + C_TYPE_FIELDS_READONLY(type) = 0;
111336 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111337 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111338 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
111339 + }
111340 +}
111341 +
111342 +static void deconstify_tree(tree node)
111343 +{
111344 + tree old_type, new_type, field;
111345 +
111346 + old_type = TREE_TYPE(node);
111347 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
111348 + node = TREE_TYPE(node) = copy_node(old_type);
111349 + old_type = TREE_TYPE(old_type);
111350 + }
111351 +
111352 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
111353 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
111354 +
111355 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
111356 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
111357 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
111358 + DECL_FIELD_CONTEXT(field) = new_type;
111359 +
111360 + deconstify_type(new_type);
111361 +
111362 + TREE_TYPE(node) = new_type;
111363 +}
111364 +
111365 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111366 +{
111367 + tree type;
111368 + constify_info cinfo = {
111369 + .has_fptr_field = false,
111370 + .has_writable_field = false,
111371 + .has_do_const_field = false,
111372 + .has_no_const_field = false
111373 + };
111374 +
111375 + *no_add_attrs = true;
111376 + if (TREE_CODE(*node) == FUNCTION_DECL) {
111377 + error("%qE attribute does not apply to functions (%qF)", name, *node);
111378 + return NULL_TREE;
111379 + }
111380 +
111381 + if (TREE_CODE(*node) == PARM_DECL) {
111382 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
111383 + return NULL_TREE;
111384 + }
111385 +
111386 + if (TREE_CODE(*node) == VAR_DECL) {
111387 + error("%qE attribute does not apply to variables (%qD)", name, *node);
111388 + return NULL_TREE;
111389 + }
111390 +
111391 + if (TYPE_P(*node)) {
111392 + type = *node;
111393 + } else {
111394 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
111395 + type = TREE_TYPE(*node);
111396 + }
111397 +
111398 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
111399 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
111400 + return NULL_TREE;
111401 + }
111402 +
111403 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
111404 + error("%qE attribute is already applied to the type %qT", name, type);
111405 + return NULL_TREE;
111406 + }
111407 +
111408 + if (TYPE_P(*node)) {
111409 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
111410 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
111411 + else
111412 + *no_add_attrs = false;
111413 + return NULL_TREE;
111414 + }
111415 +
111416 + constifiable(type, &cinfo);
111417 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111418 + deconstify_tree(*node);
111419 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
111420 + return NULL_TREE;
111421 + }
111422 +
111423 + error("%qE attribute used on type %qT that is not constified", name, type);
111424 + return NULL_TREE;
111425 +}
111426 +
111427 +static void constify_type(tree type)
111428 +{
111429 + TYPE_READONLY(type) = 1;
111430 + C_TYPE_FIELDS_READONLY(type) = 1;
111431 + TYPE_CONSTIFY_VISITED(type) = 1;
111432 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
111433 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
111434 +}
111435 +
111436 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
111437 +{
111438 + *no_add_attrs = true;
111439 + if (!TYPE_P(*node)) {
111440 + error("%qE attribute applies to types only (%qD)", name, *node);
111441 + return NULL_TREE;
111442 + }
111443 +
111444 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
111445 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
111446 + return NULL_TREE;
111447 + }
111448 +
111449 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
111450 + error("%qE attribute used on %qT is already applied to the type", name, *node);
111451 + return NULL_TREE;
111452 + }
111453 +
111454 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
111455 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
111456 + return NULL_TREE;
111457 + }
111458 +
111459 + *no_add_attrs = false;
111460 + return NULL_TREE;
111461 +}
111462 +
111463 +static struct attribute_spec no_const_attr = {
111464 + .name = "no_const",
111465 + .min_length = 0,
111466 + .max_length = 0,
111467 + .decl_required = false,
111468 + .type_required = false,
111469 + .function_type_required = false,
111470 + .handler = handle_no_const_attribute,
111471 +#if BUILDING_GCC_VERSION >= 4007
111472 + .affects_type_identity = true
111473 +#endif
111474 +};
111475 +
111476 +static struct attribute_spec do_const_attr = {
111477 + .name = "do_const",
111478 + .min_length = 0,
111479 + .max_length = 0,
111480 + .decl_required = false,
111481 + .type_required = false,
111482 + .function_type_required = false,
111483 + .handler = handle_do_const_attribute,
111484 +#if BUILDING_GCC_VERSION >= 4007
111485 + .affects_type_identity = true
111486 +#endif
111487 +};
111488 +
111489 +static void register_attributes(void *event_data, void *data)
111490 +{
111491 + register_attribute(&no_const_attr);
111492 + register_attribute(&do_const_attr);
111493 +}
111494 +
111495 +static void finish_type(void *event_data, void *data)
111496 +{
111497 + tree type = (tree)event_data;
111498 + constify_info cinfo = {
111499 + .has_fptr_field = false,
111500 + .has_writable_field = false,
111501 + .has_do_const_field = false,
111502 + .has_no_const_field = false
111503 + };
111504 +
111505 + if (type == NULL_TREE || type == error_mark_node)
111506 + return;
111507 +
111508 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
111509 + return;
111510 +
111511 + constifiable(type, &cinfo);
111512 +
111513 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
111514 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
111515 + deconstify_type(type);
111516 + TYPE_CONSTIFY_VISITED(type) = 1;
111517 + } else
111518 + error("'no_const' attribute used on type %qT that is not constified", type);
111519 + return;
111520 + }
111521 +
111522 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111523 + if (!cinfo.has_writable_field) {
111524 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
111525 + return;
111526 + }
111527 + constify_type(type);
111528 + return;
111529 + }
111530 +
111531 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
111532 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
111533 + error("'do_const' attribute used on type %qT that is constified", type);
111534 + return;
111535 + }
111536 + constify_type(type);
111537 + return;
111538 + }
111539 +
111540 + deconstify_type(type);
111541 + TYPE_CONSTIFY_VISITED(type) = 1;
111542 +}
111543 +
111544 +static void check_global_variables(void *event_data, void *data)
111545 +{
111546 +#if BUILDING_GCC_VERSION >= 4009
111547 + varpool_node *node;
111548 +#else
111549 + struct varpool_node *node;
111550 +#endif
111551 +
111552 + FOR_EACH_VARIABLE(node) {
111553 + tree var = NODE_DECL(node);
111554 + tree type = TREE_TYPE(var);
111555 +
111556 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111557 + continue;
111558 +
111559 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111560 + continue;
111561 +
111562 + if (!TYPE_CONSTIFY_VISITED(type))
111563 + continue;
111564 +
111565 + if (DECL_EXTERNAL(var))
111566 + continue;
111567 +
111568 + if (DECL_INITIAL(var))
111569 + continue;
111570 +
111571 + // this works around a gcc bug/feature where uninitialized globals
111572 + // are moved into the .bss section regardless of any constification
111573 + DECL_INITIAL(var) = build_constructor(type, NULL);
111574 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
111575 + }
111576 +}
111577 +
111578 +static unsigned int check_local_variables(void)
111579 +{
111580 + unsigned int ret = 0;
111581 + tree var;
111582 +
111583 + unsigned int i;
111584 +
111585 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
111586 + tree type = TREE_TYPE(var);
111587 +
111588 + gcc_assert(DECL_P(var));
111589 + if (is_global_var(var))
111590 + continue;
111591 +
111592 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
111593 + continue;
111594 +
111595 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
111596 + continue;
111597 +
111598 + if (!TYPE_CONSTIFY_VISITED(type))
111599 + continue;
111600 +
111601 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
111602 + ret = 1;
111603 + }
111604 + return ret;
111605 +}
111606 +
111607 +#if BUILDING_GCC_VERSION >= 4009
111608 +static const struct pass_data check_local_variables_pass_data = {
111609 +#else
111610 +static struct gimple_opt_pass check_local_variables_pass = {
111611 + .pass = {
111612 +#endif
111613 + .type = GIMPLE_PASS,
111614 + .name = "check_local_variables",
111615 +#if BUILDING_GCC_VERSION >= 4008
111616 + .optinfo_flags = OPTGROUP_NONE,
111617 +#endif
111618 +#if BUILDING_GCC_VERSION >= 5000
111619 +#elif BUILDING_GCC_VERSION >= 4009
111620 + .has_gate = false,
111621 + .has_execute = true,
111622 +#else
111623 + .gate = NULL,
111624 + .execute = check_local_variables,
111625 + .sub = NULL,
111626 + .next = NULL,
111627 + .static_pass_number = 0,
111628 +#endif
111629 + .tv_id = TV_NONE,
111630 + .properties_required = 0,
111631 + .properties_provided = 0,
111632 + .properties_destroyed = 0,
111633 + .todo_flags_start = 0,
111634 + .todo_flags_finish = 0
111635 +#if BUILDING_GCC_VERSION < 4009
111636 + }
111637 +#endif
111638 +};
111639 +
111640 +#if BUILDING_GCC_VERSION >= 4009
111641 +namespace {
111642 +class check_local_variables_pass : public gimple_opt_pass {
111643 +public:
111644 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
111645 + unsigned int execute() { return check_local_variables(); }
111646 +};
111647 +}
111648 +
111649 +static opt_pass *make_check_local_variables_pass(void)
111650 +{
111651 + return new check_local_variables_pass();
111652 +}
111653 +#else
111654 +static struct opt_pass *make_check_local_variables_pass(void)
111655 +{
111656 + return &check_local_variables_pass.pass;
111657 +}
111658 +#endif
111659 +
111660 +static struct {
111661 + const char *name;
111662 + const char *asm_op;
111663 +} sections[] = {
111664 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
111665 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
111666 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
111667 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
111668 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
111669 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
111670 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
111671 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
111672 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
111673 +};
111674 +
111675 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
111676 +
111677 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
111678 +{
111679 + size_t i;
111680 +
111681 + for (i = 0; i < ARRAY_SIZE(sections); i++)
111682 + if (!strcmp(sections[i].name, name))
111683 + return 0;
111684 + return old_section_type_flags(decl, name, reloc);
111685 +}
111686 +
111687 +static void constify_start_unit(void *gcc_data, void *user_data)
111688 +{
111689 +// size_t i;
111690 +
111691 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
111692 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
111693 +// sections[i].section = get_section(sections[i].name, 0, NULL);
111694 +
111695 + old_section_type_flags = targetm.section_type_flags;
111696 + targetm.section_type_flags = constify_section_type_flags;
111697 +}
111698 +
111699 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
111700 +{
111701 + const char * const plugin_name = plugin_info->base_name;
111702 + const int argc = plugin_info->argc;
111703 + const struct plugin_argument * const argv = plugin_info->argv;
111704 + int i;
111705 + bool constify = true;
111706 +
111707 + struct register_pass_info check_local_variables_pass_info;
111708 +
111709 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
111710 + check_local_variables_pass_info.reference_pass_name = "ssa";
111711 + check_local_variables_pass_info.ref_pass_instance_number = 1;
111712 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
111713 +
111714 + if (!plugin_default_version_check(version, &gcc_version)) {
111715 + error(G_("incompatible gcc/plugin versions"));
111716 + return 1;
111717 + }
111718 +
111719 + for (i = 0; i < argc; ++i) {
111720 + if (!(strcmp(argv[i].key, "no-constify"))) {
111721 + constify = false;
111722 + continue;
111723 + }
111724 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
111725 + }
111726 +
111727 + if (strncmp(lang_hooks.name, "GNU C", 5) && !strncmp(lang_hooks.name, "GNU C+", 6)) {
111728 + inform(UNKNOWN_LOCATION, G_("%s supports C only, not %s"), plugin_name, lang_hooks.name);
111729 + constify = false;
111730 + }
111731 +
111732 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
111733 + if (constify) {
111734 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
111735 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
111736 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
111737 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
111738 + }
111739 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
111740 +
111741 + return 0;
111742 +}
111743 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
111744 new file mode 100644
111745 index 0000000..e90c205
111746 --- /dev/null
111747 +++ b/tools/gcc/gcc-common.h
111748 @@ -0,0 +1,295 @@
111749 +#ifndef GCC_COMMON_H_INCLUDED
111750 +#define GCC_COMMON_H_INCLUDED
111751 +
111752 +#include "plugin.h"
111753 +#include "bversion.h"
111754 +#include "plugin-version.h"
111755 +#include "config.h"
111756 +#include "system.h"
111757 +#include "coretypes.h"
111758 +#include "tm.h"
111759 +#include "line-map.h"
111760 +#include "input.h"
111761 +#include "tree.h"
111762 +
111763 +#include "tree-inline.h"
111764 +#include "version.h"
111765 +#include "rtl.h"
111766 +#include "tm_p.h"
111767 +#include "flags.h"
111768 +//#include "insn-attr.h"
111769 +//#include "insn-config.h"
111770 +//#include "insn-flags.h"
111771 +#include "hard-reg-set.h"
111772 +//#include "recog.h"
111773 +#include "output.h"
111774 +#include "except.h"
111775 +#include "function.h"
111776 +#include "toplev.h"
111777 +//#include "expr.h"
111778 +#include "basic-block.h"
111779 +#include "intl.h"
111780 +#include "ggc.h"
111781 +//#include "regs.h"
111782 +#include "timevar.h"
111783 +
111784 +#include "params.h"
111785 +#include "pointer-set.h"
111786 +#include "emit-rtl.h"
111787 +//#include "reload.h"
111788 +//#include "ira.h"
111789 +//#include "dwarf2asm.h"
111790 +#include "debug.h"
111791 +#include "target.h"
111792 +#include "langhooks.h"
111793 +#include "cfgloop.h"
111794 +//#include "hosthooks.h"
111795 +#include "cgraph.h"
111796 +#include "opts.h"
111797 +//#include "coverage.h"
111798 +//#include "value-prof.h"
111799 +
111800 +#if BUILDING_GCC_VERSION >= 4007
111801 +#include "tree-pretty-print.h"
111802 +#include "gimple-pretty-print.h"
111803 +#include "c-tree.h"
111804 +//#include "alloc-pool.h"
111805 +#endif
111806 +
111807 +#if BUILDING_GCC_VERSION <= 4008
111808 +#include "tree-flow.h"
111809 +#else
111810 +#include "tree-cfgcleanup.h"
111811 +#endif
111812 +
111813 +#include "diagnostic.h"
111814 +//#include "tree-diagnostic.h"
111815 +#include "tree-dump.h"
111816 +#include "tree-pass.h"
111817 +//#include "df.h"
111818 +#include "predict.h"
111819 +#include "ipa-utils.h"
111820 +
111821 +#if BUILDING_GCC_VERSION >= 4009
111822 +#include "varasm.h"
111823 +#include "stor-layout.h"
111824 +#include "internal-fn.h"
111825 +#include "gimple-expr.h"
111826 +//#include "diagnostic-color.h"
111827 +#include "context.h"
111828 +#include "tree-ssa-alias.h"
111829 +#include "stringpool.h"
111830 +#include "tree-ssanames.h"
111831 +#include "print-tree.h"
111832 +#include "tree-eh.h"
111833 +#include "stmt.h"
111834 +#endif
111835 +
111836 +#include "gimple.h"
111837 +
111838 +#if BUILDING_GCC_VERSION >= 4009
111839 +#include "tree-ssa-operands.h"
111840 +#include "tree-phinodes.h"
111841 +#include "tree-cfg.h"
111842 +#include "gimple-iterator.h"
111843 +#include "gimple-ssa.h"
111844 +#include "ssa-iterators.h"
111845 +#endif
111846 +
111847 +//#include "lto/lto.h"
111848 +//#include "data-streamer.h"
111849 +//#include "lto-compress.h"
111850 +
111851 +//#include "expr.h" where are you...
111852 +extern rtx emit_move_insn(rtx x, rtx y);
111853 +
111854 +// missing from basic_block.h...
111855 +extern void debug_dominance_info(enum cdi_direction dir);
111856 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
111857 +
111858 +#define __unused __attribute__((__unused__))
111859 +
111860 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
111861 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
111862 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
111863 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
111864 +
111865 +#if BUILDING_GCC_VERSION == 4005
111866 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
111867 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
111868 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
111869 +#define TODO_rebuild_cgraph_edges 0
111870 +
111871 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
111872 +{
111873 + tree fndecl;
111874 +
111875 + if (!is_gimple_call(stmt))
111876 + return false;
111877 + fndecl = gimple_call_fndecl(stmt);
111878 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
111879 + return false;
111880 +// print_node(stderr, "pax", fndecl, 4);
111881 + return DECL_FUNCTION_CODE(fndecl) == code;
111882 +}
111883 +
111884 +static inline bool is_simple_builtin(tree decl)
111885 +{
111886 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
111887 + return false;
111888 +
111889 + switch (DECL_FUNCTION_CODE(decl)) {
111890 + /* Builtins that expand to constants. */
111891 + case BUILT_IN_CONSTANT_P:
111892 + case BUILT_IN_EXPECT:
111893 + case BUILT_IN_OBJECT_SIZE:
111894 + case BUILT_IN_UNREACHABLE:
111895 + /* Simple register moves or loads from stack. */
111896 + case BUILT_IN_RETURN_ADDRESS:
111897 + case BUILT_IN_EXTRACT_RETURN_ADDR:
111898 + case BUILT_IN_FROB_RETURN_ADDR:
111899 + case BUILT_IN_RETURN:
111900 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
111901 + case BUILT_IN_FRAME_ADDRESS:
111902 + case BUILT_IN_VA_END:
111903 + case BUILT_IN_STACK_SAVE:
111904 + case BUILT_IN_STACK_RESTORE:
111905 + /* Exception state returns or moves registers around. */
111906 + case BUILT_IN_EH_FILTER:
111907 + case BUILT_IN_EH_POINTER:
111908 + case BUILT_IN_EH_COPY_VALUES:
111909 + return true;
111910 +
111911 + default:
111912 + return false;
111913 + }
111914 +}
111915 +#endif
111916 +
111917 +#if BUILDING_GCC_VERSION <= 4006
111918 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
111919 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
111920 +
111921 +// should come from c-tree.h if only it were installed for gcc 4.5...
111922 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
111923 +
111924 +#define get_random_seed(noinit) ({ \
111925 + unsigned HOST_WIDE_INT seed; \
111926 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
111927 + seed * seed; })
111928 +
111929 +static inline bool gimple_clobber_p(gimple s)
111930 +{
111931 + return false;
111932 +}
111933 +
111934 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
111935 +{
111936 + return implicit_built_in_decls[fncode];
111937 +}
111938 +
111939 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
111940 +{
111941 + struct cgraph_node *node = cgraph_get_node(decl);
111942 +
111943 + return node ? node : cgraph_node(decl);
111944 +}
111945 +
111946 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
111947 +{
111948 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
111949 +}
111950 +
111951 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
111952 +{
111953 + struct cgraph_node *node;
111954 +
111955 + for (node = cgraph_nodes; node; node = node->next)
111956 + if (cgraph_function_with_gimple_body_p(node))
111957 + return node;
111958 + return NULL;
111959 +}
111960 +
111961 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
111962 +{
111963 + for (node = node->next; node; node = node->next)
111964 + if (cgraph_function_with_gimple_body_p(node))
111965 + return node;
111966 + return NULL;
111967 +}
111968 +
111969 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
111970 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
111971 + (node) = cgraph_next_function_with_gimple_body(node))
111972 +#endif
111973 +
111974 +#if BUILDING_GCC_VERSION == 4006
111975 +extern void debug_gimple_stmt(gimple);
111976 +extern void debug_gimple_seq(gimple_seq);
111977 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
111978 +extern void print_gimple_stmt(FILE *, gimple, int, int);
111979 +extern void print_gimple_expr(FILE *, gimple, int, int);
111980 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
111981 +#endif
111982 +
111983 +#if BUILDING_GCC_VERSION <= 4007
111984 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
111985 +#define PROP_loops 0
111986 +
111987 +static inline int bb_loop_depth(const_basic_block bb)
111988 +{
111989 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
111990 +}
111991 +
111992 +static inline bool gimple_store_p(gimple gs)
111993 +{
111994 + tree lhs = gimple_get_lhs(gs);
111995 + return lhs && !is_gimple_reg(lhs);
111996 +}
111997 +#endif
111998 +
111999 +#if BUILDING_GCC_VERSION >= 4007
112000 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
112001 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
112002 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
112003 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
112004 +#endif
112005 +
112006 +#if BUILDING_GCC_VERSION <= 4008
112007 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
112008 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
112009 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
112010 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
112011 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
112012 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
112013 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
112014 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
112015 +
112016 +static inline const char *get_tree_code_name(enum tree_code code)
112017 +{
112018 + gcc_assert(code < MAX_TREE_CODES);
112019 + return tree_code_name[code];
112020 +}
112021 +
112022 +#define ipa_remove_stmt_references(cnode, stmt)
112023 +#endif
112024 +
112025 +#if BUILDING_GCC_VERSION == 4008
112026 +#define NODE_DECL(node) node->symbol.decl
112027 +#else
112028 +#define NODE_DECL(node) node->decl
112029 +#endif
112030 +
112031 +#if BUILDING_GCC_VERSION >= 4008
112032 +#define add_referenced_var(var)
112033 +#define mark_sym_for_renaming(var)
112034 +#define varpool_mark_needed_node(node)
112035 +#define TODO_dump_func 0
112036 +#define TODO_dump_cgraph 0
112037 +#endif
112038 +
112039 +#if BUILDING_GCC_VERSION >= 4009
112040 +#define TODO_ggc_collect 0
112041 +#endif
112042 +
112043 +#endif
112044 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
112045 new file mode 100644
112046 index 0000000..7514850
112047 --- /dev/null
112048 +++ b/tools/gcc/gen-random-seed.sh
112049 @@ -0,0 +1,8 @@
112050 +#!/bin/sh
112051 +
112052 +if [ ! -f "$1" ]; then
112053 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
112054 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
112055 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
112056 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
112057 +fi
112058 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
112059 new file mode 100644
112060 index 0000000..d81c094
112061 --- /dev/null
112062 +++ b/tools/gcc/kallocstat_plugin.c
112063 @@ -0,0 +1,183 @@
112064 +/*
112065 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112066 + * Licensed under the GPL v2
112067 + *
112068 + * Note: the choice of the license means that the compilation process is
112069 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112070 + * but for the kernel it doesn't matter since it doesn't link against
112071 + * any of the gcc libraries
112072 + *
112073 + * gcc plugin to find the distribution of k*alloc sizes
112074 + *
112075 + * TODO:
112076 + *
112077 + * BUGS:
112078 + * - none known
112079 + */
112080 +
112081 +#include "gcc-common.h"
112082 +
112083 +int plugin_is_GPL_compatible;
112084 +
112085 +static struct plugin_info kallocstat_plugin_info = {
112086 + .version = "201401260140",
112087 + .help = NULL
112088 +};
112089 +
112090 +static const char * const kalloc_functions[] = {
112091 + "__kmalloc",
112092 + "kmalloc",
112093 + "kmalloc_large",
112094 + "kmalloc_node",
112095 + "kmalloc_order",
112096 + "kmalloc_order_trace",
112097 + "kmalloc_slab",
112098 + "kzalloc",
112099 + "kzalloc_node",
112100 +};
112101 +
112102 +static bool is_kalloc(const char *fnname)
112103 +{
112104 + size_t i;
112105 +
112106 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
112107 + if (!strcmp(fnname, kalloc_functions[i]))
112108 + return true;
112109 + return false;
112110 +}
112111 +
112112 +static unsigned int execute_kallocstat(void)
112113 +{
112114 + basic_block bb;
112115 +
112116 + // 1. loop through BBs and GIMPLE statements
112117 + FOR_EACH_BB_FN(bb, cfun) {
112118 + gimple_stmt_iterator gsi;
112119 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112120 + // gimple match:
112121 + tree fndecl, size;
112122 + gimple stmt;
112123 + const char *fnname;
112124 +
112125 + // is it a call
112126 + stmt = gsi_stmt(gsi);
112127 + if (!is_gimple_call(stmt))
112128 + continue;
112129 + fndecl = gimple_call_fndecl(stmt);
112130 + if (fndecl == NULL_TREE)
112131 + continue;
112132 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
112133 + continue;
112134 +
112135 + // is it a call to k*alloc
112136 + fnname = DECL_NAME_POINTER(fndecl);
112137 + if (!is_kalloc(fnname))
112138 + continue;
112139 +
112140 + // is the size arg const or the result of a simple const assignment
112141 + size = gimple_call_arg(stmt, 0);
112142 + while (true) {
112143 + expanded_location xloc;
112144 + size_t size_val;
112145 +
112146 + if (TREE_CONSTANT(size)) {
112147 + xloc = expand_location(gimple_location(stmt));
112148 + if (!xloc.file)
112149 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
112150 + size_val = TREE_INT_CST_LOW(size);
112151 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
112152 + break;
112153 + }
112154 +
112155 + if (TREE_CODE(size) != SSA_NAME)
112156 + break;
112157 + stmt = SSA_NAME_DEF_STMT(size);
112158 +//debug_gimple_stmt(stmt);
112159 +//debug_tree(size);
112160 + if (!stmt || !is_gimple_assign(stmt))
112161 + break;
112162 + if (gimple_num_ops(stmt) != 2)
112163 + break;
112164 + size = gimple_assign_rhs1(stmt);
112165 + }
112166 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112167 +//debug_tree(gimple_call_fn(call_stmt));
112168 +//print_node(stderr, "pax", fndecl, 4);
112169 + }
112170 + }
112171 +
112172 + return 0;
112173 +}
112174 +
112175 +#if BUILDING_GCC_VERSION >= 4009
112176 +static const struct pass_data kallocstat_pass_data = {
112177 +#else
112178 +static struct gimple_opt_pass kallocstat_pass = {
112179 + .pass = {
112180 +#endif
112181 + .type = GIMPLE_PASS,
112182 + .name = "kallocstat",
112183 +#if BUILDING_GCC_VERSION >= 4008
112184 + .optinfo_flags = OPTGROUP_NONE,
112185 +#endif
112186 +#if BUILDING_GCC_VERSION >= 4009
112187 + .has_gate = false,
112188 + .has_execute = true,
112189 +#else
112190 + .gate = NULL,
112191 + .execute = execute_kallocstat,
112192 + .sub = NULL,
112193 + .next = NULL,
112194 + .static_pass_number = 0,
112195 +#endif
112196 + .tv_id = TV_NONE,
112197 + .properties_required = 0,
112198 + .properties_provided = 0,
112199 + .properties_destroyed = 0,
112200 + .todo_flags_start = 0,
112201 + .todo_flags_finish = 0
112202 +#if BUILDING_GCC_VERSION < 4009
112203 + }
112204 +#endif
112205 +};
112206 +
112207 +#if BUILDING_GCC_VERSION >= 4009
112208 +namespace {
112209 +class kallocstat_pass : public gimple_opt_pass {
112210 +public:
112211 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
112212 + unsigned int execute() { return execute_kallocstat(); }
112213 +};
112214 +}
112215 +
112216 +static opt_pass *make_kallocstat_pass(void)
112217 +{
112218 + return new kallocstat_pass();
112219 +}
112220 +#else
112221 +static struct opt_pass *make_kallocstat_pass(void)
112222 +{
112223 + return &kallocstat_pass.pass;
112224 +}
112225 +#endif
112226 +
112227 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112228 +{
112229 + const char * const plugin_name = plugin_info->base_name;
112230 + struct register_pass_info kallocstat_pass_info;
112231 +
112232 + kallocstat_pass_info.pass = make_kallocstat_pass();
112233 + kallocstat_pass_info.reference_pass_name = "ssa";
112234 + kallocstat_pass_info.ref_pass_instance_number = 1;
112235 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112236 +
112237 + if (!plugin_default_version_check(version, &gcc_version)) {
112238 + error(G_("incompatible gcc/plugin versions"));
112239 + return 1;
112240 + }
112241 +
112242 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
112243 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
112244 +
112245 + return 0;
112246 +}
112247 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
112248 new file mode 100644
112249 index 0000000..89f256d
112250 --- /dev/null
112251 +++ b/tools/gcc/kernexec_plugin.c
112252 @@ -0,0 +1,522 @@
112253 +/*
112254 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
112255 + * Licensed under the GPL v2
112256 + *
112257 + * Note: the choice of the license means that the compilation process is
112258 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112259 + * but for the kernel it doesn't matter since it doesn't link against
112260 + * any of the gcc libraries
112261 + *
112262 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
112263 + *
112264 + * TODO:
112265 + *
112266 + * BUGS:
112267 + * - none known
112268 + */
112269 +
112270 +#include "gcc-common.h"
112271 +
112272 +int plugin_is_GPL_compatible;
112273 +
112274 +static struct plugin_info kernexec_plugin_info = {
112275 + .version = "201401260140",
112276 + .help = "method=[bts|or]\tinstrumentation method\n"
112277 +};
112278 +
112279 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
112280 +static void (*kernexec_instrument_retaddr)(rtx);
112281 +
112282 +/*
112283 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
112284 + */
112285 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
112286 +{
112287 + gimple asm_movabs_stmt;
112288 +
112289 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
112290 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
112291 + gimple_asm_set_volatile(asm_movabs_stmt, true);
112292 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
112293 + update_stmt(asm_movabs_stmt);
112294 +}
112295 +
112296 +/*
112297 + * find all asm() stmts that clobber r12 and add a reload of r12
112298 + */
112299 +static unsigned int execute_kernexec_reload(void)
112300 +{
112301 + basic_block bb;
112302 +
112303 + // 1. loop through BBs and GIMPLE statements
112304 + FOR_EACH_BB_FN(bb, cfun) {
112305 + gimple_stmt_iterator gsi;
112306 +
112307 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112308 + // gimple match: __asm__ ("" : : : "r12");
112309 + gimple asm_stmt;
112310 + size_t nclobbers;
112311 +
112312 + // is it an asm ...
112313 + asm_stmt = gsi_stmt(gsi);
112314 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
112315 + continue;
112316 +
112317 + // ... clobbering r12
112318 + nclobbers = gimple_asm_nclobbers(asm_stmt);
112319 + while (nclobbers--) {
112320 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
112321 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
112322 + continue;
112323 + kernexec_reload_fptr_mask(&gsi);
112324 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
112325 + break;
112326 + }
112327 + }
112328 + }
112329 +
112330 + return 0;
112331 +}
112332 +
112333 +/*
112334 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
112335 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
112336 + */
112337 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
112338 +{
112339 + gimple assign_intptr, assign_new_fptr, call_stmt;
112340 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
112341 +
112342 + call_stmt = gsi_stmt(*gsi);
112343 + old_fptr = gimple_call_fn(call_stmt);
112344 +
112345 + // create temporary unsigned long variable used for bitops and cast fptr to it
112346 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
112347 + add_referenced_var(intptr);
112348 + intptr = make_ssa_name(intptr, NULL);
112349 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
112350 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112351 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112352 + update_stmt(assign_intptr);
112353 +
112354 + // apply logical or to temporary unsigned long and bitmask
112355 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
112356 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
112357 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
112358 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
112359 + assign_intptr = gimple_build_assign(intptr, orptr);
112360 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
112361 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
112362 + update_stmt(assign_intptr);
112363 +
112364 + // cast temporary unsigned long back to a temporary fptr variable
112365 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
112366 + add_referenced_var(new_fptr);
112367 + new_fptr = make_ssa_name(new_fptr, NULL);
112368 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
112369 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
112370 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
112371 + update_stmt(assign_new_fptr);
112372 +
112373 + // replace call stmt fn with the new fptr
112374 + gimple_call_set_fn(call_stmt, new_fptr);
112375 + update_stmt(call_stmt);
112376 +}
112377 +
112378 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
112379 +{
112380 + gimple asm_or_stmt, call_stmt;
112381 + tree old_fptr, new_fptr, input, output;
112382 +#if BUILDING_GCC_VERSION <= 4007
112383 + VEC(tree, gc) *inputs = NULL;
112384 + VEC(tree, gc) *outputs = NULL;
112385 +#else
112386 + vec<tree, va_gc> *inputs = NULL;
112387 + vec<tree, va_gc> *outputs = NULL;
112388 +#endif
112389 +
112390 + call_stmt = gsi_stmt(*gsi);
112391 + old_fptr = gimple_call_fn(call_stmt);
112392 +
112393 + // create temporary fptr variable
112394 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
112395 + add_referenced_var(new_fptr);
112396 + new_fptr = make_ssa_name(new_fptr, NULL);
112397 +
112398 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
112399 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
112400 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
112401 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
112402 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
112403 +#if BUILDING_GCC_VERSION <= 4007
112404 + VEC_safe_push(tree, gc, inputs, input);
112405 + VEC_safe_push(tree, gc, outputs, output);
112406 +#else
112407 + vec_safe_push(inputs, input);
112408 + vec_safe_push(outputs, output);
112409 +#endif
112410 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
112411 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
112412 + gimple_asm_set_volatile(asm_or_stmt, true);
112413 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
112414 + update_stmt(asm_or_stmt);
112415 +
112416 + // replace call stmt fn with the new fptr
112417 + gimple_call_set_fn(call_stmt, new_fptr);
112418 + update_stmt(call_stmt);
112419 +}
112420 +
112421 +/*
112422 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
112423 + */
112424 +static unsigned int execute_kernexec_fptr(void)
112425 +{
112426 + basic_block bb;
112427 +
112428 + // 1. loop through BBs and GIMPLE statements
112429 + FOR_EACH_BB_FN(bb, cfun) {
112430 + gimple_stmt_iterator gsi;
112431 +
112432 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112433 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
112434 + tree fn;
112435 + gimple call_stmt;
112436 +
112437 + // is it a call ...
112438 + call_stmt = gsi_stmt(gsi);
112439 + if (!is_gimple_call(call_stmt))
112440 + continue;
112441 + fn = gimple_call_fn(call_stmt);
112442 + if (TREE_CODE(fn) == ADDR_EXPR)
112443 + continue;
112444 + if (TREE_CODE(fn) != SSA_NAME)
112445 + gcc_unreachable();
112446 +
112447 + // ... through a function pointer
112448 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
112449 + fn = SSA_NAME_VAR(fn);
112450 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
112451 + debug_tree(fn);
112452 + gcc_unreachable();
112453 + }
112454 + }
112455 + fn = TREE_TYPE(fn);
112456 + if (TREE_CODE(fn) != POINTER_TYPE)
112457 + continue;
112458 + fn = TREE_TYPE(fn);
112459 + if (TREE_CODE(fn) != FUNCTION_TYPE)
112460 + continue;
112461 +
112462 + kernexec_instrument_fptr(&gsi);
112463 +
112464 +//debug_tree(gimple_call_fn(call_stmt));
112465 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
112466 + }
112467 + }
112468 +
112469 + return 0;
112470 +}
112471 +
112472 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
112473 +static void kernexec_instrument_retaddr_bts(rtx insn)
112474 +{
112475 + rtx btsq;
112476 + rtvec argvec, constraintvec, labelvec;
112477 + int line;
112478 +
112479 + // create asm volatile("btsq $63,(%%rsp)":::)
112480 + argvec = rtvec_alloc(0);
112481 + constraintvec = rtvec_alloc(0);
112482 + labelvec = rtvec_alloc(0);
112483 + line = expand_location(RTL_LOCATION(insn)).line;
112484 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112485 + MEM_VOLATILE_P(btsq) = 1;
112486 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
112487 + emit_insn_before(btsq, insn);
112488 +}
112489 +
112490 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
112491 +static void kernexec_instrument_retaddr_or(rtx insn)
112492 +{
112493 + rtx orq;
112494 + rtvec argvec, constraintvec, labelvec;
112495 + int line;
112496 +
112497 + // create asm volatile("orq %%r12,(%%rsp)":::)
112498 + argvec = rtvec_alloc(0);
112499 + constraintvec = rtvec_alloc(0);
112500 + labelvec = rtvec_alloc(0);
112501 + line = expand_location(RTL_LOCATION(insn)).line;
112502 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
112503 + MEM_VOLATILE_P(orq) = 1;
112504 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
112505 + emit_insn_before(orq, insn);
112506 +}
112507 +
112508 +/*
112509 + * find all asm level function returns and forcibly set the highest bit of the return address
112510 + */
112511 +static unsigned int execute_kernexec_retaddr(void)
112512 +{
112513 + rtx insn;
112514 +
112515 +// if (stack_realign_drap)
112516 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
112517 +
112518 + // 1. find function returns
112519 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
112520 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
112521 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
112522 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
112523 + rtx body;
112524 +
112525 + // is it a retn
112526 + if (!JUMP_P(insn))
112527 + continue;
112528 + body = PATTERN(insn);
112529 + if (GET_CODE(body) == PARALLEL)
112530 + body = XVECEXP(body, 0, 0);
112531 + if (!ANY_RETURN_P(body))
112532 + continue;
112533 + kernexec_instrument_retaddr(insn);
112534 + }
112535 +
112536 +// print_simple_rtl(stderr, get_insns());
112537 +// print_rtl(stderr, get_insns());
112538 +
112539 + return 0;
112540 +}
112541 +
112542 +static bool kernexec_cmodel_check(void)
112543 +{
112544 + tree section;
112545 +
112546 + if (ix86_cmodel != CM_KERNEL)
112547 + return false;
112548 +
112549 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
112550 + if (!section || !TREE_VALUE(section))
112551 + return true;
112552 +
112553 + section = TREE_VALUE(TREE_VALUE(section));
112554 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
112555 + return true;
112556 +
112557 + return false;
112558 +}
112559 +
112560 +#if BUILDING_GCC_VERSION >= 4009
112561 +static const struct pass_data kernexec_reload_pass_data = {
112562 +#else
112563 +static struct gimple_opt_pass kernexec_reload_pass = {
112564 + .pass = {
112565 +#endif
112566 + .type = GIMPLE_PASS,
112567 + .name = "kernexec_reload",
112568 +#if BUILDING_GCC_VERSION >= 4008
112569 + .optinfo_flags = OPTGROUP_NONE,
112570 +#endif
112571 +#if BUILDING_GCC_VERSION >= 4009
112572 + .has_gate = true,
112573 + .has_execute = true,
112574 +#else
112575 + .gate = kernexec_cmodel_check,
112576 + .execute = execute_kernexec_reload,
112577 + .sub = NULL,
112578 + .next = NULL,
112579 + .static_pass_number = 0,
112580 +#endif
112581 + .tv_id = TV_NONE,
112582 + .properties_required = 0,
112583 + .properties_provided = 0,
112584 + .properties_destroyed = 0,
112585 + .todo_flags_start = 0,
112586 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112587 +#if BUILDING_GCC_VERSION < 4009
112588 + }
112589 +#endif
112590 +};
112591 +
112592 +#if BUILDING_GCC_VERSION >= 4009
112593 +static const struct pass_data kernexec_fptr_pass_data = {
112594 +#else
112595 +static struct gimple_opt_pass kernexec_fptr_pass = {
112596 + .pass = {
112597 +#endif
112598 + .type = GIMPLE_PASS,
112599 + .name = "kernexec_fptr",
112600 +#if BUILDING_GCC_VERSION >= 4008
112601 + .optinfo_flags = OPTGROUP_NONE,
112602 +#endif
112603 +#if BUILDING_GCC_VERSION >= 4009
112604 + .has_gate = true,
112605 + .has_execute = true,
112606 +#else
112607 + .gate = kernexec_cmodel_check,
112608 + .execute = execute_kernexec_fptr,
112609 + .sub = NULL,
112610 + .next = NULL,
112611 + .static_pass_number = 0,
112612 +#endif
112613 + .tv_id = TV_NONE,
112614 + .properties_required = 0,
112615 + .properties_provided = 0,
112616 + .properties_destroyed = 0,
112617 + .todo_flags_start = 0,
112618 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
112619 +#if BUILDING_GCC_VERSION < 4009
112620 + }
112621 +#endif
112622 +};
112623 +
112624 +#if BUILDING_GCC_VERSION >= 4009
112625 +static const struct pass_data kernexec_retaddr_pass_data = {
112626 +#else
112627 +static struct rtl_opt_pass kernexec_retaddr_pass = {
112628 + .pass = {
112629 +#endif
112630 + .type = RTL_PASS,
112631 + .name = "kernexec_retaddr",
112632 +#if BUILDING_GCC_VERSION >= 4008
112633 + .optinfo_flags = OPTGROUP_NONE,
112634 +#endif
112635 +#if BUILDING_GCC_VERSION >= 4009
112636 + .has_gate = true,
112637 + .has_execute = true,
112638 +#else
112639 + .gate = kernexec_cmodel_check,
112640 + .execute = execute_kernexec_retaddr,
112641 + .sub = NULL,
112642 + .next = NULL,
112643 + .static_pass_number = 0,
112644 +#endif
112645 + .tv_id = TV_NONE,
112646 + .properties_required = 0,
112647 + .properties_provided = 0,
112648 + .properties_destroyed = 0,
112649 + .todo_flags_start = 0,
112650 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
112651 +#if BUILDING_GCC_VERSION < 4009
112652 + }
112653 +#endif
112654 +};
112655 +
112656 +#if BUILDING_GCC_VERSION >= 4009
112657 +namespace {
112658 +class kernexec_reload_pass : public gimple_opt_pass {
112659 +public:
112660 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
112661 + bool gate() { return kernexec_cmodel_check(); }
112662 + unsigned int execute() { return execute_kernexec_reload(); }
112663 +};
112664 +
112665 +class kernexec_fptr_pass : public gimple_opt_pass {
112666 +public:
112667 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
112668 + bool gate() { return kernexec_cmodel_check(); }
112669 + unsigned int execute() { return execute_kernexec_fptr(); }
112670 +};
112671 +
112672 +class kernexec_retaddr_pass : public rtl_opt_pass {
112673 +public:
112674 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
112675 + bool gate() { return kernexec_cmodel_check(); }
112676 + unsigned int execute() { return execute_kernexec_retaddr(); }
112677 +};
112678 +}
112679 +
112680 +static opt_pass *make_kernexec_reload_pass(void)
112681 +{
112682 + return new kernexec_reload_pass();
112683 +}
112684 +
112685 +static opt_pass *make_kernexec_fptr_pass(void)
112686 +{
112687 + return new kernexec_fptr_pass();
112688 +}
112689 +
112690 +static opt_pass *make_kernexec_retaddr_pass(void)
112691 +{
112692 + return new kernexec_retaddr_pass();
112693 +}
112694 +#else
112695 +static struct opt_pass *make_kernexec_reload_pass(void)
112696 +{
112697 + return &kernexec_reload_pass.pass;
112698 +}
112699 +
112700 +static struct opt_pass *make_kernexec_fptr_pass(void)
112701 +{
112702 + return &kernexec_fptr_pass.pass;
112703 +}
112704 +
112705 +static struct opt_pass *make_kernexec_retaddr_pass(void)
112706 +{
112707 + return &kernexec_retaddr_pass.pass;
112708 +}
112709 +#endif
112710 +
112711 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
112712 +{
112713 + const char * const plugin_name = plugin_info->base_name;
112714 + const int argc = plugin_info->argc;
112715 + const struct plugin_argument * const argv = plugin_info->argv;
112716 + int i;
112717 + struct register_pass_info kernexec_reload_pass_info;
112718 + struct register_pass_info kernexec_fptr_pass_info;
112719 + struct register_pass_info kernexec_retaddr_pass_info;
112720 +
112721 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
112722 + kernexec_reload_pass_info.reference_pass_name = "ssa";
112723 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
112724 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112725 +
112726 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
112727 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
112728 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
112729 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112730 +
112731 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
112732 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
112733 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
112734 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
112735 +
112736 + if (!plugin_default_version_check(version, &gcc_version)) {
112737 + error(G_("incompatible gcc/plugin versions"));
112738 + return 1;
112739 + }
112740 +
112741 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
112742 +
112743 + if (TARGET_64BIT == 0)
112744 + return 0;
112745 +
112746 + for (i = 0; i < argc; ++i) {
112747 + if (!strcmp(argv[i].key, "method")) {
112748 + if (!argv[i].value) {
112749 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112750 + continue;
112751 + }
112752 + if (!strcmp(argv[i].value, "bts")) {
112753 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
112754 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
112755 + } else if (!strcmp(argv[i].value, "or")) {
112756 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
112757 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
112758 + fix_register("r12", 1, 1);
112759 + } else
112760 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
112761 + continue;
112762 + }
112763 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
112764 + }
112765 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
112766 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
112767 +
112768 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
112769 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
112770 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
112771 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
112772 +
112773 + return 0;
112774 +}
112775 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
112776 new file mode 100644
112777 index 0000000..e48b323
112778 --- /dev/null
112779 +++ b/tools/gcc/latent_entropy_plugin.c
112780 @@ -0,0 +1,466 @@
112781 +/*
112782 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
112783 + * Licensed under the GPL v2
112784 + *
112785 + * Note: the choice of the license means that the compilation process is
112786 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
112787 + * but for the kernel it doesn't matter since it doesn't link against
112788 + * any of the gcc libraries
112789 + *
112790 + * gcc plugin to help generate a little bit of entropy from program state,
112791 + * used throughout the uptime of the kernel
112792 + *
112793 + * TODO:
112794 + * - add ipa pass to identify not explicitly marked candidate functions
112795 + * - mix in more program state (function arguments/return values, loop variables, etc)
112796 + * - more instrumentation control via attribute parameters
112797 + *
112798 + * BUGS:
112799 + * - LTO needs -flto-partition=none for now
112800 + */
112801 +
112802 +#include "gcc-common.h"
112803 +
112804 +int plugin_is_GPL_compatible;
112805 +
112806 +static tree latent_entropy_decl;
112807 +
112808 +static struct plugin_info latent_entropy_plugin_info = {
112809 + .version = "201409101820",
112810 + .help = NULL
112811 +};
112812 +
112813 +static unsigned HOST_WIDE_INT seed;
112814 +static unsigned HOST_WIDE_INT get_random_const(void)
112815 +{
112816 + unsigned int i;
112817 + unsigned HOST_WIDE_INT ret = 0;
112818 +
112819 + for (i = 0; i < 8 * sizeof ret; i++) {
112820 + ret = (ret << 1) | (seed & 1);
112821 + seed >>= 1;
112822 + if (ret & 1)
112823 + seed ^= 0xD800000000000000ULL;
112824 + }
112825 +
112826 + return ret;
112827 +}
112828 +
112829 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
112830 +{
112831 + tree type;
112832 + unsigned long long mask;
112833 +#if BUILDING_GCC_VERSION <= 4007
112834 + VEC(constructor_elt, gc) *vals;
112835 +#else
112836 + vec<constructor_elt, va_gc> *vals;
112837 +#endif
112838 +
112839 + switch (TREE_CODE(*node)) {
112840 + default:
112841 + *no_add_attrs = true;
112842 + error("%qE attribute only applies to functions and variables", name);
112843 + break;
112844 +
112845 + case VAR_DECL:
112846 + if (DECL_INITIAL(*node)) {
112847 + *no_add_attrs = true;
112848 + error("variable %qD with %qE attribute must not be initialized", *node, name);
112849 + break;
112850 + }
112851 +
112852 + if (!TREE_STATIC(*node)) {
112853 + *no_add_attrs = true;
112854 + error("variable %qD with %qE attribute must not be local", *node, name);
112855 + break;
112856 + }
112857 +
112858 + type = TREE_TYPE(*node);
112859 + switch (TREE_CODE(type)) {
112860 + default:
112861 + *no_add_attrs = true;
112862 + 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);
112863 + break;
112864 +
112865 + case RECORD_TYPE: {
112866 + tree field;
112867 + unsigned int nelt = 0;
112868 +
112869 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
112870 + tree fieldtype;
112871 +
112872 + fieldtype = TREE_TYPE(field);
112873 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
112874 + *no_add_attrs = true;
112875 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
112876 + break;
112877 + }
112878 + }
112879 +
112880 + if (field)
112881 + break;
112882 +
112883 +#if BUILDING_GCC_VERSION <= 4007
112884 + vals = VEC_alloc(constructor_elt, gc, nelt);
112885 +#else
112886 + vec_alloc(vals, nelt);
112887 +#endif
112888 +
112889 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
112890 + tree fieldtype;
112891 +
112892 + fieldtype = TREE_TYPE(field);
112893 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
112894 + mask = 2 * (mask - 1) + 1;
112895 +
112896 + if (TYPE_UNSIGNED(fieldtype))
112897 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
112898 + else
112899 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
112900 + }
112901 +
112902 + DECL_INITIAL(*node) = build_constructor(type, vals);
112903 +//debug_tree(DECL_INITIAL(*node));
112904 + break;
112905 + }
112906 +
112907 + case INTEGER_TYPE:
112908 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
112909 + mask = 2 * (mask - 1) + 1;
112910 +
112911 + if (TYPE_UNSIGNED(type))
112912 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
112913 + else
112914 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
112915 + break;
112916 +
112917 + case ARRAY_TYPE: {
112918 + tree elt_type, array_size, elt_size;
112919 + unsigned int i, nelt;
112920 +
112921 + elt_type = TREE_TYPE(type);
112922 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
112923 + array_size = TYPE_SIZE_UNIT(type);
112924 +
112925 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
112926 + *no_add_attrs = true;
112927 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
112928 + break;
112929 + }
112930 +
112931 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
112932 +#if BUILDING_GCC_VERSION <= 4007
112933 + vals = VEC_alloc(constructor_elt, gc, nelt);
112934 +#else
112935 + vec_alloc(vals, nelt);
112936 +#endif
112937 +
112938 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
112939 + mask = 2 * (mask - 1) + 1;
112940 +
112941 + for (i = 0; i < nelt; i++)
112942 + if (TYPE_UNSIGNED(elt_type))
112943 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
112944 + else
112945 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
112946 +
112947 + DECL_INITIAL(*node) = build_constructor(type, vals);
112948 +//debug_tree(DECL_INITIAL(*node));
112949 + break;
112950 + }
112951 + }
112952 + break;
112953 +
112954 + case FUNCTION_DECL:
112955 + break;
112956 + }
112957 +
112958 + return NULL_TREE;
112959 +}
112960 +
112961 +static struct attribute_spec latent_entropy_attr = {
112962 + .name = "latent_entropy",
112963 + .min_length = 0,
112964 + .max_length = 0,
112965 + .decl_required = true,
112966 + .type_required = false,
112967 + .function_type_required = false,
112968 + .handler = handle_latent_entropy_attribute,
112969 +#if BUILDING_GCC_VERSION >= 4007
112970 + .affects_type_identity = false
112971 +#endif
112972 +};
112973 +
112974 +static void register_attributes(void *event_data, void *data)
112975 +{
112976 + register_attribute(&latent_entropy_attr);
112977 +}
112978 +
112979 +static bool gate_latent_entropy(void)
112980 +{
112981 + // don't bother with noreturn functions for now
112982 + if (TREE_THIS_VOLATILE(current_function_decl))
112983 + return false;
112984 +
112985 + // gcc-4.5 doesn't discover some trivial noreturn functions
112986 + if (EDGE_COUNT(EXIT_BLOCK_PTR_FOR_FN(cfun)->preds) == 0)
112987 + return false;
112988 +
112989 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
112990 +}
112991 +
112992 +static enum tree_code get_op(tree *rhs)
112993 +{
112994 + static enum tree_code op;
112995 + unsigned HOST_WIDE_INT random_const;
112996 +
112997 + random_const = get_random_const();
112998 +
112999 + switch (op) {
113000 + case BIT_XOR_EXPR:
113001 + op = PLUS_EXPR;
113002 + break;
113003 +
113004 + case PLUS_EXPR:
113005 + if (rhs) {
113006 + op = LROTATE_EXPR;
113007 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
113008 + break;
113009 + }
113010 +
113011 + case LROTATE_EXPR:
113012 + default:
113013 + op = BIT_XOR_EXPR;
113014 + break;
113015 + }
113016 + if (rhs)
113017 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
113018 + return op;
113019 +}
113020 +
113021 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
113022 +{
113023 + gimple_stmt_iterator gsi;
113024 + gimple assign;
113025 + tree addxorrol, rhs;
113026 + enum tree_code op;
113027 +
113028 + op = get_op(&rhs);
113029 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
113030 + assign = gimple_build_assign(local_entropy, addxorrol);
113031 + gsi = gsi_after_labels(bb);
113032 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113033 + update_stmt(assign);
113034 +//debug_bb(bb);
113035 +}
113036 +
113037 +static void perturb_latent_entropy(basic_block bb, tree rhs)
113038 +{
113039 + gimple_stmt_iterator gsi;
113040 + gimple assign;
113041 + tree addxorrol, temp;
113042 +
113043 + // 1. create temporary copy of latent_entropy
113044 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
113045 + add_referenced_var(temp);
113046 +
113047 + // 2. read...
113048 + temp = make_ssa_name(temp, NULL);
113049 + assign = gimple_build_assign(temp, latent_entropy_decl);
113050 + SSA_NAME_DEF_STMT(temp) = assign;
113051 + add_referenced_var(latent_entropy_decl);
113052 + gsi = gsi_after_labels(bb);
113053 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113054 + update_stmt(assign);
113055 +
113056 + // 3. ...modify...
113057 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
113058 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
113059 + assign = gimple_build_assign(temp, addxorrol);
113060 + SSA_NAME_DEF_STMT(temp) = assign;
113061 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113062 + update_stmt(assign);
113063 +
113064 + // 4. ...write latent_entropy
113065 + assign = gimple_build_assign(latent_entropy_decl, temp);
113066 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113067 + update_stmt(assign);
113068 +}
113069 +
113070 +static unsigned int execute_latent_entropy(void)
113071 +{
113072 + basic_block bb;
113073 + gimple assign;
113074 + gimple_stmt_iterator gsi;
113075 + tree local_entropy;
113076 +
113077 + if (!latent_entropy_decl) {
113078 +#if BUILDING_GCC_VERSION >= 4009
113079 + varpool_node *node;
113080 +#else
113081 + struct varpool_node *node;
113082 +#endif
113083 +
113084 + FOR_EACH_VARIABLE(node) {
113085 + tree var = NODE_DECL(node);
113086 +
113087 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
113088 + continue;
113089 + latent_entropy_decl = var;
113090 +// debug_tree(var);
113091 + break;
113092 + }
113093 + if (!latent_entropy_decl) {
113094 +// debug_tree(current_function_decl);
113095 + return 0;
113096 + }
113097 + }
113098 +
113099 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
113100 +
113101 + // 1. create local entropy variable
113102 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
113103 + add_referenced_var(local_entropy);
113104 + mark_sym_for_renaming(local_entropy);
113105 +
113106 + // 2. initialize local entropy variable
113107 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113108 + if (dom_info_available_p(CDI_DOMINATORS))
113109 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113110 + gsi = gsi_start_bb(bb);
113111 +
113112 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
113113 +// gimple_set_location(assign, loc);
113114 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
113115 + update_stmt(assign);
113116 +//debug_bb(bb);
113117 + gcc_assert(single_succ_p(bb));
113118 + bb = single_succ(bb);
113119 +
113120 + // 3. instrument each BB with an operation on the local entropy variable
113121 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
113122 + perturb_local_entropy(bb, local_entropy);
113123 +//debug_bb(bb);
113124 + bb = bb->next_bb;
113125 + };
113126 +
113127 + // 4. mix local entropy into the global entropy variable
113128 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113129 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
113130 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
113131 + return 0;
113132 +}
113133 +
113134 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
113135 +{
113136 + tree latent_entropy_type;
113137 +
113138 + seed = get_random_seed(false);
113139 +
113140 + if (in_lto_p)
113141 + return;
113142 +
113143 + // extern volatile u64 latent_entropy
113144 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
113145 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
113146 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
113147 +
113148 + TREE_STATIC(latent_entropy_decl) = 1;
113149 + TREE_PUBLIC(latent_entropy_decl) = 1;
113150 + TREE_USED(latent_entropy_decl) = 1;
113151 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
113152 + DECL_EXTERNAL(latent_entropy_decl) = 1;
113153 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
113154 + lang_hooks.decls.pushdecl(latent_entropy_decl);
113155 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
113156 +// varpool_finalize_decl(latent_entropy_decl);
113157 +// varpool_mark_needed_node(latent_entropy_decl);
113158 +}
113159 +
113160 +#if BUILDING_GCC_VERSION >= 4009
113161 +static const struct pass_data latent_entropy_pass_data = {
113162 +#else
113163 +static struct gimple_opt_pass latent_entropy_pass = {
113164 + .pass = {
113165 +#endif
113166 + .type = GIMPLE_PASS,
113167 + .name = "latent_entropy",
113168 +#if BUILDING_GCC_VERSION >= 4008
113169 + .optinfo_flags = OPTGROUP_NONE,
113170 +#endif
113171 +#if BUILDING_GCC_VERSION >= 4009
113172 + .has_gate = true,
113173 + .has_execute = true,
113174 +#else
113175 + .gate = gate_latent_entropy,
113176 + .execute = execute_latent_entropy,
113177 + .sub = NULL,
113178 + .next = NULL,
113179 + .static_pass_number = 0,
113180 +#endif
113181 + .tv_id = TV_NONE,
113182 + .properties_required = PROP_gimple_leh | PROP_cfg,
113183 + .properties_provided = 0,
113184 + .properties_destroyed = 0,
113185 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
113186 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
113187 +#if BUILDING_GCC_VERSION < 4009
113188 + }
113189 +#endif
113190 +};
113191 +
113192 +#if BUILDING_GCC_VERSION >= 4009
113193 +namespace {
113194 +class latent_entropy_pass : public gimple_opt_pass {
113195 +public:
113196 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
113197 + bool gate() { return gate_latent_entropy(); }
113198 + unsigned int execute() { return execute_latent_entropy(); }
113199 +};
113200 +}
113201 +
113202 +static opt_pass *make_latent_entropy_pass(void)
113203 +{
113204 + return new latent_entropy_pass();
113205 +}
113206 +#else
113207 +static struct opt_pass *make_latent_entropy_pass(void)
113208 +{
113209 + return &latent_entropy_pass.pass;
113210 +}
113211 +#endif
113212 +
113213 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
113214 +{
113215 + const char * const plugin_name = plugin_info->base_name;
113216 + struct register_pass_info latent_entropy_pass_info;
113217 +
113218 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
113219 + latent_entropy_pass_info.reference_pass_name = "optimized";
113220 + latent_entropy_pass_info.ref_pass_instance_number = 1;
113221 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
113222 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
113223 + {
113224 + .base = &latent_entropy_decl,
113225 + .nelt = 1,
113226 + .stride = sizeof(latent_entropy_decl),
113227 + .cb = &gt_ggc_mx_tree_node,
113228 + .pchw = &gt_pch_nx_tree_node
113229 + },
113230 + LAST_GGC_ROOT_TAB
113231 + };
113232 +
113233 + if (!plugin_default_version_check(version, &gcc_version)) {
113234 + error(G_("incompatible gcc/plugin versions"));
113235 + return 1;
113236 + }
113237 +
113238 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
113239 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
113240 + if (!in_lto_p)
113241 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
113242 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
113243 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
113244 +
113245 + return 0;
113246 +}
113247 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
113248 new file mode 100644
113249 index 0000000..a5cb46b
113250 --- /dev/null
113251 +++ b/tools/gcc/randomize_layout_plugin.c
113252 @@ -0,0 +1,915 @@
113253 +/*
113254 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
113255 + * and PaX Team <pageexec@freemail.hu>
113256 + * Licensed under the GPL v2
113257 + *
113258 + * Usage:
113259 + * $ # for 4.5/4.6/C based 4.7
113260 + * $ 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
113261 + * $ # for C++ based 4.7/4.8+
113262 + * $ 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
113263 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
113264 + */
113265 +
113266 +#include "gcc-common.h"
113267 +#include "randomize_layout_seed.h"
113268 +
113269 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
113270 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
113271 +#endif
113272 +
113273 +#define ORIG_TYPE_NAME(node) \
113274 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
113275 +
113276 +int plugin_is_GPL_compatible;
113277 +
113278 +static int performance_mode;
113279 +
113280 +static struct plugin_info randomize_layout_plugin_info = {
113281 + .version = "201402201816",
113282 + .help = "disable\t\t\tdo not activate plugin\n"
113283 + "performance-mode\tenable cacheline-aware layout randomization\n"
113284 +};
113285 +
113286 +/* from old Linux dcache.h */
113287 +static inline unsigned long
113288 +partial_name_hash(unsigned long c, unsigned long prevhash)
113289 +{
113290 + return (prevhash + (c << 4) + (c >> 4)) * 11;
113291 +}
113292 +static inline unsigned int
113293 +name_hash(const unsigned char *name)
113294 +{
113295 + unsigned long hash = 0;
113296 + unsigned int len = strlen((const char *)name);
113297 + while (len--)
113298 + hash = partial_name_hash(*name++, hash);
113299 + return (unsigned int)hash;
113300 +}
113301 +
113302 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113303 +{
113304 + tree type;
113305 +
113306 + *no_add_attrs = true;
113307 + if (TREE_CODE(*node) == FUNCTION_DECL) {
113308 + error("%qE attribute does not apply to functions (%qF)", name, *node);
113309 + return NULL_TREE;
113310 + }
113311 +
113312 + if (TREE_CODE(*node) == PARM_DECL) {
113313 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
113314 + return NULL_TREE;
113315 + }
113316 +
113317 + if (TREE_CODE(*node) == VAR_DECL) {
113318 + error("%qE attribute does not apply to variables (%qD)", name, *node);
113319 + return NULL_TREE;
113320 + }
113321 +
113322 + if (TYPE_P(*node)) {
113323 + type = *node;
113324 + } else {
113325 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
113326 + type = TREE_TYPE(*node);
113327 + }
113328 +
113329 + if (TREE_CODE(type) != RECORD_TYPE) {
113330 + error("%qE attribute used on %qT applies to struct types only", name, type);
113331 + return NULL_TREE;
113332 + }
113333 +
113334 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
113335 + error("%qE attribute is already applied to the type %qT", name, type);
113336 + return NULL_TREE;
113337 + }
113338 +
113339 + *no_add_attrs = false;
113340 +
113341 + return NULL_TREE;
113342 +}
113343 +
113344 +/* set on complete types that we don't need to inspect further at all */
113345 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113346 +{
113347 + *no_add_attrs = false;
113348 + return NULL_TREE;
113349 +}
113350 +
113351 +/*
113352 + * set on types that we've performed a shuffle on, to prevent re-shuffling
113353 + * this does not preclude us from inspecting its fields for potential shuffles
113354 + */
113355 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
113356 +{
113357 + *no_add_attrs = false;
113358 + return NULL_TREE;
113359 +}
113360 +
113361 +/*
113362 + * 64bit variant of Bob Jenkins' public domain PRNG
113363 + * 256 bits of internal state
113364 + */
113365 +
113366 +typedef unsigned long long u64;
113367 +
113368 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
113369 +
113370 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
113371 +static u64 ranval(ranctx *x) {
113372 + u64 e = x->a - rot(x->b, 7);
113373 + x->a = x->b ^ rot(x->c, 13);
113374 + x->b = x->c + rot(x->d, 37);
113375 + x->c = x->d + e;
113376 + x->d = e + x->a;
113377 + return x->d;
113378 +}
113379 +
113380 +static void raninit(ranctx *x, u64 *seed) {
113381 + int i;
113382 +
113383 + x->a = seed[0];
113384 + x->b = seed[1];
113385 + x->c = seed[2];
113386 + x->d = seed[3];
113387 +
113388 + for (i=0; i < 30; ++i)
113389 + (void)ranval(x);
113390 +}
113391 +
113392 +static u64 shuffle_seed[4];
113393 +
113394 +struct partition_group {
113395 + tree tree_start;
113396 + unsigned long start;
113397 + unsigned long length;
113398 +};
113399 +
113400 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
113401 +{
113402 + unsigned long i;
113403 + unsigned long accum_size = 0;
113404 + unsigned long accum_length = 0;
113405 + unsigned long group_idx = 0;
113406 +
113407 + gcc_assert(length < INT_MAX);
113408 +
113409 + memset(size_groups, 0, sizeof(struct partition_group) * length);
113410 +
113411 + for (i = 0; i < length; i++) {
113412 + if (size_groups[group_idx].tree_start == NULL_TREE) {
113413 + size_groups[group_idx].tree_start = fields[i];
113414 + size_groups[group_idx].start = i;
113415 + accum_length = 0;
113416 + accum_size = 0;
113417 + }
113418 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
113419 + accum_length++;
113420 + if (accum_size >= 64) {
113421 + size_groups[group_idx].length = accum_length;
113422 + accum_length = 0;
113423 + group_idx++;
113424 + }
113425 + }
113426 +
113427 + if (size_groups[group_idx].tree_start != NULL_TREE &&
113428 + !size_groups[group_idx].length) {
113429 + size_groups[group_idx].length = accum_length;
113430 + group_idx++;
113431 + }
113432 +
113433 + *num_groups = group_idx;
113434 +}
113435 +
113436 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113437 +{
113438 + unsigned long i, x;
113439 + struct partition_group size_group[length];
113440 + unsigned long num_groups = 0;
113441 + unsigned long randnum;
113442 +
113443 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
113444 + for (i = num_groups - 1; i > 0; i--) {
113445 + struct partition_group tmp;
113446 + randnum = ranval(prng_state) % (i + 1);
113447 + tmp = size_group[i];
113448 + size_group[i] = size_group[randnum];
113449 + size_group[randnum] = tmp;
113450 + }
113451 +
113452 + for (x = 0; x < num_groups; x++) {
113453 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
113454 + tree tmp;
113455 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
113456 + continue;
113457 + randnum = ranval(prng_state) % (i + 1);
113458 + // we could handle this case differently if desired
113459 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
113460 + continue;
113461 + tmp = newtree[i];
113462 + newtree[i] = newtree[randnum];
113463 + newtree[randnum] = tmp;
113464 + }
113465 + }
113466 +}
113467 +
113468 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
113469 +{
113470 + unsigned long i, randnum;
113471 +
113472 + for (i = length - 1; i > 0; i--) {
113473 + tree tmp;
113474 + randnum = ranval(prng_state) % (i + 1);
113475 + tmp = newtree[i];
113476 + newtree[i] = newtree[randnum];
113477 + newtree[randnum] = tmp;
113478 + }
113479 +}
113480 +
113481 +/* modern in-place Fisher-Yates shuffle */
113482 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
113483 +{
113484 + unsigned long i;
113485 + u64 seed[4];
113486 + ranctx prng_state;
113487 + const unsigned char *structname;
113488 +
113489 + if (length == 0)
113490 + return;
113491 +
113492 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113493 +
113494 + structname = ORIG_TYPE_NAME(type);
113495 +
113496 +#ifdef __DEBUG_PLUGIN
113497 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
113498 +#ifdef __DEBUG_VERBOSE
113499 + debug_tree((tree)type);
113500 +#endif
113501 +#endif
113502 +
113503 + for (i = 0; i < 4; i++) {
113504 + seed[i] = shuffle_seed[i];
113505 + seed[i] ^= name_hash(structname);
113506 + }
113507 +
113508 + raninit(&prng_state, (u64 *)&seed);
113509 +
113510 + if (performance_mode)
113511 + performance_shuffle(newtree, length, &prng_state);
113512 + else
113513 + full_shuffle(newtree, length, &prng_state);
113514 +}
113515 +
113516 +static bool is_flexible_array(const_tree field)
113517 +{
113518 + const_tree fieldtype;
113519 + const_tree typesize;
113520 + const_tree elemtype;
113521 + const_tree elemsize;
113522 +
113523 + fieldtype = TREE_TYPE(field);
113524 + typesize = TYPE_SIZE(fieldtype);
113525 +
113526 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
113527 + return false;
113528 +
113529 + elemtype = TREE_TYPE(fieldtype);
113530 + elemsize = TYPE_SIZE(elemtype);
113531 +
113532 + /* size of type is represented in bits */
113533 +
113534 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
113535 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
113536 + return true;
113537 +
113538 + if (typesize != NULL_TREE &&
113539 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
113540 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
113541 + return true;
113542 +
113543 + return false;
113544 +}
113545 +
113546 +static int relayout_struct(tree type)
113547 +{
113548 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
113549 + unsigned long shuffle_length = num_fields;
113550 + tree field;
113551 + tree newtree[num_fields];
113552 + unsigned long i;
113553 + tree list;
113554 + tree variant;
113555 + expanded_location xloc;
113556 +
113557 + if (TYPE_FIELDS(type) == NULL_TREE)
113558 + return 0;
113559 +
113560 + if (num_fields < 2)
113561 + return 0;
113562 +
113563 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113564 +
113565 + gcc_assert(num_fields < INT_MAX);
113566 +
113567 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
113568 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
113569 + return 0;
113570 +
113571 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
113572 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
113573 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
113574 + return 0;
113575 +
113576 + /* throw out any structs in uapi */
113577 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
113578 +
113579 + if (strstr(xloc.file, "/uapi/"))
113580 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
113581 +
113582 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
113583 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113584 + newtree[i] = field;
113585 + }
113586 +
113587 + /*
113588 + * enforce that we don't randomize the layout of the last
113589 + * element of a struct if it's a 0 or 1-length array
113590 + * or a proper flexible array
113591 + */
113592 + if (is_flexible_array(newtree[num_fields - 1]))
113593 + shuffle_length--;
113594 +
113595 + shuffle(type, (tree *)newtree, shuffle_length);
113596 +
113597 + /*
113598 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
113599 + * as gcc provides no other way to detect such code
113600 + */
113601 + list = make_node(FIELD_DECL);
113602 + TREE_CHAIN(list) = newtree[0];
113603 + TREE_TYPE(list) = void_type_node;
113604 + DECL_SIZE(list) = bitsize_zero_node;
113605 + DECL_NONADDRESSABLE_P(list) = 1;
113606 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
113607 + DECL_SIZE_UNIT(list) = size_zero_node;
113608 + DECL_FIELD_OFFSET(list) = size_zero_node;
113609 + // to satisfy the constify plugin
113610 + TREE_READONLY(list) = 1;
113611 +
113612 + for (i = 0; i < num_fields - 1; i++)
113613 + TREE_CHAIN(newtree[i]) = newtree[i+1];
113614 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
113615 +
113616 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113617 + TYPE_FIELDS(variant) = list;
113618 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
113619 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
113620 + // force a re-layout
113621 + TYPE_SIZE(variant) = NULL_TREE;
113622 + layout_type(variant);
113623 + }
113624 +
113625 + return 1;
113626 +}
113627 +
113628 +/* from constify plugin */
113629 +static const_tree get_field_type(const_tree field)
113630 +{
113631 + return strip_array_types(TREE_TYPE(field));
113632 +}
113633 +
113634 +/* from constify plugin */
113635 +static bool is_fptr(const_tree fieldtype)
113636 +{
113637 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
113638 + return false;
113639 +
113640 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
113641 +}
113642 +
113643 +/* derived from constify plugin */
113644 +static int is_pure_ops_struct(const_tree node)
113645 +{
113646 + const_tree field;
113647 +
113648 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
113649 +
113650 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
113651 + const_tree fieldtype = get_field_type(field);
113652 + enum tree_code code = TREE_CODE(fieldtype);
113653 +
113654 + if (node == fieldtype)
113655 + continue;
113656 +
113657 + if (!is_fptr(fieldtype))
113658 + return 0;
113659 +
113660 + if (code != RECORD_TYPE && code != UNION_TYPE)
113661 + continue;
113662 +
113663 + if (!is_pure_ops_struct(fieldtype))
113664 + return 0;
113665 + }
113666 +
113667 + return 1;
113668 +}
113669 +
113670 +static void randomize_type(tree type)
113671 +{
113672 + tree variant;
113673 +
113674 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
113675 +
113676 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113677 + return;
113678 +
113679 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
113680 + relayout_struct(type);
113681 +
113682 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
113683 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
113684 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
113685 + }
113686 +#ifdef __DEBUG_PLUGIN
113687 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
113688 +#ifdef __DEBUG_VERBOSE
113689 + debug_tree(type);
113690 +#endif
113691 +#endif
113692 +}
113693 +
113694 +static void randomize_layout_finish_decl(void *event_data, void *data)
113695 +{
113696 + tree decl = (tree)event_data;
113697 + tree type;
113698 +
113699 + if (decl == NULL_TREE || decl == error_mark_node)
113700 + return;
113701 +
113702 + type = TREE_TYPE(decl);
113703 +
113704 + if (TREE_CODE(decl) != VAR_DECL)
113705 + return;
113706 +
113707 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
113708 + return;
113709 +
113710 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
113711 + return;
113712 +
113713 + relayout_decl(decl);
113714 +}
113715 +
113716 +static void finish_type(void *event_data, void *data)
113717 +{
113718 + tree type = (tree)event_data;
113719 +
113720 + if (type == NULL_TREE || type == error_mark_node)
113721 + return;
113722 +
113723 + if (TREE_CODE(type) != RECORD_TYPE)
113724 + return;
113725 +
113726 + if (TYPE_FIELDS(type) == NULL_TREE)
113727 + return;
113728 +
113729 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
113730 + return;
113731 +
113732 +#ifdef __DEBUG_PLUGIN
113733 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
113734 +#endif
113735 +#ifdef __DEBUG_VERBOSE
113736 + debug_tree(type);
113737 +#endif
113738 + randomize_type(type);
113739 +
113740 + return;
113741 +}
113742 +
113743 +static struct attribute_spec randomize_layout_attr = {
113744 + .name = "randomize_layout",
113745 + // related to args
113746 + .min_length = 0,
113747 + .max_length = 0,
113748 + .decl_required = false,
113749 + // need type declaration
113750 + .type_required = true,
113751 + .function_type_required = false,
113752 + .handler = handle_randomize_layout_attr,
113753 +#if BUILDING_GCC_VERSION >= 4007
113754 + .affects_type_identity = true
113755 +#endif
113756 +};
113757 +
113758 +static struct attribute_spec no_randomize_layout_attr = {
113759 + .name = "no_randomize_layout",
113760 + // related to args
113761 + .min_length = 0,
113762 + .max_length = 0,
113763 + .decl_required = false,
113764 + // need type declaration
113765 + .type_required = true,
113766 + .function_type_required = false,
113767 + .handler = handle_randomize_layout_attr,
113768 +#if BUILDING_GCC_VERSION >= 4007
113769 + .affects_type_identity = true
113770 +#endif
113771 +};
113772 +
113773 +static struct attribute_spec randomize_considered_attr = {
113774 + .name = "randomize_considered",
113775 + // related to args
113776 + .min_length = 0,
113777 + .max_length = 0,
113778 + .decl_required = false,
113779 + // need type declaration
113780 + .type_required = true,
113781 + .function_type_required = false,
113782 + .handler = handle_randomize_considered_attr,
113783 +#if BUILDING_GCC_VERSION >= 4007
113784 + .affects_type_identity = false
113785 +#endif
113786 +};
113787 +
113788 +static struct attribute_spec randomize_performed_attr = {
113789 + .name = "randomize_performed",
113790 + // related to args
113791 + .min_length = 0,
113792 + .max_length = 0,
113793 + .decl_required = false,
113794 + // need type declaration
113795 + .type_required = true,
113796 + .function_type_required = false,
113797 + .handler = handle_randomize_performed_attr,
113798 +#if BUILDING_GCC_VERSION >= 4007
113799 + .affects_type_identity = false
113800 +#endif
113801 +};
113802 +
113803 +static void register_attributes(void *event_data, void *data)
113804 +{
113805 + register_attribute(&randomize_layout_attr);
113806 + register_attribute(&no_randomize_layout_attr);
113807 + register_attribute(&randomize_considered_attr);
113808 + register_attribute(&randomize_performed_attr);
113809 +}
113810 +
113811 +static void check_bad_casts_in_constructor(tree var, tree init)
113812 +{
113813 + unsigned HOST_WIDE_INT idx;
113814 + tree field, val;
113815 + tree field_type, val_type;
113816 +
113817 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
113818 + if (TREE_CODE(val) == CONSTRUCTOR) {
113819 + check_bad_casts_in_constructor(var, val);
113820 + continue;
113821 + }
113822 +
113823 + /* pipacs' plugin creates franken-arrays that differ from those produced by
113824 + normal code which all have valid 'field' trees. work around this */
113825 + if (field == NULL_TREE)
113826 + continue;
113827 + field_type = TREE_TYPE(field);
113828 + val_type = TREE_TYPE(val);
113829 +
113830 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
113831 + continue;
113832 +
113833 + if (field_type == val_type)
113834 + continue;
113835 +
113836 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
113837 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
113838 +
113839 + if (field_type == void_type_node)
113840 + continue;
113841 + if (field_type == val_type)
113842 + continue;
113843 + if (TREE_CODE(val_type) != RECORD_TYPE)
113844 + continue;
113845 +
113846 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
113847 + continue;
113848 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
113849 + }
113850 +}
113851 +
113852 +/* derived from the constify plugin */
113853 +static void check_global_variables(void *event_data, void *data)
113854 +{
113855 + struct varpool_node *node;
113856 + tree init;
113857 +
113858 + FOR_EACH_VARIABLE(node) {
113859 + tree var = NODE_DECL(node);
113860 + init = DECL_INITIAL(var);
113861 + if (init == NULL_TREE)
113862 + continue;
113863 +
113864 + if (TREE_CODE(init) != CONSTRUCTOR)
113865 + continue;
113866 +
113867 + check_bad_casts_in_constructor(var, init);
113868 + }
113869 +}
113870 +
113871 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
113872 +{
113873 + basic_block dom;
113874 + gimple dom_stmt;
113875 + gimple call_stmt;
113876 + const_tree dom_lhs;
113877 + const_tree poss_is_err_cond;
113878 + const_tree poss_is_err_func;
113879 + const_tree is_err_arg;
113880 +
113881 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
113882 + if (!dom)
113883 + return false;
113884 +
113885 + dom_stmt = last_stmt(dom);
113886 + if (!dom_stmt)
113887 + return false;
113888 +
113889 + if (gimple_code(dom_stmt) != GIMPLE_COND)
113890 + return false;
113891 +
113892 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
113893 + return false;
113894 +
113895 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
113896 + return false;
113897 +
113898 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
113899 +
113900 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
113901 + return false;
113902 +
113903 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
113904 +
113905 + if (gimple_code(call_stmt) != GIMPLE_CALL)
113906 + return false;
113907 +
113908 + dom_lhs = gimple_get_lhs(call_stmt);
113909 + poss_is_err_func = gimple_call_fndecl(call_stmt);
113910 + if (!poss_is_err_func)
113911 + return false;
113912 + if (dom_lhs != poss_is_err_cond)
113913 + return false;
113914 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
113915 + return false;
113916 +
113917 + is_err_arg = gimple_call_arg(call_stmt, 0);
113918 + if (!is_err_arg)
113919 + return false;
113920 +
113921 + if (is_err_arg != rhs)
113922 + return false;
113923 +
113924 + return true;
113925 +}
113926 +
113927 +static void handle_local_var_initializers(void)
113928 +{
113929 + tree var;
113930 + unsigned int i;
113931 +
113932 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
113933 + tree init = DECL_INITIAL(var);
113934 + if (!init)
113935 + continue;
113936 + if (TREE_CODE(init) != CONSTRUCTOR)
113937 + continue;
113938 + check_bad_casts_in_constructor(var, init);
113939 + }
113940 +}
113941 +
113942 +/*
113943 + * iterate over all statements to find "bad" casts:
113944 + * those where the address of the start of a structure is cast
113945 + * to a pointer of a structure of a different type, or a
113946 + * structure pointer type is cast to a different structure pointer type
113947 + */
113948 +static unsigned int find_bad_casts(void)
113949 +{
113950 + basic_block bb;
113951 +
113952 + handle_local_var_initializers();
113953 +
113954 + FOR_ALL_BB_FN(bb, cfun) {
113955 + gimple_stmt_iterator gsi;
113956 +
113957 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113958 + gimple stmt;
113959 + const_tree lhs;
113960 + const_tree lhs_type;
113961 + const_tree rhs1;
113962 + const_tree rhs_type;
113963 + const_tree ptr_lhs_type;
113964 + const_tree ptr_rhs_type;
113965 + const_tree op0;
113966 + const_tree op0_type;
113967 + enum tree_code rhs_code;
113968 +
113969 + stmt = gsi_stmt(gsi);
113970 +
113971 +#ifdef __DEBUG_PLUGIN
113972 +#ifdef __DEBUG_VERBOSE
113973 + debug_gimple_stmt(stmt);
113974 + debug_tree(gimple_get_lhs(stmt));
113975 +#endif
113976 +#endif
113977 +
113978 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
113979 + continue;
113980 +
113981 +#ifdef __DEBUG_PLUGIN
113982 +#ifdef __DEBUG_VERBOSE
113983 + debug_tree(gimple_assign_rhs1(stmt));
113984 +#endif
113985 +#endif
113986 +
113987 + rhs_code = gimple_assign_rhs_code(stmt);
113988 +
113989 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
113990 + continue;
113991 +
113992 + lhs = gimple_get_lhs(stmt);
113993 + lhs_type = TREE_TYPE(lhs);
113994 + rhs1 = gimple_assign_rhs1(stmt);
113995 + rhs_type = TREE_TYPE(rhs1);
113996 +
113997 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
113998 + TREE_CODE(lhs_type) != POINTER_TYPE)
113999 + continue;
114000 +
114001 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
114002 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
114003 +
114004 + if (ptr_rhs_type == void_type_node)
114005 + continue;
114006 +
114007 + if (ptr_lhs_type == void_type_node)
114008 + continue;
114009 +
114010 + if (dominated_by_is_err(rhs1, bb))
114011 + continue;
114012 +
114013 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
114014 +#ifndef __DEBUG_PLUGIN
114015 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
114016 +#endif
114017 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
114018 + continue;
114019 + }
114020 +
114021 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
114022 + continue;
114023 +
114024 + if (rhs_code == ADDR_EXPR) {
114025 + op0 = TREE_OPERAND(rhs1, 0);
114026 +
114027 + if (op0 == NULL_TREE)
114028 + continue;
114029 +
114030 + if (TREE_CODE(op0) != VAR_DECL)
114031 + continue;
114032 +
114033 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
114034 + if (op0_type == ptr_lhs_type)
114035 + continue;
114036 +
114037 +#ifndef __DEBUG_PLUGIN
114038 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
114039 +#endif
114040 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
114041 + } else {
114042 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
114043 + /* skip bogus type casts introduced by container_of */
114044 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
114045 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
114046 + continue;
114047 +#ifndef __DEBUG_PLUGIN
114048 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
114049 +#endif
114050 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
114051 + }
114052 +
114053 + }
114054 + }
114055 + return 0;
114056 +}
114057 +
114058 +#if BUILDING_GCC_VERSION >= 4009
114059 +static const struct pass_data randomize_layout_bad_cast_data = {
114060 +#else
114061 +static struct gimple_opt_pass randomize_layout_bad_cast = {
114062 + .pass = {
114063 +#endif
114064 + .type = GIMPLE_PASS,
114065 + .name = "randomize_layout_bad_cast",
114066 +#if BUILDING_GCC_VERSION >= 4008
114067 + .optinfo_flags = OPTGROUP_NONE,
114068 +#endif
114069 +#if BUILDING_GCC_VERSION >= 4009
114070 + .has_gate = false,
114071 + .has_execute = true,
114072 +#else
114073 + .gate = NULL,
114074 + .execute = find_bad_casts,
114075 + .sub = NULL,
114076 + .next = NULL,
114077 + .static_pass_number = 0,
114078 +#endif
114079 + .tv_id = TV_NONE,
114080 + .properties_required = PROP_cfg,
114081 + .properties_provided = 0,
114082 + .properties_destroyed = 0,
114083 + .todo_flags_start = 0,
114084 + .todo_flags_finish = TODO_dump_func
114085 +#if BUILDING_GCC_VERSION < 4009
114086 + }
114087 +#endif
114088 +};
114089 +
114090 +#if BUILDING_GCC_VERSION >= 4009
114091 +namespace {
114092 +class randomize_layout_bad_cast : public gimple_opt_pass {
114093 +public:
114094 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
114095 + unsigned int execute() { return find_bad_casts(); }
114096 +};
114097 +}
114098 +#endif
114099 +
114100 +static struct opt_pass *make_randomize_layout_bad_cast(void)
114101 +{
114102 +#if BUILDING_GCC_VERSION >= 4009
114103 + return new randomize_layout_bad_cast();
114104 +#else
114105 + return &randomize_layout_bad_cast.pass;
114106 +#endif
114107 +}
114108 +
114109 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
114110 +{
114111 + int i;
114112 + const char * const plugin_name = plugin_info->base_name;
114113 + const int argc = plugin_info->argc;
114114 + const struct plugin_argument * const argv = plugin_info->argv;
114115 + bool enable = true;
114116 + int obtained_seed = 0;
114117 + struct register_pass_info randomize_layout_bad_cast_info;
114118 +
114119 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
114120 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
114121 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
114122 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
114123 +
114124 + if (!plugin_default_version_check(version, &gcc_version)) {
114125 + error(G_("incompatible gcc/plugin versions"));
114126 + return 1;
114127 + }
114128 +
114129 + if (strcmp(lang_hooks.name, "GNU C")) {
114130 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
114131 + enable = false;
114132 + }
114133 +
114134 + for (i = 0; i < argc; ++i) {
114135 + if (!strcmp(argv[i].key, "disable")) {
114136 + enable = false;
114137 + continue;
114138 + }
114139 + if (!strcmp(argv[i].key, "performance-mode")) {
114140 + performance_mode = 1;
114141 + continue;
114142 + }
114143 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
114144 + }
114145 +
114146 + if (strlen(randstruct_seed) != 64) {
114147 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
114148 + return 1;
114149 + }
114150 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
114151 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
114152 + if (obtained_seed != 4) {
114153 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
114154 + return 1;
114155 + }
114156 +
114157 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
114158 + if (enable) {
114159 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
114160 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
114161 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
114162 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
114163 + }
114164 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
114165 +
114166 + return 0;
114167 +}
114168 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
114169 new file mode 100644
114170 index 0000000..1f0214f
114171 --- /dev/null
114172 +++ b/tools/gcc/size_overflow_plugin/.gitignore
114173 @@ -0,0 +1,3 @@
114174 +randomize_layout_seed.h
114175 +size_overflow_hash.h
114176 +size_overflow_hash_aux.h
114177 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
114178 new file mode 100644
114179 index 0000000..1ae2ed5
114180 --- /dev/null
114181 +++ b/tools/gcc/size_overflow_plugin/Makefile
114182 @@ -0,0 +1,20 @@
114183 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
114184 +always := $($(HOSTLIBS)-y)
114185 +
114186 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
114187 +
114188 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
114189 +
114190 +quiet_cmd_build_size_overflow_hash = GENHASH $@
114191 + cmd_build_size_overflow_hash = \
114192 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
114193 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
114194 + $(call if_changed,build_size_overflow_hash)
114195 +
114196 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
114197 + cmd_build_size_overflow_hash_aux = \
114198 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
114199 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
114200 + $(call if_changed,build_size_overflow_hash_aux)
114201 +
114202 +targets += size_overflow_hash.h size_overflow_hash_aux.h
114203 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114204 new file mode 100644
114205 index 0000000..12b1e3b
114206 --- /dev/null
114207 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
114208 @@ -0,0 +1,102 @@
114209 +#!/bin/bash
114210 +
114211 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
114212 +
114213 +header1="size_overflow_hash.h"
114214 +database="size_overflow_hash.data"
114215 +n=65536
114216 +hashtable_name="size_overflow_hash"
114217 +
114218 +usage() {
114219 +cat <<EOF
114220 +usage: $0 options
114221 +OPTIONS:
114222 + -h|--help help
114223 + -o header file
114224 + -d database file
114225 + -n hash array size
114226 + -s name of the hash table
114227 +EOF
114228 + return 0
114229 +}
114230 +
114231 +while true
114232 +do
114233 + case "$1" in
114234 + -h|--help) usage && exit 0;;
114235 + -n) n=$2; shift 2;;
114236 + -o) header1="$2"; shift 2;;
114237 + -d) database="$2"; shift 2;;
114238 + -s) hashtable_name="$2"; shift 2;;
114239 + --) shift 1; break ;;
114240 + *) break ;;
114241 + esac
114242 +done
114243 +
114244 +create_defines() {
114245 + for i in `seq 0 31`
114246 + do
114247 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
114248 + done
114249 + echo >> "$header1"
114250 +}
114251 +
114252 +create_structs() {
114253 + rm -f "$header1"
114254 +
114255 + create_defines
114256 +
114257 + cat "$database" | while read data
114258 + do
114259 + data_array=($data)
114260 + struct_hash_name="${data_array[0]}"
114261 + funcn="${data_array[1]}"
114262 + params="${data_array[2]}"
114263 + next="${data_array[4]}"
114264 +
114265 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
114266 +
114267 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
114268 + echo -en "\t.param\t= " >> "$header1"
114269 + line=
114270 + for param_num in ${params//-/ };
114271 + do
114272 + line="${line}PARAM"$param_num"|"
114273 + done
114274 +
114275 + echo -e "${line%?},\n};\n" >> "$header1"
114276 + done
114277 +}
114278 +
114279 +create_headers() {
114280 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
114281 +}
114282 +
114283 +create_array_elements() {
114284 + index=0
114285 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
114286 + do
114287 + data_array=($data)
114288 + i="${data_array[3]}"
114289 + hash="${data_array[0]}"
114290 + while [[ $index -lt $i ]]
114291 + do
114292 + echo -e "\t["$index"]\t= NULL," >> "$header1"
114293 + index=$(($index + 1))
114294 + done
114295 + index=$(($index + 1))
114296 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
114297 + done
114298 + echo '};' >> $header1
114299 +}
114300 +
114301 +size_overflow_plugin_dir=`dirname $header1`
114302 +if [ "$size_overflow_plugin_dir" != '.' ]; then
114303 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
114304 +fi
114305 +
114306 +create_structs
114307 +create_headers
114308 +create_array_elements
114309 +
114310 +exit 0
114311 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114312 new file mode 100644
114313 index 0000000..c43901f
114314 --- /dev/null
114315 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
114316 @@ -0,0 +1,748 @@
114317 +/*
114318 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114319 + * Licensed under the GPL v2, or (at your option) v3
114320 + *
114321 + * Homepage:
114322 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114323 + *
114324 + * Documentation:
114325 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114326 + *
114327 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114328 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114329 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114330 + *
114331 + * Usage:
114332 + * $ make
114333 + * $ make run
114334 + */
114335 +
114336 +#include "gcc-common.h"
114337 +#include "size_overflow.h"
114338 +
114339 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114340 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114341 +
114342 +// data for the size_overflow asm stmt
114343 +struct asm_data {
114344 + gimple def_stmt;
114345 + tree input;
114346 + tree output;
114347 +};
114348 +
114349 +#if BUILDING_GCC_VERSION <= 4007
114350 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
114351 +#else
114352 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
114353 +#endif
114354 +{
114355 + tree list;
114356 +#if BUILDING_GCC_VERSION <= 4007
114357 + VEC(tree, gc) *vec_list = NULL;
114358 +#else
114359 + vec<tree, va_gc> *vec_list = NULL;
114360 +#endif
114361 +
114362 + list = build_tree_list(NULL_TREE, string);
114363 + list = chainon(NULL_TREE, build_tree_list(list, io));
114364 +#if BUILDING_GCC_VERSION <= 4007
114365 + VEC_safe_push(tree, gc, vec_list, list);
114366 +#else
114367 + vec_safe_push(vec_list, list);
114368 +#endif
114369 + return vec_list;
114370 +}
114371 +
114372 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
114373 +{
114374 + gimple asm_stmt;
114375 + gimple_stmt_iterator gsi;
114376 +#if BUILDING_GCC_VERSION <= 4007
114377 + VEC(tree, gc) *input, *output = NULL;
114378 +#else
114379 + vec<tree, va_gc> *input, *output = NULL;
114380 +#endif
114381 +
114382 + input = create_asm_io_list(str_input, asm_data->input);
114383 +
114384 + if (asm_data->output)
114385 + output = create_asm_io_list(str_output, asm_data->output);
114386 +
114387 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
114388 + gsi = gsi_for_stmt(asm_data->def_stmt);
114389 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
114390 +
114391 + if (asm_data->output)
114392 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
114393 +}
114394 +
114395 +static void replace_call_lhs(const struct asm_data *asm_data)
114396 +{
114397 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
114398 + update_stmt(asm_data->def_stmt);
114399 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
114400 +}
114401 +
114402 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
114403 +{
114404 + enum mark cur_fndecl_attr;
114405 + gimple phi = get_def_stmt(result);
114406 + unsigned int i, n = gimple_phi_num_args(phi);
114407 +
114408 + pointer_set_insert(visited, phi);
114409 + for (i = 0; i < n; i++) {
114410 + tree arg = gimple_phi_arg_def(phi, i);
114411 +
114412 + cur_fndecl_attr = search_intentional(visited, arg);
114413 + if (cur_fndecl_attr != MARK_NO)
114414 + return cur_fndecl_attr;
114415 + }
114416 + return MARK_NO;
114417 +}
114418 +
114419 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
114420 +{
114421 + enum mark cur_fndecl_attr;
114422 + const_tree rhs1, rhs2;
114423 + gimple def_stmt = get_def_stmt(lhs);
114424 +
114425 + rhs1 = gimple_assign_rhs1(def_stmt);
114426 + rhs2 = gimple_assign_rhs2(def_stmt);
114427 +
114428 + cur_fndecl_attr = search_intentional(visited, rhs1);
114429 + if (cur_fndecl_attr != MARK_NO)
114430 + return cur_fndecl_attr;
114431 + return search_intentional(visited, rhs2);
114432 +}
114433 +
114434 +// Look up the intentional_overflow attribute on the caller and the callee functions.
114435 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
114436 +{
114437 + const_gimple def_stmt;
114438 +
114439 + if (TREE_CODE(lhs) != SSA_NAME)
114440 + return get_intentional_attr_type(lhs);
114441 +
114442 + def_stmt = get_def_stmt(lhs);
114443 + if (!def_stmt)
114444 + return MARK_NO;
114445 +
114446 + if (pointer_set_contains(visited, def_stmt))
114447 + return MARK_NO;
114448 +
114449 + switch (gimple_code(def_stmt)) {
114450 + case GIMPLE_NOP:
114451 + return search_intentional(visited, SSA_NAME_VAR(lhs));
114452 + case GIMPLE_ASM:
114453 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
114454 + return MARK_TURN_OFF;
114455 + return MARK_NO;
114456 + case GIMPLE_CALL:
114457 + return MARK_NO;
114458 + case GIMPLE_PHI:
114459 + return search_intentional_phi(visited, lhs);
114460 + case GIMPLE_ASSIGN:
114461 + switch (gimple_num_ops(def_stmt)) {
114462 + case 2:
114463 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
114464 + case 3:
114465 + return search_intentional_binary(visited, lhs);
114466 + }
114467 + case GIMPLE_RETURN:
114468 + return MARK_NO;
114469 + default:
114470 + debug_gimple_stmt((gimple)def_stmt);
114471 + error("%s: unknown gimple code", __func__);
114472 + gcc_unreachable();
114473 + }
114474 +}
114475 +
114476 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
114477 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
114478 +{
114479 + const_tree fndecl;
114480 + struct pointer_set_t *visited;
114481 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
114482 +
114483 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
114484 + if (is_end_intentional_intentional_attr(fndecl, argnum))
114485 + decl_attr = MARK_NOT_INTENTIONAL;
114486 + else if (is_yes_intentional_attr(fndecl, argnum))
114487 + decl_attr = MARK_YES;
114488 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
114489 + return MARK_TURN_OFF;
114490 + }
114491 +
114492 + visited = pointer_set_create();
114493 + cur_fndecl_attr = search_intentional(visited, arg);
114494 + pointer_set_destroy(visited);
114495 +
114496 + switch (cur_fndecl_attr) {
114497 + case MARK_NO:
114498 + case MARK_TURN_OFF:
114499 + return cur_fndecl_attr;
114500 + default:
114501 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
114502 + return MARK_YES;
114503 + }
114504 +}
114505 +
114506 +static void check_missing_size_overflow_attribute(tree var)
114507 +{
114508 + tree orig_fndecl;
114509 + unsigned int num;
114510 +
114511 + if (is_a_return_check(var))
114512 + orig_fndecl = DECL_ORIGIN(var);
114513 + else
114514 + orig_fndecl = DECL_ORIGIN(current_function_decl);
114515 +
114516 + num = get_function_num(var, orig_fndecl);
114517 + if (num == CANNOT_FIND_ARG)
114518 + return;
114519 +
114520 + is_missing_function(orig_fndecl, num);
114521 +}
114522 +
114523 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
114524 +{
114525 + gimple phi = get_def_stmt(result);
114526 + unsigned int i, n = gimple_phi_num_args(phi);
114527 +
114528 + pointer_set_insert(visited, phi);
114529 + for (i = 0; i < n; i++) {
114530 + tree arg = gimple_phi_arg_def(phi, i);
114531 +
114532 + search_size_overflow_attribute(visited, arg);
114533 + }
114534 +}
114535 +
114536 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
114537 +{
114538 + const_gimple def_stmt = get_def_stmt(lhs);
114539 + tree rhs1, rhs2;
114540 +
114541 + rhs1 = gimple_assign_rhs1(def_stmt);
114542 + rhs2 = gimple_assign_rhs2(def_stmt);
114543 +
114544 + search_size_overflow_attribute(visited, rhs1);
114545 + search_size_overflow_attribute(visited, rhs2);
114546 +}
114547 +
114548 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
114549 +{
114550 + const_gimple def_stmt;
114551 +
114552 + if (TREE_CODE(lhs) == PARM_DECL) {
114553 + check_missing_size_overflow_attribute(lhs);
114554 + return;
114555 + }
114556 +
114557 + def_stmt = get_def_stmt(lhs);
114558 + if (!def_stmt)
114559 + return;
114560 +
114561 + if (pointer_set_insert(visited, def_stmt))
114562 + return;
114563 +
114564 + switch (gimple_code(def_stmt)) {
114565 + case GIMPLE_NOP:
114566 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
114567 + case GIMPLE_ASM:
114568 + return;
114569 + case GIMPLE_CALL: {
114570 + tree fndecl = gimple_call_fndecl(def_stmt);
114571 +
114572 + if (fndecl == NULL_TREE)
114573 + return;
114574 + check_missing_size_overflow_attribute(fndecl);
114575 + return;
114576 + }
114577 + case GIMPLE_PHI:
114578 + return search_size_overflow_attribute_phi(visited, lhs);
114579 + case GIMPLE_ASSIGN:
114580 + switch (gimple_num_ops(def_stmt)) {
114581 + case 2:
114582 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
114583 + case 3:
114584 + return search_size_overflow_attribute_binary(visited, lhs);
114585 + }
114586 + default:
114587 + debug_gimple_stmt((gimple)def_stmt);
114588 + error("%s: unknown gimple code", __func__);
114589 + gcc_unreachable();
114590 + }
114591 +}
114592 +
114593 +// Search missing entries in the hash table (invoked from the gimple pass)
114594 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
114595 +{
114596 + tree fndecl = NULL_TREE;
114597 + tree lhs;
114598 + struct pointer_set_t *visited;
114599 +
114600 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
114601 + return;
114602 +
114603 + if (num == 0) {
114604 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
114605 + lhs = gimple_return_retval(stmt);
114606 + } else {
114607 + gcc_assert(is_gimple_call(stmt));
114608 + lhs = gimple_call_arg(stmt, num - 1);
114609 + fndecl = gimple_call_fndecl(stmt);
114610 + }
114611 +
114612 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
114613 + return;
114614 +
114615 + visited = pointer_set_create();
114616 + search_size_overflow_attribute(visited, lhs);
114617 + pointer_set_destroy(visited);
114618 +}
114619 +
114620 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114621 +{
114622 + gimple_stmt_iterator gsi;
114623 + gimple assign;
114624 +
114625 + assign = gimple_build_assign(asm_data->input, asm_data->output);
114626 + gsi = gsi_for_stmt(stmt);
114627 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
114628 + asm_data->def_stmt = assign;
114629 +
114630 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
114631 + asm_data->output = make_ssa_name(asm_data->output, stmt);
114632 + if (gimple_code(stmt) == GIMPLE_RETURN)
114633 + gimple_return_set_retval(stmt, asm_data->output);
114634 + else
114635 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
114636 + update_stmt(stmt);
114637 +}
114638 +
114639 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
114640 +{
114641 + const char *fn_name;
114642 + char *asm_comment;
114643 + unsigned int len;
114644 +
114645 + if (argnum == 0)
114646 + fn_name = DECL_NAME_POINTER(current_function_decl);
114647 + else
114648 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
114649 +
114650 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
114651 + gcc_assert(len > 0);
114652 +
114653 + return asm_comment;
114654 +}
114655 +
114656 +static const char *convert_mark_to_str(enum mark mark)
114657 +{
114658 + switch (mark) {
114659 + case MARK_NO:
114660 + return OK_ASM_STR;
114661 + case MARK_YES:
114662 + case MARK_NOT_INTENTIONAL:
114663 + return YES_ASM_STR;
114664 + case MARK_TURN_OFF:
114665 + return TURN_OFF_ASM_STR;
114666 + }
114667 +
114668 + gcc_unreachable();
114669 +}
114670 +
114671 +/* Create the input of the size_overflow asm stmt.
114672 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
114673 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114674 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
114675 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
114676 + */
114677 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
114678 +{
114679 + if (!asm_data->def_stmt) {
114680 + asm_data->input = NULL_TREE;
114681 + return;
114682 + }
114683 +
114684 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
114685 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
114686 +
114687 + switch (gimple_code(asm_data->def_stmt)) {
114688 + case GIMPLE_ASSIGN:
114689 + case GIMPLE_CALL:
114690 + replace_call_lhs(asm_data);
114691 + break;
114692 + case GIMPLE_PHI:
114693 + create_output_from_phi(stmt, argnum, asm_data);
114694 + break;
114695 + case GIMPLE_NOP: {
114696 + enum mark mark;
114697 + const char *mark_str;
114698 + char *asm_comment;
114699 +
114700 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
114701 +
114702 + asm_data->input = asm_data->output;
114703 + asm_data->output = NULL;
114704 + asm_data->def_stmt = stmt;
114705 +
114706 + mark_str = convert_mark_to_str(mark);
114707 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114708 +
114709 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
114710 + free(asm_comment);
114711 + asm_data->input = NULL_TREE;
114712 + break;
114713 + }
114714 + case GIMPLE_ASM:
114715 + if (is_size_overflow_asm(asm_data->def_stmt)) {
114716 + asm_data->input = NULL_TREE;
114717 + break;
114718 + }
114719 + default:
114720 + debug_gimple_stmt(asm_data->def_stmt);
114721 + gcc_unreachable();
114722 + }
114723 +}
114724 +
114725 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
114726 + * is of the right kind create the appropriate size_overflow asm stmts:
114727 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
114728 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
114729 + */
114730 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
114731 +{
114732 + struct asm_data asm_data;
114733 + const char *mark_str;
114734 + char *asm_comment;
114735 + enum mark mark;
114736 +
114737 + if (is_gimple_constant(output_node))
114738 + return;
114739 +
114740 + asm_data.output = output_node;
114741 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
114742 + if (mark != MARK_TURN_OFF)
114743 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
114744 +
114745 + asm_data.def_stmt = get_def_stmt(asm_data.output);
114746 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
114747 + return;
114748 +
114749 + create_asm_input(stmt, argnum, &asm_data);
114750 + if (asm_data.input == NULL_TREE)
114751 + return;
114752 +
114753 + mark_str = convert_mark_to_str(mark);
114754 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
114755 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114756 + free(asm_comment);
114757 +}
114758 +
114759 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
114760 +static bool create_mark_asm(gimple stmt, enum mark mark)
114761 +{
114762 + struct asm_data asm_data;
114763 + const char *asm_str;
114764 +
114765 + switch (mark) {
114766 + case MARK_TURN_OFF:
114767 + asm_str = TURN_OFF_ASM_STR;
114768 + break;
114769 + case MARK_NOT_INTENTIONAL:
114770 + case MARK_YES:
114771 + asm_str = YES_ASM_STR;
114772 + break;
114773 + default:
114774 + gcc_unreachable();
114775 + }
114776 +
114777 + asm_data.def_stmt = stmt;
114778 + asm_data.output = gimple_call_lhs(stmt);
114779 +
114780 + if (asm_data.output == NULL_TREE) {
114781 + asm_data.input = gimple_call_arg(stmt, 0);
114782 + if (is_gimple_constant(asm_data.input))
114783 + return false;
114784 + asm_data.output = NULL;
114785 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
114786 + return true;
114787 + }
114788 +
114789 + create_asm_input(stmt, 0, &asm_data);
114790 + gcc_assert(asm_data.input != NULL_TREE);
114791 +
114792 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
114793 + return true;
114794 +}
114795 +
114796 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
114797 +{
114798 + gimple def_stmt;
114799 +
114800 + def_stmt = get_def_stmt(lhs);
114801 + if (!def_stmt)
114802 + return;
114803 +
114804 + if (pointer_set_insert(visited, def_stmt))
114805 + return;
114806 +
114807 + switch (gimple_code(def_stmt)) {
114808 + case GIMPLE_NOP:
114809 + case GIMPLE_ASM:
114810 + case GIMPLE_CALL:
114811 + break;
114812 + case GIMPLE_PHI: {
114813 + unsigned int i, n = gimple_phi_num_args(def_stmt);
114814 +
114815 + pointer_set_insert(visited, def_stmt);
114816 +
114817 + for (i = 0; i < n; i++) {
114818 + tree arg = gimple_phi_arg_def(def_stmt, i);
114819 +
114820 + walk_use_def_ptr(visited, arg);
114821 + }
114822 + }
114823 + case GIMPLE_ASSIGN:
114824 + switch (gimple_num_ops(def_stmt)) {
114825 + case 2:
114826 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114827 + return;
114828 + case 3:
114829 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
114830 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
114831 + return;
114832 + default:
114833 + return;
114834 + }
114835 + default:
114836 + debug_gimple_stmt((gimple)def_stmt);
114837 + error("%s: unknown gimple code", __func__);
114838 + gcc_unreachable();
114839 + }
114840 +}
114841 +
114842 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
114843 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
114844 +{
114845 + struct pointer_set_t *visited;
114846 +
114847 + visited = pointer_set_create();
114848 + walk_use_def_ptr(visited, arg);
114849 + pointer_set_destroy(visited);
114850 +}
114851 +
114852 +// Determine the return value and insert the asm stmt to mark the return stmt.
114853 +static void insert_asm_ret(gimple stmt)
114854 +{
114855 + tree ret;
114856 +
114857 + ret = gimple_return_retval(stmt);
114858 + create_size_overflow_asm(stmt, ret, 0);
114859 +}
114860 +
114861 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
114862 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
114863 +{
114864 + tree arg;
114865 + unsigned int argnum;
114866 +
114867 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
114868 + gcc_assert(argnum != 0);
114869 + if (argnum == CANNOT_FIND_ARG)
114870 + return;
114871 +
114872 + arg = gimple_call_arg(stmt, argnum - 1);
114873 + gcc_assert(arg != NULL_TREE);
114874 +
114875 + // skip all ptr - ptr expressions
114876 + insert_mark_not_intentional_asm_at_ptr(arg);
114877 +
114878 + create_size_overflow_asm(stmt, arg, argnum);
114879 +}
114880 +
114881 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
114882 +static void set_argnum_attribute(const_tree attr, bool *argnums)
114883 +{
114884 + unsigned int argnum;
114885 + tree attr_value;
114886 +
114887 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
114888 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
114889 + argnums[argnum] = true;
114890 + }
114891 +}
114892 +
114893 +// If a function arg or the return value is in the hash table then set its index in the array.
114894 +static void set_argnum_hash(tree fndecl, bool *argnums)
114895 +{
114896 + unsigned int num;
114897 + const struct size_overflow_hash *hash;
114898 +
114899 + hash = get_function_hash(DECL_ORIGIN(fndecl));
114900 + if (!hash)
114901 + return;
114902 +
114903 + for (num = 0; num <= MAX_PARAM; num++) {
114904 + if (!(hash->param & (1U << num)))
114905 + continue;
114906 +
114907 + argnums[num] = true;
114908 + }
114909 +}
114910 +
114911 +static bool is_all_the_argnums_empty(bool *argnums)
114912 +{
114913 + unsigned int i;
114914 +
114915 + for (i = 0; i <= MAX_PARAM; i++)
114916 + if (argnums[i])
114917 + return false;
114918 + return true;
114919 +}
114920 +
114921 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
114922 +static void search_interesting_args(tree fndecl, bool *argnums)
114923 +{
114924 + const_tree attr;
114925 +
114926 + set_argnum_hash(fndecl, argnums);
114927 + if (!is_all_the_argnums_empty(argnums))
114928 + return;
114929 +
114930 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
114931 + if (attr && TREE_VALUE(attr))
114932 + set_argnum_attribute(attr, argnums);
114933 +}
114934 +
114935 +/*
114936 + * Look up the intentional_overflow attribute that turns off ipa based duplication
114937 + * on the callee function.
114938 + */
114939 +static bool is_mark_turn_off_attribute(gimple stmt)
114940 +{
114941 + enum mark mark;
114942 + const_tree fndecl = gimple_call_fndecl(stmt);
114943 +
114944 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
114945 + if (mark == MARK_TURN_OFF)
114946 + return true;
114947 + return false;
114948 +}
114949 +
114950 +// 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
114951 +static void handle_interesting_function(gimple stmt)
114952 +{
114953 + unsigned int argnum;
114954 + tree fndecl;
114955 + bool orig_argnums[MAX_PARAM + 1] = {false};
114956 +
114957 + if (gimple_call_num_args(stmt) == 0)
114958 + return;
114959 + fndecl = gimple_call_fndecl(stmt);
114960 + if (fndecl == NULL_TREE)
114961 + return;
114962 + fndecl = DECL_ORIGIN(fndecl);
114963 +
114964 + if (is_mark_turn_off_attribute(stmt)) {
114965 + create_mark_asm(stmt, MARK_TURN_OFF);
114966 + return;
114967 + }
114968 +
114969 + search_interesting_args(fndecl, orig_argnums);
114970 +
114971 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
114972 + if (orig_argnums[argnum])
114973 + insert_asm_arg(stmt, argnum);
114974 +}
114975 +
114976 +// 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
114977 +static void handle_interesting_ret(gimple stmt)
114978 +{
114979 + bool orig_argnums[MAX_PARAM + 1] = {false};
114980 +
114981 + search_interesting_args(current_function_decl, orig_argnums);
114982 +
114983 + if (orig_argnums[0])
114984 + insert_asm_ret(stmt);
114985 +}
114986 +
114987 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
114988 +static unsigned int search_interesting_functions(void)
114989 +{
114990 + basic_block bb;
114991 +
114992 + FOR_ALL_BB_FN(bb, cfun) {
114993 + gimple_stmt_iterator gsi;
114994 +
114995 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
114996 + gimple stmt = gsi_stmt(gsi);
114997 +
114998 + if (is_size_overflow_asm(stmt))
114999 + continue;
115000 +
115001 + if (is_gimple_call(stmt))
115002 + handle_interesting_function(stmt);
115003 + else if (gimple_code(stmt) == GIMPLE_RETURN)
115004 + handle_interesting_ret(stmt);
115005 + }
115006 + }
115007 + return 0;
115008 +}
115009 +
115010 +/*
115011 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
115012 + * this pass inserts asm stmts to mark the interesting args
115013 + * that the ipa pass will detect and insert the size overflow checks for.
115014 + */
115015 +#if BUILDING_GCC_VERSION >= 4009
115016 +static const struct pass_data insert_size_overflow_asm_pass_data = {
115017 +#else
115018 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
115019 + .pass = {
115020 +#endif
115021 + .type = GIMPLE_PASS,
115022 + .name = "insert_size_overflow_asm",
115023 +#if BUILDING_GCC_VERSION >= 4008
115024 + .optinfo_flags = OPTGROUP_NONE,
115025 +#endif
115026 +#if BUILDING_GCC_VERSION >= 4009
115027 + .has_gate = false,
115028 + .has_execute = true,
115029 +#else
115030 + .gate = NULL,
115031 + .execute = search_interesting_functions,
115032 + .sub = NULL,
115033 + .next = NULL,
115034 + .static_pass_number = 0,
115035 +#endif
115036 + .tv_id = TV_NONE,
115037 + .properties_required = PROP_cfg,
115038 + .properties_provided = 0,
115039 + .properties_destroyed = 0,
115040 + .todo_flags_start = 0,
115041 + .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
115042 +#if BUILDING_GCC_VERSION < 4009
115043 + }
115044 +#endif
115045 +};
115046 +
115047 +#if BUILDING_GCC_VERSION >= 4009
115048 +namespace {
115049 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
115050 +public:
115051 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
115052 + unsigned int execute() { return search_interesting_functions(); }
115053 +};
115054 +}
115055 +#endif
115056 +
115057 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
115058 +{
115059 +#if BUILDING_GCC_VERSION >= 4009
115060 + return new insert_size_overflow_asm_pass();
115061 +#else
115062 + return &insert_size_overflow_asm_pass.pass;
115063 +#endif
115064 +}
115065 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
115066 new file mode 100644
115067 index 0000000..73f0a12
115068 --- /dev/null
115069 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
115070 @@ -0,0 +1,943 @@
115071 +/*
115072 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
115073 + * Licensed under the GPL v2, or (at your option) v3
115074 + *
115075 + * Homepage:
115076 + * http://www.grsecurity.net/~ephox/overflow_plugin/
115077 + *
115078 + * Documentation:
115079 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
115080 + *
115081 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
115082 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
115083 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
115084 + *
115085 + * Usage:
115086 + * $ make
115087 + * $ make run
115088 + */
115089 +
115090 +#include "gcc-common.h"
115091 +#include "size_overflow.h"
115092 +
115093 +#define MIN_CHECK true
115094 +#define MAX_CHECK false
115095 +
115096 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
115097 +{
115098 + const_tree type;
115099 + tree new_type;
115100 +
115101 + gcc_assert(node != NULL_TREE);
115102 +
115103 + type = TREE_TYPE(node);
115104 +
115105 + if (pointer_set_contains(visited->my_stmts, stmt))
115106 + return TREE_TYPE(node);
115107 +
115108 + switch (TYPE_MODE(type)) {
115109 + case QImode:
115110 + new_type = size_overflow_type_HI;
115111 + break;
115112 + case HImode:
115113 + new_type = size_overflow_type_SI;
115114 + break;
115115 + case SImode:
115116 + new_type = size_overflow_type_DI;
115117 + break;
115118 + case DImode:
115119 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115120 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
115121 + else
115122 + new_type = size_overflow_type_TI;
115123 + break;
115124 + case TImode:
115125 + gcc_assert(!TYPE_UNSIGNED(type));
115126 + new_type = size_overflow_type_TI;
115127 + break;
115128 + default:
115129 + debug_tree((tree)node);
115130 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
115131 + gcc_unreachable();
115132 + }
115133 +
115134 + if (TYPE_QUALS(type) != 0)
115135 + return build_qualified_type(new_type, TYPE_QUALS(type));
115136 + return new_type;
115137 +}
115138 +
115139 +static tree get_lhs(const_gimple stmt)
115140 +{
115141 + switch (gimple_code(stmt)) {
115142 + case GIMPLE_ASSIGN:
115143 + case GIMPLE_CALL:
115144 + return gimple_get_lhs(stmt);
115145 + case GIMPLE_PHI:
115146 + return gimple_phi_result(stmt);
115147 + default:
115148 + return NULL_TREE;
115149 + }
115150 +}
115151 +
115152 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
115153 +{
115154 + gimple_stmt_iterator gsi;
115155 + tree lhs;
115156 + gimple new_stmt;
115157 +
115158 + if (rhs == NULL_TREE)
115159 + return NULL_TREE;
115160 +
115161 + gsi = gsi_for_stmt(stmt);
115162 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115163 + pointer_set_insert(visited->my_stmts, new_stmt);
115164 +
115165 + lhs = get_lhs(new_stmt);
115166 + gcc_assert(lhs != NULL_TREE);
115167 + return lhs;
115168 +}
115169 +
115170 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
115171 +{
115172 + tree lhs, dst_type;
115173 + gimple_stmt_iterator gsi;
115174 +
115175 + if (rhs1 == NULL_TREE) {
115176 + debug_gimple_stmt(oldstmt);
115177 + error("%s: rhs1 is NULL_TREE", __func__);
115178 + gcc_unreachable();
115179 + }
115180 +
115181 + switch (gimple_code(oldstmt)) {
115182 + case GIMPLE_ASM:
115183 + lhs = rhs1;
115184 + break;
115185 + case GIMPLE_CALL:
115186 + case GIMPLE_ASSIGN:
115187 + lhs = gimple_get_lhs(oldstmt);
115188 + break;
115189 + default:
115190 + debug_gimple_stmt(oldstmt);
115191 + gcc_unreachable();
115192 + }
115193 +
115194 + gsi = gsi_for_stmt(oldstmt);
115195 + pointer_set_insert(visited->stmts, oldstmt);
115196 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115197 + basic_block next_bb, cur_bb;
115198 + const_edge e;
115199 +
115200 + gcc_assert(before == false);
115201 + gcc_assert(stmt_can_throw_internal(oldstmt));
115202 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115203 + gcc_assert(!gsi_end_p(gsi));
115204 +
115205 + cur_bb = gimple_bb(oldstmt);
115206 + next_bb = cur_bb->next_bb;
115207 + e = find_edge(cur_bb, next_bb);
115208 + gcc_assert(e != NULL);
115209 + gcc_assert(e->flags & EDGE_FALLTHRU);
115210 +
115211 + gsi = gsi_after_labels(next_bb);
115212 + gcc_assert(!gsi_end_p(gsi));
115213 +
115214 + before = true;
115215 + oldstmt = gsi_stmt(gsi);
115216 + }
115217 +
115218 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
115219 +
115220 + if (is_gimple_constant(rhs1))
115221 + return cast_a_tree(dst_type, rhs1);
115222 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
115223 +}
115224 +
115225 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115226 +{
115227 + gimple stmt;
115228 + gimple_stmt_iterator gsi;
115229 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115230 +
115231 + if (pointer_set_contains(visited->my_stmts, oldstmt))
115232 + return lhs;
115233 +
115234 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115235 + rhs1 = gimple_assign_rhs1(oldstmt);
115236 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115237 + }
115238 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115239 + rhs2 = gimple_assign_rhs2(oldstmt);
115240 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115241 + }
115242 +
115243 + stmt = gimple_copy(oldstmt);
115244 + gimple_set_location(stmt, gimple_location(oldstmt));
115245 + pointer_set_insert(visited->my_stmts, stmt);
115246 +
115247 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115248 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115249 +
115250 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
115251 +
115252 + new_var = create_new_var(size_overflow_type);
115253 + new_var = make_ssa_name(new_var, stmt);
115254 + gimple_assign_set_lhs(stmt, new_var);
115255 +
115256 + if (rhs1 != NULL_TREE)
115257 + gimple_assign_set_rhs1(stmt, rhs1);
115258 +
115259 + if (rhs2 != NULL_TREE)
115260 + gimple_assign_set_rhs2(stmt, rhs2);
115261 +#if BUILDING_GCC_VERSION >= 4006
115262 + if (rhs3 != NULL_TREE)
115263 + gimple_assign_set_rhs3(stmt, rhs3);
115264 +#endif
115265 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115266 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115267 +
115268 + gsi = gsi_for_stmt(oldstmt);
115269 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115270 + update_stmt(stmt);
115271 + pointer_set_insert(visited->stmts, oldstmt);
115272 + return gimple_assign_lhs(stmt);
115273 +}
115274 +
115275 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115276 +{
115277 + gimple assign;
115278 + gimple_stmt_iterator gsi;
115279 + basic_block first_bb;
115280 +
115281 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115282 +
115283 + if (bb->index == 0) {
115284 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115285 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115286 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115287 + bb = first_bb;
115288 + }
115289 +
115290 + gsi = gsi_after_labels(bb);
115291 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115292 + pointer_set_insert(visited->my_stmts, assign);
115293 +
115294 + return gimple_assign_lhs(assign);
115295 +}
115296 +
115297 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
115298 +{
115299 + gimple_stmt_iterator gsi;
115300 + gimple assign, def_stmt = get_def_stmt(new_arg);
115301 +
115302 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115303 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115304 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115305 + } else {
115306 + gsi = gsi_for_stmt(def_stmt);
115307 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115308 + }
115309 +
115310 + pointer_set_insert(visited->my_stmts, assign);
115311 + return gimple_assign_lhs(assign);
115312 +}
115313 +
115314 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
115315 +{
115316 + basic_block bb;
115317 + gimple_stmt_iterator gsi;
115318 + const_gimple def_stmt;
115319 + gimple assign;
115320 +
115321 + def_stmt = get_def_stmt(arg);
115322 + bb = gimple_bb(def_stmt);
115323 + gcc_assert(bb->index != 0);
115324 + gsi = gsi_after_labels(bb);
115325 +
115326 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115327 + pointer_set_insert(visited->my_stmts, assign);
115328 + return gimple_assign_lhs(assign);
115329 +}
115330 +
115331 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115332 +{
115333 + tree size_overflow_type;
115334 + tree arg;
115335 + const_gimple def_stmt;
115336 +
115337 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115338 + return new_arg;
115339 +
115340 + arg = gimple_phi_arg_def(oldstmt, i);
115341 + def_stmt = get_def_stmt(arg);
115342 + gcc_assert(def_stmt != NULL);
115343 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115344 +
115345 + switch (gimple_code(def_stmt)) {
115346 + case GIMPLE_PHI:
115347 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
115348 + case GIMPLE_NOP: {
115349 + basic_block bb;
115350 +
115351 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115352 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
115353 + }
115354 + case GIMPLE_ASM: {
115355 + gimple_stmt_iterator gsi;
115356 + gimple assign, stmt = get_def_stmt(arg);
115357 +
115358 + gsi = gsi_for_stmt(stmt);
115359 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115360 + pointer_set_insert(visited->my_stmts, assign);
115361 + return gimple_assign_lhs(assign);
115362 + }
115363 + default:
115364 + gcc_assert(new_arg != NULL_TREE);
115365 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115366 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
115367 + }
115368 +}
115369 +
115370 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
115371 +{
115372 + basic_block bb;
115373 + gimple phi;
115374 + gimple_seq seq;
115375 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115376 +
115377 + bb = gsi_bb(gsi);
115378 +
115379 + if (result == NULL_TREE) {
115380 + tree old_result = gimple_phi_result(oldstmt);
115381 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
115382 +
115383 + result = create_new_var(size_overflow_type);
115384 + }
115385 +
115386 + phi = create_phi_node(result, bb);
115387 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115388 + seq = phi_nodes(bb);
115389 + gsi = gsi_last(seq);
115390 + gsi_remove(&gsi, false);
115391 +
115392 + gsi = gsi_for_stmt(oldstmt);
115393 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115394 + gimple_set_bb(phi, bb);
115395 + return phi;
115396 +}
115397 +
115398 +#if BUILDING_GCC_VERSION <= 4007
115399 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115400 +#else
115401 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115402 +#endif
115403 +{
115404 + gimple new_phi;
115405 + unsigned int i;
115406 + tree arg, result;
115407 + location_t loc = gimple_location(oldstmt);
115408 +
115409 +#if BUILDING_GCC_VERSION <= 4007
115410 + gcc_assert(!VEC_empty(tree, *args));
115411 +#else
115412 + gcc_assert(!args->is_empty());
115413 +#endif
115414 +
115415 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
115416 + result = gimple_phi_result(new_phi);
115417 + ssa_name_var = SSA_NAME_VAR(result);
115418 +
115419 +#if BUILDING_GCC_VERSION <= 4007
115420 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115421 +#else
115422 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115423 +#endif
115424 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
115425 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115426 + }
115427 +
115428 +#if BUILDING_GCC_VERSION <= 4007
115429 + VEC_free(tree, heap, *args);
115430 +#else
115431 + vec_free(args);
115432 +#endif
115433 + update_stmt(new_phi);
115434 + pointer_set_insert(visited->my_stmts, new_phi);
115435 + return result;
115436 +}
115437 +
115438 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
115439 +{
115440 + tree ssa_name_var = NULL_TREE;
115441 +#if BUILDING_GCC_VERSION <= 4007
115442 + VEC(tree, heap) *args = NULL;
115443 +#else
115444 + vec<tree, va_heap, vl_embed> *args = NULL;
115445 +#endif
115446 + gimple oldstmt = get_def_stmt(orig_result);
115447 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115448 +
115449 + pointer_set_insert(visited->stmts, oldstmt);
115450 + for (i = 0; i < len; i++) {
115451 + tree arg, new_arg;
115452 +
115453 + arg = gimple_phi_arg_def(oldstmt, i);
115454 + new_arg = expand(visited, caller_node, arg);
115455 +
115456 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115457 + ssa_name_var = SSA_NAME_VAR(new_arg);
115458 +
115459 + if (is_gimple_constant(arg)) {
115460 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
115461 +
115462 + new_arg = cast_a_tree(size_overflow_type, arg);
115463 + }
115464 +
115465 +#if BUILDING_GCC_VERSION <= 4007
115466 + VEC_safe_push(tree, heap, args, new_arg);
115467 +#else
115468 + vec_safe_push(args, new_arg);
115469 +#endif
115470 + }
115471 +
115472 +#if BUILDING_GCC_VERSION <= 4007
115473 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
115474 +#else
115475 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
115476 +#endif
115477 +}
115478 +
115479 +static tree create_cast_assign(struct visited *visited, gimple stmt)
115480 +{
115481 + tree rhs1 = gimple_assign_rhs1(stmt);
115482 + tree lhs = gimple_assign_lhs(stmt);
115483 + const_tree rhs1_type = TREE_TYPE(rhs1);
115484 + const_tree lhs_type = TREE_TYPE(lhs);
115485 +
115486 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115487 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115488 +
115489 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115490 +}
115491 +
115492 +static bool skip_lhs_cast_check(const_gimple stmt)
115493 +{
115494 + const_tree rhs = gimple_assign_rhs1(stmt);
115495 + const_gimple def_stmt = get_def_stmt(rhs);
115496 +
115497 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115498 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115499 + return true;
115500 +
115501 + if (is_const_plus_unsigned_signed_truncation(rhs))
115502 + return true;
115503 +
115504 + return false;
115505 +}
115506 +
115507 +static tree create_string_param(tree string)
115508 +{
115509 + tree i_type, a_type;
115510 + const int length = TREE_STRING_LENGTH(string);
115511 +
115512 + gcc_assert(length > 0);
115513 +
115514 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115515 + a_type = build_array_type(char_type_node, i_type);
115516 +
115517 + TREE_TYPE(string) = a_type;
115518 + TREE_CONSTANT(string) = 1;
115519 + TREE_READONLY(string) = 1;
115520 +
115521 + return build1(ADDR_EXPR, ptr_type_node, string);
115522 +}
115523 +
115524 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115525 +{
115526 + gimple cond_stmt;
115527 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115528 +
115529 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115530 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115531 + update_stmt(cond_stmt);
115532 +}
115533 +
115534 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115535 +{
115536 + gimple func_stmt;
115537 + const_gimple def_stmt;
115538 + const_tree loc_line;
115539 + tree loc_file, ssa_name, current_func;
115540 + expanded_location xloc;
115541 + char *ssa_name_buf;
115542 + int len;
115543 + struct cgraph_edge *edge;
115544 + struct cgraph_node *callee_node;
115545 + int frequency;
115546 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115547 +
115548 + def_stmt = get_def_stmt(arg);
115549 + xloc = expand_location(gimple_location(def_stmt));
115550 +
115551 + if (!gimple_has_location(def_stmt)) {
115552 + xloc = expand_location(gimple_location(stmt));
115553 + if (!gimple_has_location(stmt))
115554 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115555 + }
115556 +
115557 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115558 +
115559 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115560 + loc_file = create_string_param(loc_file);
115561 +
115562 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115563 + current_func = create_string_param(current_func);
115564 +
115565 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115566 + call_count++;
115567 + 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);
115568 + gcc_assert(len > 0);
115569 + ssa_name = build_string(len + 1, ssa_name_buf);
115570 + free(ssa_name_buf);
115571 + ssa_name = create_string_param(ssa_name);
115572 +
115573 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115574 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115575 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115576 +
115577 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115578 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115579 +
115580 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115581 + gcc_assert(edge != NULL);
115582 +}
115583 +
115584 +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)
115585 +{
115586 + basic_block cond_bb, join_bb, bb_true;
115587 + edge e;
115588 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115589 +
115590 + cond_bb = gimple_bb(stmt);
115591 + if (before)
115592 + gsi_prev(&gsi);
115593 + if (gsi_end_p(gsi))
115594 + e = split_block_after_labels(cond_bb);
115595 + else
115596 + e = split_block(cond_bb, gsi_stmt(gsi));
115597 + cond_bb = e->src;
115598 + join_bb = e->dest;
115599 + e->flags = EDGE_FALSE_VALUE;
115600 + e->probability = REG_BR_PROB_BASE;
115601 +
115602 + bb_true = create_empty_bb(cond_bb);
115603 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115604 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115605 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115606 +
115607 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115608 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115609 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115610 +
115611 + if (current_loops != NULL) {
115612 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115613 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115614 + }
115615 +
115616 + insert_cond(cond_bb, arg, cond_code, type_value);
115617 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115618 +
115619 +// print_the_code_insertions(stmt);
115620 +}
115621 +
115622 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115623 +{
115624 + const_tree rhs_type = TREE_TYPE(rhs);
115625 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115626 +
115627 + gcc_assert(rhs_type != NULL_TREE);
115628 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115629 + return;
115630 +
115631 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115632 +
115633 + if (is_const_plus_unsigned_signed_truncation(rhs))
115634 + return;
115635 +
115636 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115637 + // typemax (-1) < typemin (0)
115638 + if (TREE_OVERFLOW(type_max))
115639 + return;
115640 +
115641 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115642 +
115643 + cast_rhs_type = TREE_TYPE(cast_rhs);
115644 + type_max_type = TREE_TYPE(type_max);
115645 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115646 +
115647 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115648 +
115649 + // special case: get_size_overflow_type(), 32, u64->s
115650 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115651 + return;
115652 +
115653 + type_min_type = TREE_TYPE(type_min);
115654 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115655 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115656 +}
115657 +
115658 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115659 +{
115660 + bool cast_lhs, cast_rhs;
115661 + tree lhs = gimple_assign_lhs(stmt);
115662 + tree rhs = gimple_assign_rhs1(stmt);
115663 + const_tree lhs_type = TREE_TYPE(lhs);
115664 + const_tree rhs_type = TREE_TYPE(rhs);
115665 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115666 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115667 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115668 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115669 +
115670 + static bool check_lhs[3][4] = {
115671 + // ss su us uu
115672 + { false, true, true, false }, // lhs > rhs
115673 + { false, false, false, false }, // lhs = rhs
115674 + { true, true, true, true }, // lhs < rhs
115675 + };
115676 +
115677 + static bool check_rhs[3][4] = {
115678 + // ss su us uu
115679 + { true, false, true, true }, // lhs > rhs
115680 + { true, false, true, true }, // lhs = rhs
115681 + { true, false, true, true }, // lhs < rhs
115682 + };
115683 +
115684 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115685 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115686 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115687 +
115688 + if (lhs_size > rhs_size) {
115689 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115690 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115691 + } else if (lhs_size == rhs_size) {
115692 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115693 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115694 + } else {
115695 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115696 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115697 + }
115698 +
115699 + if (!cast_lhs && !cast_rhs)
115700 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115701 +
115702 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115703 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115704 +
115705 + if (cast_rhs)
115706 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115707 +
115708 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115709 +}
115710 +
115711 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115712 +{
115713 + enum tree_code rhs_code;
115714 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115715 +
115716 + if (pointer_set_contains(visited->my_stmts, stmt))
115717 + return lhs;
115718 +
115719 + rhs1 = gimple_assign_rhs1(stmt);
115720 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115721 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115722 +
115723 + new_rhs1 = expand(visited, caller_node, rhs1);
115724 +
115725 + if (new_rhs1 == NULL_TREE)
115726 + return create_cast_assign(visited, stmt);
115727 +
115728 + if (pointer_set_contains(visited->no_cast_check, stmt))
115729 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115730 +
115731 + rhs_code = gimple_assign_rhs_code(stmt);
115732 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
115733 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
115734 +
115735 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115736 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115737 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115738 + }
115739 +
115740 + if (!gimple_assign_cast_p(stmt))
115741 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115742 +
115743 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115744 +}
115745 +
115746 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
115747 +{
115748 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115749 + gimple def_stmt = get_def_stmt(lhs);
115750 +
115751 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115752 + rhs1 = gimple_assign_rhs1(def_stmt);
115753 +
115754 + if (is_gimple_constant(rhs1))
115755 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115756 +
115757 + switch (TREE_CODE(rhs1)) {
115758 + case SSA_NAME: {
115759 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
115760 +
115761 + if (gimple_assign_cast_p(stmt))
115762 + unsigned_signed_cast_intentional_overflow(visited, stmt);
115763 + return ret;
115764 + }
115765 + case ARRAY_REF:
115766 + case BIT_FIELD_REF:
115767 + case ADDR_EXPR:
115768 + case COMPONENT_REF:
115769 + case INDIRECT_REF:
115770 +#if BUILDING_GCC_VERSION >= 4006
115771 + case MEM_REF:
115772 +#endif
115773 + case TARGET_MEM_REF:
115774 + case VIEW_CONVERT_EXPR:
115775 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115776 + case PARM_DECL:
115777 + case VAR_DECL:
115778 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115779 +
115780 + default:
115781 + debug_gimple_stmt(def_stmt);
115782 + debug_tree(rhs1);
115783 + gcc_unreachable();
115784 + }
115785 +}
115786 +
115787 +static void __unused print_the_code_insertions(const_gimple stmt)
115788 +{
115789 + location_t loc = gimple_location(stmt);
115790 +
115791 + inform(loc, "Integer size_overflow check applied here.");
115792 +}
115793 +
115794 +static bool is_from_cast(const_tree node)
115795 +{
115796 + gimple def_stmt = get_def_stmt(node);
115797 +
115798 + if (!def_stmt)
115799 + return false;
115800 +
115801 + if (gimple_assign_cast_p(def_stmt))
115802 + return true;
115803 +
115804 + return false;
115805 +}
115806 +
115807 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
115808 +static bool is_a_ptr_minus(gimple stmt)
115809 +{
115810 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
115811 +
115812 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
115813 + return false;
115814 +
115815 + rhs1 = gimple_assign_rhs1(stmt);
115816 + if (!is_from_cast(rhs1))
115817 + return false;
115818 +
115819 + rhs2 = gimple_assign_rhs2(stmt);
115820 + if (!is_from_cast(rhs2))
115821 + return false;
115822 +
115823 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
115824 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
115825 +
115826 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
115827 + return false;
115828 +
115829 + return true;
115830 +}
115831 +
115832 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115833 +{
115834 + enum intentional_overflow_type res;
115835 + tree rhs1, rhs2, new_lhs;
115836 + gimple def_stmt = get_def_stmt(lhs);
115837 + tree new_rhs1 = NULL_TREE;
115838 + tree new_rhs2 = NULL_TREE;
115839 +
115840 + if (is_a_ptr_minus(def_stmt))
115841 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115842 +
115843 + rhs1 = gimple_assign_rhs1(def_stmt);
115844 + rhs2 = gimple_assign_rhs2(def_stmt);
115845 +
115846 + /* no DImode/TImode division in the 32/64 bit kernel */
115847 + switch (gimple_assign_rhs_code(def_stmt)) {
115848 + case RDIV_EXPR:
115849 + case TRUNC_DIV_EXPR:
115850 + case CEIL_DIV_EXPR:
115851 + case FLOOR_DIV_EXPR:
115852 + case ROUND_DIV_EXPR:
115853 + case TRUNC_MOD_EXPR:
115854 + case CEIL_MOD_EXPR:
115855 + case FLOOR_MOD_EXPR:
115856 + case ROUND_MOD_EXPR:
115857 + case EXACT_DIV_EXPR:
115858 + case POINTER_PLUS_EXPR:
115859 + case BIT_AND_EXPR:
115860 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115861 + default:
115862 + break;
115863 + }
115864 +
115865 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
115866 + if (new_lhs != NULL_TREE)
115867 + return new_lhs;
115868 +
115869 + if (TREE_CODE(rhs1) == SSA_NAME)
115870 + new_rhs1 = expand(visited, caller_node, rhs1);
115871 + if (TREE_CODE(rhs2) == SSA_NAME)
115872 + new_rhs2 = expand(visited, caller_node, rhs2);
115873 +
115874 + res = add_mul_intentional_overflow(def_stmt);
115875 + if (res != NO_INTENTIONAL_OVERFLOW) {
115876 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115877 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
115878 + return new_lhs;
115879 + }
115880 +
115881 + if (skip_expr_on_double_type(def_stmt)) {
115882 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115883 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
115884 + return new_lhs;
115885 + }
115886 +
115887 + if (is_a_neg_overflow(def_stmt, rhs2))
115888 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
115889 + if (is_a_neg_overflow(def_stmt, rhs1))
115890 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
115891 +
115892 +
115893 + if (is_a_constant_overflow(def_stmt, rhs2))
115894 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
115895 + if (is_a_constant_overflow(def_stmt, rhs1))
115896 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
115897 +
115898 + // the const is between 0 and (signed) MAX
115899 + if (is_gimple_constant(rhs1))
115900 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
115901 + if (is_gimple_constant(rhs2))
115902 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
115903 +
115904 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
115905 +}
115906 +
115907 +#if BUILDING_GCC_VERSION >= 4006
115908 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
115909 +{
115910 + if (is_gimple_constant(rhs))
115911 + return cast_a_tree(size_overflow_type, rhs);
115912 + if (TREE_CODE(rhs) != SSA_NAME)
115913 + return NULL_TREE;
115914 + return expand(visited, caller_node, rhs);
115915 +}
115916 +
115917 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115918 +{
115919 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
115920 + gimple def_stmt = get_def_stmt(lhs);
115921 +
115922 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
115923 +
115924 + rhs1 = gimple_assign_rhs1(def_stmt);
115925 + rhs2 = gimple_assign_rhs2(def_stmt);
115926 + rhs3 = gimple_assign_rhs3(def_stmt);
115927 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
115928 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
115929 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
115930 +
115931 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
115932 +}
115933 +#endif
115934 +
115935 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
115936 +{
115937 + gimple_stmt_iterator gsi;
115938 + gimple next_stmt = NULL;
115939 +
115940 + gsi = gsi_for_stmt(stmt);
115941 +
115942 + do {
115943 + gsi_next(&gsi);
115944 + next_stmt = gsi_stmt(gsi);
115945 +
115946 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
115947 + return NULL_TREE;
115948 +
115949 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
115950 + break;
115951 +
115952 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
115953 + } while (!gsi_end_p(gsi));
115954 +
115955 + gcc_assert(next_stmt);
115956 + return get_lhs(next_stmt);
115957 +}
115958 +
115959 +static tree expand_visited(struct visited *visited, gimple def_stmt)
115960 +{
115961 + gimple_stmt_iterator gsi;
115962 + enum gimple_code code = gimple_code(def_stmt);
115963 +
115964 + if (code == GIMPLE_ASM)
115965 + return NULL_TREE;
115966 +
115967 + gsi = gsi_for_stmt(def_stmt);
115968 + gsi_next(&gsi);
115969 +
115970 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
115971 + return NULL_TREE;
115972 + return get_my_stmt_lhs(visited, def_stmt);
115973 +}
115974 +
115975 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
115976 +{
115977 + gimple def_stmt;
115978 +
115979 + def_stmt = get_def_stmt(lhs);
115980 +
115981 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115982 + return NULL_TREE;
115983 +
115984 + if (pointer_set_contains(visited->my_stmts, def_stmt))
115985 + return lhs;
115986 +
115987 + if (pointer_set_contains(visited->stmts, def_stmt))
115988 + return expand_visited(visited, def_stmt);
115989 +
115990 + switch (gimple_code(def_stmt)) {
115991 + case GIMPLE_PHI:
115992 + return handle_phi(visited, caller_node, lhs);
115993 + case GIMPLE_CALL:
115994 + case GIMPLE_ASM:
115995 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115996 + case GIMPLE_ASSIGN:
115997 + switch (gimple_num_ops(def_stmt)) {
115998 + case 2:
115999 + return handle_unary_ops(visited, caller_node, def_stmt);
116000 + case 3:
116001 + return handle_binary_ops(visited, caller_node, lhs);
116002 +#if BUILDING_GCC_VERSION >= 4006
116003 + case 4:
116004 + return handle_ternary_ops(visited, caller_node, lhs);
116005 +#endif
116006 + }
116007 + default:
116008 + debug_gimple_stmt(def_stmt);
116009 + error("%s: unknown gimple code", __func__);
116010 + gcc_unreachable();
116011 + }
116012 +}
116013 +
116014 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
116015 new file mode 100644
116016 index 0000000..df50164
116017 --- /dev/null
116018 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
116019 @@ -0,0 +1,1141 @@
116020 +/*
116021 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
116022 + * Licensed under the GPL v2, or (at your option) v3
116023 + *
116024 + * Homepage:
116025 + * http://www.grsecurity.net/~ephox/overflow_plugin/
116026 + *
116027 + * Documentation:
116028 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
116029 + *
116030 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
116031 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
116032 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
116033 + *
116034 + * Usage:
116035 + * $ make
116036 + * $ make run
116037 + */
116038 +
116039 +#include "gcc-common.h"
116040 +#include "size_overflow.h"
116041 +
116042 +#define VEC_LEN 128
116043 +#define RET_CHECK NULL_TREE
116044 +#define WRONG_NODE 32
116045 +#define NOT_INTENTIONAL_ASM NULL
116046 +
116047 +unsigned int call_count;
116048 +
116049 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
116050 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
116051 +
116052 +struct visited_fns {
116053 + struct visited_fns *next;
116054 + const_tree fndecl;
116055 + unsigned int num;
116056 + const_gimple first_stmt;
116057 +};
116058 +
116059 +struct next_cgraph_node {
116060 + struct next_cgraph_node *next;
116061 + struct cgraph_node *current_function;
116062 + tree callee_fndecl;
116063 + unsigned int num;
116064 +};
116065 +
116066 +// Don't want to duplicate entries in next_cgraph_node
116067 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116068 +{
116069 + const_tree new_callee_fndecl;
116070 + struct next_cgraph_node *cur_node;
116071 +
116072 + if (fndecl == RET_CHECK)
116073 + new_callee_fndecl = NODE_DECL(node);
116074 + else
116075 + new_callee_fndecl = fndecl;
116076 +
116077 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116078 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116079 + continue;
116080 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116081 + continue;
116082 + if (num == cur_node->num)
116083 + return true;
116084 + }
116085 + return false;
116086 +}
116087 +
116088 +/* Add a next_cgraph_node into the list for handle_function().
116089 + * handle_function() iterates over all the next cgraph nodes and
116090 + * starts the overflow check insertion process.
116091 + */
116092 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116093 +{
116094 + struct next_cgraph_node *new_node;
116095 +
116096 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116097 + return head;
116098 +
116099 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116100 + new_node->current_function = node;
116101 + new_node->next = NULL;
116102 + new_node->num = num;
116103 + if (fndecl == RET_CHECK)
116104 + new_node->callee_fndecl = NODE_DECL(node);
116105 + else
116106 + new_node->callee_fndecl = fndecl;
116107 +
116108 + if (!head)
116109 + return new_node;
116110 +
116111 + new_node->next = head;
116112 + return new_node;
116113 +}
116114 +
116115 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116116 +{
116117 + struct cgraph_edge *e;
116118 +
116119 + if (num == 0)
116120 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116121 +
116122 + for (e = node->callers; e; e = e->next_caller) {
116123 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116124 +
116125 + gcc_assert(fndecl != NULL_TREE);
116126 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116127 + }
116128 +
116129 + return head;
116130 +}
116131 +
116132 +struct missing_functions {
116133 + struct missing_functions *next;
116134 + const_tree node;
116135 + tree fndecl;
116136 +};
116137 +
116138 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116139 +{
116140 + struct missing_functions *new_function;
116141 +
116142 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116143 + new_function->node = node;
116144 + new_function->next = NULL;
116145 +
116146 + if (TREE_CODE(node) == FUNCTION_DECL)
116147 + new_function->fndecl = node;
116148 + else
116149 + new_function->fndecl = current_function_decl;
116150 + gcc_assert(new_function->fndecl);
116151 +
116152 + if (!missing_fn_head)
116153 + return new_function;
116154 +
116155 + new_function->next = missing_fn_head;
116156 + return new_function;
116157 +}
116158 +
116159 +/* If the function is missing from the hash table and it is a static function
116160 + * then create a next_cgraph_node from it for handle_function()
116161 + */
116162 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116163 +{
116164 + unsigned int num;
116165 + const_tree orig_fndecl;
116166 + struct cgraph_node *next_node = NULL;
116167 +
116168 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116169 +
116170 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116171 + if (num == CANNOT_FIND_ARG)
116172 + return cnodes;
116173 +
116174 + if (!is_missing_function(orig_fndecl, num))
116175 + return cnodes;
116176 +
116177 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116178 + if (next_node && next_node->local.local)
116179 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116180 + return cnodes;
116181 +}
116182 +
116183 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116184 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116185 + */
116186 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116187 +{
116188 + unsigned int i;
116189 + tree node;
116190 + struct missing_functions *cur, *missing_fn_head = NULL;
116191 +
116192 +#if BUILDING_GCC_VERSION <= 4007
116193 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116194 +#else
116195 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116196 +#endif
116197 + switch (TREE_CODE(node)) {
116198 + case PARM_DECL:
116199 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116200 + break;
116201 + case FUNCTION_DECL:
116202 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116203 + break;
116204 + default:
116205 + break;
116206 + }
116207 + }
116208 +
116209 + while (missing_fn_head) {
116210 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116211 +
116212 + cur = missing_fn_head->next;
116213 + free(missing_fn_head);
116214 + missing_fn_head = cur;
116215 + }
116216 +
116217 + return cnodes;
116218 +}
116219 +
116220 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116221 +{
116222 + gimple phi = get_def_stmt(result);
116223 + unsigned int i, n = gimple_phi_num_args(phi);
116224 +
116225 + pointer_set_insert(visited, phi);
116226 + for (i = 0; i < n; i++) {
116227 + const_tree arg = gimple_phi_arg_def(phi, i);
116228 +
116229 + set_conditions(visited, interesting_conditions, arg);
116230 + }
116231 +}
116232 +
116233 +enum conditions {
116234 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
116235 +};
116236 +
116237 +// Search for constants, cast assignments and binary/ternary assignments
116238 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116239 +{
116240 + gimple def_stmt = get_def_stmt(lhs);
116241 +
116242 + if (is_gimple_constant(lhs)) {
116243 + interesting_conditions[FROM_CONST] = true;
116244 + return;
116245 + }
116246 +
116247 + if (!def_stmt)
116248 + return;
116249 +
116250 + if (pointer_set_contains(visited, def_stmt))
116251 + return;
116252 +
116253 + switch (gimple_code(def_stmt)) {
116254 + case GIMPLE_CALL:
116255 + if (lhs == gimple_call_lhs(def_stmt))
116256 + interesting_conditions[RET] = true;
116257 + return;
116258 + case GIMPLE_NOP:
116259 + case GIMPLE_ASM:
116260 + return;
116261 + case GIMPLE_PHI:
116262 + interesting_conditions[PHI] = true;
116263 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116264 + case GIMPLE_ASSIGN:
116265 + if (gimple_num_ops(def_stmt) == 2) {
116266 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116267 +
116268 + if (gimple_assign_cast_p(def_stmt))
116269 + interesting_conditions[CAST] = true;
116270 +
116271 + return set_conditions(visited, interesting_conditions, rhs);
116272 + } else {
116273 + interesting_conditions[NOT_UNARY] = true;
116274 + return;
116275 + }
116276 + default:
116277 + debug_gimple_stmt(def_stmt);
116278 + gcc_unreachable();
116279 + }
116280 +}
116281 +
116282 +// determine whether duplication will be necessary or not.
116283 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116284 +{
116285 + struct pointer_set_t *visited;
116286 +
116287 + if (gimple_assign_cast_p(cur_node->first_stmt))
116288 + interesting_conditions[CAST] = true;
116289 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116290 + interesting_conditions[NOT_UNARY] = true;
116291 +
116292 + visited = pointer_set_create();
116293 + set_conditions(visited, interesting_conditions, cur_node->node);
116294 + pointer_set_destroy(visited);
116295 +}
116296 +
116297 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116298 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116299 +{
116300 + gimple assign;
116301 + gimple_stmt_iterator gsi;
116302 +
116303 + // already removed
116304 + if (gimple_bb(asm_stmt) == NULL)
116305 + return;
116306 + gsi = gsi_for_stmt(asm_stmt);
116307 +
116308 + assign = gimple_build_assign(lhs, rhs);
116309 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116310 + SSA_NAME_DEF_STMT(lhs) = assign;
116311 +
116312 + gsi_remove(&gsi, true);
116313 +}
116314 +
116315 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116316 + * stmt is a return otherwise it is the callee function.
116317 + */
116318 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116319 +{
116320 + const_tree fndecl;
116321 +
116322 + if (argnum == 0)
116323 + fndecl = current_function_decl;
116324 + else
116325 + fndecl = gimple_call_fndecl(stmt);
116326 +
116327 + if (fndecl == NULL_TREE)
116328 + return NULL_TREE;
116329 +
116330 + return DECL_ORIGIN(fndecl);
116331 +}
116332 +
116333 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116334 +static bool skip_asm(const_tree arg)
116335 +{
116336 + gimple def_stmt = get_def_stmt(arg);
116337 +
116338 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116339 + return false;
116340 +
116341 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116342 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116343 +}
116344 +
116345 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116346 +{
116347 + gimple phi = get_def_stmt(result);
116348 + unsigned int i, n = gimple_phi_num_args(phi);
116349 +
116350 + pointer_set_insert(visited, phi);
116351 + for (i = 0; i < n; i++) {
116352 + tree arg = gimple_phi_arg_def(phi, i);
116353 +
116354 + walk_use_def(visited, cur_node, arg);
116355 + }
116356 +}
116357 +
116358 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116359 +{
116360 + gimple def_stmt = get_def_stmt(lhs);
116361 + tree rhs1, rhs2;
116362 +
116363 + rhs1 = gimple_assign_rhs1(def_stmt);
116364 + rhs2 = gimple_assign_rhs2(def_stmt);
116365 +
116366 + walk_use_def(visited, cur_node, rhs1);
116367 + walk_use_def(visited, cur_node, rhs2);
116368 +}
116369 +
116370 +static void insert_last_node(struct interesting_node *cur_node, tree node)
116371 +{
116372 + unsigned int i;
116373 + tree element;
116374 + enum tree_code code;
116375 +
116376 + gcc_assert(node != NULL_TREE);
116377 +
116378 + if (is_gimple_constant(node))
116379 + return;
116380 +
116381 + code = TREE_CODE(node);
116382 + if (code == VAR_DECL) {
116383 + node = DECL_ORIGIN(node);
116384 + code = TREE_CODE(node);
116385 + }
116386 +
116387 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
116388 + return;
116389 +
116390 +#if BUILDING_GCC_VERSION <= 4007
116391 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
116392 +#else
116393 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
116394 +#endif
116395 + if (operand_equal_p(node, element, 0))
116396 + return;
116397 + }
116398 +
116399 +#if BUILDING_GCC_VERSION <= 4007
116400 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
116401 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
116402 +#else
116403 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
116404 + vec_safe_push(cur_node->last_nodes, node);
116405 +#endif
116406 +}
116407 +
116408 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
116409 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
116410 +{
116411 + if (!is_size_overflow_asm(stmt))
116412 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116413 +}
116414 +
116415 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
116416 + * and component refs (for checking the intentional_overflow attribute).
116417 + */
116418 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116419 +{
116420 + const_gimple def_stmt;
116421 +
116422 + if (TREE_CODE(lhs) != SSA_NAME) {
116423 + insert_last_node(cur_node, lhs);
116424 + return;
116425 + }
116426 +
116427 + def_stmt = get_def_stmt(lhs);
116428 + if (!def_stmt)
116429 + return;
116430 +
116431 + if (pointer_set_insert(visited, def_stmt))
116432 + return;
116433 +
116434 + switch (gimple_code(def_stmt)) {
116435 + case GIMPLE_NOP:
116436 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
116437 + case GIMPLE_ASM:
116438 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
116439 + case GIMPLE_CALL: {
116440 + tree fndecl = gimple_call_fndecl(def_stmt);
116441 +
116442 + if (fndecl == NULL_TREE)
116443 + return;
116444 + insert_last_node(cur_node, fndecl);
116445 + return;
116446 + }
116447 + case GIMPLE_PHI:
116448 + return walk_use_def_phi(visited, cur_node, lhs);
116449 + case GIMPLE_ASSIGN:
116450 + switch (gimple_num_ops(def_stmt)) {
116451 + case 2:
116452 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
116453 + case 3:
116454 + return walk_use_def_binary(visited, cur_node, lhs);
116455 + }
116456 + default:
116457 + debug_gimple_stmt((gimple)def_stmt);
116458 + error("%s: unknown gimple code", __func__);
116459 + gcc_unreachable();
116460 + }
116461 +}
116462 +
116463 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
116464 +static void set_last_nodes(struct interesting_node *cur_node)
116465 +{
116466 + struct pointer_set_t *visited;
116467 +
116468 + visited = pointer_set_create();
116469 + walk_use_def(visited, cur_node, cur_node->node);
116470 + pointer_set_destroy(visited);
116471 +}
116472 +
116473 +enum precond {
116474 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
116475 +};
116476 +
116477 +/* 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.
116478 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
116479 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
116480 + * It skips the possible error codes too.
116481 + */
116482 +static enum precond check_preconditions(struct interesting_node *cur_node)
116483 +{
116484 + bool interesting_conditions[5] = {false, false, false, false, false};
116485 +
116486 + set_last_nodes(cur_node);
116487 +
116488 + check_intentional_attribute_ipa(cur_node);
116489 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
116490 + return NO_ATTRIBUTE_SEARCH;
116491 +
116492 + search_interesting_conditions(cur_node, interesting_conditions);
116493 +
116494 + // error code: a phi, unary assign (not cast) and returns only
116495 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
116496 + return NO_ATTRIBUTE_SEARCH;
116497 +
116498 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
116499 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
116500 + return NO_ATTRIBUTE_SEARCH;
116501 +
116502 + // unnecessary overflow check
116503 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
116504 + return NO_CHECK_INSERT;
116505 +
116506 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
116507 + return NO_CHECK_INSERT;
116508 +
116509 + return NONE;
116510 +}
116511 +
116512 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
116513 +{
116514 + const_gimple assign;
116515 + tree orig_type = TREE_TYPE(orig_node);
116516 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116517 +
116518 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116519 + return gimple_assign_lhs(assign);
116520 +}
116521 +
116522 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
116523 +{
116524 + void (*set_rhs)(gimple, tree);
116525 + gimple stmt = cur_node->first_stmt;
116526 + const_tree orig_node = cur_node->node;
116527 +
116528 + switch (gimple_code(stmt)) {
116529 + case GIMPLE_RETURN:
116530 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116531 + break;
116532 + case GIMPLE_CALL:
116533 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
116534 + break;
116535 + case GIMPLE_ASSIGN:
116536 + switch (cur_node->num) {
116537 + case 1:
116538 + set_rhs = &gimple_assign_set_rhs1;
116539 + break;
116540 + case 2:
116541 + set_rhs = &gimple_assign_set_rhs2;
116542 + break;
116543 +#if BUILDING_GCC_VERSION >= 4006
116544 + case 3:
116545 + set_rhs = &gimple_assign_set_rhs3;
116546 + break;
116547 +#endif
116548 + default:
116549 + gcc_unreachable();
116550 + }
116551 +
116552 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
116553 + break;
116554 + default:
116555 + debug_gimple_stmt(stmt);
116556 + gcc_unreachable();
116557 + }
116558 +
116559 + update_stmt(stmt);
116560 +}
116561 +
116562 +static struct visited *create_visited(void)
116563 +{
116564 + struct visited *new_node;
116565 +
116566 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
116567 + new_node->stmts = pointer_set_create();
116568 + new_node->my_stmts = pointer_set_create();
116569 + new_node->skip_expr_casts = pointer_set_create();
116570 + new_node->no_cast_check = pointer_set_create();
116571 + return new_node;
116572 +}
116573 +
116574 +static void free_visited(struct visited *visited)
116575 +{
116576 + pointer_set_destroy(visited->stmts);
116577 + pointer_set_destroy(visited->my_stmts);
116578 + pointer_set_destroy(visited->skip_expr_casts);
116579 + pointer_set_destroy(visited->no_cast_check);
116580 +
116581 + free(visited);
116582 +}
116583 +
116584 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
116585 + * 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
116586 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
116587 + */
116588 +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)
116589 +{
116590 + enum precond ret;
116591 + tree new_node, orig_node = cur_node->node;
116592 +
116593 + ret = check_preconditions(cur_node);
116594 + if (ret == NO_ATTRIBUTE_SEARCH)
116595 + return cnodes;
116596 +
116597 + cnodes = search_overflow_attribute(cnodes, cur_node);
116598 +
116599 + if (ret == NO_CHECK_INSERT)
116600 + return cnodes;
116601 +
116602 + new_node = expand(visited, caller_node, orig_node);
116603 + if (new_node == NULL_TREE)
116604 + return cnodes;
116605 +
116606 + change_orig_node(visited, cur_node, new_node);
116607 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
116608 +
116609 + return cnodes;
116610 +}
116611 +
116612 +// Check visited_fns interesting nodes.
116613 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
116614 +{
116615 + struct interesting_node *cur;
116616 +
116617 + for (cur = head; cur; cur = cur->next) {
116618 + if (!operand_equal_p(node, cur->node, 0))
116619 + continue;
116620 + if (num != cur->num)
116621 + continue;
116622 + if (first_stmt == cur->first_stmt)
116623 + return true;
116624 + }
116625 + return false;
116626 +}
116627 +
116628 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
116629 + 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
116630 + 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
116631 + the intentional_overflow attribute check. They are collected by set_last_nodes().
116632 + num: arg count of a call stmt or 0 when it is a ret
116633 + node: the recursion starts from here, it is a call arg or a return value
116634 + 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.
116635 + intentional_attr_decl: intentional_overflow attribute of the callee function
116636 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
116637 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
116638 + */
116639 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
116640 +{
116641 + struct interesting_node *new_node;
116642 + tree fndecl;
116643 + enum gimple_code code;
116644 +
116645 + gcc_assert(node != NULL_TREE);
116646 + code = gimple_code(first_stmt);
116647 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
116648 +
116649 + if (num == CANNOT_FIND_ARG)
116650 + return head;
116651 +
116652 + if (skip_types(node))
116653 + return head;
116654 +
116655 + if (skip_asm(node))
116656 + return head;
116657 +
116658 + if (is_gimple_call(first_stmt))
116659 + fndecl = gimple_call_fndecl(first_stmt);
116660 + else
116661 + fndecl = current_function_decl;
116662 +
116663 + if (fndecl == NULL_TREE)
116664 + return head;
116665 +
116666 + if (is_in_interesting_node(head, first_stmt, node, num))
116667 + return head;
116668 +
116669 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
116670 +
116671 + new_node->next = NULL;
116672 + new_node->first_stmt = first_stmt;
116673 +#if BUILDING_GCC_VERSION <= 4007
116674 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
116675 +#else
116676 + vec_alloc(new_node->last_nodes, VEC_LEN);
116677 +#endif
116678 + new_node->num = num;
116679 + new_node->node = node;
116680 + new_node->fndecl = fndecl;
116681 + new_node->intentional_attr_decl = MARK_NO;
116682 + new_node->intentional_attr_cur_fndecl = MARK_NO;
116683 + new_node->intentional_mark_from_gimple = asm_stmt;
116684 +
116685 + if (!head)
116686 + return new_node;
116687 +
116688 + new_node->next = head;
116689 + return new_node;
116690 +}
116691 +
116692 +/* 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).
116693 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
116694 + */
116695 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116696 +{
116697 + struct next_cgraph_node *cur_node;
116698 + tree ret = gimple_return_retval(stmt);
116699 +
116700 + if (ret == NULL_TREE)
116701 + return head;
116702 +
116703 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116704 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
116705 + continue;
116706 + if (cur_node->num == 0)
116707 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
116708 + }
116709 +
116710 + return head;
116711 +}
116712 +
116713 +/* 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).
116714 + * If the call stmt is in the next cgraph node list then it's an interesting call.
116715 + */
116716 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
116717 +{
116718 + unsigned int argnum;
116719 + tree arg;
116720 + const_tree fndecl;
116721 + struct next_cgraph_node *cur_node;
116722 +
116723 + fndecl = gimple_call_fndecl(stmt);
116724 + if (fndecl == NULL_TREE)
116725 + return head;
116726 +
116727 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
116728 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
116729 + continue;
116730 + argnum = get_correct_arg_count(cur_node->num, fndecl);
116731 + gcc_assert(argnum != CANNOT_FIND_ARG);
116732 + if (argnum == 0)
116733 + continue;
116734 +
116735 + arg = gimple_call_arg(stmt, argnum - 1);
116736 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
116737 + }
116738 +
116739 + return head;
116740 +}
116741 +
116742 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
116743 +{
116744 + if (!operand_equal_p(orig_node, node, 0))
116745 + return WRONG_NODE;
116746 + if (skip_types(node))
116747 + return WRONG_NODE;
116748 + return ret_count;
116749 +}
116750 +
116751 +// Get the index of the rhs node in an assignment
116752 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
116753 +{
116754 + const_tree rhs1, rhs2;
116755 + unsigned int ret;
116756 +
116757 + gcc_assert(stmt);
116758 + gcc_assert(is_gimple_assign(stmt));
116759 +
116760 + rhs1 = gimple_assign_rhs1(stmt);
116761 + gcc_assert(rhs1 != NULL_TREE);
116762 +
116763 + switch (gimple_num_ops(stmt)) {
116764 + case 2:
116765 + return check_ops(node, rhs1, 1);
116766 + case 3:
116767 + ret = check_ops(node, rhs1, 1);
116768 + if (ret != WRONG_NODE)
116769 + return ret;
116770 +
116771 + rhs2 = gimple_assign_rhs2(stmt);
116772 + gcc_assert(rhs2 != NULL_TREE);
116773 + return check_ops(node, rhs2, 2);
116774 + default:
116775 + gcc_unreachable();
116776 + }
116777 +}
116778 +
116779 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
116780 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
116781 +{
116782 + unsigned int i;
116783 +
116784 + if (gimple_call_fndecl(stmt) == NULL_TREE)
116785 + return CANNOT_FIND_ARG;
116786 +
116787 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
116788 + tree node;
116789 +
116790 + node = gimple_call_arg(stmt, i);
116791 + if (!operand_equal_p(arg, node, 0))
116792 + continue;
116793 + if (!skip_types(node))
116794 + return i + 1;
116795 + }
116796 +
116797 + return CANNOT_FIND_ARG;
116798 +}
116799 +
116800 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
116801 + * any of return, call or assignment stmts (because of inlining).
116802 + */
116803 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
116804 +{
116805 + use_operand_p use_p;
116806 + imm_use_iterator imm_iter;
116807 + unsigned int argnum;
116808 +
116809 + gcc_assert(TREE_CODE(node) == SSA_NAME);
116810 +
116811 + if (pointer_set_insert(visited, node))
116812 + return head;
116813 +
116814 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
116815 + gimple stmt = USE_STMT(use_p);
116816 +
116817 + if (stmt == NULL)
116818 + return head;
116819 + if (is_gimple_debug(stmt))
116820 + continue;
116821 +
116822 + switch (gimple_code(stmt)) {
116823 + case GIMPLE_CALL:
116824 + argnum = find_arg_number_gimple(node, stmt);
116825 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116826 + break;
116827 + case GIMPLE_RETURN:
116828 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
116829 + break;
116830 + case GIMPLE_ASSIGN:
116831 + argnum = get_assign_ops_count(stmt, node);
116832 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
116833 + break;
116834 + case GIMPLE_PHI: {
116835 + tree result = gimple_phi_result(stmt);
116836 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
116837 + break;
116838 + }
116839 + case GIMPLE_ASM:
116840 + if (gimple_asm_noutputs(stmt) != 0)
116841 + break;
116842 + if (!is_size_overflow_asm(stmt))
116843 + break;
116844 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
116845 + break;
116846 + case GIMPLE_COND:
116847 + case GIMPLE_SWITCH:
116848 + break;
116849 + default:
116850 + debug_gimple_stmt(stmt);
116851 + gcc_unreachable();
116852 + break;
116853 + }
116854 + }
116855 + return head;
116856 +}
116857 +
116858 +static void remove_size_overflow_asm(gimple stmt)
116859 +{
116860 + gimple_stmt_iterator gsi;
116861 + tree input, output;
116862 +
116863 + if (!is_size_overflow_asm(stmt))
116864 + return;
116865 +
116866 + if (gimple_asm_noutputs(stmt) == 0) {
116867 + gsi = gsi_for_stmt(stmt);
116868 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
116869 + gsi_remove(&gsi, true);
116870 + return;
116871 + }
116872 +
116873 + input = gimple_asm_input_op(stmt, 0);
116874 + output = gimple_asm_output_op(stmt, 0);
116875 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
116876 +}
116877 +
116878 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
116879 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
116880 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
116881 + */
116882 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
116883 +{
116884 + const_tree output;
116885 + struct pointer_set_t *visited;
116886 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
116887 +
116888 + if (!is_size_overflow_asm(stmt))
116889 + return head;
116890 +
116891 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
116892 + intentional_asm = stmt;
116893 +
116894 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
116895 +
116896 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
116897 + return head;
116898 +
116899 + if (gimple_asm_noutputs(stmt) == 0) {
116900 + const_tree input;
116901 +
116902 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
116903 + return head;
116904 +
116905 + input = gimple_asm_input_op(stmt, 0);
116906 + remove_size_overflow_asm(stmt);
116907 + if (is_gimple_constant(TREE_VALUE(input)))
116908 + return head;
116909 + visited = pointer_set_create();
116910 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
116911 + pointer_set_destroy(visited);
116912 + return head;
116913 + }
116914 +
116915 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
116916 + remove_size_overflow_asm(stmt);
116917 +
116918 + visited = pointer_set_create();
116919 + output = gimple_asm_output_op(stmt, 0);
116920 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
116921 + pointer_set_destroy(visited);
116922 + return head;
116923 +}
116924 +
116925 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
116926 + * or a call stmt or a return stmt and store them in the interesting_node list
116927 + */
116928 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
116929 +{
116930 + basic_block bb;
116931 + struct interesting_node *head = NULL;
116932 +
116933 + FOR_ALL_BB_FN(bb, cfun) {
116934 + gimple_stmt_iterator gsi;
116935 +
116936 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116937 + enum gimple_code code;
116938 + gimple stmt = gsi_stmt(gsi);
116939 +
116940 + code = gimple_code(stmt);
116941 +
116942 + if (code == GIMPLE_ASM)
116943 + head = handle_stmt_by_size_overflow_asm(stmt, head);
116944 +
116945 + if (!next_node)
116946 + continue;
116947 + if (code == GIMPLE_CALL)
116948 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
116949 + if (code == GIMPLE_RETURN)
116950 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
116951 + }
116952 + }
116953 + return head;
116954 +}
116955 +
116956 +static void free_interesting_node(struct interesting_node *head)
116957 +{
116958 + struct interesting_node *cur;
116959 +
116960 + while (head) {
116961 + cur = head->next;
116962 +#if BUILDING_GCC_VERSION <= 4007
116963 + VEC_free(tree, gc, head->last_nodes);
116964 +#else
116965 + vec_free(head->last_nodes);
116966 +#endif
116967 + free(head);
116968 + head = cur;
116969 + }
116970 +}
116971 +
116972 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116973 +{
116974 + struct visited_fns *new_visited_fns;
116975 +
116976 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
116977 + new_visited_fns->fndecl = cur_node->fndecl;
116978 + new_visited_fns->num = cur_node->num;
116979 + new_visited_fns->first_stmt = cur_node->first_stmt;
116980 + new_visited_fns->next = NULL;
116981 +
116982 + if (!head)
116983 + return new_visited_fns;
116984 +
116985 + new_visited_fns->next = head;
116986 + return new_visited_fns;
116987 +}
116988 +
116989 +/* 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
116990 + * it is a visited_fns function.
116991 + */
116992 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
116993 +{
116994 + struct visited_fns *cur;
116995 +
116996 + if (!head)
116997 + return false;
116998 +
116999 + for (cur = head; cur; cur = cur->next) {
117000 + if (cur_node->first_stmt != cur->first_stmt)
117001 + continue;
117002 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117003 + continue;
117004 + if (cur_node->num == cur->num)
117005 + return true;
117006 + }
117007 + return false;
117008 +}
117009 +
117010 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117011 +{
117012 + struct next_cgraph_node *cur;
117013 +
117014 + while (head) {
117015 + cur = head->next;
117016 + free(head);
117017 + head = cur;
117018 + }
117019 +}
117020 +
117021 +static void remove_all_size_overflow_asm(void)
117022 +{
117023 + basic_block bb;
117024 +
117025 + FOR_ALL_BB_FN(bb, cfun) {
117026 + gimple_stmt_iterator si;
117027 +
117028 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117029 + remove_size_overflow_asm(gsi_stmt(si));
117030 + }
117031 +}
117032 +
117033 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117034 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117035 + * the newly collected interesting functions (they are interesting if there is control flow between
117036 + * the interesting stmts and them).
117037 + */
117038 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
117039 +{
117040 + struct visited *visited;
117041 + struct interesting_node *head, *cur_node;
117042 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117043 +
117044 + set_current_function_decl(NODE_DECL(node));
117045 + call_count = 0;
117046 +
117047 + head = collect_interesting_stmts(next_node);
117048 +
117049 + visited = create_visited();
117050 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117051 + if (is_visited_fns_function(visited_fns, cur_node))
117052 + continue;
117053 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
117054 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
117055 + }
117056 +
117057 + free_visited(visited);
117058 + free_interesting_node(head);
117059 + remove_all_size_overflow_asm();
117060 + unset_current_function_decl();
117061 +
117062 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117063 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
117064 +
117065 + free_next_cgraph_node(cnodes_head);
117066 + return visited_fns;
117067 +}
117068 +
117069 +static void free_visited_fns(struct visited_fns *head)
117070 +{
117071 + struct visited_fns *cur;
117072 +
117073 + while (head) {
117074 + cur = head->next;
117075 + free(head);
117076 + head = cur;
117077 + }
117078 +}
117079 +
117080 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117081 +unsigned int search_function(void)
117082 +{
117083 + struct cgraph_node *node;
117084 + struct visited_fns *visited_fns = NULL;
117085 +
117086 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117087 + gcc_assert(cgraph_function_flags_ready);
117088 +#if BUILDING_GCC_VERSION <= 4007
117089 + gcc_assert(node->reachable);
117090 +#endif
117091 +
117092 + visited_fns = handle_function(node, NULL, visited_fns);
117093 + }
117094 +
117095 + free_visited_fns(visited_fns);
117096 + return 0;
117097 +}
117098 +
117099 +#if BUILDING_GCC_VERSION >= 4009
117100 +static const struct pass_data insert_size_overflow_check_data = {
117101 +#else
117102 +static struct ipa_opt_pass_d insert_size_overflow_check = {
117103 + .pass = {
117104 +#endif
117105 + .type = SIMPLE_IPA_PASS,
117106 + .name = "size_overflow",
117107 +#if BUILDING_GCC_VERSION >= 4008
117108 + .optinfo_flags = OPTGROUP_NONE,
117109 +#endif
117110 +#if BUILDING_GCC_VERSION >= 4009
117111 + .has_gate = false,
117112 + .has_execute = true,
117113 +#else
117114 + .gate = NULL,
117115 + .execute = search_function,
117116 + .sub = NULL,
117117 + .next = NULL,
117118 + .static_pass_number = 0,
117119 +#endif
117120 + .tv_id = TV_NONE,
117121 + .properties_required = 0,
117122 + .properties_provided = 0,
117123 + .properties_destroyed = 0,
117124 + .todo_flags_start = 0,
117125 + .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,
117126 +#if BUILDING_GCC_VERSION < 4009
117127 + },
117128 + .generate_summary = NULL,
117129 + .write_summary = NULL,
117130 + .read_summary = NULL,
117131 +#if BUILDING_GCC_VERSION >= 4006
117132 + .write_optimization_summary = NULL,
117133 + .read_optimization_summary = NULL,
117134 +#endif
117135 + .stmt_fixup = NULL,
117136 + .function_transform_todo_flags_start = 0,
117137 + .function_transform = NULL,
117138 + .variable_transform = NULL,
117139 +#endif
117140 +};
117141 +
117142 +#if BUILDING_GCC_VERSION >= 4009
117143 +namespace {
117144 +class insert_size_overflow_check : public ipa_opt_pass_d {
117145 +public:
117146 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117147 + unsigned int execute() { return search_function(); }
117148 +};
117149 +}
117150 +#endif
117151 +
117152 +struct opt_pass *make_insert_size_overflow_check(void)
117153 +{
117154 +#if BUILDING_GCC_VERSION >= 4009
117155 + return new insert_size_overflow_check();
117156 +#else
117157 + return &insert_size_overflow_check.pass;
117158 +#endif
117159 +}
117160 +
117161 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117162 new file mode 100644
117163 index 0000000..d71d72a
117164 --- /dev/null
117165 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
117166 @@ -0,0 +1,736 @@
117167 +/*
117168 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117169 + * Licensed under the GPL v2, or (at your option) v3
117170 + *
117171 + * Homepage:
117172 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117173 + *
117174 + * Documentation:
117175 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117176 + *
117177 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117178 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117179 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117180 + *
117181 + * Usage:
117182 + * $ make
117183 + * $ make run
117184 + */
117185 +
117186 +#include "gcc-common.h"
117187 +#include "size_overflow.h"
117188 +
117189 +/* Get the param of the intentional_overflow attribute.
117190 + * * 0: MARK_NOT_INTENTIONAL
117191 + * * 1..MAX_PARAM: MARK_YES
117192 + * * -1: MARK_TURN_OFF
117193 + */
117194 +static tree get_attribute_param(const_tree decl)
117195 +{
117196 + const_tree attr;
117197 +
117198 + if (decl == NULL_TREE)
117199 + return NULL_TREE;
117200 +
117201 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117202 + if (!attr || !TREE_VALUE(attr))
117203 + return NULL_TREE;
117204 +
117205 + return TREE_VALUE(attr);
117206 +}
117207 +
117208 +// MARK_TURN_OFF
117209 +bool is_turn_off_intentional_attr(const_tree decl)
117210 +{
117211 + const_tree param_head;
117212 +
117213 + param_head = get_attribute_param(decl);
117214 + if (param_head == NULL_TREE)
117215 + return false;
117216 +
117217 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117218 + return true;
117219 + return false;
117220 +}
117221 +
117222 +// MARK_NOT_INTENTIONAL
117223 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117224 +{
117225 + const_tree param_head;
117226 +
117227 + if (argnum == 0)
117228 + return false;
117229 +
117230 + param_head = get_attribute_param(decl);
117231 + if (param_head == NULL_TREE)
117232 + return false;
117233 +
117234 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117235 + return true;
117236 + return false;
117237 +}
117238 +
117239 +// MARK_YES
117240 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117241 +{
117242 + tree param, param_head;
117243 +
117244 + if (argnum == 0)
117245 + return false;
117246 +
117247 + param_head = get_attribute_param(decl);
117248 + for (param = param_head; param; param = TREE_CHAIN(param))
117249 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117250 + return true;
117251 + return false;
117252 +}
117253 +
117254 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117255 +{
117256 + location_t loc;
117257 +
117258 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117259 + return;
117260 +
117261 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117262 + return;
117263 +
117264 + loc = DECL_SOURCE_LOCATION(decl);
117265 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117266 +}
117267 +
117268 +// Get the field decl of a component ref for intentional_overflow checking
117269 +static const_tree search_field_decl(const_tree comp_ref)
117270 +{
117271 + const_tree field = NULL_TREE;
117272 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
117273 +
117274 + for (i = 0; i < len; i++) {
117275 + field = TREE_OPERAND(comp_ref, i);
117276 + if (TREE_CODE(field) == FIELD_DECL)
117277 + break;
117278 + }
117279 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
117280 + return field;
117281 +}
117282 +
117283 +/* Get the type of the intentional_overflow attribute of a node
117284 + * * MARK_TURN_OFF
117285 + * * MARK_YES
117286 + * * MARK_NO
117287 + * * MARK_NOT_INTENTIONAL
117288 + */
117289 +enum mark get_intentional_attr_type(const_tree node)
117290 +{
117291 + const_tree cur_decl;
117292 +
117293 + if (node == NULL_TREE)
117294 + return MARK_NO;
117295 +
117296 + switch (TREE_CODE(node)) {
117297 + case COMPONENT_REF:
117298 + cur_decl = search_field_decl(node);
117299 + if (is_turn_off_intentional_attr(cur_decl))
117300 + return MARK_TURN_OFF;
117301 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117302 + return MARK_YES;
117303 + break;
117304 + case PARM_DECL: {
117305 + unsigned int argnum;
117306 +
117307 + cur_decl = DECL_ORIGIN(current_function_decl);
117308 + argnum = find_arg_number_tree(node, cur_decl);
117309 + if (argnum == CANNOT_FIND_ARG)
117310 + return MARK_NO;
117311 + if (is_yes_intentional_attr(cur_decl, argnum))
117312 + return MARK_YES;
117313 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117314 + return MARK_NOT_INTENTIONAL;
117315 + break;
117316 + }
117317 + case FUNCTION_DECL:
117318 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117319 + return MARK_TURN_OFF;
117320 + break;
117321 + default:
117322 + break;
117323 + }
117324 + return MARK_NO;
117325 +}
117326 +
117327 +// Search for the intentional_overflow attribute on the last nodes
117328 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117329 +{
117330 + unsigned int i;
117331 + tree last_node;
117332 + enum mark mark = MARK_NO;
117333 +
117334 +#if BUILDING_GCC_VERSION <= 4007
117335 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117336 +#else
117337 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117338 +#endif
117339 + mark = get_intentional_attr_type(last_node);
117340 + if (mark != MARK_NO)
117341 + break;
117342 + }
117343 + return mark;
117344 +}
117345 +
117346 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117347 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117348 + */
117349 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117350 +{
117351 + if (!cur_node->intentional_mark_from_gimple)
117352 + return false;
117353 +
117354 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117355 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117356 + else
117357 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117358 +
117359 + // skip param decls
117360 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117361 + return true;
117362 + return true;
117363 +}
117364 +
117365 +/* Search intentional_overflow attribute on caller and on callee too.
117366 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117367 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117368 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117369 +*/
117370 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117371 +{
117372 + const_tree fndecl;
117373 +
117374 + if (is_intentional_attribute_from_gimple(cur_node))
117375 + return;
117376 +
117377 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117378 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117379 + return;
117380 + }
117381 +
117382 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117383 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117384 + return;
117385 + }
117386 +
117387 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117388 + return;
117389 +
117390 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117391 + if (is_turn_off_intentional_attr(fndecl)) {
117392 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117393 + return;
117394 + }
117395 +
117396 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117397 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117398 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117399 + cur_node->intentional_attr_decl = MARK_YES;
117400 +
117401 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117402 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117403 +}
117404 +
117405 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
117406 +{
117407 + const_tree rhs1, lhs, rhs1_type, lhs_type;
117408 + enum machine_mode lhs_mode, rhs_mode;
117409 + gimple def_stmt = get_def_stmt(no_const_rhs);
117410 +
117411 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117412 + return false;
117413 +
117414 + rhs1 = gimple_assign_rhs1(def_stmt);
117415 + lhs = gimple_assign_lhs(def_stmt);
117416 + rhs1_type = TREE_TYPE(rhs1);
117417 + lhs_type = TREE_TYPE(lhs);
117418 + rhs_mode = TYPE_MODE(rhs1_type);
117419 + lhs_mode = TYPE_MODE(lhs_type);
117420 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
117421 + return false;
117422 +
117423 + return true;
117424 +}
117425 +
117426 +static unsigned int uses_num(tree node)
117427 +{
117428 + imm_use_iterator imm_iter;
117429 + use_operand_p use_p;
117430 + unsigned int num = 0;
117431 +
117432 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117433 + gimple use_stmt = USE_STMT(use_p);
117434 +
117435 + if (use_stmt == NULL)
117436 + return num;
117437 + if (is_gimple_debug(use_stmt))
117438 + continue;
117439 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
117440 + continue;
117441 + num++;
117442 + }
117443 + return num;
117444 +}
117445 +
117446 +static bool no_uses(tree node)
117447 +{
117448 + return !uses_num(node);
117449 +}
117450 +
117451 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
117452 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
117453 +{
117454 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
117455 + gimple def_stmt = get_def_stmt(lhs);
117456 +
117457 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117458 + return false;
117459 +
117460 + rhs1 = gimple_assign_rhs1(def_stmt);
117461 + rhs_type = TREE_TYPE(rhs1);
117462 + lhs_type = TREE_TYPE(lhs);
117463 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
117464 + return false;
117465 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
117466 + return false;
117467 +
117468 + def_stmt = get_def_stmt(rhs1);
117469 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
117470 + return false;
117471 +
117472 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
117473 + return false;
117474 +
117475 + rhs1 = gimple_assign_rhs1(def_stmt);
117476 + rhs2 = gimple_assign_rhs2(def_stmt);
117477 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117478 + return false;
117479 +
117480 + if (is_gimple_constant(rhs2))
117481 + not_const_rhs = rhs1;
117482 + else
117483 + not_const_rhs = rhs2;
117484 +
117485 + return no_uses(not_const_rhs);
117486 +}
117487 +
117488 +static bool is_lt_signed_type_max(const_tree rhs)
117489 +{
117490 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
117491 +
117492 + if (!TYPE_UNSIGNED(type))
117493 + return true;
117494 +
117495 + switch (TYPE_MODE(type)) {
117496 + case QImode:
117497 + new_type = intQI_type_node;
117498 + break;
117499 + case HImode:
117500 + new_type = intHI_type_node;
117501 + break;
117502 + case SImode:
117503 + new_type = intSI_type_node;
117504 + break;
117505 + case DImode:
117506 + new_type = intDI_type_node;
117507 + break;
117508 + default:
117509 + debug_tree((tree)type);
117510 + gcc_unreachable();
117511 + }
117512 +
117513 + type_max = TYPE_MAX_VALUE(new_type);
117514 + if (!tree_int_cst_lt(type_max, rhs))
117515 + return true;
117516 +
117517 + return false;
117518 +}
117519 +
117520 +static bool is_gt_zero(const_tree rhs)
117521 +{
117522 + const_tree type = TREE_TYPE(rhs);
117523 +
117524 + if (TYPE_UNSIGNED(type))
117525 + return true;
117526 +
117527 + if (!tree_int_cst_lt(rhs, integer_zero_node))
117528 + return true;
117529 +
117530 + return false;
117531 +}
117532 +
117533 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
117534 +{
117535 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
117536 + return false;
117537 + if (!is_gimple_constant(rhs))
117538 + return false;
117539 +
117540 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
117541 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
117542 + return false;
117543 +
117544 + return true;
117545 +}
117546 +
117547 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
117548 +{
117549 + gimple assign;
117550 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117551 + tree origtype = TREE_TYPE(orig_rhs);
117552 +
117553 + gcc_assert(is_gimple_assign(stmt));
117554 +
117555 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117556 + pointer_set_insert(visited->my_stmts, assign);
117557 + return gimple_assign_lhs(assign);
117558 +}
117559 +
117560 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
117561 +{
117562 + tree new_rhs, orig_rhs;
117563 + void (*gimple_assign_set_rhs)(gimple, tree);
117564 + tree rhs1 = gimple_assign_rhs1(stmt);
117565 + tree rhs2 = gimple_assign_rhs2(stmt);
117566 + tree lhs = gimple_assign_lhs(stmt);
117567 +
117568 + if (!check_overflow)
117569 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117570 +
117571 + if (change_rhs == NULL_TREE)
117572 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117573 +
117574 + if (new_rhs2 == NULL_TREE) {
117575 + orig_rhs = rhs1;
117576 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
117577 + } else {
117578 + orig_rhs = rhs2;
117579 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
117580 + }
117581 +
117582 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
117583 +
117584 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
117585 + gimple_assign_set_rhs(stmt, new_rhs);
117586 + update_stmt(stmt);
117587 +
117588 + return create_assign(visited, stmt, lhs, AFTER_STMT);
117589 +}
117590 +
117591 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
117592 +{
117593 + gimple rhs1_def_stmt, rhs2_def_stmt;
117594 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
117595 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
117596 + const_tree rhs1 = gimple_assign_rhs1(stmt);
117597 + const_tree rhs2 = gimple_assign_rhs2(stmt);
117598 +
117599 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
117600 + return false;
117601 +
117602 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
117603 +
117604 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
117605 + return false;
117606 +
117607 + rhs1_def_stmt = get_def_stmt(rhs1);
117608 + rhs2_def_stmt = get_def_stmt(rhs2);
117609 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
117610 + return false;
117611 +
117612 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117613 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
117614 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
117615 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
117616 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
117617 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
117618 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
117619 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
117620 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
117621 + return false;
117622 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
117623 + return false;
117624 +
117625 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
117626 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
117627 + return true;
117628 +}
117629 +
117630 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
117631 +{
117632 + gimple assign;
117633 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117634 + tree type = TREE_TYPE(rhs1);
117635 + tree lhs = create_new_var(type);
117636 +
117637 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
117638 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
117639 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
117640 +
117641 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
117642 + update_stmt(assign);
117643 + pointer_set_insert(visited->my_stmts, assign);
117644 + return assign;
117645 +}
117646 +
117647 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
117648 +{
117649 + gimple_stmt_iterator gsi;
117650 + gimple cast_stmt;
117651 + tree type = TREE_TYPE(node);
117652 +
117653 + if (types_compatible_p(type, intTI_type_node))
117654 + return node;
117655 +
117656 + gsi = gsi_for_stmt(stmt);
117657 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
117658 + pointer_set_insert(visited->my_stmts, cast_stmt);
117659 + return gimple_assign_lhs(cast_stmt);
117660 +}
117661 +
117662 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
117663 +{
117664 + tree rhs1, def_stmt_rhs1;
117665 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
117666 +
117667 + def_stmt = get_def_stmt(var);
117668 + if (!gimple_assign_cast_p(def_stmt))
117669 + return NULL_TREE;
117670 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
117671 +
117672 + rhs1 = gimple_assign_rhs1(def_stmt);
117673 + rhs1_def_stmt = get_def_stmt(rhs1);
117674 + if (!gimple_assign_cast_p(rhs1_def_stmt))
117675 + return rhs1;
117676 +
117677 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
117678 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
117679 +
117680 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
117681 + case GIMPLE_CALL:
117682 + case GIMPLE_NOP:
117683 + case GIMPLE_ASM:
117684 + case GIMPLE_PHI:
117685 + return def_stmt_rhs1;
117686 + case GIMPLE_ASSIGN:
117687 + return rhs1;
117688 + default:
117689 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
117690 + gcc_unreachable();
117691 + }
117692 +}
117693 +
117694 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
117695 +{
117696 + tree new_rhs1, new_rhs2;
117697 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
117698 + gimple assign, stmt = get_def_stmt(lhs);
117699 + tree rhs1 = gimple_assign_rhs1(stmt);
117700 + tree rhs2 = gimple_assign_rhs2(stmt);
117701 +
117702 + if (!is_subtraction_special(visited, stmt))
117703 + return NULL_TREE;
117704 +
117705 + new_rhs1 = expand(visited, caller_node, rhs1);
117706 + new_rhs2 = expand(visited, caller_node, rhs2);
117707 +
117708 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
117709 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
117710 +
117711 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
117712 + return NULL_TREE;
117713 +
117714 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
117715 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
117716 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
117717 + }
117718 +
117719 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
117720 + new_lhs = gimple_assign_lhs(assign);
117721 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
117722 +
117723 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
117724 +}
117725 +
117726 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
117727 +{
117728 + const_gimple def_stmt;
117729 +
117730 + if (TREE_CODE(rhs) != SSA_NAME)
117731 + return false;
117732 +
117733 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
117734 + return false;
117735 +
117736 + def_stmt = get_def_stmt(rhs);
117737 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
117738 + return false;
117739 +
117740 + return true;
117741 +}
117742 +
117743 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
117744 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
117745 + * fffffff * 16 > signed max -> truncate
117746 + */
117747 +static bool look_for_mult_and_add(const_gimple stmt)
117748 +{
117749 + const_tree res;
117750 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
117751 + const_gimple def_stmt;
117752 +
117753 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
117754 + return false;
117755 + if (!is_gimple_assign(stmt))
117756 + return false;
117757 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
117758 + return false;
117759 +
117760 + rhs1 = gimple_assign_rhs1(stmt);
117761 + rhs2 = gimple_assign_rhs2(stmt);
117762 + if (is_gimple_constant(rhs1)) {
117763 + const_rhs = rhs1;
117764 + def_stmt = get_def_stmt(rhs2);
117765 + } else if (is_gimple_constant(rhs2)) {
117766 + const_rhs = rhs2;
117767 + def_stmt = get_def_stmt(rhs1);
117768 + } else
117769 + return false;
117770 +
117771 + if (!is_gimple_assign(def_stmt))
117772 + return false;
117773 +
117774 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
117775 + return false;
117776 +
117777 + def_rhs1 = gimple_assign_rhs1(def_stmt);
117778 + def_rhs2 = gimple_assign_rhs2(def_stmt);
117779 + if (is_gimple_constant(def_rhs1))
117780 + def_const_rhs = def_rhs1;
117781 + else if (is_gimple_constant(def_rhs2))
117782 + def_const_rhs = def_rhs2;
117783 + else
117784 + return false;
117785 +
117786 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
117787 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
117788 + return false;
117789 + return true;
117790 +}
117791 +
117792 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
117793 +{
117794 + const_gimple def_stmt_1, def_stmt_2;
117795 + const_tree rhs1, rhs2;
117796 + bool add_mul_rhs1, add_mul_rhs2;
117797 +
117798 + rhs1 = gimple_assign_rhs1(stmt);
117799 + def_stmt_1 = get_def_stmt(rhs1);
117800 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
117801 +
117802 + rhs2 = gimple_assign_rhs2(stmt);
117803 + def_stmt_2 = get_def_stmt(rhs2);
117804 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
117805 +
117806 + if (add_mul_rhs1)
117807 + return RHS1_INTENTIONAL_OVERFLOW;
117808 + if (add_mul_rhs2)
117809 + return RHS2_INTENTIONAL_OVERFLOW;
117810 + return NO_INTENTIONAL_OVERFLOW;
117811 +}
117812 +
117813 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
117814 +{
117815 + gimple my_stmt;
117816 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
117817 +
117818 + gsi_next(&gsi);
117819 + my_stmt = gsi_stmt(gsi);
117820 +
117821 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
117822 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
117823 +
117824 + return my_stmt;
117825 +}
117826 +
117827 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
117828 + * unsigned type cast to signed type, unsigned type: no more uses
117829 + * e.g., lib/vsprintf.c:simple_strtol()
117830 + * _10 = (unsigned long int) _9
117831 + * _11 = -_10;
117832 + * _12 = (long int) _11; (_11_ no more uses)
117833 + */
117834 +static bool is_call_or_cast(gimple stmt)
117835 +{
117836 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
117837 +}
117838 +
117839 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
117840 +{
117841 + const_tree rhs;
117842 + gimple def_stmt;
117843 +
117844 + if (node == NULL_TREE)
117845 + return true;
117846 + if (is_gimple_constant(node))
117847 + return true;
117848 +
117849 + def_stmt = get_def_stmt(node);
117850 + if (!def_stmt)
117851 + return false;
117852 +
117853 + if (is_call_or_cast(def_stmt))
117854 + return true;
117855 +
117856 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
117857 + return false;
117858 + rhs = gimple_assign_rhs1(def_stmt);
117859 + def_stmt = get_def_stmt(rhs);
117860 + if (!def_stmt)
117861 + return false;
117862 + return is_call_or_cast(def_stmt);
117863 +}
117864 +
117865 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
117866 +{
117867 + unsigned int use_num;
117868 + gimple so_stmt;
117869 + const_gimple def_stmt;
117870 + const_tree rhs1, rhs2;
117871 + tree rhs = gimple_assign_rhs1(stmt);
117872 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
117873 + const_tree rhs_type = TREE_TYPE(rhs);
117874 +
117875 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
117876 + return;
117877 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
117878 + return;
117879 + use_num = uses_num(rhs);
117880 + if (use_num != 1)
117881 + return;
117882 +
117883 + def_stmt = get_def_stmt(rhs);
117884 + if (!def_stmt)
117885 + return;
117886 + if (!is_gimple_assign(def_stmt))
117887 + return;
117888 +
117889 + rhs1 = gimple_assign_rhs1(def_stmt);
117890 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
117891 + return;
117892 +
117893 + rhs2 = gimple_assign_rhs2(def_stmt);
117894 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
117895 + return;
117896 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
117897 + return;
117898 +
117899 + so_stmt = get_dup_stmt(visited, stmt);
117900 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
117901 +}
117902 +
117903 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
117904 new file mode 100644
117905 index 0000000..4bddad2
117906 --- /dev/null
117907 +++ b/tools/gcc/size_overflow_plugin/misc.c
117908 @@ -0,0 +1,203 @@
117909 +/*
117910 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
117911 + * Licensed under the GPL v2, or (at your option) v3
117912 + *
117913 + * Homepage:
117914 + * http://www.grsecurity.net/~ephox/overflow_plugin/
117915 + *
117916 + * Documentation:
117917 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
117918 + *
117919 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
117920 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
117921 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
117922 + *
117923 + * Usage:
117924 + * $ make
117925 + * $ make run
117926 + */
117927 +
117928 +#include "gcc-common.h"
117929 +#include "size_overflow.h"
117930 +
117931 +void set_current_function_decl(tree fndecl)
117932 +{
117933 + gcc_assert(fndecl != NULL_TREE);
117934 +
117935 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117936 + calculate_dominance_info(CDI_DOMINATORS);
117937 + current_function_decl = fndecl;
117938 +}
117939 +
117940 +void unset_current_function_decl(void)
117941 +{
117942 + free_dominance_info(CDI_DOMINATORS);
117943 + pop_cfun();
117944 + current_function_decl = NULL_TREE;
117945 +}
117946 +
117947 +static bool is_bool(const_tree node)
117948 +{
117949 + const_tree type;
117950 +
117951 + if (node == NULL_TREE)
117952 + return false;
117953 +
117954 + type = TREE_TYPE(node);
117955 + if (!INTEGRAL_TYPE_P(type))
117956 + return false;
117957 + if (TREE_CODE(type) == BOOLEAN_TYPE)
117958 + return true;
117959 + if (TYPE_PRECISION(type) == 1)
117960 + return true;
117961 + return false;
117962 +}
117963 +
117964 +bool skip_types(const_tree var)
117965 +{
117966 + tree type;
117967 + enum tree_code code;
117968 +
117969 + if (is_gimple_constant(var))
117970 + return true;
117971 +
117972 + switch (TREE_CODE(var)) {
117973 + case ADDR_EXPR:
117974 +#if BUILDING_GCC_VERSION >= 4006
117975 + case MEM_REF:
117976 +#endif
117977 + case ARRAY_REF:
117978 + case BIT_FIELD_REF:
117979 + case INDIRECT_REF:
117980 + case TARGET_MEM_REF:
117981 + case COMPONENT_REF:
117982 + case VAR_DECL:
117983 + case VIEW_CONVERT_EXPR:
117984 + return true;
117985 + default:
117986 + break;
117987 + }
117988 +
117989 + code = TREE_CODE(var);
117990 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
117991 +
117992 + type = TREE_TYPE(var);
117993 + switch (TREE_CODE(type)) {
117994 + case INTEGER_TYPE:
117995 + case ENUMERAL_TYPE:
117996 + return false;
117997 + case BOOLEAN_TYPE:
117998 + return is_bool(var);
117999 + default:
118000 + return true;
118001 + }
118002 +}
118003 +
118004 +gimple get_def_stmt(const_tree node)
118005 +{
118006 + gcc_assert(node != NULL_TREE);
118007 +
118008 + if (skip_types(node))
118009 + return NULL;
118010 +
118011 + if (TREE_CODE(node) != SSA_NAME)
118012 + return NULL;
118013 + return SSA_NAME_DEF_STMT(node);
118014 +}
118015 +
118016 +tree create_new_var(tree type)
118017 +{
118018 + tree new_var = create_tmp_var(type, "cicus");
118019 +
118020 + add_referenced_var(new_var);
118021 + return new_var;
118022 +}
118023 +
118024 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
118025 +{
118026 + const_gimple def_stmt = get_def_stmt(rhs);
118027 +
118028 + if (force)
118029 + return false;
118030 +
118031 + if (is_gimple_constant(rhs))
118032 + return false;
118033 +
118034 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
118035 + return false;
118036 +
118037 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
118038 + return false;
118039 +
118040 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
118041 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
118042 + return false;
118043 +
118044 + return true;
118045 +}
118046 +
118047 +tree cast_a_tree(tree type, tree var)
118048 +{
118049 + gcc_assert(type != NULL_TREE);
118050 + gcc_assert(var != NULL_TREE);
118051 + gcc_assert(fold_convertible_p(type, var));
118052 +
118053 + return fold_convert(type, var);
118054 +}
118055 +
118056 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
118057 +{
118058 + gimple assign, def_stmt;
118059 +
118060 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
118061 + gcc_assert(!is_gimple_constant(rhs));
118062 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
118063 + gcc_unreachable();
118064 +
118065 + def_stmt = get_def_stmt(rhs);
118066 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
118067 + return def_stmt;
118068 +
118069 + if (lhs == CREATE_NEW_VAR)
118070 + lhs = create_new_var(dst_type);
118071 +
118072 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
118073 +
118074 + if (!gsi_end_p(*gsi)) {
118075 + location_t loc = gimple_location(gsi_stmt(*gsi));
118076 + gimple_set_location(assign, loc);
118077 + }
118078 +
118079 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
118080 +
118081 + if (before)
118082 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
118083 + else
118084 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
118085 + update_stmt(assign);
118086 + return assign;
118087 +}
118088 +
118089 +bool is_size_overflow_type(const_tree var)
118090 +{
118091 + const char *name;
118092 + const_tree type_name, type;
118093 +
118094 + if (var == NULL_TREE)
118095 + return false;
118096 +
118097 + type = TREE_TYPE(var);
118098 + type_name = TYPE_NAME(type);
118099 + if (type_name == NULL_TREE)
118100 + return false;
118101 +
118102 + if (DECL_P(type_name))
118103 + name = DECL_NAME_POINTER(type_name);
118104 + else
118105 + name = IDENTIFIER_POINTER(type_name);
118106 +
118107 + if (!strncmp(name, "size_overflow_type", 18))
118108 + return true;
118109 + return false;
118110 +}
118111 +
118112 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
118113 new file mode 100644
118114 index 0000000..7c9e6d1
118115 --- /dev/null
118116 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
118117 @@ -0,0 +1,138 @@
118118 +/*
118119 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118120 + * Licensed under the GPL v2, or (at your option) v3
118121 + *
118122 + * Homepage:
118123 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118124 + *
118125 + * Documentation:
118126 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118127 + *
118128 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118129 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118130 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118131 + *
118132 + * Usage:
118133 + * $ make
118134 + * $ make run
118135 + */
118136 +
118137 +#include "gcc-common.h"
118138 +#include "size_overflow.h"
118139 +
118140 +bool skip_expr_on_double_type(const_gimple stmt)
118141 +{
118142 + enum tree_code code = gimple_assign_rhs_code(stmt);
118143 +
118144 + switch (code) {
118145 + case RSHIFT_EXPR:
118146 + case TRUNC_DIV_EXPR:
118147 + case CEIL_DIV_EXPR:
118148 + case FLOOR_DIV_EXPR:
118149 + case ROUND_DIV_EXPR:
118150 + case EXACT_DIV_EXPR:
118151 + case RDIV_EXPR:
118152 + case TRUNC_MOD_EXPR:
118153 + case CEIL_MOD_EXPR:
118154 + case FLOOR_MOD_EXPR:
118155 + case ROUND_MOD_EXPR:
118156 + return true;
118157 + default:
118158 + return false;
118159 + }
118160 +}
118161 +
118162 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
118163 +{
118164 + const_tree orig_rhs1;
118165 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
118166 + gimple down_cast, up_cast;
118167 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
118168 +
118169 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118170 + down_lhs = gimple_assign_lhs(down_cast);
118171 +
118172 + gsi = gsi_for_stmt(use_stmt);
118173 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
118174 + new_lhs = gimple_assign_lhs(up_cast);
118175 +
118176 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
118177 + if (operand_equal_p(orig_rhs1, rhs, 0))
118178 + gimple_assign_set_rhs1(use_stmt, new_lhs);
118179 + else
118180 + gimple_assign_set_rhs2(use_stmt, new_lhs);
118181 + update_stmt(use_stmt);
118182 +
118183 + pointer_set_insert(visited->my_stmts, up_cast);
118184 + pointer_set_insert(visited->my_stmts, down_cast);
118185 + pointer_set_insert(visited->skip_expr_casts, up_cast);
118186 + pointer_set_insert(visited->skip_expr_casts, down_cast);
118187 +}
118188 +
118189 +static tree get_proper_unsigned_half_type(const_tree node)
118190 +{
118191 + tree new_type, type;
118192 +
118193 + gcc_assert(is_size_overflow_type(node));
118194 +
118195 + type = TREE_TYPE(node);
118196 + switch (TYPE_MODE(type)) {
118197 + case HImode:
118198 + new_type = unsigned_intQI_type_node;
118199 + break;
118200 + case SImode:
118201 + new_type = unsigned_intHI_type_node;
118202 + break;
118203 + case DImode:
118204 + new_type = unsigned_intSI_type_node;
118205 + break;
118206 + case TImode:
118207 + new_type = unsigned_intDI_type_node;
118208 + break;
118209 + default:
118210 + gcc_unreachable();
118211 + }
118212 +
118213 + if (TYPE_QUALS(type) != 0)
118214 + return build_qualified_type(new_type, TYPE_QUALS(type));
118215 + return new_type;
118216 +}
118217 +
118218 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
118219 +{
118220 + tree type;
118221 +
118222 + if (rhs == NULL_TREE)
118223 + return;
118224 + if (!is_size_overflow_type(rhs))
118225 + return;
118226 +
118227 + type = get_proper_unsigned_half_type(rhs);
118228 + if (is_gimple_constant(rhs))
118229 + return;
118230 + create_up_and_down_cast(visited, stmt, type, rhs);
118231 +}
118232 +
118233 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
118234 +{
118235 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
118236 + return;
118237 + gcc_assert(is_size_overflow_type(rhs));
118238 + insert_cast_rhs(visited, stmt, rhs);
118239 +}
118240 +
118241 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
118242 +{
118243 + tree rhs1, rhs2;
118244 +
118245 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
118246 + rhs1 = gimple_assign_rhs1(stmt);
118247 + insert_cast(visited, stmt, rhs1);
118248 + }
118249 +
118250 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
118251 + rhs2 = gimple_assign_rhs2(stmt);
118252 + insert_cast(visited, stmt, rhs2);
118253 + }
118254 +}
118255 +
118256 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
118257 new file mode 100644
118258 index 0000000..e5b4e50
118259 --- /dev/null
118260 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
118261 @@ -0,0 +1,127 @@
118262 +#ifndef SIZE_OVERFLOW_H
118263 +#define SIZE_OVERFLOW_H
118264 +
118265 +#define CREATE_NEW_VAR NULL_TREE
118266 +#define CANNOT_FIND_ARG 32
118267 +#define MAX_PARAM 31
118268 +#define BEFORE_STMT true
118269 +#define AFTER_STMT false
118270 +
118271 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
118272 +#define YES_ASM_STR "# size_overflow MARK_YES "
118273 +#define OK_ASM_STR "# size_overflow "
118274 +
118275 +enum mark {
118276 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
118277 +};
118278 +
118279 +enum intentional_overflow_type {
118280 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
118281 +};
118282 +
118283 +struct visited {
118284 + struct pointer_set_t *stmts;
118285 + struct pointer_set_t *my_stmts;
118286 + struct pointer_set_t *skip_expr_casts;
118287 + struct pointer_set_t *no_cast_check;
118288 +};
118289 +
118290 +// size_overflow_plugin.c
118291 +extern tree report_size_overflow_decl;
118292 +extern tree size_overflow_type_HI;
118293 +extern tree size_overflow_type_SI;
118294 +extern tree size_overflow_type_DI;
118295 +extern tree size_overflow_type_TI;
118296 +
118297 +
118298 +// size_overflow_plugin_hash.c
118299 +struct size_overflow_hash {
118300 + const struct size_overflow_hash * const next;
118301 + const char * const name;
118302 + const unsigned int param;
118303 +};
118304 +
118305 +struct interesting_node {
118306 + struct interesting_node *next;
118307 + gimple first_stmt;
118308 + const_tree fndecl;
118309 + tree node;
118310 +#if BUILDING_GCC_VERSION <= 4007
118311 + VEC(tree, gc) *last_nodes;
118312 +#else
118313 + vec<tree, va_gc> *last_nodes;
118314 +#endif
118315 + unsigned int num;
118316 + enum mark intentional_attr_decl;
118317 + enum mark intentional_attr_cur_fndecl;
118318 + gimple intentional_mark_from_gimple;
118319 +};
118320 +
118321 +extern bool is_size_overflow_asm(const_gimple stmt);
118322 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
118323 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
118324 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
118325 +extern bool is_a_return_check(const_tree node);
118326 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
118327 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
118328 +
118329 +
118330 +// size_overflow_debug.c
118331 +extern struct opt_pass *make_dump_pass(void);
118332 +
118333 +
118334 +// intentional_overflow.c
118335 +extern enum mark get_intentional_attr_type(const_tree node);
118336 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
118337 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
118338 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
118339 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
118340 +extern bool is_turn_off_intentional_attr(const_tree decl);
118341 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
118342 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
118343 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
118344 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
118345 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
118346 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
118347 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
118348 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
118349 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
118350 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
118351 +
118352 +
118353 +// insert_size_overflow_check_ipa.c
118354 +extern unsigned int search_function(void);
118355 +extern unsigned int call_count;
118356 +extern struct opt_pass *make_insert_size_overflow_check(void);
118357 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
118358 +
118359 +
118360 +// insert_size_overflow_asm.c
118361 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
118362 +
118363 +
118364 +// misc.c
118365 +extern void set_current_function_decl(tree fndecl);
118366 +extern void unset_current_function_decl(void);
118367 +extern gimple get_def_stmt(const_tree node);
118368 +extern tree create_new_var(tree type);
118369 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
118370 +extern bool skip_types(const_tree var);
118371 +extern tree cast_a_tree(tree type, tree var);
118372 +extern bool is_size_overflow_type(const_tree var);
118373 +
118374 +
118375 +// insert_size_overflow_check_core.c
118376 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
118377 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
118378 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
118379 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
118380 +
118381 +
118382 +// remove_unnecessary_dup.c
118383 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
118384 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
118385 +extern bool skip_expr_on_double_type(const_gimple stmt);
118386 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
118387 +
118388 +#endif
118389 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118390 new file mode 100644
118391 index 0000000..4378111
118392 --- /dev/null
118393 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
118394 @@ -0,0 +1,116 @@
118395 +/*
118396 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
118397 + * Licensed under the GPL v2, or (at your option) v3
118398 + *
118399 + * Homepage:
118400 + * http://www.grsecurity.net/~ephox/overflow_plugin/
118401 + *
118402 + * Documentation:
118403 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
118404 + *
118405 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
118406 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
118407 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
118408 + *
118409 + * Usage:
118410 + * $ make
118411 + * $ make run
118412 + */
118413 +
118414 +#include "gcc-common.h"
118415 +
118416 +static unsigned int dump_functions(void)
118417 +{
118418 + struct cgraph_node *node;
118419 +
118420 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118421 + basic_block bb;
118422 +
118423 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118424 + current_function_decl = NODE_DECL(node);
118425 +
118426 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118427 +
118428 + FOR_ALL_BB_FN(bb, cfun) {
118429 + gimple_stmt_iterator si;
118430 +
118431 + fprintf(stderr, "<bb %u>:\n", bb->index);
118432 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118433 + debug_gimple_stmt(gsi_stmt(si));
118434 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118435 + debug_gimple_stmt(gsi_stmt(si));
118436 + fprintf(stderr, "\n");
118437 + }
118438 +
118439 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118440 +
118441 + pop_cfun();
118442 + current_function_decl = NULL_TREE;
118443 + }
118444 +
118445 + fprintf(stderr, "###############################################################################\n");
118446 +
118447 + return 0;
118448 +}
118449 +
118450 +#if BUILDING_GCC_VERSION >= 4009
118451 +static const struct pass_data dump_pass_data = {
118452 +#else
118453 +static struct ipa_opt_pass_d dump_pass = {
118454 + .pass = {
118455 +#endif
118456 + .type = SIMPLE_IPA_PASS,
118457 + .name = "dump",
118458 +#if BUILDING_GCC_VERSION >= 4008
118459 + .optinfo_flags = OPTGROUP_NONE,
118460 +#endif
118461 +#if BUILDING_GCC_VERSION >= 4009
118462 + .has_gate = false,
118463 + .has_execute = true,
118464 +#else
118465 + .gate = NULL,
118466 + .execute = dump_functions,
118467 + .sub = NULL,
118468 + .next = NULL,
118469 + .static_pass_number = 0,
118470 +#endif
118471 + .tv_id = TV_NONE,
118472 + .properties_required = 0,
118473 + .properties_provided = 0,
118474 + .properties_destroyed = 0,
118475 + .todo_flags_start = 0,
118476 + .todo_flags_finish = 0,
118477 +#if BUILDING_GCC_VERSION < 4009
118478 + },
118479 + .generate_summary = NULL,
118480 + .write_summary = NULL,
118481 + .read_summary = NULL,
118482 +#if BUILDING_GCC_VERSION >= 4006
118483 + .write_optimization_summary = NULL,
118484 + .read_optimization_summary = NULL,
118485 +#endif
118486 + .stmt_fixup = NULL,
118487 + .function_transform_todo_flags_start = 0,
118488 + .function_transform = NULL,
118489 + .variable_transform = NULL,
118490 +#endif
118491 +};
118492 +
118493 +#if BUILDING_GCC_VERSION >= 4009
118494 +namespace {
118495 +class dump_pass : public ipa_opt_pass_d {
118496 +public:
118497 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118498 + unsigned int execute() { return dump_functions(); }
118499 +};
118500 +}
118501 +#endif
118502 +
118503 +struct opt_pass *make_dump_pass(void)
118504 +{
118505 +#if BUILDING_GCC_VERSION >= 4009
118506 + return new dump_pass();
118507 +#else
118508 + return &dump_pass.pass;
118509 +#endif
118510 +}
118511 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118512 new file mode 100644
118513 index 0000000..1f45ba9
118514 --- /dev/null
118515 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
118516 @@ -0,0 +1,6032 @@
118517 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
118518 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
118519 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
118520 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
118521 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
118522 +padzero_55 padzero 1 55 &sel_read_policyvers_55
118523 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
118524 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
118525 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
118526 +load_msg_95 load_msg 2 95 NULL
118527 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
118528 +init_q_132 init_q 4 132 NULL
118529 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
118530 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
118531 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
118532 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
118533 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
118534 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
118535 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
118536 +obd_proc_jobid_var_seq_write_199 obd_proc_jobid_var_seq_write 3 199 NULL
118537 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
118538 +vpdma_create_desc_list_255 vpdma_create_desc_list 2 255 NULL
118539 +br_port_info_size_268 br_port_info_size 0 268 NULL
118540 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
118541 +SYSC_connect_304 SYSC_connect 3 304 NULL
118542 +syslog_print_307 syslog_print 2 307 NULL
118543 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
118544 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
118545 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
118546 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
118547 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
118548 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
118549 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
118550 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
118551 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
118552 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
118553 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
118554 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
118555 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
118556 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
118557 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
118558 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
118559 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
118560 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
118561 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
118562 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
118563 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
118564 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
118565 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
118566 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
118567 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
118568 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
118569 +unlink_queued_645 unlink_queued 4 645 NULL
118570 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
118571 +nvif_notify_new_671 nvif_notify_new 6 671 NULL
118572 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
118573 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
118574 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
118575 +dvb_video_write_754 dvb_video_write 3 754 NULL
118576 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
118577 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
118578 +if_writecmd_815 if_writecmd 2 815 NULL
118579 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
118580 +error_state_read_859 error_state_read 6 859 NULL
118581 +lustre_init_msg_v2_864 lustre_init_msg_v2 2 864 NULL
118582 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
118583 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
118584 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
118585 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
118586 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
118587 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
118588 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
118589 +readreg_1017 readreg 0-1 1017 NULL
118590 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
118591 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
118592 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
118593 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
118594 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
118595 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
118596 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
118597 +__arch_hweight8_1105 __arch_hweight8 0 1105 NULL
118598 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
118599 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
118600 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
118601 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
118602 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
118603 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
118604 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
118605 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
118606 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
118607 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
118608 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
118609 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
118610 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
118611 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
118612 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
118613 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
118614 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
118615 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
118616 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
118617 +ffs_1322 ffs 0 1322 NULL
118618 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
118619 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
118620 +bond_verify_device_path_1352 bond_verify_device_path 3 1352 NULL
118621 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
118622 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
118623 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
118624 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
118625 +xpcs_reg_addr_read_1381 xpcs_reg_addr_read 3 1381 NULL
118626 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
118627 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
118628 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
118629 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
118630 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
118631 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
118632 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
118633 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
118634 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
118635 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
118636 +fpregs_set_1497 fpregs_set 4 1497 NULL
118637 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
118638 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
118639 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
118640 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
118641 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
118642 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
118643 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
118644 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
118645 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
118646 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
118647 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
118648 +rmap_add_1677 rmap_add 3 1677 NULL
118649 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
118650 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
118651 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
118652 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
118653 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
118654 +internal_create_group_1733 internal_create_group 0 1733 NULL
118655 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
118656 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
118657 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
118658 +cosa_write_1774 cosa_write 3 1774 NULL
118659 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
118660 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
118661 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
118662 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
118663 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
118664 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
118665 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
118666 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
118667 +azx_get_position_1927 azx_get_position 0 1927 NULL
118668 +bdev_erase_1933 bdev_erase 3 1933 NULL
118669 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
118670 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL nohasharray
118671 +nvif_object_sclass_1940 nvif_object_sclass 3 1940 &cyttsp_probe_1940
118672 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
118673 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
118674 +qla2xxx_get_vpd_field_1965 qla2xxx_get_vpd_field 4 1965 NULL
118675 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
118676 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
118677 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
118678 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
118679 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
118680 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
118681 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
118682 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
118683 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
118684 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
118685 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
118686 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
118687 +xgmac_reg_value_read_2095 xgmac_reg_value_read 3 2095 NULL
118688 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
118689 +audit_expand_2098 audit_expand 0 2098 NULL
118690 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
118691 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
118692 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
118693 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
118694 +enable_read_2117 enable_read 3 2117 NULL
118695 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
118696 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
118697 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
118698 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
118699 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
118700 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
118701 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
118702 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
118703 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
118704 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
118705 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
118706 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
118707 +do_update_counters_2259 do_update_counters 4 2259 NULL
118708 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
118709 +vpdma_alloc_desc_buf_2278 vpdma_alloc_desc_buf 2 2278 NULL
118710 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
118711 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
118712 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
118713 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
118714 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
118715 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
118716 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
118717 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
118718 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
118719 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
118720 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
118721 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
118722 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
118723 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
118724 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
118725 +raid1_size_2419 raid1_size 0-2 2419 NULL
118726 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
118727 +wiphy_new_2482 wiphy_new 2 2482 NULL
118728 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
118729 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
118730 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
118731 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
118732 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
118733 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
118734 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
118735 +sfw_create_rpc_2562 sfw_create_rpc 4 2562 NULL
118736 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
118737 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
118738 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
118739 +slot_bytes_2609 slot_bytes 0 2609 NULL
118740 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
118741 +switch_status_2629 switch_status 5 2629 NULL
118742 +_proc_do_string_2632 _proc_do_string 2 2632 NULL
118743 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
118744 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
118745 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
118746 +oti6858_write_2692 oti6858_write 4 2692 NULL
118747 +copy_to_iter_iovec_2697 copy_to_iter_iovec 2 2697 NULL
118748 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
118749 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
118750 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
118751 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
118752 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
118753 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
118754 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
118755 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
118756 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
118757 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
118758 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
118759 +sock_create_2838 sock_create 0 2838 NULL
118760 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
118761 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
118762 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
118763 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
118764 +nla_padlen_2883 nla_padlen 1 2883 NULL
118765 +cmm_write_2896 cmm_write 3 2896 NULL
118766 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
118767 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
118768 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
118769 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
118770 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
118771 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
118772 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
118773 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
118774 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
118775 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
118776 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
118777 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
118778 +depth_write_3021 depth_write 3 3021 NULL
118779 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
118780 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
118781 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
118782 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
118783 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
118784 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
118785 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
118786 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
118787 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
118788 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
118789 +hfsplus_asc2uni_3071 hfsplus_asc2uni 0 3071 NULL nohasharray
118790 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 &hfsplus_asc2uni_3071
118791 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
118792 +bio_integrity_intervals_3094 bio_integrity_intervals 0-2 3094 NULL
118793 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
118794 +rb_alloc_3102 rb_alloc 1 3102 NULL
118795 +ufshcd_get_rsp_upiu_result_3114 ufshcd_get_rsp_upiu_result 0 3114 NULL
118796 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
118797 +print_time_3132 print_time 0 3132 NULL
118798 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
118799 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
118800 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
118801 +pkcs7_sig_note_signature_3178 pkcs7_sig_note_signature 5 3178 NULL
118802 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
118803 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
118804 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
118805 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
118806 +alloc_context_3194 alloc_context 1 3194 NULL
118807 +dma_init_coherent_memory_3197 dma_init_coherent_memory 3 3197 NULL
118808 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
118809 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
118810 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
118811 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
118812 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
118813 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
118814 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
118815 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
118816 +key_key_read_3241 key_key_read 3 3241 NULL
118817 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
118818 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
118819 +cgroup_name_3300 cgroup_name 3 3300 NULL
118820 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
118821 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
118822 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
118823 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
118824 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
118825 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
118826 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
118827 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
118828 +scnprintf_3360 scnprintf 0-2 3360 NULL
118829 +sr_read_3366 sr_read 3 3366 NULL
118830 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
118831 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
118832 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
118833 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
118834 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
118835 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
118836 +softsynth_write_3455 softsynth_write 3 3455 NULL
118837 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
118838 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
118839 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
118840 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
118841 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
118842 +SyS_readv_3539 SyS_readv 3 3539 NULL
118843 +nouveau_fuse_create__3546 nouveau_fuse_create_ 4 3546 NULL
118844 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
118845 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
118846 +evtchn_read_3569 evtchn_read 3 3569 NULL
118847 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
118848 +vc_resize_3585 vc_resize 3-2 3585 NULL
118849 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
118850 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
118851 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
118852 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
118853 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
118854 +fm10k_alloc_q_vector_3638 fm10k_alloc_q_vector 4-6 3638 NULL
118855 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
118856 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
118857 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
118858 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
118859 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
118860 +msm_otg_mode_write_3788 msm_otg_mode_write 3 3788 NULL
118861 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
118862 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
118863 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
118864 +ceph_do_getattr_3838 ceph_do_getattr 0 3838 NULL
118865 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
118866 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
118867 +get_fd_set_3866 get_fd_set 1 3866 NULL
118868 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
118869 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
118870 +nvram_write_3894 nvram_write 3 3894 NULL
118871 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
118872 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
118873 +vcs_write_3910 vcs_write 3 3910 NULL
118874 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
118875 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
118876 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
118877 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
118878 +copy_from_user_atomic_iovec_3990 copy_from_user_atomic_iovec 0-4 3990 NULL
118879 +do_add_counters_3992 do_add_counters 3 3992 NULL
118880 +userspace_status_4004 userspace_status 4 4004 NULL
118881 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
118882 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
118883 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
118884 +blk_end_request_4024 blk_end_request 3 4024 NULL
118885 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
118886 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
118887 +read_file_queues_4078 read_file_queues 3 4078 NULL
118888 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
118889 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
118890 +tm6000_read_4151 tm6000_read 3 4151 NULL
118891 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
118892 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
118893 +get_alua_req_4166 get_alua_req 3 4166 NULL
118894 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
118895 +read_file_bool_4180 read_file_bool 3 4180 NULL
118896 +lstcon_test_add_4190 lstcon_test_add 10 4190 NULL
118897 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
118898 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
118899 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
118900 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
118901 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
118902 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
118903 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
118904 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
118905 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
118906 +count_strings_4315 count_strings 0 4315 NULL nohasharray
118907 +cfg80211_inform_bss_4315 cfg80211_inform_bss 9 4315 &count_strings_4315
118908 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
118909 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
118910 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
118911 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
118912 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
118913 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
118914 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
118915 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
118916 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
118917 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
118918 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
118919 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
118920 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
118921 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
118922 +set_link_security_4502 set_link_security 4 4502 NULL
118923 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
118924 +tty_register_device_4544 tty_register_device 2 4544 NULL
118925 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
118926 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
118927 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
118928 +bch_alloc_4593 bch_alloc 1 4593 NULL
118929 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
118930 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
118931 +nve0_gpio_intr_mask_4665 nve0_gpio_intr_mask 4-3 4665 NULL
118932 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
118933 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
118934 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
118935 +kone_receive_4690 kone_receive 4 4690 NULL
118936 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
118937 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
118938 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
118939 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
118940 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
118941 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
118942 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
118943 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
118944 +create_subvol_4791 create_subvol 4 4791 NULL
118945 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
118946 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
118947 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
118948 +scsi_end_request_4839 scsi_end_request 3-4 4839 NULL
118949 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
118950 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
118951 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
118952 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
118953 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
118954 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
118955 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
118956 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
118957 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
118958 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
118959 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
118960 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
118961 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
118962 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
118963 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
118964 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
118965 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
118966 +get_random_bytes_5091 get_random_bytes 2 5091 NULL nohasharray
118967 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 &get_random_bytes_5091 nohasharray
118968 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &kfifo_copy_from_user_5091
118969 +sound_write_5102 sound_write 3 5102 NULL
118970 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
118971 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
118972 +bucket_table_alloc_5149 bucket_table_alloc 1 5149 NULL
118973 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
118974 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
118975 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
118976 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
118977 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
118978 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
118979 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
118980 +ipv4_tun_to_nlattr_5261 ipv4_tun_to_nlattr 4 5261 NULL
118981 +dvb_ringbuffer_write_user_5270 dvb_ringbuffer_write_user 3 5270 NULL
118982 +xgmac_reg_addr_read_5278 xgmac_reg_addr_read 3 5278 NULL
118983 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
118984 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
118985 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
118986 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
118987 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
118988 +cq_free_res_5355 cq_free_res 5 5355 NULL
118989 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
118990 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
118991 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
118992 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
118993 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
118994 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
118995 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3 5482 NULL
118996 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
118997 +tty_write_5494 tty_write 3 5494 NULL
118998 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
118999 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
119000 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
119001 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
119002 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
119003 +le_readq_5557 le_readq 0 5557 NULL
119004 +inw_5558 inw 0 5558 NULL
119005 +bioset_create_5580 bioset_create 1 5580 NULL
119006 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
119007 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
119008 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
119009 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
119010 +get_arg_5694 get_arg 3 5694 NULL
119011 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
119012 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
119013 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
119014 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
119015 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
119016 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL nohasharray
119017 +ath10k_core_create_5806 ath10k_core_create 1 5806 &skb_copy_datagram_iovec_5806
119018 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
119019 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
119020 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
119021 +setup_req_5848 setup_req 3 5848 NULL
119022 +ria_page_count_5849 ria_page_count 0 5849 NULL
119023 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
119024 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
119025 +config_buf_5862 config_buf 0 5862 NULL nohasharray
119026 +ufshcd_check_query_response_5862 ufshcd_check_query_response 0 5862 &config_buf_5862
119027 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
119028 +port_show_regs_5904 port_show_regs 3 5904 NULL
119029 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
119030 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
119031 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
119032 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
119033 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
119034 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
119035 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
119036 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
119037 +SyS_semop_5980 SyS_semop 3 5980 NULL
119038 +btrfs_item_offset_6019 btrfs_item_offset 0 6019 NULL
119039 +alloc_msg_6072 alloc_msg 1 6072 NULL
119040 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
119041 +_random_read_6098 _random_read 3 6098 NULL
119042 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
119043 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
119044 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
119045 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
119046 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
119047 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
119048 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
119049 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
119050 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
119051 +snd_efw_command_get_phys_meters_6190 snd_efw_command_get_phys_meters 3 6190 NULL
119052 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
119053 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
119054 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
119055 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
119056 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
119057 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
119058 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
119059 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
119060 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
119061 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
119062 +serial_port_in_6291 serial_port_in 0 6291 NULL
119063 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
119064 +hfsplus_direct_IO_6313 hfsplus_direct_IO 4 6313 NULL
119065 +SyS_mincore_6329 SyS_mincore 2-1 6329 NULL nohasharray
119066 +hfa384x_inw_6329 hfa384x_inw 0 6329 &SyS_mincore_6329
119067 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
119068 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
119069 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
119070 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
119071 +arch_gnttab_valloc_6372 arch_gnttab_valloc 2 6372 NULL
119072 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL nohasharray
119073 +sync_fence_alloc_6378 sync_fence_alloc 1 6378 &osd_req_read_sg_kern_6378
119074 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
119075 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
119076 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
119077 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
119078 +C_SYSC_vmsplice_6470 C_SYSC_vmsplice 3 6470 NULL
119079 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
119080 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
119081 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
119082 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
119083 +mei_read_6507 mei_read 3 6507 NULL
119084 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
119085 +wdm_read_6549 wdm_read 3 6549 NULL
119086 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
119087 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
119088 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
119089 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
119090 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
119091 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
119092 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
119093 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
119094 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
119095 +mpeg_read_6708 mpeg_read 3 6708 NULL
119096 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
119097 +check_clk_sync_6717 check_clk_sync 2 6717 NULL
119098 +video_proc_write_6724 video_proc_write 3 6724 NULL
119099 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
119100 +inet_recv_error_6744 inet_recv_error 3 6744 NULL
119101 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
119102 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
119103 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
119104 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
119105 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
119106 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
119107 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
119108 +rounded_hashtable_size_6802 rounded_hashtable_size 0 6802 NULL
119109 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
119110 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
119111 +blk_alloc_flush_queue_6839 blk_alloc_flush_queue 3 6839 NULL
119112 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
119113 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
119114 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
119115 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
119116 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
119117 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
119118 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
119119 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
119120 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
119121 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
119122 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
119123 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
119124 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
119125 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
119126 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
119127 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
119128 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
119129 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
119130 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
119131 +lustre_pack_reply_6982 lustre_pack_reply 2 6982 NULL
119132 +request_key_async_6990 request_key_async 4 6990 NULL
119133 +tpl_write_6998 tpl_write 3 6998 NULL
119134 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
119135 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
119136 +copy_items_7012 copy_items 7 7012 NULL
119137 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
119138 +wimax_msg_7030 wimax_msg 4 7030 NULL
119139 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
119140 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
119141 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
119142 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
119143 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
119144 +event_enable_read_7074 event_enable_read 3 7074 NULL
119145 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL nohasharray
119146 +tipc_send_packet_7091 tipc_send_packet 4 7091 &beacon_interval_read_7091
119147 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
119148 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
119149 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
119150 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
119151 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
119152 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
119153 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
119154 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL nohasharray
119155 +kimage_alloc_init_7282 kimage_alloc_init 3 7282 &rx_rate_rx_frames_per_rates_read_7282
119156 +get_string_7302 get_string 0 7302 NULL
119157 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
119158 +mgmt_control_7349 mgmt_control 3 7349 NULL
119159 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
119160 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
119161 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
119162 +hweight_long_7388 hweight_long 0-1 7388 NULL
119163 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
119164 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
119165 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
119166 +readb_7401 readb 0 7401 NULL
119167 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
119168 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
119169 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
119170 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
119171 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
119172 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
119173 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
119174 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
119175 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
119176 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
119177 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
119178 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
119179 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
119180 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
119181 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
119182 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
119183 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
119184 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
119185 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
119186 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
119187 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
119188 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
119189 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
119190 +dev_write_7708 dev_write 3 7708 NULL
119191 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
119192 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
119193 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
119194 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
119195 +__videobuf_read_start_7782 __videobuf_read_start 0 7782 NULL
119196 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
119197 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
119198 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
119199 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
119200 +seq_buf_alloc_7828 seq_buf_alloc 1 7828 NULL
119201 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
119202 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
119203 +config_desc_7878 config_desc 0 7878 NULL
119204 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
119205 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
119206 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
119207 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
119208 +integrity_digsig_verify_7956 integrity_digsig_verify 3 7956 NULL
119209 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
119210 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
119211 +vcs_read_8017 vcs_read 3 8017 NULL
119212 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
119213 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
119214 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
119215 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
119216 +venus_lookup_8121 venus_lookup 4 8121 NULL
119217 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
119218 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
119219 +ufshcd_wait_for_dev_cmd_8168 ufshcd_wait_for_dev_cmd 0 8168 NULL
119220 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
119221 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
119222 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
119223 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
119224 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
119225 +play_iframe_8219 play_iframe 3 8219 NULL
119226 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
119227 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
119228 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
119229 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
119230 +init_cdev_8274 init_cdev 1 8274 NULL
119231 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
119232 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
119233 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
119234 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
119235 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
119236 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
119237 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
119238 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
119239 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
119240 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
119241 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
119242 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
119243 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
119244 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
119245 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
119246 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
119247 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
119248 +dev_config_8506 dev_config 3 8506 NULL
119249 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
119250 +nouveau_platform_device_create__8514 nouveau_platform_device_create_ 2 8514 NULL
119251 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
119252 +user_on_off_8552 user_on_off 2 8552 NULL
119253 +profile_remove_8556 profile_remove 3 8556 NULL
119254 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
119255 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
119256 +tower_write_8580 tower_write 3 8580 NULL
119257 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
119258 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
119259 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
119260 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
119261 +fuse_send_write_pages_8636 fuse_send_write_pages 5-0 8636 NULL
119262 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
119263 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
119264 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
119265 +bpf_prog_size_8685 bpf_prog_size 0 8685 NULL
119266 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
119267 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
119268 +arcfb_write_8702 arcfb_write 3 8702 NULL
119269 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
119270 +init_header_8703 init_header 0 8703 &i_size_read_8703
119271 +ufshcd_get_tr_ocs_8706 ufshcd_get_tr_ocs 0 8706 NULL
119272 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
119273 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
119274 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
119275 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
119276 +iov_iter_zero_8748 iov_iter_zero 1 8748 NULL
119277 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
119278 +compound_order_8750 compound_order 0 8750 NULL
119279 +cfg80211_inform_bss_width_8754 cfg80211_inform_bss_width 10 8754 NULL
119280 +yurex_write_8761 yurex_write 3 8761 NULL
119281 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
119282 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
119283 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
119284 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 4-3 8785 NULL
119285 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
119286 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
119287 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
119288 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
119289 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
119290 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
119291 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
119292 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
119293 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
119294 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
119295 +xgmac_reg_value_write_8860 xgmac_reg_value_write 3 8860 NULL
119296 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
119297 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
119298 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
119299 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
119300 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
119301 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
119302 +write_file_ani_8918 write_file_ani 3 8918 NULL
119303 +layout_commit_8926 layout_commit 3 8926 NULL
119304 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
119305 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
119306 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
119307 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
119308 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
119309 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
119310 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
119311 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
119312 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
119313 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
119314 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
119315 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
119316 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
119317 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
119318 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
119319 +nla_put_9042 nla_put 3 9042 NULL
119320 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
119321 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
119322 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
119323 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
119324 +create_queues_9088 create_queues 2-3 9088 NULL
119325 +nvkm_output_create__9091 nvkm_output_create_ 6 9091 NULL
119326 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
119327 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
119328 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 NULL nohasharray
119329 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 &gfn_to_rmap_9110
119330 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
119331 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
119332 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
119333 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
119334 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
119335 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
119336 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
119337 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
119338 +card_send_command_9215 card_send_command 3 9215 NULL
119339 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
119340 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
119341 +l2cap_create_connless_pdu_9222 l2cap_create_connless_pdu 3 9222 NULL
119342 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
119343 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
119344 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
119345 +flakey_status_9274 flakey_status 5 9274 NULL
119346 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
119347 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
119348 +__blockdev_direct_IO_9321 __blockdev_direct_IO 0-6 9321 NULL
119349 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
119350 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
119351 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
119352 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
119353 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
119354 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
119355 +read_9397 read 3 9397 NULL
119356 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
119357 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
119358 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
119359 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
119360 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
119361 +get_registers_9470 get_registers 4 9470 NULL nohasharray
119362 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
119363 +crypt_status_9492 crypt_status 5 9492 NULL
119364 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
119365 +lp_write_9511 lp_write 3 9511 NULL
119366 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
119367 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
119368 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
119369 +read_file_dma_9530 read_file_dma 3 9530 NULL
119370 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
119371 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
119372 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
119373 +fw_node_create_9559 fw_node_create 2 9559 NULL
119374 +kobj_map_9566 kobj_map 2-3 9566 NULL
119375 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
119376 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
119377 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
119378 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
119379 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
119380 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
119381 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
119382 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
119383 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
119384 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
119385 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
119386 +dns_query_9676 dns_query 3 9676 NULL
119387 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
119388 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
119389 +lowpan_control_write_9699 lowpan_control_write 3 9699 NULL
119390 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
119391 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
119392 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
119393 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
119394 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
119395 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
119396 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
119397 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
119398 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
119399 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
119400 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
119401 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
119402 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
119403 +copy_page_from_iter_bvec_9767 copy_page_from_iter_bvec 0-3 9767 NULL
119404 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
119405 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
119406 +bio_alloc_map_data_9798 bio_alloc_map_data 1 9798 NULL
119407 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
119408 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
119409 +compat_SyS_vmsplice_9828 compat_SyS_vmsplice 3 9828 NULL
119410 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
119411 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
119412 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
119413 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
119414 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
119415 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
119416 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
119417 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
119418 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
119419 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
119420 +read_file_misc_9948 read_file_misc 3 9948 NULL
119421 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
119422 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
119423 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
119424 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
119425 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
119426 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
119427 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
119428 +asymmetric_key_generate_id_10064 asymmetric_key_generate_id 2-4 10064 NULL
119429 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
119430 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
119431 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
119432 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
119433 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
119434 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
119435 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL nohasharray
119436 +tracing_nsecs_write_10157 tracing_nsecs_write 3 10157 &rx_out_of_mem_read_10157
119437 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
119438 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
119439 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
119440 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
119441 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
119442 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
119443 +lmv_hsm_req_count_10245 lmv_hsm_req_count 0 10245 NULL
119444 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
119445 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
119446 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
119447 +nvif_object_new_10300 nvif_object_new 5 10300 NULL
119448 +read_emulate_10310 read_emulate 2-4 10310 NULL
119449 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
119450 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
119451 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
119452 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
119453 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
119454 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
119455 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
119456 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
119457 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
119458 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
119459 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
119460 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
119461 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
119462 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
119463 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
119464 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
119465 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
119466 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
119467 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
119468 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
119469 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
119470 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
119471 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
119472 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
119473 +otp_read_10594 otp_read 2-4-5 10594 NULL
119474 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
119475 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
119476 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
119477 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
119478 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
119479 +parport_write_10669 parport_write 0 10669 NULL
119480 +edge_write_10692 edge_write 4 10692 NULL
119481 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
119482 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
119483 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
119484 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
119485 +spi_sync_10731 spi_sync 0 10731 NULL
119486 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
119487 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
119488 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
119489 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
119490 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
119491 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
119492 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
119493 +ttm_dma_page_pool_free_10796 ttm_dma_page_pool_free 2-0 10796 NULL
119494 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
119495 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
119496 +ext4_direct_IO_10843 ext4_direct_IO 4 10843 NULL
119497 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
119498 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
119499 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
119500 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
119501 +get_scq_10897 get_scq 2 10897 NULL
119502 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
119503 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
119504 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
119505 +kobject_add_10919 kobject_add 0 10919 NULL
119506 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
119507 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
119508 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
119509 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
119510 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
119511 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
119512 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
119513 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
119514 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
119515 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL nohasharray
119516 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 &insert_inline_extent_backref_11063
119517 +xfs_collapse_file_space_11075 xfs_collapse_file_space 2-3 11075 NULL
119518 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
119519 +count_argc_11083 count_argc 0 11083 NULL
119520 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
119521 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
119522 +tc90522_master_xfer_11119 tc90522_master_xfer 3 11119 NULL
119523 +page_offset_11120 page_offset 0 11120 NULL
119524 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
119525 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
119526 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
119527 +copy_from_iter_iovec_11196 copy_from_iter_iovec 2 11196 NULL
119528 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
119529 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
119530 +of_irq_count_11253 of_irq_count 0 11253 NULL
119531 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
119532 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
119533 +SYSC_getrandom_11294 SYSC_getrandom 2 11294 NULL
119534 +tipc_msg_build_11304 tipc_msg_build 3-4-5 11304 NULL
119535 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
119536 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
119537 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
119538 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
119539 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
119540 +construct_key_11329 construct_key 3 11329 NULL nohasharray
119541 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
119542 +next_segment_11330 next_segment 0-2-1 11330 NULL
119543 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
119544 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
119545 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
119546 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
119547 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
119548 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
119549 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
119550 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
119551 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
119552 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
119553 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
119554 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
119555 +str_to_user_11411 str_to_user 2 11411 NULL
119556 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
119557 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
119558 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
119559 +trace_options_read_11419 trace_options_read 3 11419 NULL
119560 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
119561 +bttv_read_11432 bttv_read 3 11432 NULL
119562 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
119563 +ufshcd_change_queue_depth_11477 ufshcd_change_queue_depth 2 11477 NULL
119564 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
119565 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
119566 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
119567 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
119568 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
119569 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
119570 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
119571 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
119572 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
119573 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
119574 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
119575 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
119576 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
119577 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
119578 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
119579 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
119580 +nla_total_size_11658 nla_total_size 0-1 11658 NULL
119581 +srpc_create_client_rpc_11664 srpc_create_client_rpc 3 11664 NULL nohasharray
119582 +slab_ksize_11664 slab_ksize 0 11664 &srpc_create_client_rpc_11664
119583 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
119584 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
119585 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
119586 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
119587 +split_11691 split 2 11691 NULL
119588 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
119589 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
119590 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
119591 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
119592 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
119593 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
119594 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
119595 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
119596 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
119597 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
119598 +umc_device_register_11824 umc_device_register 0 11824 NULL
119599 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
119600 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
119601 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
119602 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
119603 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
119604 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
119605 +l2cap_chan_send_11878 l2cap_chan_send 3 11878 NULL
119606 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
119607 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
119608 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
119609 +ti_write_11916 ti_write 4 11916 NULL
119610 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
119611 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
119612 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
119613 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
119614 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
119615 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
119616 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
119617 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
119618 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
119619 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
119620 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
119621 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
119622 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
119623 +set_powered_12129 set_powered 4 12129 NULL
119624 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
119625 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
119626 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
119627 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
119628 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
119629 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
119630 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
119631 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
119632 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
119633 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
119634 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
119635 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
119636 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
119637 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
119638 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
119639 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
119640 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
119641 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
119642 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
119643 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
119644 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
119645 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
119646 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
119647 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
119648 +ufshcd_copy_query_response_12324 ufshcd_copy_query_response 0 12324 NULL
119649 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
119650 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
119651 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
119652 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
119653 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
119654 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 &write_file_dump_12391 nohasharray
119655 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391
119656 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
119657 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
119658 +cfs_array_alloc_12441 cfs_array_alloc 1-2 12441 NULL
119659 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
119660 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
119661 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
119662 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
119663 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
119664 +nvkm_event_init_12565 nvkm_event_init 3-2 12565 NULL
119665 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
119666 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
119667 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
119668 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
119669 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
119670 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
119671 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
119672 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
119673 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
119674 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
119675 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
119676 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
119677 +lustre_pack_request_v2_12665 lustre_pack_request_v2 2 12665 NULL
119678 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
119679 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
119680 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
119681 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
119682 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
119683 +ivtv_write_12721 ivtv_write 3 12721 NULL
119684 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
119685 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
119686 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
119687 +listxattr_12769 listxattr 3 12769 NULL
119688 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
119689 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
119690 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
119691 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
119692 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
119693 +spidev_sync_12842 spidev_sync 0 12842 NULL
119694 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
119695 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
119696 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
119697 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
119698 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
119699 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
119700 +bm_status_write_12964 bm_status_write 3 12964 NULL
119701 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
119702 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
119703 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
119704 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
119705 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
119706 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
119707 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
119708 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
119709 +ufshcd_compose_upiu_13076 ufshcd_compose_upiu 0 13076 NULL
119710 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
119711 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
119712 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
119713 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
119714 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
119715 +blk_update_request_13146 blk_update_request 3 13146 NULL
119716 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
119717 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
119718 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
119719 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
119720 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
119721 +comedi_read_13199 comedi_read 3 13199 NULL
119722 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
119723 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
119724 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
119725 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
119726 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
119727 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
119728 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
119729 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
119730 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
119731 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
119732 +nvkm_ltc_create__13275 nvkm_ltc_create_ 4 13275 NULL
119733 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
119734 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
119735 +nvkm_i2c_pad_create__13292 nvkm_i2c_pad_create_ 5 13292 NULL
119736 +sd_major_13294 sd_major 0-1 13294 NULL
119737 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
119738 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
119739 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
119740 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
119741 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
119742 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
119743 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
119744 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
119745 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
119746 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
119747 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
119748 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
119749 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
119750 +data_read_13494 data_read 3 13494 NULL nohasharray
119751 +ext_prop_data_store_13494 ext_prop_data_store 3 13494 &data_read_13494
119752 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
119753 +core_status_13515 core_status 4 13515 NULL
119754 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
119755 +bm_init_13529 bm_init 2 13529 NULL
119756 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
119757 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
119758 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
119759 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
119760 +cache_write_13589 cache_write 3 13589 NULL
119761 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
119762 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
119763 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
119764 +packet_snd_13634 packet_snd 3 13634 NULL
119765 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
119766 +cache_downcall_13666 cache_downcall 3 13666 NULL
119767 +usb_get_string_13693 usb_get_string 0 13693 NULL
119768 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
119769 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
119770 +udf_direct_IO_13765 udf_direct_IO 4 13765 NULL
119771 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
119772 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
119773 +alloc_indirect_13783 alloc_indirect 1 13783 NULL
119774 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
119775 +random_read_13815 random_read 3 13815 NULL
119776 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
119777 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
119778 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
119779 +qce_ahash_hmac_setkey_13837 qce_ahash_hmac_setkey 3 13837 NULL
119780 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
119781 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
119782 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
119783 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
119784 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
119785 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
119786 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
119787 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
119788 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
119789 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
119790 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
119791 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
119792 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
119793 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
119794 +qcam_read_13977 qcam_read 3 13977 NULL
119795 +dsp_read_13980 dsp_read 2 13980 NULL
119796 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
119797 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
119798 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
119799 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
119800 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
119801 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
119802 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
119803 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
119804 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
119805 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
119806 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
119807 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
119808 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
119809 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
119810 +em_canid_change_14150 em_canid_change 3 14150 NULL
119811 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
119812 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
119813 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
119814 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
119815 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
119816 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
119817 +alloc_async_14208 alloc_async 1 14208 NULL
119818 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
119819 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
119820 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
119821 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
119822 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
119823 +rr_status_14293 rr_status 5 14293 NULL
119824 +read_default_ldt_14302 read_default_ldt 2 14302 NULL nohasharray
119825 +lustre_pack_reply_flags_14302 lustre_pack_reply_flags 2 14302 &read_default_ldt_14302
119826 +oo_objects_14319 oo_objects 0 14319 NULL
119827 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
119828 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
119829 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
119830 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
119831 +lowpan_read_14369 lowpan_read 3 14369 NULL
119832 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
119833 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
119834 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
119835 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
119836 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
119837 +block_size_14443 block_size 0 14443 NULL
119838 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
119839 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
119840 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
119841 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0-1 14470 NULL
119842 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
119843 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
119844 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
119845 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
119846 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
119847 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
119848 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
119849 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
119850 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
119851 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
119852 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
119853 +ufshcd_compose_dev_cmd_14626 ufshcd_compose_dev_cmd 0 14626 NULL
119854 +dbJoin_14644 dbJoin 0 14644 NULL
119855 +profile_replace_14652 profile_replace 3 14652 NULL
119856 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
119857 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
119858 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
119859 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
119860 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
119861 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
119862 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
119863 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
119864 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
119865 +vfd_write_14717 vfd_write 3 14717 NULL
119866 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
119867 +raid1_resize_14740 raid1_resize 2 14740 NULL
119868 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
119869 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
119870 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
119871 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
119872 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
119873 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
119874 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
119875 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL nohasharray
119876 +ttm_page_pool_free_14797 ttm_page_pool_free 2-0 14797 &__kfifo_in_14797
119877 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
119878 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
119879 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
119880 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
119881 +lcd_write_14857 lcd_write 3 14857 NULL
119882 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
119883 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
119884 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
119885 +netlbl_catmap_walk_14902 netlbl_catmap_walk 0-2 14902 NULL
119886 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
119887 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923 nohasharray
119888 +ptlrpc_prep_req_pool_14923 ptlrpc_prep_req_pool 4 14923 &qp_memcpy_to_queue_iov_14923
119889 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
119890 +queue_cnt_14951 queue_cnt 0 14951 NULL
119891 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
119892 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
119893 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
119894 +setkey_14987 setkey 3 14987 NULL nohasharray
119895 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
119896 +sctp_setsockopt_default_sndinfo_15011 sctp_setsockopt_default_sndinfo 3 15011 NULL
119897 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
119898 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
119899 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
119900 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
119901 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
119902 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
119903 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
119904 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
119905 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
119906 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
119907 +start_port_15124 start_port 0 15124 NULL
119908 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
119909 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
119910 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
119911 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
119912 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
119913 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
119914 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
119915 +wacom_led_putimage_15264 wacom_led_putimage 4 15264 NULL
119916 +simple_strtol_15273 simple_strtol 0 15273 NULL
119917 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
119918 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
119919 +ioread16_15342 ioread16 0 15342 NULL
119920 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
119921 +blkdev_readpages_15357 blkdev_readpages 4 15357 NULL
119922 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
119923 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
119924 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
119925 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
119926 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
119927 +get_modalias_15406 get_modalias 2 15406 NULL
119928 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
119929 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
119930 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
119931 +memweight_15450 memweight 2 15450 NULL
119932 +__clone_and_map_data_bio_15498 __clone_and_map_data_bio 3 15498 NULL
119933 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
119934 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
119935 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
119936 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
119937 +persistent_status_15574 persistent_status 4 15574 NULL
119938 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
119939 +vme_user_write_15587 vme_user_write 3 15587 NULL
119940 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
119941 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
119942 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
119943 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
119944 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
119945 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
119946 +fs_path_add_15648 fs_path_add 3 15648 NULL
119947 +xsd_read_15653 xsd_read 3 15653 NULL
119948 +unix_bind_15668 unix_bind 3 15668 NULL
119949 +dm_read_15674 dm_read 3 15674 NULL nohasharray
119950 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
119951 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
119952 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
119953 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
119954 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
119955 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
119956 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
119957 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
119958 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
119959 +table_size_15851 table_size 0-1-2 15851 NULL
119960 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
119961 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
119962 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
119963 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
119964 +power_read_15939 power_read 3 15939 NULL
119965 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
119966 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
119967 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
119968 +smk_read_ptrace_15974 smk_read_ptrace 3 15974 NULL
119969 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
119970 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
119971 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
119972 +SYSC_kexec_file_load_16058 SYSC_kexec_file_load 3 16058 NULL
119973 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
119974 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
119975 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
119976 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
119977 +udelay_test_write_16111 udelay_test_write 3 16111 NULL
119978 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
119979 +fsm_init_16134 fsm_init 2 16134 NULL
119980 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
119981 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
119982 +mapping_level_16188 mapping_level 2-0 16188 NULL
119983 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
119984 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
119985 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
119986 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
119987 +create_table_16213 create_table 2 16213 NULL
119988 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
119989 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
119990 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
119991 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
119992 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
119993 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
119994 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
119995 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
119996 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
119997 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
119998 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
119999 +account_16283 account 0-4-2 16283 NULL nohasharray
120000 +mirror_status_16283 mirror_status 5 16283 &account_16283
120001 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
120002 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
120003 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
120004 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
120005 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
120006 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
120007 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
120008 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
120009 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
120010 +nv50_pioc_create_16389 nv50_pioc_create 5 16389 NULL
120011 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
120012 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
120013 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
120014 +cmdline_store_16442 cmdline_store 4 16442 NULL
120015 +copy_from_user_bvec_16447 copy_from_user_bvec 0-4 16447 NULL
120016 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
120017 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
120018 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
120019 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
120020 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
120021 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
120022 +raid10_resize_16537 raid10_resize 2 16537 NULL
120023 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
120024 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
120025 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0-1 16589 NULL
120026 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
120027 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
120028 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
120029 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
120030 +_iwl_dbgfs_bt_force_ant_write_16701 _iwl_dbgfs_bt_force_ant_write 3 16701 NULL
120031 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
120032 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
120033 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
120034 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
120035 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
120036 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
120037 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
120038 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
120039 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
120040 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
120041 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
120042 +st_write_16874 st_write 3 16874 NULL
120043 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
120044 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
120045 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
120046 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
120047 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
120048 +svcxdr_dupstr_16963 svcxdr_dupstr 3 16963 NULL
120049 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
120050 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
120051 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
120052 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
120053 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
120054 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
120055 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
120056 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
120057 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
120058 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
120059 +entry_length_17093 entry_length 0 17093 NULL
120060 +write_mem_17114 write_mem 3 17114 NULL
120061 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
120062 +do_blockdev_direct_IO_17143 do_blockdev_direct_IO 0-6 17143 NULL
120063 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
120064 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
120065 +mxt_upload_cfg_mem_17157 mxt_upload_cfg_mem 4 17157 NULL
120066 +sep_read_17161 sep_read 3 17161 NULL
120067 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
120068 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
120069 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
120070 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
120071 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
120072 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
120073 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
120074 +sync_request_17208 sync_request 2 17208 NULL
120075 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
120076 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
120077 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
120078 +alloc_ep_17269 alloc_ep 1 17269 NULL
120079 +pg_read_17276 pg_read 3 17276 NULL
120080 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
120081 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
120082 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
120083 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
120084 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 4 17298 NULL
120085 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
120086 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
120087 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
120088 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
120089 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
120090 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
120091 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
120092 +copy_from_iter_17433 copy_from_iter 2 17433 NULL
120093 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
120094 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
120095 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
120096 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
120097 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
120098 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
120099 +copy_page_from_iter_17512 copy_page_from_iter 3-0 17512 NULL
120100 +reiserfs_direct_IO_17513 reiserfs_direct_IO 4 17513 NULL
120101 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
120102 +qp_free_res_17541 qp_free_res 5 17541 NULL
120103 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
120104 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
120105 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
120106 +wil_write_file_rxon_17581 wil_write_file_rxon 3 17581 NULL
120107 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
120108 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
120109 +osst_execute_17607 osst_execute 7-6 17607 NULL
120110 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
120111 +dma_map_page_17628 dma_map_page 0 17628 NULL
120112 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
120113 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
120114 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
120115 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
120116 +venus_rename_17707 venus_rename 4-5 17707 NULL
120117 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
120118 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
120119 +nv92_gpio_intr_mask_17773 nv92_gpio_intr_mask 4-3 17773 NULL
120120 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
120121 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
120122 +_iwl_dbgfs_set_nic_temperature_write_17804 _iwl_dbgfs_set_nic_temperature_write 3 17804 NULL
120123 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
120124 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
120125 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
120126 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
120127 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
120128 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
120129 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
120130 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
120131 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
120132 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
120133 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
120134 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
120135 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
120136 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
120137 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
120138 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
120139 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
120140 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
120141 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
120142 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
120143 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
120144 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
120145 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
120146 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
120147 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
120148 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
120149 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
120150 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
120151 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
120152 +fpregs_get_18066 fpregs_get 4 18066 NULL
120153 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
120154 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
120155 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
120156 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
120157 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
120158 +svc_getnl_18120 svc_getnl 0 18120 NULL
120159 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
120160 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
120161 +enable_ints_write_18170 enable_ints_write 3 18170 NULL
120162 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
120163 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
120164 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
120165 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
120166 +fill_ext_prop_18233 fill_ext_prop 0 18233 NULL
120167 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
120168 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
120169 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
120170 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
120171 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
120172 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
120173 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
120174 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
120175 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
120176 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
120177 +um_idi_write_18293 um_idi_write 3 18293 NULL
120178 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
120179 +lustre_msg_hdr_size_18308 lustre_msg_hdr_size 2 18308 NULL
120180 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
120181 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
120182 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
120183 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
120184 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
120185 +copy_page_to_iter_18345 copy_page_to_iter 0-3 18345 NULL
120186 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
120187 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
120188 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
120189 +ep_io_18367 ep_io 0 18367 NULL
120190 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
120191 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
120192 +ci_role_write_18388 ci_role_write 3 18388 NULL
120193 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
120194 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
120195 +nvif_device_init_18418 nvif_device_init 6 18418 NULL
120196 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
120197 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
120198 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
120199 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
120200 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
120201 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
120202 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
120203 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
120204 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
120205 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
120206 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
120207 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
120208 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
120209 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
120210 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
120211 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
120212 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
120213 +debug_output_18575 debug_output 3 18575 NULL
120214 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
120215 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
120216 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
120217 +from_buffer_18625 from_buffer 3 18625 NULL
120218 +kmalloc_kernel_18641 kmalloc_kernel 1 18641 NULL
120219 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
120220 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
120221 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
120222 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
120223 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
120224 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
120225 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
120226 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
120227 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
120228 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
120229 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
120230 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
120231 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
120232 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
120233 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
120234 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
120235 +fence_context_alloc_18792 fence_context_alloc 1 18792 NULL
120236 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
120237 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
120238 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
120239 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
120240 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
120241 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
120242 +devm_mdiobus_alloc_size_18902 devm_mdiobus_alloc_size 2 18902 NULL
120243 +tracing_thresh_write_18909 tracing_thresh_write 3 18909 NULL
120244 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
120245 +xfs_buf_read_uncached_18922 xfs_buf_read_uncached 3 18922 NULL
120246 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
120247 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
120248 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
120249 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
120250 +huge_page_size_19008 huge_page_size 0 19008 NULL
120251 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
120252 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
120253 +revalidate_19043 revalidate 2 19043 NULL
120254 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
120255 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
120256 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
120257 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
120258 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
120259 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
120260 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
120261 +cma_bitmap_maxno_19135 cma_bitmap_maxno 0 19135 NULL
120262 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
120263 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
120264 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
120265 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
120266 +read_extent_buffer_to_user_19189 read_extent_buffer_to_user 4-3 19189 NULL
120267 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
120268 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 0-3 19214 NULL
120269 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
120270 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
120271 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
120272 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
120273 +ucma_query_19260 ucma_query 4 19260 NULL
120274 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
120275 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
120276 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
120277 +qc_capture_19298 qc_capture 3 19298 NULL
120278 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
120279 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
120280 +debug_read_19322 debug_read 3 19322 NULL
120281 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
120282 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
120283 +closure_sub_19359 closure_sub 2 19359 NULL
120284 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
120285 +read_zero_19366 read_zero 3 19366 NULL
120286 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
120287 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
120288 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
120289 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
120290 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
120291 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
120292 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
120293 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
120294 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
120295 +sky2_read16_19475 sky2_read16 0 19475 NULL
120296 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
120297 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
120298 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
120299 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
120300 +ttm_dma_page_pool_free_19527 ttm_dma_page_pool_free 2-0 19527 NULL
120301 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
120302 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
120303 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
120304 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
120305 +nfsd_read_19568 nfsd_read 5 19568 NULL
120306 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
120307 +bm_status_read_19583 bm_status_read 3 19583 NULL
120308 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
120309 +drbg_sec_strength_19604 drbg_sec_strength 0 19604 NULL
120310 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
120311 +parser_init_19651 parser_init 2 19651 NULL
120312 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
120313 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
120314 +read_reg_19723 read_reg 0 19723 NULL
120315 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
120316 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
120317 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
120318 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
120319 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
120320 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
120321 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
120322 +readhscx_19769 readhscx 0 19769 NULL
120323 +ath10k_write_htt_max_amsdu_ampdu_19820 ath10k_write_htt_max_amsdu_ampdu 3 19820 NULL
120324 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
120325 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
120326 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
120327 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
120328 +__nla_put_19857 __nla_put 3 19857 NULL
120329 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
120330 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
120331 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
120332 +mangle_name_19923 mangle_name 0 19923 NULL
120333 +tipc_sk_show_19928 tipc_sk_show 3-0 19928 NULL
120334 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
120335 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
120336 +azx_get_pos_lpib_19933 azx_get_pos_lpib 0 19933 NULL
120337 +v4l2_ctrl_new_19942 v4l2_ctrl_new 8-12 19942 NULL
120338 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
120339 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
120340 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
120341 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
120342 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
120343 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
120344 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
120345 +lustre_pack_request_19992 lustre_pack_request 3 19992 NULL
120346 +find_overflow_devnum_19995 find_overflow_devnum 0 19995 NULL
120347 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
120348 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
120349 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
120350 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
120351 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
120352 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
120353 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
120354 +target_message_20072 target_message 2 20072 NULL
120355 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
120356 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
120357 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
120358 +team_options_register_20091 team_options_register 3 20091 NULL
120359 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
120360 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
120361 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
120362 +ext4_ext_direct_IO_20165 ext4_ext_direct_IO 4 20165 NULL
120363 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
120364 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
120365 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
120366 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
120367 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
120368 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
120369 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
120370 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
120371 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
120372 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
120373 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
120374 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
120375 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
120376 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
120377 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
120378 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
120379 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
120380 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
120381 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
120382 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
120383 +read_buf_20469 read_buf 2 20469 NULL
120384 +bio_trim_20472 bio_trim 2 20472 NULL
120385 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
120386 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
120387 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
120388 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
120389 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
120390 +venus_create_20555 venus_create 4 20555 NULL
120391 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
120392 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
120393 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
120394 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
120395 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
120396 +lirc_write_20604 lirc_write 3 20604 NULL
120397 +qib_qsfp_write_20614 qib_qsfp_write 0-4-2 20614 NULL
120398 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
120399 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
120400 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
120401 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
120402 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
120403 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
120404 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
120405 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
120406 +cpumask_size_20683 cpumask_size 0 20683 NULL
120407 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
120408 +xpcs_reg_addr_write_20694 xpcs_reg_addr_write 3 20694 NULL
120409 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
120410 +__maestro_read_20700 __maestro_read 0 20700 NULL
120411 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
120412 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
120413 +hfs_direct_IO_20714 hfs_direct_IO 4 20714 NULL
120414 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
120415 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
120416 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
120417 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
120418 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
120419 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
120420 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
120421 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
120422 +edid_write_20797 edid_write 3 20797 NULL
120423 +lowpan_write_20800 lowpan_write 3 20800 NULL
120424 +strndup_user_20819 strndup_user 2 20819 NULL
120425 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
120426 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
120427 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
120428 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
120429 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
120430 +get_name_20855 get_name 4 20855 NULL
120431 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
120432 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
120433 +srq_free_res_20868 srq_free_res 5 20868 NULL
120434 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
120435 +req_capsule_filled_sizes_20888 req_capsule_filled_sizes 0 20888 NULL
120436 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
120437 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
120438 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
120439 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
120440 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
120441 +htable_bits_20933 htable_bits 0 20933 NULL
120442 +cfg80211_rx_assoc_resp_20934 cfg80211_rx_assoc_resp 4 20934 NULL
120443 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
120444 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
120445 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
120446 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
120447 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
120448 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
120449 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
120450 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
120451 +arch_gnttab_init_21030 arch_gnttab_init 1 21030 NULL
120452 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
120453 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
120454 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
120455 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
120456 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
120457 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
120458 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
120459 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
120460 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
120461 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
120462 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
120463 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
120464 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
120465 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
120466 +bioset_create_nobvec_21180 bioset_create_nobvec 1 21180 NULL
120467 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
120468 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
120469 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
120470 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
120471 +input_ff_create_21240 input_ff_create 2 21240 NULL
120472 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
120473 +fru_length_21257 fru_length 0 21257 NULL
120474 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
120475 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
120476 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
120477 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
120478 +add_res_range_21310 add_res_range 4 21310 NULL
120479 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
120480 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
120481 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
120482 +azx_get_delay_from_lpib_21348 azx_get_delay_from_lpib 3 21348 NULL
120483 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
120484 +allocate_cmdlines_buffer_21355 allocate_cmdlines_buffer 1 21355 NULL
120485 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
120486 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
120487 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
120488 +insert_ptr_21386 insert_ptr 6 21386 NULL
120489 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
120490 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
120491 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
120492 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
120493 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
120494 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
120495 +nouveau_clock_create__21449 nouveau_clock_create_ 8 21449 NULL
120496 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
120497 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
120498 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
120499 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
120500 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
120501 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
120502 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
120503 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
120504 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
120505 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
120506 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
120507 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
120508 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
120509 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
120510 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
120511 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
120512 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
120513 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL nohasharray
120514 +proc_maps_open_21687 proc_maps_open 4 21687 &rtllib_alloc_txb_21687
120515 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
120516 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
120517 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
120518 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
120519 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
120520 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
120521 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
120522 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
120523 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
120524 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
120525 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
120526 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
120527 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
120528 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
120529 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
120530 +__btrfs_direct_write_21894 __btrfs_direct_write 3 21894 NULL
120531 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL nohasharray
120532 +nvme_submit_sync_cmd_21911 nvme_submit_sync_cmd 0 21911 &dbAllocCtl_21911
120533 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
120534 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
120535 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
120536 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
120537 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
120538 +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
120539 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
120540 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
120541 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
120542 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
120543 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
120544 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
120545 +mem_rw_22085 mem_rw 3 22085 NULL
120546 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
120547 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
120548 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
120549 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
120550 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
120551 +nve0_aux_mask_22158 nve0_aux_mask 2 22158 NULL
120552 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
120553 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
120554 +mem_write_22232 mem_write 3 22232 NULL
120555 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
120556 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
120557 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
120558 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
120559 +add_res_tree_22263 add_res_tree 7 22263 NULL
120560 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
120561 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
120562 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
120563 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
120564 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
120565 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
120566 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
120567 +atomic_read_22342 atomic_read 0 22342 NULL
120568 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
120569 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
120570 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
120571 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
120572 +zoran_write_22404 zoran_write 3 22404 NULL
120573 +queue_reply_22416 queue_reply 3 22416 NULL
120574 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
120575 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
120576 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
120577 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
120578 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL nohasharray
120579 +video_write_22490 video_write 3 22490 &qib_user_sdma_alloc_header_22490
120580 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
120581 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
120582 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
120583 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2 22549 NULL
120584 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
120585 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
120586 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
120587 +cfs_expr_list_values_22600 cfs_expr_list_values 0 22600 NULL
120588 +snapshot_read_22601 snapshot_read 3 22601 NULL
120589 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
120590 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
120591 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
120592 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
120593 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
120594 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
120595 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
120596 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
120597 +reg_umr_22686 reg_umr 5 22686 NULL
120598 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
120599 +nr_cpusets_22705 nr_cpusets 0 22705 NULL
120600 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
120601 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
120602 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
120603 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
120604 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
120605 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
120606 +print_frame_22769 print_frame 0 22769 NULL
120607 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
120608 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
120609 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
120610 +create_attr_set_22861 create_attr_set 1 22861 NULL
120611 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
120612 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
120613 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
120614 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
120615 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
120616 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
120617 +nfs4_acl_bytes_22915 nfs4_acl_bytes 0-1 22915 NULL
120618 +__set_xattr_22923 __set_xattr 0 22923 NULL
120619 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
120620 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
120621 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
120622 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
120623 +vme_get_size_22964 vme_get_size 0 22964 NULL
120624 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
120625 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
120626 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
120627 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
120628 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
120629 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
120630 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 6-7 23029 NULL
120631 +st_status_23032 st_status 5 23032 NULL
120632 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
120633 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
120634 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
120635 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
120636 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
120637 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
120638 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
120639 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
120640 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
120641 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
120642 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
120643 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
120644 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
120645 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
120646 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
120647 +__clear_user_23118 __clear_user 0-2 23118 NULL
120648 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
120649 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
120650 +read_file_ani_23161 read_file_ani 3 23161 NULL
120651 +usblp_write_23178 usblp_write 3 23178 NULL
120652 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
120653 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
120654 +tipc_sendmcast_23214 tipc_sendmcast 4 23214 NULL
120655 +mcryptd_alloc_instance_23221 mcryptd_alloc_instance 2-3 23221 NULL
120656 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
120657 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
120658 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
120659 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
120660 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
120661 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
120662 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
120663 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
120664 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
120665 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
120666 +ec_i2c_count_message_23285 ec_i2c_count_message 0-2 23285 NULL
120667 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
120668 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
120669 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
120670 +page_readlink_23346 page_readlink 3 23346 NULL
120671 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
120672 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
120673 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
120674 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
120675 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
120676 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
120677 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
120678 +linear_conf_23485 linear_conf 2 23485 NULL
120679 +event_filter_read_23494 event_filter_read 3 23494 NULL
120680 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
120681 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
120682 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
120683 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
120684 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
120685 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
120686 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
120687 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
120688 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
120689 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
120690 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
120691 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
120692 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
120693 +sInW_23663 sInW 0 23663 NULL
120694 +SyS_connect_23669 SyS_connect 3 23669 NULL
120695 +cx18_read_23699 cx18_read 3 23699 NULL
120696 +at_get_23708 at_get 0 23708 NULL
120697 +get_conn_info_23723 get_conn_info 4 23723 NULL
120698 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
120699 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
120700 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
120701 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
120702 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
120703 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
120704 +map_write_23795 map_write 3 23795 NULL
120705 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
120706 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
120707 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
120708 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
120709 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
120710 +p54_init_common_23850 p54_init_common 1 23850 NULL
120711 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
120712 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
120713 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
120714 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
120715 +iov_iter_get_pages_alloc_23903 iov_iter_get_pages_alloc 3-0 23903 NULL
120716 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
120717 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
120718 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
120719 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
120720 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
120721 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
120722 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
120723 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
120724 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
120725 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
120726 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
120727 +xfs_zero_file_space_24000 xfs_zero_file_space 2-3 24000 NULL
120728 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
120729 +give_pages_24021 give_pages 3 24021 NULL
120730 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
120731 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
120732 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
120733 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
120734 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
120735 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
120736 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
120737 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
120738 +lov_brw_24122 lov_brw 4 24122 NULL
120739 +mpu401_read_24126 mpu401_read 3 24126 NULL
120740 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
120741 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
120742 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
120743 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
120744 +adu_read_24177 adu_read 3 24177 NULL
120745 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
120746 +nv94_aux_24197 nv94_aux 3-6 24197 NULL
120747 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
120748 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
120749 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
120750 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
120751 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
120752 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
120753 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
120754 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
120755 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
120756 +thin_status_24278 thin_status 5 24278 NULL
120757 +msg_size_24288 msg_size 0 24288 NULL
120758 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
120759 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
120760 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
120761 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
120762 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
120763 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
120764 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
120765 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
120766 +igetword_24373 igetword 0 24373 NULL
120767 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
120768 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
120769 +getxattr_24398 getxattr 4 24398 NULL nohasharray
120770 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
120771 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
120772 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
120773 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
120774 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
120775 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
120776 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
120777 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
120778 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
120779 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
120780 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
120781 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
120782 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
120783 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
120784 +ttm_page_pool_free_24486 ttm_page_pool_free 2-0 24486 NULL
120785 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
120786 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
120787 +pd_video_read_24510 pd_video_read 3 24510 NULL
120788 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
120789 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
120790 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
120791 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
120792 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
120793 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
120794 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
120795 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605 nohasharray
120796 +i915_error_state_buf_init_24605 i915_error_state_buf_init 3 24605 &lov_alloc_memmd_24605
120797 +SyS_poll_24620 SyS_poll 2 24620 NULL
120798 +context_alloc_24645 context_alloc 3 24645 NULL
120799 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
120800 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
120801 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
120802 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
120803 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
120804 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
120805 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
120806 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
120807 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
120808 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
120809 +cache_read_24790 cache_read 3 24790 NULL
120810 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
120811 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
120812 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
120813 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
120814 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
120815 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
120816 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
120817 +queues_read_24877 queues_read 3 24877 NULL
120818 +iov_iter_npages_bvec_24905 iov_iter_npages_bvec 0-2 24905 NULL
120819 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
120820 +xpcs_reg_value_write_24922 xpcs_reg_value_write 3 24922 NULL
120821 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
120822 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
120823 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
120824 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
120825 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL nohasharray
120826 +ath10k_fw_crash_dump_read_24987 ath10k_fw_crash_dump_read 3 24987 &llc_ui_sendmsg_24987
120827 +info_debugfs_read_helper_24988 info_debugfs_read_helper 0 24988 NULL
120828 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
120829 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
120830 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
120831 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
120832 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
120833 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
120834 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
120835 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
120836 +do_add_page_to_bio_25071 do_add_page_to_bio 2 25071 NULL
120837 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
120838 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
120839 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
120840 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
120841 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
120842 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
120843 +security_socket_post_create_25221 security_socket_post_create 0 25221 NULL
120844 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
120845 +stripe_status_25259 stripe_status 5 25259 NULL
120846 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
120847 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
120848 +vfs_writev_25278 vfs_writev 3 25278 NULL
120849 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
120850 +cx25821_write_frame_25315 cx25821_write_frame 3 25315 NULL
120851 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
120852 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
120853 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
120854 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
120855 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
120856 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
120857 +mcp795_rtcc_read_25415 mcp795_rtcc_read 4 25415 NULL
120858 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
120859 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
120860 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
120861 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
120862 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
120863 +mxt_obj_size_25510 mxt_obj_size 0 25510 NULL
120864 +sb_permission_25523 sb_permission 0 25523 NULL
120865 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
120866 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
120867 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
120868 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
120869 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
120870 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
120871 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
120872 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
120873 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
120874 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
120875 +__direct_map_25647 __direct_map 6-5 25647 NULL
120876 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
120877 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
120878 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
120879 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
120880 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
120881 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
120882 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
120883 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
120884 +xgbe_common_read_25743 xgbe_common_read 2 25743 NULL
120885 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
120886 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
120887 +sg_read_25799 sg_read 3 25799 NULL
120888 +system_enable_read_25815 system_enable_read 3 25815 NULL
120889 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
120890 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
120891 +parport_read_25855 parport_read 0 25855 NULL
120892 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
120893 +key_attr_size_25865 key_attr_size 0 25865 NULL
120894 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
120895 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
120896 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
120897 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
120898 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
120899 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
120900 +rcname_read_25919 rcname_read 3 25919 NULL
120901 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
120902 +key_flags_read_25931 key_flags_read 3 25931 NULL
120903 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
120904 +flush_25957 flush 2 25957 NULL
120905 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
120906 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
120907 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
120908 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
120909 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
120910 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
120911 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
120912 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
120913 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
120914 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
120915 +read_sb_page_26119 read_sb_page 5 26119 NULL
120916 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
120917 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
120918 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
120919 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
120920 +disk_devt_26180 disk_devt 0 26180 NULL
120921 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
120922 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
120923 +mce_write_26201 mce_write 3 26201 NULL
120924 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
120925 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
120926 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
120927 +nlm_end_grace_read_26234 nlm_end_grace_read 3 26234 NULL
120928 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
120929 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
120930 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
120931 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
120932 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
120933 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
120934 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
120935 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
120936 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
120937 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
120938 +ntty_write_26404 ntty_write 3 26404 NULL
120939 +firmware_store_26408 firmware_store 4 26408 NULL
120940 +pagemap_read_26441 pagemap_read 3 26441 NULL
120941 +tower_read_26461 tower_read 3 26461 NULL nohasharray
120942 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
120943 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
120944 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
120945 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL nohasharray
120946 +msi_verify_entries_26490 msi_verify_entries 0 26490 &dvb_ca_en50221_io_ioctl_26490
120947 +read_vmcore_26501 read_vmcore 3 26501 NULL
120948 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
120949 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
120950 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
120951 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
120952 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
120953 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
120954 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
120955 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
120956 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
120957 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
120958 +amdtp_stream_get_max_payload_26645 amdtp_stream_get_max_payload 0 26645 NULL
120959 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
120960 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
120961 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
120962 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
120963 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
120964 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
120965 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
120966 +bos_desc_26752 bos_desc 0 26752 NULL
120967 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
120968 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
120969 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
120970 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
120971 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
120972 +smk_write_load_26829 smk_write_load 3 26829 NULL
120973 +snd_pcm_action_mutex_26832 snd_pcm_action_mutex 0 26832 NULL
120974 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
120975 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
120976 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
120977 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
120978 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
120979 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
120980 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
120981 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
120982 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
120983 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
120984 +brcmf_usb_dl_cmd_26931 brcmf_usb_dl_cmd 4 26931 NULL
120985 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
120986 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
120987 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
120988 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
120989 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
120990 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
120991 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
120992 +lustre_msg_size_26995 lustre_msg_size 2 26995 NULL
120993 +sc16is7xx_port_read_27051 sc16is7xx_port_read 0 27051 NULL
120994 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
120995 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3 27064 NULL
120996 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
120997 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
120998 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
120999 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
121000 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
121001 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
121002 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
121003 +pms_capture_27142 pms_capture 4 27142 NULL
121004 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
121005 +wil_write_file_wmi_27150 wil_write_file_wmi 3 27150 NULL
121006 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
121007 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
121008 +write_kmem_27225 write_kmem 3 27225 NULL nohasharray
121009 +svcxdr_tmpalloc_27225 svcxdr_tmpalloc 2 27225 &write_kmem_27225
121010 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
121011 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
121012 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
121013 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
121014 +get_rx_fifo_content_27283 get_rx_fifo_content 0 27283 NULL
121015 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
121016 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
121017 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
121018 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
121019 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
121020 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
121021 +seq_read_27411 seq_read 3 27411 NULL
121022 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
121023 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
121024 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 3-4 27422 NULL
121025 +cypress_write_27423 cypress_write 4 27423 NULL
121026 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
121027 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
121028 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
121029 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
121030 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
121031 +garmin_read_process_27509 garmin_read_process 3 27509 NULL nohasharray
121032 +mcryptd_hash_setkey_27509 mcryptd_hash_setkey 3 27509 &garmin_read_process_27509
121033 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
121034 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
121035 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
121036 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
121037 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
121038 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
121039 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
121040 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
121041 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
121042 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642
121043 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
121044 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
121045 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
121046 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
121047 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
121048 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
121049 +evm_write_key_27715 evm_write_key 3 27715 NULL
121050 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
121051 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
121052 +load_scode_27738 load_scode 2 27738 NULL
121053 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
121054 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
121055 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
121056 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
121057 +SyS_readv_27804 SyS_readv 3 27804 NULL
121058 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
121059 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
121060 +init_header_complete_27833 init_header_complete 0 27833 NULL
121061 +read_profile_27859 read_profile 3 27859 NULL
121062 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
121063 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
121064 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
121065 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
121066 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
121067 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
121068 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
121069 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
121070 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
121071 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
121072 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
121073 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
121074 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
121075 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
121076 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
121077 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
121078 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
121079 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
121080 +pool_status_28055 pool_status 5 28055 NULL
121081 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
121082 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
121083 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
121084 +acpi_gsb_i2c_write_bytes_28082 acpi_gsb_i2c_write_bytes 4 28082 NULL
121085 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
121086 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
121087 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
121088 +m25p80_read_reg_28132 m25p80_read_reg 4 28132 NULL
121089 +video_read_28148 video_read 3 28148 NULL
121090 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
121091 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
121092 +vread_28173 vread 0-3 28173 NULL
121093 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
121094 +counter_free_res_28187 counter_free_res 5 28187 NULL
121095 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
121096 +nvkm_output_dp_create__28192 nvkm_output_dp_create_ 6 28192 NULL
121097 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
121098 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
121099 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
121100 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
121101 +usemap_size_28281 usemap_size 0 28281 NULL
121102 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
121103 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
121104 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
121105 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
121106 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
121107 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
121108 +xpcs_mmd_read_28331 xpcs_mmd_read 3 28331 NULL
121109 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
121110 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
121111 +snapshot_write_28351 snapshot_write 3 28351 NULL
121112 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
121113 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
121114 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
121115 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
121116 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
121117 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
121118 +__videobuf_mmap_setup_28421 __videobuf_mmap_setup 0 28421 NULL
121119 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
121120 +hid_hw_output_report_28429 hid_hw_output_report 0 28429 NULL
121121 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
121122 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
121123 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
121124 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
121125 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
121126 +sh_irda_init_iobuf_28527 sh_irda_init_iobuf 2 28527 NULL nohasharray
121127 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 &sh_irda_init_iobuf_28527
121128 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
121129 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
121130 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 NULL nohasharray
121131 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545 nohasharray
121132 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 &aio_read_events_28545
121133 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
121134 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
121135 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
121136 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
121137 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
121138 +xgbe_common_write_28609 xgbe_common_write 2 28609 NULL
121139 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
121140 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
121141 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
121142 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
121143 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
121144 +iwl_dbgfs_nic_temp_read_28662 iwl_dbgfs_nic_temp_read 3 28662 NULL
121145 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
121146 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
121147 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
121148 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
121149 +spi_execute_28736 spi_execute 5 28736 NULL
121150 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
121151 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
121152 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
121153 +nv50_dmac_create_28762 nv50_dmac_create 5 28762 NULL
121154 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
121155 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
121156 +sel_write_member_28800 sel_write_member 3 28800 NULL
121157 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
121158 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
121159 +parser_init_byteStream_28841 parser_init_byteStream 2 28841 NULL
121160 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
121161 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
121162 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
121163 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
121164 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
121165 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
121166 +push_rx_28939 push_rx 3 28939 NULL
121167 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
121168 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
121169 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
121170 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
121171 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
121172 +bin_uuid_28999 bin_uuid 3 28999 NULL
121173 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
121174 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
121175 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
121176 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
121177 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
121178 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
121179 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
121180 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
121181 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
121182 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
121183 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
121184 +snprintf_29125 snprintf 0 29125 NULL
121185 +iov_shorten_29130 iov_shorten 0 29130 NULL
121186 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
121187 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
121188 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
121189 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
121190 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
121191 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
121192 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
121193 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
121194 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
121195 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
121196 +mwifiex_hscfg_write_29262 mwifiex_hscfg_write 3 29262 NULL
121197 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
121198 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
121199 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
121200 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
121201 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
121202 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
121203 +obd_proc_jobid_name_seq_write_29332 obd_proc_jobid_name_seq_write 3 29332 NULL
121204 +tun_put_user_29337 tun_put_user 5 29337 NULL
121205 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
121206 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
121207 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
121208 +mempool_create_29437 mempool_create 1 29437 NULL
121209 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
121210 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
121211 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
121212 +memcg_update_cache_params_29465 memcg_update_cache_params 2 29465 NULL
121213 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
121214 +do_register_entry_29478 do_register_entry 4 29478 NULL
121215 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
121216 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
121217 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
121218 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
121219 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
121220 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
121221 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
121222 +mic_vringh_copy_29531 mic_vringh_copy 4 29531 NULL
121223 +ftrace_write_29551 ftrace_write 3 29551 NULL
121224 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
121225 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
121226 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
121227 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
121228 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
121229 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
121230 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
121231 +slots_per_page_29601 slots_per_page 0 29601 NULL
121232 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
121233 +lstcon_rpc_init_29623 lstcon_rpc_init 4 29623 NULL
121234 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
121235 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
121236 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
121237 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
121238 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
121239 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
121240 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
121241 +probes_write_29711 probes_write 3 29711 NULL
121242 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
121243 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
121244 +std_nic_write_29752 std_nic_write 3 29752 NULL
121245 +static_key_count_29771 static_key_count 0 29771 NULL
121246 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
121247 +dbAlloc_29794 dbAlloc 0 29794 NULL
121248 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
121249 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
121250 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
121251 +count_partial_29850 count_partial 0 29850 NULL
121252 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
121253 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
121254 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
121255 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
121256 +nv94_gpio_intr_mask_29907 nv94_gpio_intr_mask 4-3 29907 NULL
121257 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
121258 +write_file_queue_29922 write_file_queue 3 29922 NULL
121259 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
121260 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
121261 +zero_iovec_29955 zero_iovec 1 29955 NULL
121262 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
121263 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
121264 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
121265 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
121266 +drp_wmove_30043 drp_wmove 4 30043 NULL
121267 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
121268 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
121269 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
121270 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
121271 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
121272 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
121273 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
121274 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
121275 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
121276 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
121277 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
121278 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
121279 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
121280 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
121281 +SyS_semop_30227 SyS_semop 3 30227 NULL
121282 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
121283 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
121284 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
121285 +compat_readv_30273 compat_readv 3 30273 NULL
121286 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
121287 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
121288 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
121289 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
121290 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
121291 +i8254_read_30330 i8254_read 0 30330 NULL
121292 +resource_from_user_30341 resource_from_user 3 30341 NULL
121293 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
121294 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
121295 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
121296 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
121297 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
121298 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
121299 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
121300 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
121301 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
121302 +enable_write_30456 enable_write 3 30456 NULL
121303 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
121304 +urandom_read_30462 urandom_read 3 30462 NULL
121305 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
121306 +adu_write_30487 adu_write 3 30487 NULL
121307 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
121308 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
121309 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
121310 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
121311 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL nohasharray
121312 +set_config_30526 set_config 0 30526 &debug_debug2_read_30526
121313 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL nohasharray
121314 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 &xfs_sb_version_hasftype_30559
121315 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
121316 +set_le_30581 set_le 4 30581 NULL
121317 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
121318 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
121319 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
121320 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
121321 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
121322 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
121323 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
121324 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
121325 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
121326 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
121327 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
121328 +get_pages_alloc_iovec_30699 get_pages_alloc_iovec 3-0 30699 NULL
121329 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
121330 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
121331 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
121332 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
121333 +snapshot_status_30744 snapshot_status 5 30744 NULL
121334 +fuse_direct_IO_30753 fuse_direct_IO 4 30753 NULL
121335 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
121336 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
121337 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
121338 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
121339 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
121340 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
121341 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
121342 +cfg80211_rx_mgmt_30844 cfg80211_rx_mgmt 5 30844 NULL
121343 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
121344 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
121345 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
121346 +copy_to_iter_30901 copy_to_iter 2 30901 NULL
121347 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
121348 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
121349 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
121350 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
121351 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
121352 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
121353 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
121354 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
121355 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
121356 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
121357 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
121358 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
121359 +depth_read_31112 depth_read 3 31112 NULL
121360 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
121361 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
121362 +size_inside_page_31141 size_inside_page 0 31141 NULL
121363 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
121364 +nvme_set_features_31169 nvme_set_features 0 31169 NULL
121365 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
121366 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
121367 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
121368 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
121369 +__read_reg_31216 __read_reg 0 31216 NULL
121370 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
121371 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
121372 +cyy_readb_31240 cyy_readb 0 31240 NULL
121373 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
121374 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
121375 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
121376 +iwl_dbgfs_set_nic_temperature_read_31300 iwl_dbgfs_set_nic_temperature_read 3 31300 NULL
121377 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
121378 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
121379 +command_file_write_31318 command_file_write 3 31318 NULL
121380 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
121381 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
121382 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
121383 +outlen_write_31358 outlen_write 3 31358 NULL
121384 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
121385 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
121386 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
121387 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
121388 +inb_31388 inb 0 31388 NULL
121389 +mp_ioapic_pin_count_31393 mp_ioapic_pin_count 0 31393 NULL
121390 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
121391 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
121392 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
121393 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
121394 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
121395 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
121396 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
121397 +alg_setkey_31485 alg_setkey 3 31485 NULL
121398 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
121399 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
121400 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
121401 +hidraw_write_31536 hidraw_write 3 31536 NULL
121402 +usbvision_read_31555 usbvision_read 3 31555 NULL
121403 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
121404 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
121405 +osst_write_31581 osst_write 3 31581 NULL
121406 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
121407 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
121408 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 NULL nohasharray
121409 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 &memblock_virt_alloc_nopanic_31617
121410 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
121411 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
121412 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
121413 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
121414 +__lgread_31668 __lgread 4 31668 NULL
121415 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
121416 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
121417 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
121418 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
121419 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
121420 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
121421 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
121422 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
121423 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
121424 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
121425 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
121426 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
121427 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
121428 +get_count_order_31800 get_count_order 0 31800 NULL
121429 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
121430 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
121431 +data_write_31805 data_write 3 31805 NULL
121432 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
121433 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
121434 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
121435 +clone_bio_31854 clone_bio 4-3 31854 NULL
121436 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
121437 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
121438 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
121439 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
121440 +xattr_permission_31907 xattr_permission 0 31907 NULL
121441 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
121442 +new_dir_31919 new_dir 3 31919 NULL
121443 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
121444 +era_status_31934 era_status 5 31934 NULL
121445 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
121446 +read_mem_31942 read_mem 3 31942 NULL
121447 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
121448 +vb2_write_31948 vb2_write 3 31948 NULL
121449 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
121450 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
121451 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
121452 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
121453 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
121454 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
121455 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
121456 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
121457 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
121458 +calc_hmac_32010 calc_hmac 3 32010 NULL
121459 +aead_len_32021 aead_len 0 32021 NULL
121460 +sci_dma_rx_push_32029 sci_dma_rx_push 2 32029 NULL
121461 +stk_read_32038 stk_read 3 32038 NULL
121462 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
121463 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
121464 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
121465 +kiblnd_alloc_pages_32092 kiblnd_alloc_pages 3 32092 NULL
121466 +bio_alloc_32095 bio_alloc 2 32095 NULL
121467 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
121468 +wil_read_file_recovery_32104 wil_read_file_recovery 3 32104 NULL
121469 +disk_status_32120 disk_status 4 32120 NULL
121470 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
121471 +venus_link_32165 venus_link 5 32165 NULL
121472 +ocfs2_direct_IO_32168 ocfs2_direct_IO 4 32168 NULL
121473 +do_writepages_32173 do_writepages 0 32173 NULL
121474 +del_ptr_32197 del_ptr 4 32197 NULL
121475 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
121476 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
121477 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
121478 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
121479 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
121480 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
121481 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
121482 +SyS_select_32319 SyS_select 1 32319 NULL
121483 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
121484 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
121485 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
121486 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
121487 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
121488 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL nohasharray
121489 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 &sel_read_initcon_32362
121490 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
121491 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
121492 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
121493 +cache_status_32462 cache_status 5 32462 NULL
121494 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
121495 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
121496 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
121497 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
121498 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
121499 +disconnect_32521 disconnect 4 32521 NULL
121500 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
121501 +ilo_read_32531 ilo_read 3 32531 NULL
121502 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
121503 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
121504 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
121505 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
121506 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
121507 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
121508 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
121509 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
121510 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
121511 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
121512 +xpcs_reg_value_read_32644 xpcs_reg_value_read 3 32644 NULL
121513 +kvmalloc_32646 kvmalloc 1 32646 NULL
121514 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
121515 +generic_readlink_32654 generic_readlink 3 32654 NULL
121516 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
121517 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
121518 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
121519 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
121520 +_xfs_buf_get_pages_32715 _xfs_buf_get_pages 2 32715 NULL
121521 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
121522 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
121523 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
121524 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
121525 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
121526 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
121527 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
121528 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
121529 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
121530 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
121531 +visorchannel_dump_section_32893 visorchannel_dump_section 4 32893 NULL
121532 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
121533 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
121534 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
121535 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
121536 +ptlrpc_prep_bulk_imp_32997 ptlrpc_prep_bulk_imp 2 32997 NULL
121537 +compat_filldir_32999 compat_filldir 3 32999 NULL
121538 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
121539 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
121540 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
121541 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
121542 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
121543 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
121544 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
121545 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
121546 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
121547 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
121548 +alloc_tio_33077 alloc_tio 3 33077 NULL
121549 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
121550 +f2fs_llseek_33098 f2fs_llseek 2 33098 NULL
121551 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
121552 +SyS_poll_33152 SyS_poll 2 33152 NULL
121553 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
121554 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
121555 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
121556 +pp_read_33210 pp_read 3 33210 NULL
121557 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
121558 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
121559 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
121560 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
121561 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
121562 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
121563 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
121564 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
121565 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
121566 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
121567 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
121568 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
121569 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
121570 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
121571 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
121572 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
121573 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
121574 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
121575 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
121576 +message_stats_list_33440 message_stats_list 5 33440 NULL
121577 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
121578 +create_entry_33479 create_entry 2 33479 NULL
121579 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
121580 +res_counter_read_33499 res_counter_read 4 33499 NULL
121581 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
121582 +fb_read_33506 fb_read 3 33506 NULL
121583 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
121584 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
121585 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
121586 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
121587 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
121588 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
121589 +count_subheaders_33591 count_subheaders 0 33591 NULL
121590 +scsi_execute_33596 scsi_execute 5 33596 NULL
121591 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
121592 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
121593 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL nohasharray
121594 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 &il_dbgfs_qos_read_33615
121595 +stride_page_count_33641 stride_page_count 2 33641 NULL
121596 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
121597 +inw_p_33668 inw_p 0 33668 NULL
121598 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
121599 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
121600 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
121601 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
121602 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
121603 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
121604 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
121605 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
121606 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
121607 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
121608 +hashtab_create_33769 hashtab_create 3 33769 NULL
121609 +__btrfs_free_reserved_extent_33782 __btrfs_free_reserved_extent 2 33782 NULL
121610 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
121611 +filter_write_33819 filter_write 3 33819 NULL
121612 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
121613 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
121614 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
121615 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
121616 +azx_get_pos_posbuf_33867 azx_get_pos_posbuf 0 33867 NULL
121617 +get_user_pages_33908 get_user_pages 0 33908 NULL
121618 +sg_nents_33909 sg_nents 0 33909 NULL
121619 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
121620 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
121621 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
121622 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
121623 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
121624 +rs_sta_dbgfs_drv_tx_stats_read_33946 rs_sta_dbgfs_drv_tx_stats_read 3 33946 NULL
121625 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
121626 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
121627 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
121628 +ppp_write_34034 ppp_write 3 34034 NULL
121629 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
121630 +bm_page_io_async_34050 bm_page_io_async 2 34050 NULL
121631 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
121632 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
121633 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
121634 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
121635 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
121636 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
121637 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
121638 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
121639 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
121640 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
121641 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL nohasharray
121642 +rbd_osd_req_create_34206 rbd_osd_req_create 3 34206 &rsi_debug_zone_write_34206
121643 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
121644 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
121645 +device_private_init_34279 device_private_init 0 34279 NULL
121646 +xgmac_reg_addr_write_34284 xgmac_reg_addr_write 3 34284 NULL
121647 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
121648 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
121649 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
121650 +proc_thread_self_readlink_34357 proc_thread_self_readlink 3 34357 NULL
121651 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
121652 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
121653 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
121654 +ea_read_34378 ea_read 0 34378 NULL nohasharray
121655 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 &ea_read_34378
121656 +fuse_send_read_34379 fuse_send_read 0-4 34379 NULL
121657 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
121658 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
121659 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
121660 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 NULL nohasharray
121661 +iwl_calib_set_34400 iwl_calib_set 3 34400 &ivtv_read_pos_34400
121662 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
121663 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
121664 +security_socket_create_34439 security_socket_create 0 34439 NULL
121665 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
121666 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
121667 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
121668 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
121669 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
121670 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
121671 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
121672 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
121673 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
121674 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
121675 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
121676 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
121677 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
121678 +ext4_ind_direct_IO_34574 ext4_ind_direct_IO 4 34574 NULL
121679 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
121680 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
121681 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
121682 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
121683 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
121684 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
121685 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
121686 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
121687 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
121688 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
121689 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
121690 +f2fs_direct_IO_34685 f2fs_direct_IO 4 34685 NULL
121691 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
121692 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
121693 +port_print_34704 port_print 3 34704 NULL
121694 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
121695 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
121696 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
121697 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
121698 +bootmode_store_34762 bootmode_store 4 34762 NULL
121699 +device_add_34766 device_add 0 34766 NULL
121700 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
121701 +ext3_direct_IO_34798 ext3_direct_IO 4 34798 NULL
121702 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
121703 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
121704 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
121705 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
121706 +file_page_index_34820 file_page_index 0-2 34820 NULL
121707 +bio_segments_34832 bio_segments 0 34832 NULL
121708 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
121709 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
121710 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
121711 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
121712 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
121713 +msg_print_text_34889 msg_print_text 0 34889 NULL
121714 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
121715 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
121716 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
121717 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
121718 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
121719 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
121720 +compat_SyS_kexec_load_34947 compat_SyS_kexec_load 2 34947 NULL
121721 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
121722 +sdebug_change_qdepth_34994 sdebug_change_qdepth 2 34994 NULL
121723 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
121724 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
121725 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
121726 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
121727 +hwdep_read_locked_35037 hwdep_read_locked 3 35037 NULL
121728 +proc_setgroups_write_35039 proc_setgroups_write 3 35039 NULL
121729 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
121730 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
121731 +capi_write_35104 capi_write 3 35104 NULL nohasharray
121732 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
121733 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
121734 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
121735 +addrs_per_inode_35151 addrs_per_inode 0 35151 NULL
121736 +message_stats_print_35158 message_stats_print 6 35158 NULL
121737 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
121738 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
121739 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
121740 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
121741 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
121742 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
121743 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
121744 +kimage_file_prepare_segments_35232 kimage_file_prepare_segments 5 35232 NULL
121745 +set_fd_set_35249 set_fd_set 1 35249 NULL
121746 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
121747 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
121748 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
121749 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
121750 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
121751 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL nohasharray
121752 +nvkm_notify_init_35283 nvkm_notify_init 7 35283 &isr_rx_rdys_read_35283
121753 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
121754 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
121755 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
121756 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
121757 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
121758 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
121759 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
121760 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
121761 +read_kmem_35372 read_kmem 3 35372 NULL
121762 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
121763 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
121764 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
121765 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
121766 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
121767 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
121768 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
121769 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
121770 +async_setkey_35521 async_setkey 3 35521 NULL
121771 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
121772 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
121773 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
121774 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
121775 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
121776 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
121777 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
121778 +C_SYSC_kexec_load_35565 C_SYSC_kexec_load 2 35565 NULL
121779 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
121780 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
121781 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
121782 +kernel_readv_35617 kernel_readv 3 35617 NULL
121783 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
121784 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
121785 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
121786 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
121787 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
121788 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
121789 +md_super_write_35703 md_super_write 4 35703 NULL
121790 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
121791 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
121792 +alloc_netdev_mqs_35806 alloc_netdev_mqs 1 35806 NULL
121793 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
121794 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
121795 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
121796 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
121797 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
121798 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
121799 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
121800 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
121801 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
121802 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
121803 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
121804 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
121805 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
121806 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
121807 +acl_alloc_35979 acl_alloc 1 35979 NULL
121808 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
121809 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
121810 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
121811 +lov_mds_md_max_stripe_count_36008 lov_mds_md_max_stripe_count 0-1 36008 NULL
121812 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
121813 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
121814 +account_shadowed_36048 account_shadowed 2 36048 NULL
121815 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
121816 +write_emulate_36065 write_emulate 2-4 36065 NULL
121817 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
121818 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
121819 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
121820 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
121821 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
121822 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
121823 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
121824 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
121825 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
121826 +twl_set_36154 twl_set 2 36154 NULL
121827 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
121828 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
121829 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
121830 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
121831 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
121832 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
121833 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
121834 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
121835 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
121836 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
121837 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
121838 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL
121839 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
121840 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
121841 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
121842 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
121843 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
121844 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL nohasharray
121845 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 &fat_compat_ioctl_filldir_36328
121846 +lc_create_36332 lc_create 4 36332 NULL
121847 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
121848 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
121849 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
121850 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
121851 +to_sector_36361 to_sector 0-1 36361 NULL
121852 +tunables_read_36385 tunables_read 3 36385 NULL
121853 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
121854 +sierra_write_36402 sierra_write 4 36402 NULL
121855 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
121856 +soc_pcm_codec_params_fixup_36434 soc_pcm_codec_params_fixup 2 36434 NULL
121857 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
121858 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
121859 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
121860 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
121861 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
121862 +ds1343_nvram_write_36489 ds1343_nvram_write 5-6 36489 NULL
121863 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
121864 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
121865 +cmd_loop_36491 cmd_loop 0 36491 NULL
121866 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
121867 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
121868 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
121869 +get_param_l_36518 get_param_l 0 36518 NULL
121870 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
121871 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
121872 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
121873 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
121874 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
121875 +__erst_read_36579 __erst_read 0 36579 NULL
121876 +put_cmsg_36589 put_cmsg 4 36589 NULL
121877 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
121878 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
121879 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
121880 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
121881 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
121882 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
121883 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
121884 +xillybus_read_36678 xillybus_read 3 36678 NULL
121885 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
121886 +path_getxattr_36717 path_getxattr 4 36717 NULL
121887 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
121888 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
121889 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
121890 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
121891 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
121892 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
121893 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
121894 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
121895 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
121896 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
121897 +cm_write_36858 cm_write 3 36858 NULL
121898 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
121899 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
121900 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
121901 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
121902 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
121903 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
121904 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
121905 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
121906 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
121907 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
121908 +setxattr_37006 setxattr 4 37006 NULL
121909 +ec_i2c_xfer_37029 ec_i2c_xfer 3 37029 NULL
121910 +ieee80211_chsw_switch_vifs_37030 ieee80211_chsw_switch_vifs 2 37030 NULL
121911 +command_file_read_37038 command_file_read 3 37038 NULL
121912 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
121913 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
121914 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
121915 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
121916 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
121917 +parse_command_37079 parse_command 2 37079 NULL
121918 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
121919 +tun_get_user_37094 tun_get_user 5 37094 NULL
121920 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
121921 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
121922 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
121923 +msg_word_37164 msg_word 0 37164 NULL
121924 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
121925 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
121926 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL
121927 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
121928 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
121929 +__do_replace_37227 __do_replace 5 37227 NULL
121930 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
121931 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL nohasharray
121932 +__btrfs_inc_extent_ref_37238 __btrfs_inc_extent_ref 7 37238 &rx_filter_dup_filter_read_37238
121933 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
121934 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
121935 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
121936 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
121937 +tipc_send_37315 tipc_send 3 37315 NULL
121938 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
121939 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
121940 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
121941 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
121942 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
121943 +seek_firmware_37372 seek_firmware 2 37372 NULL
121944 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
121945 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
121946 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
121947 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
121948 +fru_alloc_37442 fru_alloc 1 37442 NULL
121949 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
121950 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
121951 +get_est_timing_37484 get_est_timing 0 37484 NULL
121952 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
121953 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
121954 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
121955 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
121956 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
121957 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
121958 +hdr_size_37536 hdr_size 0 37536 NULL
121959 +extent_map_end_37550 extent_map_end 0 37550 NULL
121960 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
121961 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
121962 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
121963 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
121964 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
121965 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
121966 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
121967 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
121968 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
121969 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
121970 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
121971 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
121972 +tracing_saved_cmdlines_size_write_37684 tracing_saved_cmdlines_size_write 3 37684 NULL
121973 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
121974 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
121975 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
121976 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
121977 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
121978 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
121979 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
121980 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
121981 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
121982 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
121983 +nvkm_notify_init_37806 nvkm_notify_init 6 37806 NULL
121984 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
121985 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
121986 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
121987 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
121988 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
121989 +btrfs_leaf_data_37869 btrfs_leaf_data 0 37869 NULL
121990 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
121991 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
121992 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
121993 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
121994 +write_file_bool_37957 write_file_bool 3 37957 NULL
121995 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
121996 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
121997 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
121998 +vfs_readv_38011 vfs_readv 3 38011 NULL
121999 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
122000 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
122001 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
122002 +parser_init_guts_38046 parser_init_guts 2 38046 NULL
122003 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
122004 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
122005 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
122006 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
122007 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
122008 +cifs_send_async_read_38077 cifs_send_async_read 2 38077 NULL
122009 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL
122010 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
122011 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
122012 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
122013 +ep0_read_38095 ep0_read 3 38095 NULL
122014 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
122015 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
122016 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
122017 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
122018 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
122019 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4-0 38153 NULL
122020 +btrfs_extent_same_38163 btrfs_extent_same 3-2-5 38163 NULL
122021 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
122022 +cdev_add_38176 cdev_add 2-3 38176 NULL
122023 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
122024 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
122025 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
122026 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
122027 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
122028 +nvkm_dmaobj_create__38250 nvkm_dmaobj_create_ 6 38250 NULL
122029 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
122030 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
122031 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
122032 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
122033 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
122034 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
122035 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
122036 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
122037 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
122038 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
122039 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
122040 +usb_ext_prop_put_name_38352 usb_ext_prop_put_name 0-3 38352 NULL
122041 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
122042 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
122043 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
122044 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
122045 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
122046 +iov_iter_npages_iovec_38448 iov_iter_npages_iovec 0-2 38448 NULL
122047 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
122048 +videobuf_waiton_38459 videobuf_waiton 0 38459 NULL
122049 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
122050 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
122051 +dev_names_read_38509 dev_names_read 3 38509 NULL
122052 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
122053 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
122054 +set_queue_count_38519 set_queue_count 0 38519 NULL
122055 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
122056 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
122057 +kuc_len_38557 kuc_len 0-1 38557 NULL
122058 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
122059 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
122060 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
122061 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
122062 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
122063 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
122064 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
122065 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
122066 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
122067 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
122068 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
122069 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
122070 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
122071 +ufshcd_read_sdev_qdepth_38676 ufshcd_read_sdev_qdepth 0 38676 NULL
122072 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
122073 +tracing_nsecs_read_38689 tracing_nsecs_read 3 38689 NULL
122074 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
122075 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
122076 +udf_readpages_38761 udf_readpages 4 38761 NULL
122077 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
122078 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
122079 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
122080 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
122081 +err_decode_38804 err_decode 2 38804 NULL
122082 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
122083 +direct_entry_38836 direct_entry 3 38836 NULL
122084 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
122085 +interfaces_38859 interfaces 2 38859 NULL
122086 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
122087 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
122088 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
122089 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
122090 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
122091 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
122092 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
122093 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
122094 +get_nodes_39012 get_nodes 3 39012 NULL
122095 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
122096 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
122097 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
122098 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
122099 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
122100 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
122101 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
122102 +ea_foreach_39133 ea_foreach 0 39133 NULL
122103 +generic_permission_39150 generic_permission 0 39150 NULL
122104 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
122105 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
122106 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
122107 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
122108 +mlx4_en_create_tx_ring_39179 mlx4_en_create_tx_ring 4 39179 NULL
122109 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
122110 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
122111 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
122112 +SyS_getrandom_39235 SyS_getrandom 2 39235 NULL
122113 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
122114 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
122115 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
122116 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
122117 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
122118 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
122119 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
122120 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
122121 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
122122 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
122123 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
122124 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
122125 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
122126 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
122127 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
122128 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
122129 +__send_to_port_39386 __send_to_port 3 39386 NULL
122130 +user_power_read_39414 user_power_read 3 39414 NULL
122131 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
122132 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
122133 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
122134 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
122135 +usif_ioctl_39481 usif_ioctl 3 39481 NULL
122136 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
122137 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
122138 +int_proc_write_39542 int_proc_write 3 39542 NULL
122139 +pp_write_39554 pp_write 3 39554 NULL
122140 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
122141 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
122142 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
122143 +ext_depth_39607 ext_depth 0 39607 NULL
122144 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
122145 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
122146 +sdio_readb_39618 sdio_readb 0 39618 NULL
122147 +set_dev_class_39645 set_dev_class 4 39645 NULL
122148 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
122149 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
122150 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
122151 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
122152 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
122153 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
122154 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
122155 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
122156 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
122157 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
122158 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
122159 +netlbl_catmap_walkrng_39885 netlbl_catmap_walkrng 0-2 39885 NULL
122160 +pkt_add_39897 pkt_add 3 39897 NULL
122161 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
122162 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
122163 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
122164 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
122165 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 NULL nohasharray
122166 +exofs_read_kern_39921 exofs_read_kern 6 39921 &oom_score_adj_read_39921
122167 +__spi_async_39932 __spi_async 0 39932 NULL
122168 +__get_order_39935 __get_order 0 39935 NULL
122169 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
122170 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
122171 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
122172 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
122173 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
122174 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
122175 +lustre_pack_reply_v2_39978 lustre_pack_reply_v2 2 39978 NULL
122176 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
122177 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
122178 +server_name2svname_39998 server_name2svname 4 39998 NULL
122179 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
122180 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
122181 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
122182 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
122183 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
122184 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
122185 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
122186 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
122187 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
122188 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
122189 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
122190 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL nohasharray
122191 +kvm_mmu_notifier_clear_flush_young_40143 kvm_mmu_notifier_clear_flush_young 3-4 40143 &ath10k_write_simulate_fw_crash_40143
122192 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
122193 +pt_write_40159 pt_write 3 40159 NULL
122194 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
122195 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
122196 +allocate_probes_40204 allocate_probes 1 40204 NULL
122197 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
122198 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
122199 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
122200 +osst_read_40237 osst_read 3 40237 NULL
122201 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
122202 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
122203 +of_get_child_count_40254 of_get_child_count 0 40254 NULL nohasharray
122204 +fsl_edma_prep_dma_cyclic_40254 fsl_edma_prep_dma_cyclic 3-4 40254 &of_get_child_count_40254
122205 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
122206 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
122207 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
122208 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
122209 +tracing_thresh_read_40295 tracing_thresh_read 3 40295 NULL
122210 +SyS_bind_40303 SyS_bind 3 40303 NULL
122211 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
122212 +mmio_read_40348 mmio_read 4 40348 NULL
122213 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
122214 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
122215 +get_chars_40373 get_chars 3 40373 NULL
122216 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
122217 +proc_write_driver_40432 proc_write_driver 3 40432 NULL
122218 +repair_io_failure_40452 repair_io_failure 4-3 40452 NULL
122219 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
122220 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
122221 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
122222 +SyS_writev_40467 SyS_writev 3 40467 NULL
122223 +SyS_select_40473 SyS_select 1 40473 NULL
122224 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
122225 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
122226 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
122227 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
122228 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
122229 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
122230 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
122231 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
122232 +bl_alloc_init_bio_40569 bl_alloc_init_bio 1 40569 NULL
122233 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
122234 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
122235 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
122236 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
122237 +fops_read_40672 fops_read 3 40672 NULL
122238 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
122239 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
122240 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
122241 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
122242 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
122243 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
122244 +lnet_new_text_buf_40717 lnet_new_text_buf 1 40717 NULL
122245 +ip_skb_dst_mtu_40718 ip_skb_dst_mtu 0 40718 NULL
122246 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
122247 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
122248 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
122249 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
122250 +card_send_command_40757 card_send_command 3 40757 NULL
122251 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
122252 +pg_write_40766 pg_write 3 40766 NULL
122253 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
122254 +show_list_40775 show_list 3-0 40775 NULL
122255 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
122256 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
122257 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
122258 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
122259 +add_action_40811 add_action 4 40811 NULL
122260 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
122261 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
122262 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
122263 +read_file_queue_40895 read_file_queue 3 40895 NULL
122264 +waiters_read_40902 waiters_read 3 40902 NULL
122265 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
122266 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
122267 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
122268 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
122269 +path_listxattr_40949 path_listxattr 3 40949 NULL
122270 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
122271 +ima_appraise_measurement_40978 ima_appraise_measurement 6 40978 NULL
122272 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
122273 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
122274 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
122275 +get_pages_alloc_bvec_41012 get_pages_alloc_bvec 0-3 41012 NULL
122276 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
122277 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
122278 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
122279 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
122280 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
122281 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
122282 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
122283 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
122284 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
122285 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
122286 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
122287 +dma_attach_41094 dma_attach 5-6 41094 NULL
122288 +nl80211_send_mlme_event_41099 nl80211_send_mlme_event 4 41099 NULL
122289 +provide_user_output_41105 provide_user_output 3 41105 NULL
122290 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
122291 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
122292 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
122293 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
122294 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
122295 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
122296 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
122297 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
122298 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
122299 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
122300 +erst_read_41260 erst_read 0 41260 NULL
122301 +alloc_context_41283 alloc_context 1 41283 NULL
122302 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
122303 +virtscsi_change_queue_depth_41327 virtscsi_change_queue_depth 2 41327 NULL
122304 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
122305 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
122306 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
122307 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
122308 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
122309 +kmp_init_41373 kmp_init 2 41373 NULL
122310 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
122311 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
122312 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
122313 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
122314 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
122315 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
122316 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
122317 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
122318 +se_io_cb_41461 se_io_cb 3 41461 NULL
122319 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
122320 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
122321 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
122322 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
122323 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
122324 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
122325 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
122326 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
122327 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
122328 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
122329 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
122330 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
122331 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
122332 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
122333 +nfsd_readv_41585 nfsd_readv 4 41585 NULL
122334 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
122335 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
122336 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
122337 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
122338 +a2mp_send_41615 a2mp_send 4 41615 NULL
122339 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
122340 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
122341 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
122342 +get_std_timing_41654 get_std_timing 0 41654 NULL
122343 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
122344 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
122345 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
122346 +connector_write_41709 connector_write 3 41709 NULL
122347 +fillonedir_41746 fillonedir 3 41746 NULL
122348 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
122349 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
122350 +ptlrpc_new_bulk_41804 ptlrpc_new_bulk 1 41804 NULL
122351 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
122352 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
122353 +kimage_file_alloc_init_41827 kimage_file_alloc_init 5 41827 NULL
122354 +copy_page_to_iter_bvec_41830 copy_page_to_iter_bvec 0-3 41830 NULL
122355 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
122356 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
122357 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
122358 +pci_map_single_41869 pci_map_single 0 41869 NULL
122359 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
122360 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
122361 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
122362 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 4-3 41935 NULL
122363 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
122364 +read_gssp_41947 read_gssp 3 41947 NULL
122365 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
122366 +portnames_read_41958 portnames_read 3 41958 NULL
122367 +dst_mtu_41969 dst_mtu 0 41969 NULL
122368 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
122369 +pool_allocate_42012 pool_allocate 3 42012 NULL
122370 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
122371 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
122372 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
122373 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
122374 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
122375 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
122376 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
122377 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
122378 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
122379 +ufshcd_dev_cmd_completion_42080 ufshcd_dev_cmd_completion 0 42080 NULL
122380 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
122381 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
122382 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
122383 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
122384 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
122385 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
122386 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
122387 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
122388 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
122389 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
122390 +blockdev_direct_IO_42235 blockdev_direct_IO 5 42235 NULL nohasharray
122391 +pla_ocp_read_42235 pla_ocp_read 3 42235 &blockdev_direct_IO_42235
122392 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
122393 +find_last_bit_42260 find_last_bit 0 42260 NULL
122394 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
122395 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
122396 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
122397 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
122398 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
122399 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
122400 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
122401 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
122402 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
122403 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
122404 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
122405 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
122406 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
122407 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
122408 +krng_get_random_42420 krng_get_random 3 42420 NULL
122409 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
122410 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
122411 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
122412 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
122413 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
122414 +kuc_free_42455 kuc_free 2 42455 NULL
122415 +cp2112_gpio_get_42467 cp2112_gpio_get 2 42467 NULL
122416 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
122417 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
122418 +bypass_write_42498 bypass_write 3 42498 NULL
122419 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
122420 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
122421 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
122422 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
122423 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
122424 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
122425 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
122426 +iwl_print_event_log_42566 iwl_print_event_log 0-7-5 42566 NULL
122427 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
122428 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
122429 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
122430 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
122431 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
122432 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL nohasharray
122433 +num_controllers_42644 num_controllers 0 42644 &parport_pc_compat_write_block_pio_42644
122434 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
122435 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
122436 +vb2_read_42703 vb2_read 3 42703 NULL
122437 +read_status_42722 read_status 0 42722 NULL
122438 +iwl_mvm_coex_dump_mbox_old_42727 iwl_mvm_coex_dump_mbox_old 4-3-0 42727 NULL
122439 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
122440 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
122441 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
122442 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
122443 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
122444 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
122445 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
122446 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
122447 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
122448 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
122449 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
122450 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
122451 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
122452 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
122453 +set_arg_42824 set_arg 3 42824 NULL
122454 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
122455 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
122456 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
122457 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
122458 +hd_end_request_42904 hd_end_request 2 42904 NULL
122459 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
122460 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
122461 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
122462 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2 42971 NULL
122463 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
122464 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
122465 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
122466 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
122467 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
122468 +__bioset_create_43059 __bioset_create 1 43059 NULL
122469 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
122470 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
122471 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
122472 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
122473 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
122474 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
122475 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
122476 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
122477 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
122478 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
122479 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
122480 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
122481 +uio_write_43202 uio_write 3 43202 NULL
122482 +iso_callback_43208 iso_callback 3 43208 NULL
122483 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
122484 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
122485 +atomic_long_add_return_43217 atomic_long_add_return 1 43217 NULL
122486 +gfs2_direct_IO_43220 gfs2_direct_IO 4 43220 NULL
122487 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
122488 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
122489 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
122490 +evtchn_write_43278 evtchn_write 3 43278 NULL nohasharray
122491 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 &evtchn_write_43278
122492 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
122493 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
122494 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
122495 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
122496 +xenfb_write_43412 xenfb_write 3 43412 NULL
122497 +ext4_xattr_check_names_43422 ext4_xattr_check_names 0 43422 NULL
122498 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
122499 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
122500 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
122501 +usemap_size_43443 usemap_size 0-2-1 43443 NULL nohasharray
122502 +usb_string_43443 usb_string 0 43443 &usemap_size_43443
122503 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
122504 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
122505 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
122506 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
122507 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
122508 +ll_direct_IO_26_43530 ll_direct_IO_26 4 43530 NULL
122509 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
122510 +read_events_43534 read_events 3 43534 NULL
122511 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
122512 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
122513 +request_resource_43548 request_resource 0 43548 NULL
122514 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
122515 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
122516 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
122517 +proc_read_43614 proc_read 3 43614 NULL
122518 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
122519 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
122520 +random_write_43656 random_write 3 43656 NULL
122521 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
122522 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
122523 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
122524 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
122525 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
122526 +nvkm_connector_create__43711 nvkm_connector_create_ 6 43711 NULL
122527 +fuse_send_read_43725 fuse_send_read 4-0 43725 NULL
122528 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
122529 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
122530 +__alloc_alien_cache_43734 __alloc_alien_cache 2 43734 NULL
122531 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
122532 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
122533 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
122534 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
122535 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
122536 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
122537 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
122538 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
122539 +read_flush_43851 read_flush 3 43851 NULL
122540 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
122541 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
122542 +SendString_43928 SendString 3 43928 NULL
122543 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
122544 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
122545 +nla_reserve_43984 nla_reserve 3 43984 NULL
122546 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
122547 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 NULL nohasharray
122548 +scsi_command_size_43992 scsi_command_size 0 43992 &kvm_read_guest_virt_43992 nohasharray
122549 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992
122550 +emit_flags_44006 emit_flags 4-3 44006 NULL
122551 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
122552 +fru_strlen_44046 fru_strlen 0 44046 NULL
122553 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
122554 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
122555 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
122556 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
122557 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
122558 +nouveau_clock_create__44116 nouveau_clock_create_ 6 44116 NULL
122559 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
122560 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
122561 +tracing_resize_saved_cmdlines_44140 tracing_resize_saved_cmdlines 1 44140 NULL
122562 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
122563 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
122564 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
122565 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
122566 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
122567 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
122568 +btrfs_item_offset_nr_44220 btrfs_item_offset_nr 0 44220 NULL
122569 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
122570 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
122571 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
122572 +device_create_file_44285 device_create_file 0 44285 NULL
122573 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
122574 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
122575 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
122576 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
122577 +rs_init_44327 rs_init 1 44327 NULL
122578 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
122579 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
122580 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
122581 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
122582 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
122583 +strlcpy_44400 strlcpy 3 44400 NULL
122584 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
122585 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
122586 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
122587 +mic_virtio_copy_to_user_44472 mic_virtio_copy_to_user 3-4 44472 NULL
122588 +write_file_debug_44476 write_file_debug 3 44476 NULL
122589 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
122590 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
122591 +bio_advance_44496 bio_advance 2 44496 NULL
122592 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
122593 +ac_register_board_44504 ac_register_board 3 44504 NULL
122594 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
122595 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
122596 +spidev_write_44510 spidev_write 3 44510 NULL
122597 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
122598 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
122599 +comm_write_44537 comm_write 3 44537 NULL
122600 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
122601 +l2cap_sock_memcpy_fromiovec_cb_44573 l2cap_sock_memcpy_fromiovec_cb 4 44573 NULL
122602 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
122603 +xpcs_mmd_write_44633 xpcs_mmd_write 3 44633 NULL
122604 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
122605 +mpi_resize_44674 mpi_resize 2 44674 NULL
122606 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
122607 +ts_read_44687 ts_read 3 44687 NULL
122608 +write_file_spectral_bins_44696 write_file_spectral_bins 3 44696 NULL
122609 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
122610 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
122611 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
122612 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
122613 +nft_hash_tbl_size_44724 nft_hash_tbl_size 0 44724 NULL
122614 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
122615 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
122616 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
122617 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
122618 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
122619 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
122620 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
122621 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
122622 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
122623 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
122624 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
122625 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
122626 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
122627 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
122628 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
122629 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
122630 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
122631 +sisusb_write_44834 sisusb_write 3 44834 NULL
122632 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
122633 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
122634 +copydesc_user_44855 copydesc_user 3 44855 NULL
122635 +set_advertising_44870 set_advertising 4 44870 NULL
122636 +init_rs_44873 init_rs 1 44873 NULL
122637 +skb_availroom_44883 skb_availroom 0 44883 NULL
122638 +do_tty_write_44896 do_tty_write 5 44896 NULL
122639 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
122640 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
122641 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
122642 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
122643 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
122644 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
122645 +sel_write_user_45060 sel_write_user 3 45060 NULL
122646 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
122647 +lnet_expand1tb_45102 lnet_expand1tb 6 45102 NULL
122648 +snd_card_new_45104 snd_card_new 5 45104 NULL
122649 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
122650 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
122651 +usbdev_read_45114 usbdev_read 3 45114 NULL
122652 +send_to_tty_45141 send_to_tty 3 45141 NULL
122653 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
122654 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
122655 +device_write_45156 device_write 3 45156 NULL nohasharray
122656 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
122657 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
122658 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
122659 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
122660 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
122661 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
122662 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
122663 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
122664 +event_enable_write_45238 event_enable_write 3 45238 NULL
122665 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
122666 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
122667 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
122668 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
122669 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
122670 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
122671 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
122672 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
122673 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
122674 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
122675 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
122676 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
122677 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
122678 +blkdev_direct_IO_45440 blkdev_direct_IO 4 45440 NULL
122679 +__node_remap_45458 __node_remap 4 45458 NULL
122680 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
122681 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
122682 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
122683 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
122684 +copy_macs_45534 copy_macs 4 45534 NULL
122685 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
122686 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
122687 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
122688 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
122689 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
122690 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
122691 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
122692 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
122693 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
122694 +ip_dst_mtu_maybe_forward_45627 ip_dst_mtu_maybe_forward 0 45627 NULL
122695 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
122696 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
122697 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
122698 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
122699 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
122700 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
122701 +wlcore_smart_config_decode_event_45714 wlcore_smart_config_decode_event 2-4 45714 NULL
122702 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
122703 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
122704 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
122705 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
122706 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
122707 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
122708 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
122709 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
122710 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
122711 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
122712 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
122713 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
122714 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
122715 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
122716 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
122717 +isdn_write_45863 isdn_write 3 45863 NULL
122718 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
122719 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
122720 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
122721 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
122722 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
122723 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
122724 +alloc_mr_45935 alloc_mr 1 45935 NULL
122725 +copy_to_45969 copy_to 3 45969 NULL
122726 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
122727 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
122728 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
122729 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
122730 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
122731 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
122732 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
122733 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL nohasharray
122734 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 &dma_tx_errors_read_46060
122735 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
122736 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
122737 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
122738 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
122739 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
122740 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
122741 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
122742 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
122743 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
122744 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
122745 +fq_resize_46195 fq_resize 2 46195 NULL
122746 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
122747 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
122748 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
122749 +dsp_write_46218 dsp_write 2 46218 NULL
122750 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
122751 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
122752 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
122753 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
122754 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
122755 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
122756 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
122757 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
122758 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
122759 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
122760 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
122761 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
122762 +wdata_alloc_and_fillpages_46437 wdata_alloc_and_fillpages 1 46437 NULL
122763 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
122764 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
122765 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
122766 +filldir64_46469 filldir64 3 46469 NULL
122767 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
122768 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
122769 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
122770 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
122771 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
122772 +nlm_end_grace_write_46517 nlm_end_grace_write 3 46517 NULL
122773 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
122774 +__btrfs_free_extent_46573 __btrfs_free_extent 7 46573 NULL
122775 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
122776 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
122777 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
122778 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
122779 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
122780 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
122781 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
122782 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
122783 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
122784 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
122785 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
122786 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
122787 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
122788 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
122789 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
122790 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
122791 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
122792 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
122793 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
122794 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
122795 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
122796 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
122797 +readreg_46845 readreg 0 46845 NULL
122798 +spi_async_46857 spi_async 0 46857 NULL
122799 +vsnprintf_46863 vsnprintf 0 46863 NULL
122800 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
122801 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
122802 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
122803 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
122804 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
122805 +alloc_cmdid_46904 alloc_cmdid 0 46904 NULL
122806 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
122807 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
122808 +fb_write_46924 fb_write 3 46924 NULL
122809 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
122810 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
122811 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
122812 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
122813 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
122814 +strlcat_46985 strlcat 3 46985 NULL
122815 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
122816 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
122817 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
122818 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
122819 +fs_path_len_47060 fs_path_len 0 47060 NULL
122820 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
122821 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
122822 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
122823 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
122824 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
122825 +mousedev_read_47123 mousedev_read 3 47123 NULL
122826 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
122827 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
122828 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
122829 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
122830 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
122831 +options_write_47243 options_write 3 47243 NULL
122832 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
122833 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
122834 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
122835 +vsnprintf_47291 vsnprintf 0 47291 NULL
122836 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
122837 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
122838 +virtqueue_add_47306 virtqueue_add 3 47306 NULL
122839 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
122840 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
122841 +nvme_submit_admin_cmd_47357 nvme_submit_admin_cmd 0 47357 NULL
122842 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
122843 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
122844 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
122845 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
122846 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
122847 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
122848 +nametbl_list_47391 nametbl_list 2 47391 NULL
122849 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
122850 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
122851 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
122852 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
122853 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
122854 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
122855 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
122856 +lprocfs_fid_write_common_47471 lprocfs_fid_write_common 2 47471 NULL
122857 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
122858 +newpart_47485 newpart 6-4 47485 NULL
122859 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
122860 +core_sys_select_47494 core_sys_select 1 47494 NULL
122861 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
122862 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
122863 +unlink_simple_47506 unlink_simple 3 47506 NULL
122864 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
122865 +ec_i2c_count_response_47518 ec_i2c_count_response 0 47518 NULL
122866 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
122867 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
122868 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
122869 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
122870 +drbg_statelen_47551 drbg_statelen 0 47551 NULL
122871 +read_ldt_47570 read_ldt 2 47570 NULL
122872 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
122873 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
122874 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
122875 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
122876 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
122877 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
122878 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
122879 +get_size_47644 get_size 1-2 47644 NULL
122880 +osc_brw_prep_request_47680 osc_brw_prep_request 5 47680 NULL
122881 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
122882 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
122883 +save_microcode_47717 save_microcode 3 47717 NULL
122884 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
122885 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
122886 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
122887 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
122888 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
122889 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
122890 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
122891 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
122892 +ptlrpc_prep_req_47792 ptlrpc_prep_req 4 47792 NULL
122893 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
122894 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
122895 +lov_packmd_47810 lov_packmd 0 47810 NULL
122896 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
122897 +read_file_spectral_bins_47829 read_file_spectral_bins 3 47829 NULL
122898 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
122899 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
122900 +vhci_read_47878 vhci_read 3 47878 NULL
122901 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
122902 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
122903 +comedi_write_47926 comedi_write 3 47926 NULL
122904 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
122905 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
122906 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
122907 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
122908 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
122909 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
122910 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
122911 +lustre_cfg_len_48002 lustre_cfg_len 0-1 48002 NULL
122912 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
122913 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
122914 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
122915 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
122916 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
122917 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
122918 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
122919 +disc_write_48070 disc_write 3 48070 NULL
122920 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
122921 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
122922 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
122923 +load_firmware_48128 load_firmware 2 48128 NULL
122924 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
122925 +set_discoverable_48141 set_discoverable 4 48141 NULL
122926 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
122927 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
122928 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
122929 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
122930 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
122931 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
122932 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
122933 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
122934 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
122935 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
122936 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
122937 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
122938 +read_file_recv_48232 read_file_recv 3 48232 NULL
122939 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
122940 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
122941 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
122942 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
122943 +__videobuf_free_48260 __videobuf_free 0 48260 NULL
122944 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
122945 +trace_options_write_48275 trace_options_write 3 48275 NULL
122946 +send_set_info_48288 send_set_info 7 48288 NULL
122947 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
122948 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
122949 +hash_setkey_48310 hash_setkey 3 48310 NULL
122950 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
122951 +skb_add_data_48363 skb_add_data 3 48363 NULL
122952 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
122953 +ath10k_read_htt_max_amsdu_ampdu_48401 ath10k_read_htt_max_amsdu_ampdu 3 48401 NULL
122954 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
122955 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
122956 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
122957 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
122958 +print_filtered_48442 print_filtered 2-0 48442 NULL
122959 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
122960 +copy_page_from_iter_iovec_48466 copy_page_from_iter_iovec 3-0 48466 NULL
122961 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
122962 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
122963 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
122964 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
122965 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
122966 +send_control_msg_48498 send_control_msg 6 48498 NULL
122967 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
122968 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
122969 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
122970 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
122971 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
122972 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
122973 +nvif_notify_init_48578 nvif_notify_init 7 48578 NULL
122974 +llog_data_len_48607 llog_data_len 1 48607 NULL
122975 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
122976 +kernel_sock_ioctl_48644 kernel_sock_ioctl 0 48644 NULL
122977 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
122978 +mtd_read_48655 mtd_read 0 48655 NULL
122979 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
122980 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
122981 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
122982 +altera_drscan_48698 altera_drscan 2 48698 NULL
122983 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
122984 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
122985 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
122986 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
122987 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
122988 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
122989 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
122990 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
122991 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
122992 +azx_get_position_48841 azx_get_position 0 48841 NULL
122993 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
122994 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
122995 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
122996 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL nohasharray
122997 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 &viafb_dvp1_proc_write_48864
122998 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
122999 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
123000 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
123001 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
123002 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
123003 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
123004 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
123005 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
123006 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
123007 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
123008 +nilfs_direct_IO_48981 nilfs_direct_IO 4 48981 NULL
123009 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
123010 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
123011 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
123012 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
123013 +transient_status_49027 transient_status 4 49027 NULL
123014 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
123015 +scsi_register_49094 scsi_register 2 49094 NULL
123016 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
123017 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
123018 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
123019 +pt_read_49136 pt_read 3 49136 NULL nohasharray
123020 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
123021 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
123022 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
123023 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
123024 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
123025 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
123026 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
123027 +print_queue_49191 print_queue 0-4 49191 NULL
123028 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
123029 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
123030 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
123031 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
123032 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
123033 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
123034 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
123035 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
123036 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
123037 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
123038 +uio_read_49300 uio_read 3 49300 NULL
123039 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
123040 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
123041 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
123042 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
123043 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
123044 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
123045 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
123046 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
123047 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
123048 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
123049 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
123050 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
123051 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
123052 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
123053 +tipc_bclink_get_mtu_49483 tipc_bclink_get_mtu 0 49483 NULL
123054 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
123055 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
123056 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
123057 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
123058 +smk_write_access_49561 smk_write_access 3 49561 NULL
123059 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
123060 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
123061 +readfifo_49583 readfifo 1 49583 NULL
123062 +tap_write_49595 tap_write 3 49595 NULL
123063 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
123064 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
123065 +heap_init_49617 heap_init 2 49617 NULL
123066 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
123067 +port_fops_read_49626 port_fops_read 3 49626 NULL
123068 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
123069 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
123070 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
123071 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
123072 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
123073 +write_pool_49718 write_pool 3 49718 NULL
123074 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL nohasharray
123075 +sfw_create_test_rpc_49723 sfw_create_test_rpc 4 49723 &kvm_mmu_notifier_invalidate_page_49723
123076 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
123077 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
123078 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
123079 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
123080 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
123081 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
123082 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
123083 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
123084 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
123085 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
123086 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
123087 +add_uuid_49831 add_uuid 4 49831 NULL
123088 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
123089 +twl4030_write_49846 twl4030_write 2 49846 NULL
123090 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
123091 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
123092 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
123093 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
123094 +osc_brw_49896 osc_brw 4 49896 NULL
123095 +fuse_send_write_49915 fuse_send_write 4-0 49915 NULL
123096 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
123097 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
123098 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
123099 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
123100 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
123101 +isdn_read_50021 isdn_read 3 50021 NULL
123102 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
123103 +xlog_recovery_process_trans_50028 xlog_recovery_process_trans 4 50028 NULL
123104 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
123105 +ioread8_50049 ioread8 0 50049 NULL
123106 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
123107 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
123108 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
123109 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
123110 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
123111 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
123112 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
123113 +read_file_slot_50111 read_file_slot 3 50111 NULL
123114 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
123115 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
123116 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
123117 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
123118 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
123119 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
123120 +odev_update_50169 odev_update 2 50169 NULL
123121 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
123122 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
123123 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
123124 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
123125 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
123126 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
123127 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
123128 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
123129 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
123130 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
123131 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
123132 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
123133 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
123134 +do_launder_page_50329 do_launder_page 0 50329 NULL
123135 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
123136 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
123137 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
123138 +tpm_read_50344 tpm_read 3 50344 NULL
123139 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
123140 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
123141 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
123142 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
123143 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
123144 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
123145 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
123146 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
123147 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
123148 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
123149 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
123150 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
123151 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
123152 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
123153 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
123154 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
123155 +trigger_request_store_50548 trigger_request_store 4 50548 NULL
123156 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
123157 +fat_readpages_50582 fat_readpages 4 50582 NULL
123158 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
123159 +xillybus_write_50605 xillybus_write 3 50605 NULL
123160 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
123161 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
123162 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
123163 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
123164 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
123165 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
123166 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
123167 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
123168 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
123169 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
123170 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
123171 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
123172 +tpm_write_50798 tpm_write 3 50798 NULL
123173 +tun_do_read_50800 tun_do_read 4 50800 NULL
123174 +write_flush_50803 write_flush 3 50803 NULL
123175 +dvb_play_50814 dvb_play 3 50814 NULL
123176 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
123177 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
123178 +SetArea_50835 SetArea 4 50835 NULL
123179 +nft_trans_alloc_50836 nft_trans_alloc 3 50836 NULL
123180 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
123181 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
123182 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
123183 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
123184 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
123185 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
123186 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
123187 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
123188 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
123189 +show_device_status_50947 show_device_status 0 50947 NULL
123190 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
123191 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
123192 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
123193 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
123194 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
123195 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
123196 +timeout_write_50991 timeout_write 3 50991 NULL
123197 +proc_write_51003 proc_write 3 51003 NULL
123198 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
123199 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
123200 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
123201 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
123202 +dump_midi_51040 dump_midi 3 51040 NULL
123203 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
123204 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
123205 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
123206 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
123207 +rsc_mgr_init_51067 rsc_mgr_init 3 51067 NULL
123208 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
123209 +__ipv4_tun_to_nlattr_51095 __ipv4_tun_to_nlattr 4 51095 NULL
123210 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
123211 +ti_recv_51110 ti_recv 3 51110 NULL
123212 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
123213 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
123214 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
123215 +i40evf_acquire_msix_vectors_51190 i40evf_acquire_msix_vectors 2 51190 NULL
123216 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
123217 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
123218 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
123219 +drm_property_create_51239 drm_property_create 4 51239 NULL
123220 +st_read_51251 st_read 3 51251 NULL
123221 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
123222 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
123223 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
123224 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
123225 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
123226 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
123227 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
123228 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
123229 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
123230 +smk_write_ptrace_51333 smk_write_ptrace 3 51333 NULL
123231 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
123232 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
123233 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
123234 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
123235 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
123236 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
123237 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
123238 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
123239 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
123240 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
123241 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
123242 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
123243 +osc_brw_internal_51489 osc_brw_internal 5 51489 NULL
123244 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
123245 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
123246 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
123247 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
123248 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
123249 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
123250 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
123251 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
123252 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
123253 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
123254 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
123255 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
123256 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
123257 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
123258 +sel_write_access_51704 sel_write_access 3 51704 NULL
123259 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
123260 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
123261 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
123262 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
123263 +str_read_51731 str_read 4 51731 NULL
123264 +cm4040_read_51732 cm4040_read 3 51732 NULL
123265 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
123266 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
123267 +if_write_51756 if_write 3 51756 NULL
123268 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
123269 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
123270 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
123271 +ioread32_51847 ioread32 0 51847 NULL nohasharray
123272 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
123273 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
123274 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
123275 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
123276 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
123277 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
123278 +user_read_51881 user_read 3 51881 NULL
123279 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
123280 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
123281 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
123282 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
123283 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
123284 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
123285 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
123286 +get_clock_info_51952 get_clock_info 4 51952 NULL
123287 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
123288 +get_zone_51981 get_zone 0-1 51981 NULL
123289 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
123290 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
123291 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
123292 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
123293 +rdmalt_52022 rdmalt 0 52022 NULL
123294 +override_release_52032 override_release 2 52032 NULL
123295 +end_port_52042 end_port 0 52042 NULL
123296 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
123297 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
123298 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
123299 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
123300 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
123301 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
123302 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
123303 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
123304 +smsdvb_stats_read_52114 smsdvb_stats_read 3 52114 NULL
123305 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
123306 +retry_count_read_52129 retry_count_read 3 52129 NULL
123307 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
123308 +sub_alloc_52140 sub_alloc 0 52140 NULL
123309 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
123310 +htable_size_52148 htable_size 0-1 52148 NULL
123311 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
123312 +tipc_node_get_mtu_52157 tipc_node_get_mtu 0 52157 NULL
123313 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
123314 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
123315 +print_prefix_52176 print_prefix 0 52176 NULL
123316 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
123317 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
123318 +f2fs_seek_block_52194 f2fs_seek_block 2 52194 NULL
123319 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
123320 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
123321 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
123322 +shrink_slab_52261 shrink_slab 2 52261 NULL
123323 +ext2_direct_IO_52270 ext2_direct_IO 4 52270 NULL
123324 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
123325 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
123326 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
123327 +read_file_reset_52310 read_file_reset 3 52310 NULL
123328 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
123329 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
123330 +hwflags_read_52318 hwflags_read 3 52318 NULL
123331 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
123332 +hur_len_52339 hur_len 0 52339 NULL
123333 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
123334 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
123335 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
123336 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
123337 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
123338 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
123339 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
123340 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
123341 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
123342 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
123343 +delay_status_52431 delay_status 5 52431 NULL
123344 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
123345 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
123346 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
123347 +bt_alloc_52457 bt_alloc 2 52457 NULL
123348 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
123349 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
123350 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
123351 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
123352 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
123353 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
123354 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
123355 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
123356 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
123357 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
123358 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
123359 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
123360 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
123361 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
123362 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
123363 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
123364 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
123365 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
123366 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
123367 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
123368 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
123369 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
123370 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
123371 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
123372 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
123373 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
123374 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
123375 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
123376 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
123377 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
123378 +xenvif_write_io_ring_52802 xenvif_write_io_ring 3 52802 NULL
123379 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
123380 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
123381 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
123382 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
123383 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
123384 +twlreg_write_52880 twlreg_write 3 52880 NULL
123385 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
123386 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
123387 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
123388 +copy_from_iter_bvec_52912 copy_from_iter_bvec 0-2 52912 NULL
123389 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
123390 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
123391 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
123392 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
123393 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
123394 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
123395 +num_node_state_52989 num_node_state 0 52989 NULL
123396 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
123397 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
123398 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
123399 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
123400 +nv50_chan_create_53039 nv50_chan_create 5 53039 NULL
123401 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
123402 +fimc_get_alpha_mask_53057 fimc_get_alpha_mask 0 53057 NULL
123403 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
123404 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
123405 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
123406 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
123407 +ath10k_mac_create_53118 ath10k_mac_create 1 53118 NULL
123408 +verity_status_53120 verity_status 5 53120 NULL
123409 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
123410 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
123411 +copy_user_segment_list_53150 copy_user_segment_list 2 53150 NULL
123412 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
123413 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
123414 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
123415 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
123416 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
123417 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
123418 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
123419 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
123420 +f2fs_fiemap_53310 f2fs_fiemap 4 53310 NULL
123421 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
123422 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
123423 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
123424 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
123425 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
123426 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
123427 +test_fw_misc_read_53384 test_fw_misc_read 3 53384 NULL
123428 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
123429 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
123430 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
123431 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
123432 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
123433 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
123434 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
123435 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
123436 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
123437 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
123438 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
123439 +check_acl_53512 check_acl 0 53512 NULL nohasharray
123440 +force_sc_support_write_53512 force_sc_support_write 3 53512 &check_acl_53512
123441 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
123442 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
123443 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
123444 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
123445 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
123446 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL nohasharray
123447 +wil_write_file_txmgmt_53626 wil_write_file_txmgmt 3 53626 &___alloc_bootmem_nopanic_53626
123448 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
123449 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
123450 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
123451 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
123452 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
123453 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
123454 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
123455 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
123456 +wdm_write_53735 wdm_write 3 53735 NULL
123457 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL
123458 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
123459 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
123460 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
123461 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
123462 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
123463 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
123464 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
123465 +setup_data_read_53822 setup_data_read 3 53822 NULL
123466 +btrfs_free_reserved_extent_53873 btrfs_free_reserved_extent 2 53873 NULL nohasharray
123467 +pms_read_53873 pms_read 3 53873 &btrfs_free_reserved_extent_53873
123468 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
123469 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
123470 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
123471 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
123472 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
123473 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
123474 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
123475 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
123476 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
123477 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
123478 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
123479 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
123480 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
123481 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
123482 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
123483 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
123484 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
123485 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
123486 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
123487 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
123488 +strn_len_54122 strn_len 0 54122 NULL
123489 +isku_receive_54130 isku_receive 4 54130 NULL
123490 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
123491 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
123492 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
123493 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
123494 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
123495 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
123496 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
123497 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
123498 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
123499 +reada_add_block_54247 reada_add_block 2 54247 NULL
123500 +write_file_spec_scan_ctl_54248 write_file_spec_scan_ctl 3 54248 NULL
123501 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
123502 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
123503 +audio_write_54261 audio_write 4 54261 NULL nohasharray
123504 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
123505 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
123506 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
123507 +sizeof_long_54276 sizeof_long 0 54276 NULL
123508 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
123509 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
123510 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
123511 +sprintf_54306 sprintf 0 54306 NULL
123512 +path_setxattr_54308 path_setxattr 4 54308 NULL
123513 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
123514 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
123515 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
123516 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
123517 +readlink_copy_54366 readlink_copy 2 54366 NULL
123518 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
123519 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 NULL nohasharray
123520 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 &intel_sdvo_write_cmd_54377
123521 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
123522 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
123523 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL nohasharray
123524 +hash_mac4_expire_54392 hash_mac4_expire 4 54392 &iwl_dbgfs_power_save_status_read_54392
123525 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
123526 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
123527 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
123528 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
123529 +l2cap_create_basic_pdu_54508 l2cap_create_basic_pdu 3 54508 NULL
123530 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
123531 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
123532 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
123533 +viacam_read_54526 viacam_read 3 54526 NULL
123534 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
123535 +setsockopt_54539 setsockopt 5 54539 NULL
123536 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
123537 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
123538 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
123539 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
123540 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
123541 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
123542 +port_fops_write_54627 port_fops_write 3 54627 NULL
123543 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
123544 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
123545 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
123546 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
123547 +simple_alloc_urb_54661 simple_alloc_urb 3 54661 NULL
123548 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
123549 +bus_add_device_54665 bus_add_device 0 54665 NULL
123550 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
123551 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
123552 +evm_read_key_54674 evm_read_key 3 54674 NULL
123553 +jfs_direct_IO_54687 jfs_direct_IO 4 54687 NULL
123554 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
123555 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
123556 +kzalloc_54740 kzalloc 1 54740 NULL
123557 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
123558 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
123559 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
123560 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
123561 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
123562 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
123563 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
123564 +nfsd_write_54809 nfsd_write 6 54809 NULL
123565 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
123566 +kvzalloc_54815 kvzalloc 1 54815 NULL nohasharray
123567 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 &kvzalloc_54815 nohasharray
123568 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &crypto_tfm_ctx_alignment_54815
123569 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
123570 +write_rio_54837 write_rio 3 54837 NULL
123571 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
123572 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
123573 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
123574 +printer_read_54851 printer_read 3 54851 NULL
123575 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
123576 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
123577 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
123578 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
123579 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
123580 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
123581 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
123582 +add_port_54941 add_port 2 54941 NULL
123583 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
123584 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
123585 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
123586 +c4_add_card_54968 c4_add_card 3 54968 NULL
123587 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
123588 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
123589 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
123590 +efw_transaction_55052 efw_transaction 5-7 55052 NULL
123591 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
123592 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
123593 +read_dma_55086 read_dma 3 55086 NULL
123594 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
123595 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
123596 +filldir_55137 filldir 3 55137 NULL
123597 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
123598 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
123599 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
123600 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
123601 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
123602 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
123603 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
123604 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
123605 +mlx4_load_one_55213 mlx4_load_one 3 55213 NULL
123606 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
123607 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
123608 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
123609 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
123610 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
123611 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
123612 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
123613 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
123614 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
123615 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
123616 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
123617 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
123618 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
123619 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
123620 +vme_user_read_55338 vme_user_read 3 55338 NULL
123621 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
123622 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
123623 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
123624 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
123625 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
123626 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
123627 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
123628 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
123629 +ufshcd_exec_dev_cmd_55479 ufshcd_exec_dev_cmd 0 55479 NULL
123630 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
123631 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
123632 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
123633 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
123634 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
123635 +ea_get_55522 ea_get 3-0 55522 NULL
123636 +buffer_size_55534 buffer_size 0 55534 NULL
123637 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
123638 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
123639 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
123640 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
123641 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
123642 +add_partition_55588 add_partition 2 55588 NULL
123643 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
123644 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
123645 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
123646 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
123647 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
123648 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
123649 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
123650 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
123651 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
123652 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
123653 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
123654 +get_info_55681 get_info 3 55681 NULL
123655 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
123656 +ext4_alloc_file_blocks_55689 ext4_alloc_file_blocks 3 55689 NULL
123657 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
123658 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
123659 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
123660 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
123661 +set_local_name_55757 set_local_name 4 55757 NULL
123662 +ethtool_copy_validate_indir_55769 ethtool_copy_validate_indir 4 55769 NULL
123663 +strlen_55778 strlen 0 55778 NULL
123664 +set_spte_55783 set_spte 4-5 55783 NULL
123665 +conf_read_55786 conf_read 3 55786 NULL nohasharray
123666 +req_bio_endio_55786 req_bio_endio 3 55786 &conf_read_55786
123667 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
123668 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
123669 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
123670 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
123671 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
123672 +hsc_write_55875 hsc_write 3 55875 NULL
123673 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
123674 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
123675 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
123676 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
123677 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
123678 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
123679 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
123680 +simple_read_from_buffer_55957 simple_read_from_buffer 5-2-0 55957 NULL
123681 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
123682 +btrfs_clone_55977 btrfs_clone 5-3-6 55977 NULL
123683 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
123684 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
123685 +iwl_trans_read_prph_56052 iwl_trans_read_prph 0 56052 NULL
123686 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
123687 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
123688 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
123689 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
123690 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
123691 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
123692 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 0-3 56194 NULL
123693 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
123694 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
123695 +ufshcd_query_descriptor_56236 ufshcd_query_descriptor 0 56236 NULL
123696 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
123697 +fd_copyin_56247 fd_copyin 3 56247 NULL
123698 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
123699 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
123700 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
123701 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
123702 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
123703 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
123704 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
123705 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
123706 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
123707 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
123708 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
123709 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
123710 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
123711 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 0-4 56368 NULL
123712 +dev_read_56369 dev_read 3 56369 NULL
123713 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
123714 +lnet_ping_56378 lnet_ping 4 56378 NULL
123715 +write_gssp_56404 write_gssp 3 56404 NULL
123716 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
123717 +store_msg_56417 store_msg 3 56417 NULL
123718 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
123719 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL nohasharray
123720 +nvme_submit_cmd_56426 nvme_submit_cmd 0 56426 &l2cap_segment_le_sdu_56426
123721 +lprocfs_fid_space_seq_write_56431 lprocfs_fid_space_seq_write 3 56431 NULL nohasharray
123722 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 &lprocfs_fid_space_seq_write_56431
123723 +fl_create_56435 fl_create 5 56435 NULL
123724 +gnttab_map_56439 gnttab_map 2 56439 NULL
123725 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
123726 +set_connectable_56458 set_connectable 4 56458 NULL
123727 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
123728 +putused_user_56467 putused_user 3 56467 NULL
123729 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
123730 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
123731 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
123732 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
123733 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
123734 +init_map_ip_56508 init_map_ip 5 56508 NULL
123735 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
123736 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
123737 +ip_options_get_56538 ip_options_get 4 56538 NULL
123738 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
123739 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
123740 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
123741 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
123742 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
123743 +event_filter_write_56609 event_filter_write 3 56609 NULL
123744 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
123745 +gather_array_56641 gather_array 3 56641 NULL
123746 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
123747 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
123748 +nv50_gpio_intr_mask_56665 nv50_gpio_intr_mask 4-3 56665 NULL
123749 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
123750 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
123751 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
123752 +sfw_alloc_pages_56709 sfw_alloc_pages 3 56709 NULL
123753 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
123754 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
123755 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
123756 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
123757 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
123758 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
123759 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
123760 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
123761 +do_syslog_56807 do_syslog 3 56807 NULL
123762 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
123763 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
123764 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
123765 +gk20a_ram_get_56863 gk20a_ram_get 2 56863 NULL
123766 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
123767 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
123768 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
123769 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 NULL nohasharray
123770 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 &le_auto_conn_write_56895
123771 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
123772 +strcspn_56913 strcspn 0 56913 NULL
123773 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
123774 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
123775 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
123776 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
123777 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
123778 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
123779 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
123780 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
123781 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
123782 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
123783 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
123784 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
123785 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
123786 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
123787 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
123788 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
123789 +altera_get_note_57099 altera_get_note 6 57099 NULL
123790 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
123791 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
123792 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
123793 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
123794 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
123795 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
123796 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
123797 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
123798 +acpi_gsb_i2c_read_bytes_57145 acpi_gsb_i2c_read_bytes 4 57145 NULL
123799 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
123800 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
123801 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
123802 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
123803 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
123804 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
123805 +drbg_blocklen_57239 drbg_blocklen 0 57239 NULL
123806 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
123807 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
123808 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
123809 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
123810 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
123811 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
123812 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
123813 +string_length_no_trail_57290 string_length_no_trail 0-2 57290 NULL
123814 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
123815 +write_file_regval_57313 write_file_regval 3 57313 NULL
123816 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
123817 +usblp_read_57342 usblp_read 3 57342 NULL
123818 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
123819 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
123820 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
123821 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
123822 +bzImage64_load_57388 bzImage64_load 7 57388 NULL
123823 +read_file_blob_57406 read_file_blob 3 57406 NULL
123824 +enclosure_register_57412 enclosure_register 3 57412 NULL
123825 +read_file_eeprom_57428 read_file_eeprom 3 57428 NULL
123826 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
123827 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
123828 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
123829 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
123830 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
123831 +read_file_skb_rx_57490 read_file_skb_rx 3 57490 NULL
123832 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
123833 +skb_headlen_57501 skb_headlen 0 57501 NULL
123834 +copy_in_user_57502 copy_in_user 3 57502 NULL
123835 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
123836 +init_tag_map_57515 init_tag_map 3 57515 NULL
123837 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
123838 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
123839 +cmm_read_57520 cmm_read 3 57520 NULL
123840 +inode_permission_57531 inode_permission 0 57531 NULL
123841 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
123842 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
123843 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
123844 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
123845 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
123846 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
123847 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
123848 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
123849 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
123850 +copy_to_iter_bvec_57604 copy_to_iter_bvec 0-2 57604 NULL
123851 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
123852 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
123853 +mem_read_57631 mem_read 3 57631 NULL
123854 +r3964_write_57662 r3964_write 4 57662 NULL
123855 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
123856 +__lgwrite_57669 __lgwrite 4 57669 NULL
123857 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
123858 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
123859 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
123860 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
123861 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
123862 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
123863 +ld2_57794 ld2 0 57794 NULL
123864 +ivtv_read_57796 ivtv_read 3 57796 NULL
123865 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
123866 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
123867 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
123868 +flash_read_57843 flash_read 3 57843 NULL
123869 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
123870 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
123871 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
123872 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
123873 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
123874 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
123875 +mwifiex_hscfg_read_57920 mwifiex_hscfg_read 3 57920 NULL
123876 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
123877 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
123878 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
123879 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
123880 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
123881 +arch_gnttab_init_57948 arch_gnttab_init 2-1 57948 NULL
123882 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
123883 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
123884 +iov_iter_npages_57979 iov_iter_npages 0-2 57979 NULL
123885 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
123886 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
123887 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
123888 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
123889 +mce_async_out_58056 mce_async_out 3 58056 NULL
123890 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
123891 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
123892 +cm4040_write_58079 cm4040_write 3 58079 NULL
123893 +savemem_58129 savemem 3 58129 NULL
123894 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
123895 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
123896 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
123897 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
123898 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
123899 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
123900 +read_file_debug_58256 read_file_debug 3 58256 NULL
123901 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
123902 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
123903 +profile_load_58267 profile_load 3 58267 NULL
123904 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
123905 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
123906 +r100_mm_rreg_58276 r100_mm_rreg 0 58276 NULL
123907 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
123908 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
123909 +mic_virtio_copy_from_user_58323 mic_virtio_copy_from_user 3 58323 NULL
123910 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
123911 +lstcon_rpc_prep_58325 lstcon_rpc_prep 4 58325 NULL
123912 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
123913 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
123914 +ec_i2c_parse_response_58347 ec_i2c_parse_response 0 58347 NULL
123915 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
123916 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
123917 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
123918 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
123919 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
123920 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
123921 +capabilities_read_58457 capabilities_read 3 58457 NULL
123922 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
123923 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
123924 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
123925 +nv_rd08_58472 nv_rd08 0 58472 NULL
123926 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
123927 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
123928 +dw_spi_show_regs_58486 dw_spi_show_regs 3 58486 NULL
123929 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
123930 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
123931 +cifs_write_from_iter_58526 cifs_write_from_iter 2 58526 NULL
123932 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
123933 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
123934 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
123935 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
123936 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
123937 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
123938 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
123939 +xip_file_read_58592 xip_file_read 3 58592 NULL
123940 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
123941 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
123942 +btrfs_direct_IO_58608 btrfs_direct_IO 4 58608 NULL
123943 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
123944 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
123945 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
123946 +find_zero_58685 find_zero 0-1 58685 NULL
123947 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
123948 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
123949 +visor_charqueue_create_58703 visor_charqueue_create 1 58703 NULL
123950 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
123951 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
123952 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
123953 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
123954 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
123955 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
123956 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
123957 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
123958 +ep_read_58813 ep_read 3 58813 NULL
123959 +command_write_58841 command_write 3 58841 NULL
123960 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
123961 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
123962 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
123963 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
123964 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
123965 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
123966 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
123967 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
123968 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
123969 +init_list_set_59005 init_list_set 3 59005 NULL
123970 +ep_write_59008 ep_write 3 59008 NULL
123971 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
123972 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
123973 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
123974 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
123975 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
123976 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
123977 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
123978 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
123979 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
123980 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
123981 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
123982 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
123983 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
123984 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
123985 +ksize_59176 ksize 0 59176 NULL
123986 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
123987 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
123988 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
123989 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
123990 +dt3155_read_59226 dt3155_read 3 59226 NULL
123991 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
123992 +nla_len_59258 nla_len 0 59258 NULL
123993 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
123994 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
123995 +fd_copyout_59323 fd_copyout 3 59323 NULL
123996 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
123997 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
123998 +__map_request_59350 __map_request 0 59350 NULL
123999 +SyS_getrandom_59366 SyS_getrandom 2 59366 NULL
124000 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
124001 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
124002 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
124003 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
124004 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
124005 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
124006 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
124007 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
124008 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
124009 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
124010 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
124011 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
124012 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
124013 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL
124014 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
124015 +tunables_write_59563 tunables_write 3 59563 NULL
124016 +bio_split_59564 bio_split 2 59564 NULL
124017 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
124018 +write_pbl_59583 write_pbl 4 59583 NULL
124019 +memdup_user_59590 memdup_user 2 59590 NULL
124020 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL nohasharray
124021 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 &mem_fwlog_free_mem_blks_read_59616
124022 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
124023 +mtrr_write_59622 mtrr_write 3 59622 NULL
124024 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
124025 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
124026 +hidraw_read_59650 hidraw_read 3 59650 NULL
124027 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
124028 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
124029 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
124030 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
124031 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
124032 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
124033 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
124034 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL nohasharray
124035 +nv94_aux_mask_59740 nv94_aux_mask 2 59740 &ieee80211_if_read_fwded_unicast_59740
124036 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
124037 +strnlen_59746 strnlen 0 59746 NULL
124038 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
124039 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
124040 +venus_remove_59781 venus_remove 4 59781 NULL
124041 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
124042 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
124043 +ipw_write_59807 ipw_write 3 59807 NULL
124044 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
124045 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
124046 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
124047 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
124048 +biovec_create_pool_59878 biovec_create_pool 1 59878 NULL
124049 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
124050 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
124051 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
124052 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
124053 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
124054 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
124055 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
124056 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
124057 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
124058 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
124059 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
124060 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
124061 +copy_items_60009 copy_items 7 60009 NULL
124062 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
124063 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
124064 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
124065 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
124066 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
124067 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
124068 +vcs_size_60050 vcs_size 0 60050 NULL
124069 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
124070 +compat_writev_60063 compat_writev 3 60063 NULL
124071 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
124072 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
124073 +usb_os_desc_prepare_interf_dir_60075 usb_os_desc_prepare_interf_dir 2 60075 NULL
124074 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
124075 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
124076 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
124077 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
124078 +pcpu_need_to_extend_60133 pcpu_need_to_extend 0 60133 NULL
124079 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
124080 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
124081 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
124082 +init_state_60165 init_state 2 60165 NULL
124083 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
124084 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
124085 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
124086 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL nohasharray
124087 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 &rx_rx_tkip_replays_read_60193
124088 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
124089 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
124090 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
124091 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
124092 +printer_write_60276 printer_write 3 60276 NULL
124093 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
124094 +getDataLength_60301 getDataLength 0 60301 NULL
124095 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
124096 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
124097 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
124098 +max_unfragmented_pages_60362 max_unfragmented_pages 0 60362 NULL
124099 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
124100 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
124101 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
124102 +driver_names_read_60399 driver_names_read 3 60399 NULL
124103 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
124104 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
124105 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
124106 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
124107 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
124108 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
124109 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
124110 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
124111 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
124112 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
124113 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
124114 +xfs_vm_direct_IO_60557 xfs_vm_direct_IO 4 60557 NULL
124115 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
124116 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
124117 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
124118 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
124119 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
124120 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
124121 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
124122 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
124123 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
124124 +raid_status_60755 raid_status 5 60755 NULL
124125 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
124126 +opticon_write_60775 opticon_write 4 60775 NULL
124127 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
124128 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
124129 +nvif_object_init_60848 nvif_object_init 6 60848 NULL
124130 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
124131 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
124132 +generic_writepages_60871 generic_writepages 0 60871 NULL
124133 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
124134 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
124135 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
124136 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
124137 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
124138 +pti_char_write_60960 pti_char_write 3 60960 NULL
124139 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
124140 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
124141 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
124142 +generic_file_direct_write_60995 generic_file_direct_write 0 60995 NULL
124143 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
124144 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
124145 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
124146 +read_file_ackto_61037 read_file_ackto 3 61037 NULL
124147 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
124148 +symtab_init_61050 symtab_init 2 61050 NULL
124149 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
124150 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
124151 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
124152 +get_derived_key_61100 get_derived_key 4 61100 NULL
124153 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
124154 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
124155 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
124156 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
124157 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
124158 +pair_device_61175 pair_device 4 61175 NULL nohasharray
124159 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
124160 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
124161 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
124162 +srp_create_fr_pool_61207 srp_create_fr_pool 3 61207 NULL
124163 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
124164 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
124165 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
124166 +kvm_age_hva_61267 kvm_age_hva 2-3 61267 NULL
124167 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 NULL nohasharray
124168 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 &find_get_pages_tag_61270 nohasharray
124169 +ifalias_store_61270 ifalias_store 4 61270 &btrfs_bio_alloc_61270
124170 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 NULL nohasharray
124171 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 &hfsplus_getxattr_finder_info_61283
124172 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
124173 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
124174 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
124175 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
124176 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
124177 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
124178 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
124179 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
124180 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
124181 +wil_write_file_recovery_61354 wil_write_file_recovery 3 61354 NULL
124182 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
124183 +system_enable_write_61396 system_enable_write 3 61396 NULL
124184 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
124185 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
124186 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
124187 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
124188 +erst_errno_61526 erst_errno 0 61526 NULL
124189 +proc_write_device_61541 proc_write_device 3 61541 NULL
124190 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
124191 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
124192 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
124193 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
124194 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
124195 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
124196 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
124197 +seq_open_private_61589 seq_open_private 3 61589 NULL
124198 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
124199 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
124200 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
124201 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
124202 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
124203 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
124204 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
124205 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
124206 +resize_stripes_61650 resize_stripes 2 61650 NULL
124207 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
124208 +insert_one_name_61668 insert_one_name 7 61668 NULL
124209 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
124210 +lock_loop_61681 lock_loop 1 61681 NULL
124211 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
124212 +filter_read_61692 filter_read 3 61692 NULL
124213 +SyS_kexec_file_load_61715 SyS_kexec_file_load 3 61715 NULL
124214 +iov_length_61716 iov_length 0 61716 NULL
124215 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
124216 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
124217 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
124218 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
124219 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
124220 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
124221 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
124222 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
124223 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
124224 +__skb_flow_dissect_61855 __skb_flow_dissect 5 61855 NULL
124225 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
124226 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
124227 +get_fw_name_61874 get_fw_name 3 61874 NULL
124228 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
124229 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
124230 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
124231 +kernfs_name_61910 kernfs_name 3 61910 NULL
124232 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
124233 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
124234 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
124235 +efi_get_runtime_map_size_61927 efi_get_runtime_map_size 0 61927 NULL
124236 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
124237 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
124238 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
124239 +fix_read_error_61965 fix_read_error 4 61965 NULL
124240 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
124241 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
124242 +cow_file_range_61979 cow_file_range 3 61979 NULL
124243 +dequeue_event_62000 dequeue_event 3 62000 NULL
124244 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
124245 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
124246 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
124247 +SYSC_select_62024 SYSC_select 1 62024 NULL
124248 +comedi_write_array_to_buffer_62032 comedi_write_array_to_buffer 3 62032 NULL
124249 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
124250 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
124251 +do_pselect_62061 do_pselect 1 62061 NULL
124252 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
124253 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
124254 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
124255 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
124256 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
124257 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
124258 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
124259 +ql_status_62135 ql_status 5 62135 NULL nohasharray
124260 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
124261 +video_usercopy_62151 video_usercopy 2 62151 NULL
124262 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
124263 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
124264 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
124265 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
124266 +rounded_hashtable_size_62198 rounded_hashtable_size 0 62198 NULL
124267 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
124268 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
124269 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
124270 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
124271 +get_random_int_62279 get_random_int 0 62279 NULL
124272 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
124273 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
124274 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
124275 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
124276 +subseq_list_62332 subseq_list 3-0 62332 NULL
124277 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
124278 +flash_write_62354 flash_write 3 62354 NULL
124279 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
124280 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
124281 +altera_irscan_62396 altera_irscan 2 62396 NULL
124282 +set_ssp_62411 set_ssp 4 62411 NULL
124283 +tracing_saved_cmdlines_size_read_62491 tracing_saved_cmdlines_size_read 3 62491 NULL
124284 +srpc_alloc_bulk_62522 srpc_alloc_bulk 2 62522 NULL
124285 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
124286 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
124287 +debugfs_read_62535 debugfs_read 3 62535 NULL
124288 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
124289 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
124290 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
124291 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
124292 +get_subdir_62581 get_subdir 3 62581 NULL
124293 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
124294 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
124295 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
124296 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
124297 +ieee80211_set_probe_resp_62700 ieee80211_set_probe_resp 3 62700 NULL
124298 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
124299 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
124300 +rdm_62719 rdm 0 62719 NULL
124301 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
124302 +key_replays_read_62746 key_replays_read 3 62746 NULL
124303 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
124304 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
124305 +mxt_obj_instances_62764 mxt_obj_instances 0 62764 NULL
124306 +copy_page_to_iter_iovec_62770 copy_page_to_iter_iovec 0-3 62770 NULL nohasharray
124307 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 &copy_page_to_iter_iovec_62770
124308 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
124309 +ptlrpc_req_set_repsize_62784 ptlrpc_req_set_repsize 2 62784 NULL
124310 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
124311 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
124312 +__add_action_62798 __add_action 4 62798 NULL
124313 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
124314 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
124315 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
124316 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
124317 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
124318 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
124319 +aoechr_write_62883 aoechr_write 3 62883 NULL
124320 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
124321 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
124322 +getdqbuf_62908 getdqbuf 1 62908 NULL
124323 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
124324 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
124325 +nvif_object_mthd_62960 nvif_object_mthd 4 62960 NULL
124326 +hwdep_read_62992 hwdep_read 3 62992 NULL
124327 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
124328 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
124329 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
124330 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
124331 +unlink1_63059 unlink1 3 63059 NULL
124332 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
124333 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
124334 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
124335 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
124336 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
124337 +iwl_mvm_coex_dump_mbox_63153 iwl_mvm_coex_dump_mbox 4-3-0 63153 NULL
124338 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
124339 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
124340 +vme_master_read_63221 vme_master_read 0 63221 NULL
124341 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
124342 +ptp_read_63251 ptp_read 4 63251 NULL
124343 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
124344 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
124345 +raid5_resize_63306 raid5_resize 2 63306 NULL
124346 +nfsd_vfs_read_63307 nfsd_vfs_read 5 63307 NULL
124347 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
124348 +proc_info_read_63344 proc_info_read 3 63344 NULL
124349 +nvif_device_new_63358 nvif_device_new 5 63358 NULL
124350 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
124351 +idmouse_read_63374 idmouse_read 3 63374 NULL
124352 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL nohasharray
124353 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 &edac_pci_alloc_ctl_info_63388
124354 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
124355 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
124356 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
124357 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
124358 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
124359 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
124360 +read_kcore_63488 read_kcore 3 63488 NULL
124361 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
124362 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
124363 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
124364 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
124365 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
124366 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
124367 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
124368 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
124369 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
124370 +write_debug_level_63613 write_debug_level 3 63613 NULL
124371 +__spi_validate_63618 __spi_validate 0 63618 NULL
124372 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
124373 +hid_report_len_63637 hid_report_len 0 63637 NULL
124374 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
124375 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
124376 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
124377 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
124378 +vbi_read_63673 vbi_read 3 63673 NULL
124379 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
124380 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
124381 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
124382 +ntb_debugfs_read_63728 ntb_debugfs_read 3 63728 NULL
124383 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
124384 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
124385 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
124386 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
124387 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
124388 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
124389 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
124390 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL nohasharray
124391 +prepare_copy_63826 prepare_copy 2 63826 &regmap_multi_reg_write_63826
124392 +sel_write_load_63830 sel_write_load 3 63830 NULL
124393 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
124394 +nv10_gpio_intr_mask_63862 nv10_gpio_intr_mask 4-3 63862 NULL
124395 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
124396 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
124397 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
124398 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
124399 +__team_options_register_63941 __team_options_register 3 63941 NULL
124400 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
124401 +set_bredr_63975 set_bredr 4 63975 NULL
124402 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
124403 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
124404 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
124405 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
124406 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
124407 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
124408 +nl80211_send_rx_assoc_64040 nl80211_send_rx_assoc 4 64040 NULL
124409 +__sock_create_64069 __sock_create 0 64069 NULL
124410 +get_u8_64076 get_u8 0 64076 NULL
124411 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
124412 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
124413 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
124414 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
124415 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
124416 +to_bytes_64103 to_bytes 0-1 64103 NULL
124417 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
124418 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
124419 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
124420 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
124421 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
124422 +init_bch_64130 init_bch 1-2 64130 NULL
124423 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
124424 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
124425 +number_of_tds_64156 number_of_tds 0 64156 NULL
124426 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
124427 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
124428 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
124429 +read_pulse_64227 read_pulse 0-3 64227 NULL
124430 +ea_len_64229 ea_len 0 64229 NULL
124431 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
124432 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL nohasharray
124433 +bpf_check_classic_64278 bpf_check_classic 2 64278 &btrfs_file_extent_offset_64278
124434 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
124435 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
124436 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
124437 +info_debugfs_read_64291 info_debugfs_read 3 64291 NULL
124438 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
124439 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
124440 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
124441 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
124442 +ts_write_64336 ts_write 3 64336 NULL
124443 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
124444 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
124445 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
124446 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
124447 +reg_create_64372 reg_create 5 64372 NULL nohasharray
124448 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
124449 +ilo_write_64378 ilo_write 3 64378 NULL
124450 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
124451 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
124452 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
124453 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
124454 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
124455 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
124456 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
124457 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
124458 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
124459 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
124460 +single_open_size_64483 single_open_size 4 64483 NULL
124461 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
124462 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
124463 +remove_uuid_64505 remove_uuid 4 64505 NULL
124464 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
124465 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
124466 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
124467 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
124468 +SyS_bind_64544 SyS_bind 3 64544 NULL
124469 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
124470 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
124471 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
124472 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
124473 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
124474 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
124475 +do_erase_64574 do_erase 4 64574 NULL
124476 +fanotify_write_64623 fanotify_write 3 64623 NULL
124477 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
124478 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
124479 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
124480 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
124481 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
124482 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
124483 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
124484 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
124485 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
124486 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
124487 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
124488 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
124489 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
124490 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
124491 +hwdep_write_64776 hwdep_write 3 64776 NULL
124492 +message_for_md_64777 message_for_md 5 64777 NULL
124493 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
124494 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
124495 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
124496 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL nohasharray
124497 +nv_mask_64808 nv_mask 0 64808 &rfkill_fop_write_64808
124498 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
124499 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
124500 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
124501 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
124502 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
124503 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
124504 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
124505 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
124506 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
124507 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
124508 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
124509 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
124510 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
124511 +insert_dent_65034 insert_dent 7 65034 NULL
124512 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
124513 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
124514 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
124515 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
124516 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
124517 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
124518 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 0-3 65090 NULL
124519 +usbtest_alloc_urb_65115 usbtest_alloc_urb 3-5 65115 NULL
124520 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
124521 +nouveau_event_create_65229 nouveau_event_create 2-1 65229 NULL
124522 +print_endpoint_stat_65232 print_endpoint_stat 0-4-3 65232 NULL
124523 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
124524 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
124525 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
124526 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
124527 +fat_direct_IO_65295 fat_direct_IO 4 65295 NULL
124528 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
124529 +get_var_len_65304 get_var_len 0 65304 NULL
124530 +unpack_array_65318 unpack_array 0 65318 NULL
124531 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
124532 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
124533 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
124534 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
124535 +SyS_writev_65372 SyS_writev 3 65372 NULL
124536 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
124537 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
124538 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
124539 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
124540 +device_add_groups_65423 device_add_groups 0 65423 NULL
124541 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
124542 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
124543 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
124544 +clear_user_65470 clear_user 2 65470 NULL
124545 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
124546 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
124547 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
124548 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
124549 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124550 new file mode 100644
124551 index 0000000..560cd7b
124552 --- /dev/null
124553 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
124554 @@ -0,0 +1,92 @@
124555 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
124556 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
124557 +mappedread_2627 mappedread 2 2627 NULL
124558 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
124559 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
124560 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
124561 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
124562 +dmu_write_6048 dmu_write 4-3 6048 NULL
124563 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
124564 +update_pages_6225 update_pages 2-3 6225 NULL
124565 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
124566 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
124567 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
124568 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
124569 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
124570 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
124571 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
124572 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
124573 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
124574 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
124575 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
124576 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
124577 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
124578 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
124579 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
124580 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
124581 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
124582 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
124583 +uiocopy_18680 uiocopy 2 18680 NULL
124584 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
124585 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
124586 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
124587 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
124588 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
124589 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
124590 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
124591 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
124592 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
124593 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
124594 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
124595 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
124596 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
124597 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
124598 +splat_write_30943 splat_write 3 30943 NULL
124599 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
124600 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
124601 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
124602 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
124603 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
124604 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
124605 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
124606 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
124607 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
124608 +copyinstr_36980 copyinstr 3 36980 NULL
124609 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
124610 +splat_read_38116 splat_read 3 38116 NULL
124611 +sa_setup_38756 sa_setup 4 38756 NULL
124612 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
124613 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
124614 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
124615 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
124616 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
124617 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
124618 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
124619 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
124620 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
124621 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
124622 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
124623 +kcopy_write_43683 kcopy_write 3 43683 NULL
124624 +uiomove_44355 uiomove 2 44355 NULL
124625 +dmu_read_44418 dmu_read 4-3 44418 NULL
124626 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
124627 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
124628 +copyin_45945 copyin 3 45945 NULL
124629 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
124630 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
124631 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
124632 +spa_history_write_49650 spa_history_write 3 49650 NULL
124633 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
124634 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
124635 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
124636 +copyout_51409 copyout 3 51409 NULL
124637 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
124638 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
124639 +get_nvlist_56685 get_nvlist 2 56685 NULL
124640 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
124641 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
124642 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
124643 +zpios_write_61823 zpios_write 3 61823 NULL
124644 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
124645 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
124646 +zpios_read_64734 zpios_read 3 64734 NULL
124647 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124648 new file mode 100644
124649 index 0000000..95f7abd
124650 --- /dev/null
124651 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
124652 @@ -0,0 +1,259 @@
124653 +/*
124654 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124655 + * Licensed under the GPL v2, or (at your option) v3
124656 + *
124657 + * Homepage:
124658 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124659 + *
124660 + * Documentation:
124661 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124662 + *
124663 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124664 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124665 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124666 + *
124667 + * Usage:
124668 + * $ make
124669 + * $ make run
124670 + */
124671 +
124672 +#include "gcc-common.h"
124673 +#include "size_overflow.h"
124674 +
124675 +int plugin_is_GPL_compatible;
124676 +
124677 +tree report_size_overflow_decl;
124678 +
124679 +tree size_overflow_type_HI;
124680 +tree size_overflow_type_SI;
124681 +tree size_overflow_type_DI;
124682 +tree size_overflow_type_TI;
124683 +
124684 +static struct plugin_info size_overflow_plugin_info = {
124685 + .version = "20140725",
124686 + .help = "no-size-overflow\tturn off size overflow checking\n",
124687 +};
124688 +
124689 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124690 +{
124691 + unsigned int arg_count;
124692 + enum tree_code code = TREE_CODE(*node);
124693 +
124694 + switch (code) {
124695 + case FUNCTION_DECL:
124696 + arg_count = type_num_arguments(TREE_TYPE(*node));
124697 + break;
124698 + case FUNCTION_TYPE:
124699 + case METHOD_TYPE:
124700 + arg_count = type_num_arguments(*node);
124701 + break;
124702 + default:
124703 + *no_add_attrs = true;
124704 + error("%s: %qE attribute only applies to functions", __func__, name);
124705 + return NULL_TREE;
124706 + }
124707 +
124708 + for (; args; args = TREE_CHAIN(args)) {
124709 + tree position = TREE_VALUE(args);
124710 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124711 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124712 + *no_add_attrs = true;
124713 + }
124714 + }
124715 + return NULL_TREE;
124716 +}
124717 +
124718 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
124719 +{
124720 + unsigned int arg_count;
124721 + enum tree_code code = TREE_CODE(*node);
124722 +
124723 + switch (code) {
124724 + case FUNCTION_DECL:
124725 + arg_count = type_num_arguments(TREE_TYPE(*node));
124726 + break;
124727 + case FUNCTION_TYPE:
124728 + case METHOD_TYPE:
124729 + arg_count = type_num_arguments(*node);
124730 + break;
124731 + case FIELD_DECL:
124732 + return NULL_TREE;
124733 + default:
124734 + *no_add_attrs = true;
124735 + error("%qE attribute only applies to functions", name);
124736 + return NULL_TREE;
124737 + }
124738 +
124739 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
124740 + return NULL_TREE;
124741 +
124742 + for (; args; args = TREE_CHAIN(args)) {
124743 + tree position = TREE_VALUE(args);
124744 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
124745 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
124746 + *no_add_attrs = true;
124747 + }
124748 + }
124749 + return NULL_TREE;
124750 +}
124751 +
124752 +static struct attribute_spec size_overflow_attr = {
124753 + .name = "size_overflow",
124754 + .min_length = 1,
124755 + .max_length = -1,
124756 + .decl_required = true,
124757 + .type_required = false,
124758 + .function_type_required = false,
124759 + .handler = handle_size_overflow_attribute,
124760 +#if BUILDING_GCC_VERSION >= 4007
124761 + .affects_type_identity = false
124762 +#endif
124763 +};
124764 +
124765 +static struct attribute_spec intentional_overflow_attr = {
124766 + .name = "intentional_overflow",
124767 + .min_length = 1,
124768 + .max_length = -1,
124769 + .decl_required = true,
124770 + .type_required = false,
124771 + .function_type_required = false,
124772 + .handler = handle_intentional_overflow_attribute,
124773 +#if BUILDING_GCC_VERSION >= 4007
124774 + .affects_type_identity = false
124775 +#endif
124776 +};
124777 +
124778 +static void register_attributes(void __unused *event_data, void __unused *data)
124779 +{
124780 + register_attribute(&size_overflow_attr);
124781 + register_attribute(&intentional_overflow_attr);
124782 +}
124783 +
124784 +static tree create_typedef(tree type, const char* ident)
124785 +{
124786 + tree new_type, decl;
124787 +
124788 + new_type = build_variant_type_copy(type);
124789 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
124790 + DECL_ORIGINAL_TYPE(decl) = type;
124791 + TYPE_NAME(new_type) = decl;
124792 + return new_type;
124793 +}
124794 +
124795 +// Create the noreturn report_size_overflow() function decl.
124796 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
124797 +{
124798 + tree const_char_ptr_type_node;
124799 + tree fntype;
124800 +
124801 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
124802 +
124803 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
124804 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
124805 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
124806 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
124807 +
124808 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
124809 + fntype = build_function_type_list(void_type_node,
124810 + const_char_ptr_type_node,
124811 + unsigned_type_node,
124812 + const_char_ptr_type_node,
124813 + const_char_ptr_type_node,
124814 + NULL_TREE);
124815 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
124816 +
124817 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
124818 + TREE_PUBLIC(report_size_overflow_decl) = 1;
124819 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
124820 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
124821 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
124822 +}
124823 +
124824 +
124825 +extern struct gimple_opt_pass pass_dce;
124826 +
124827 +static struct opt_pass *make_dce_pass(void)
124828 +{
124829 +#if BUILDING_GCC_VERSION >= 4009
124830 + return make_pass_dce(g);
124831 +#else
124832 + return &pass_dce.pass;
124833 +#endif
124834 +}
124835 +
124836 +
124837 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
124838 +{
124839 + int i;
124840 + const char * const plugin_name = plugin_info->base_name;
124841 + const int argc = plugin_info->argc;
124842 + const struct plugin_argument * const argv = plugin_info->argv;
124843 + bool enable = true;
124844 + struct register_pass_info insert_size_overflow_asm_pass_info;
124845 + struct register_pass_info __unused dump_before_pass_info;
124846 + struct register_pass_info __unused dump_after_pass_info;
124847 + struct register_pass_info insert_size_overflow_check_info;
124848 + struct register_pass_info dce_pass_info;
124849 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
124850 + {
124851 + .base = &report_size_overflow_decl,
124852 + .nelt = 1,
124853 + .stride = sizeof(report_size_overflow_decl),
124854 + .cb = &gt_ggc_mx_tree_node,
124855 + .pchw = &gt_pch_nx_tree_node
124856 + },
124857 + LAST_GGC_ROOT_TAB
124858 + };
124859 +
124860 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
124861 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
124862 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
124863 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124864 +
124865 + dump_before_pass_info.pass = make_dump_pass();
124866 + dump_before_pass_info.reference_pass_name = "increase_alignment";
124867 + dump_before_pass_info.ref_pass_instance_number = 1;
124868 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124869 +
124870 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
124871 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
124872 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
124873 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
124874 +
124875 + dump_after_pass_info.pass = make_dump_pass();
124876 + dump_after_pass_info.reference_pass_name = "increase_alignment";
124877 + dump_after_pass_info.ref_pass_instance_number = 1;
124878 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
124879 +
124880 + dce_pass_info.pass = make_dce_pass();
124881 + dce_pass_info.reference_pass_name = "vrp";
124882 + dce_pass_info.ref_pass_instance_number = 1;
124883 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
124884 +
124885 + if (!plugin_default_version_check(version, &gcc_version)) {
124886 + error(G_("incompatible gcc/plugin versions"));
124887 + return 1;
124888 + }
124889 +
124890 + for (i = 0; i < argc; ++i) {
124891 + if (!strcmp(argv[i].key, "no-size-overflow")) {
124892 + enable = false;
124893 + continue;
124894 + }
124895 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
124896 + }
124897 +
124898 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
124899 + if (enable) {
124900 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
124901 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
124902 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
124903 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
124904 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
124905 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
124906 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
124907 + }
124908 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
124909 +
124910 + return 0;
124911 +}
124912 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124913 new file mode 100644
124914 index 0000000..0888f6c
124915 --- /dev/null
124916 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
124917 @@ -0,0 +1,364 @@
124918 +/*
124919 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
124920 + * Licensed under the GPL v2, or (at your option) v3
124921 + *
124922 + * Homepage:
124923 + * http://www.grsecurity.net/~ephox/overflow_plugin/
124924 + *
124925 + * Documentation:
124926 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
124927 + *
124928 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
124929 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
124930 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
124931 + *
124932 + * Usage:
124933 + * $ make
124934 + * $ make run
124935 + */
124936 +
124937 +#include "gcc-common.h"
124938 +#include "size_overflow.h"
124939 +
124940 +#include "size_overflow_hash.h"
124941 +#include "size_overflow_hash_aux.h"
124942 +
124943 +#define CODES_LIMIT 32
124944 +
124945 +static unsigned char get_tree_code(const_tree type)
124946 +{
124947 + switch (TREE_CODE(type)) {
124948 + case ARRAY_TYPE:
124949 + return 0;
124950 + case BOOLEAN_TYPE:
124951 + return 1;
124952 + case ENUMERAL_TYPE:
124953 + return 2;
124954 + case FUNCTION_TYPE:
124955 + return 3;
124956 + case INTEGER_TYPE:
124957 + return 4;
124958 + case POINTER_TYPE:
124959 + return 5;
124960 + case RECORD_TYPE:
124961 + return 6;
124962 + case UNION_TYPE:
124963 + return 7;
124964 + case VOID_TYPE:
124965 + return 8;
124966 + case REAL_TYPE:
124967 + return 9;
124968 + case VECTOR_TYPE:
124969 + return 10;
124970 + case REFERENCE_TYPE:
124971 + return 11;
124972 + case OFFSET_TYPE:
124973 + return 12;
124974 + case COMPLEX_TYPE:
124975 + return 13;
124976 + default:
124977 + debug_tree((tree)type);
124978 + gcc_unreachable();
124979 + }
124980 +}
124981 +
124982 +struct function_hash {
124983 + size_t tree_codes_len;
124984 + unsigned char tree_codes[CODES_LIMIT];
124985 + const_tree fndecl;
124986 + unsigned int hash;
124987 +};
124988 +
124989 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
124990 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
124991 +{
124992 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
124993 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
124994 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
124995 +
124996 + unsigned int m = 0x57559429;
124997 + unsigned int n = 0x5052acdb;
124998 + const unsigned int *key4 = (const unsigned int *)key;
124999 + unsigned int h = len;
125000 + unsigned int k = len + seed + n;
125001 + unsigned long long p;
125002 +
125003 + while (len >= 8) {
125004 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
125005 + len -= 8;
125006 + }
125007 + if (len >= 4) {
125008 + cwmixb(key4[0]) key4 += 1;
125009 + len -= 4;
125010 + }
125011 + if (len)
125012 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
125013 + cwmixb(h ^ (k + n));
125014 + return k ^ h;
125015 +
125016 +#undef cwfold
125017 +#undef cwmixa
125018 +#undef cwmixb
125019 +}
125020 +
125021 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
125022 +{
125023 + unsigned int fn, codes, seed = 0;
125024 +
125025 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
125026 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
125027 +
125028 + fn_hash_data->hash = fn ^ codes;
125029 +}
125030 +
125031 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
125032 +{
125033 + gcc_assert(type != NULL_TREE);
125034 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
125035 +
125036 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
125037 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
125038 + fn_hash_data->tree_codes_len++;
125039 + type = TREE_TYPE(type);
125040 + }
125041 +}
125042 +
125043 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
125044 +{
125045 + const_tree result;
125046 +
125047 + gcc_assert(node != NULL_TREE);
125048 +
125049 + if (DECL_P(node)) {
125050 + result = DECL_RESULT(node);
125051 + if (result != NULL_TREE)
125052 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
125053 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
125054 + }
125055 +
125056 + gcc_assert(TYPE_P(node));
125057 +
125058 + if (TREE_CODE(node) == FUNCTION_TYPE)
125059 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
125060 +
125061 + return set_node_codes(node, fn_hash_data);
125062 +}
125063 +
125064 +static void set_function_codes(struct function_hash *fn_hash_data)
125065 +{
125066 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
125067 + enum tree_code code = TREE_CODE(type);
125068 +
125069 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
125070 +
125071 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
125072 +
125073 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
125074 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
125075 +}
125076 +
125077 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
125078 +{
125079 + while (entry) {
125080 + if (!strcmp(entry->name, func_name))
125081 + return entry;
125082 + entry = entry->next;
125083 + }
125084 + return NULL;
125085 +}
125086 +
125087 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
125088 +{
125089 + const struct size_overflow_hash *entry;
125090 + struct function_hash fn_hash_data;
125091 + const char *func_name;
125092 +
125093 + // skip builtins __builtin_constant_p
125094 + if (DECL_BUILT_IN(fndecl))
125095 + return NULL;
125096 +
125097 + fn_hash_data.fndecl = fndecl;
125098 + fn_hash_data.tree_codes_len = 0;
125099 +
125100 + set_function_codes(&fn_hash_data);
125101 + gcc_assert(fn_hash_data.tree_codes_len != 0);
125102 +
125103 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
125104 + set_hash(func_name, &fn_hash_data);
125105 +
125106 + entry = size_overflow_hash[fn_hash_data.hash];
125107 + entry = get_proper_hash_chain(entry, func_name);
125108 + if (entry)
125109 + return entry;
125110 + entry = size_overflow_hash_aux[fn_hash_data.hash];
125111 + return get_proper_hash_chain(entry, func_name);
125112 +}
125113 +
125114 +static void print_missing_msg(const_tree func, unsigned int argnum)
125115 +{
125116 + location_t loc;
125117 + const char *curfunc;
125118 + struct function_hash fn_hash_data;
125119 +
125120 + fn_hash_data.fndecl = DECL_ORIGIN(func);
125121 + fn_hash_data.tree_codes_len = 0;
125122 +
125123 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
125124 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
125125 +
125126 + set_function_codes(&fn_hash_data);
125127 + set_hash(curfunc, &fn_hash_data);
125128 +
125129 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
125130 +}
125131 +
125132 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
125133 +{
125134 + tree var;
125135 + unsigned int argnum = 1;
125136 +
125137 + if (TREE_CODE(arg) == SSA_NAME)
125138 + arg = SSA_NAME_VAR(arg);
125139 +
125140 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
125141 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
125142 + continue;
125143 + if (!skip_types(var))
125144 + return argnum;
125145 + }
125146 +
125147 + return CANNOT_FIND_ARG;
125148 +}
125149 +
125150 +static const char *get_asm_string(const_gimple stmt)
125151 +{
125152 + if (!stmt)
125153 + return NULL;
125154 + if (gimple_code(stmt) != GIMPLE_ASM)
125155 + return NULL;
125156 +
125157 + return gimple_asm_string(stmt);
125158 +}
125159 +
125160 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
125161 +{
125162 + const char *str;
125163 +
125164 + str = get_asm_string(stmt);
125165 + if (!str)
125166 + return false;
125167 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
125168 +}
125169 +
125170 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
125171 +{
125172 + const char *str;
125173 +
125174 + str = get_asm_string(stmt);
125175 + if (!str)
125176 + return false;
125177 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
125178 +}
125179 +
125180 +bool is_size_overflow_asm(const_gimple stmt)
125181 +{
125182 + const char *str;
125183 +
125184 + str = get_asm_string(stmt);
125185 + if (!str)
125186 + return false;
125187 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
125188 +}
125189 +
125190 +bool is_a_return_check(const_tree node)
125191 +{
125192 + if (TREE_CODE(node) == FUNCTION_DECL)
125193 + return true;
125194 +
125195 + gcc_assert(TREE_CODE(node) == PARM_DECL);
125196 + return false;
125197 +}
125198 +
125199 +// Get the argnum of a function decl, if node is a return then the argnum is 0
125200 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
125201 +{
125202 + if (is_a_return_check(node))
125203 + return 0;
125204 + else
125205 + return find_arg_number_tree(node, orig_fndecl);
125206 +}
125207 +
125208 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
125209 +{
125210 + const struct size_overflow_hash *hash;
125211 + unsigned int new_argnum;
125212 + tree arg;
125213 + const_tree origarg;
125214 +
125215 + if (argnum == 0)
125216 + return argnum;
125217 +
125218 + hash = get_function_hash(fndecl);
125219 + if (hash && hash->param & (1U << argnum))
125220 + return argnum;
125221 +
125222 + if (DECL_EXTERNAL(fndecl))
125223 + return argnum;
125224 +
125225 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
125226 + argnum--;
125227 + while (origarg && argnum) {
125228 + origarg = TREE_CHAIN(origarg);
125229 + argnum--;
125230 + }
125231 + gcc_assert(argnum == 0);
125232 + gcc_assert(origarg != NULL_TREE);
125233 +
125234 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
125235 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
125236 + return new_argnum;
125237 +
125238 + return CANNOT_FIND_ARG;
125239 +}
125240 +
125241 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
125242 +{
125243 + const struct size_overflow_hash *hash;
125244 +
125245 + hash = get_function_hash(fndecl);
125246 + if (hash && (hash->param & (1U << num)))
125247 + return true;
125248 + return false;
125249 +}
125250 +
125251 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
125252 + * If the function is missing everywhere then print the missing message into stderr.
125253 + */
125254 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
125255 +{
125256 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
125257 +#if BUILDING_GCC_VERSION >= 4008
125258 + case BUILT_IN_BSWAP16:
125259 +#endif
125260 + case BUILT_IN_BSWAP32:
125261 + case BUILT_IN_BSWAP64:
125262 + case BUILT_IN_EXPECT:
125263 + case BUILT_IN_MEMCMP:
125264 + return false;
125265 + default:
125266 + break;
125267 + }
125268 +
125269 + // skip test.c
125270 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
125271 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
125272 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
125273 + }
125274 +
125275 + if (is_in_hash_table(orig_fndecl, num))
125276 + return false;
125277 +
125278 + print_missing_msg(orig_fndecl, num);
125279 + return true;
125280 +}
125281 +
125282 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
125283 new file mode 100644
125284 index 0000000..924652b
125285 --- /dev/null
125286 +++ b/tools/gcc/stackleak_plugin.c
125287 @@ -0,0 +1,395 @@
125288 +/*
125289 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
125290 + * Licensed under the GPL v2
125291 + *
125292 + * Note: the choice of the license means that the compilation process is
125293 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125294 + * but for the kernel it doesn't matter since it doesn't link against
125295 + * any of the gcc libraries
125296 + *
125297 + * gcc plugin to help implement various PaX features
125298 + *
125299 + * - track lowest stack pointer
125300 + *
125301 + * TODO:
125302 + * - initialize all local variables
125303 + *
125304 + * BUGS:
125305 + * - none known
125306 + */
125307 +
125308 +#include "gcc-common.h"
125309 +
125310 +int plugin_is_GPL_compatible;
125311 +
125312 +static int track_frame_size = -1;
125313 +static const char track_function[] = "pax_track_stack";
125314 +static const char check_function[] = "pax_check_alloca";
125315 +static tree track_function_decl, check_function_decl;
125316 +static bool init_locals;
125317 +
125318 +static struct plugin_info stackleak_plugin_info = {
125319 + .version = "201408011900",
125320 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
125321 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
125322 +};
125323 +
125324 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
125325 +{
125326 + gimple check_alloca;
125327 + tree alloca_size;
125328 +
125329 + // insert call to void pax_check_alloca(unsigned long size)
125330 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
125331 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
125332 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
125333 +}
125334 +
125335 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
125336 +{
125337 + gimple track_stack;
125338 +
125339 + // insert call to void pax_track_stack(void)
125340 + track_stack = gimple_build_call(track_function_decl, 0);
125341 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
125342 +}
125343 +
125344 +static bool is_alloca(gimple stmt)
125345 +{
125346 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
125347 + return true;
125348 +
125349 +#if BUILDING_GCC_VERSION >= 4007
125350 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
125351 + return true;
125352 +#endif
125353 +
125354 + return false;
125355 +}
125356 +
125357 +static unsigned int execute_stackleak_tree_instrument(void)
125358 +{
125359 + basic_block bb, entry_bb;
125360 + bool prologue_instrumented = false, is_leaf = true;
125361 +
125362 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
125363 +
125364 + // 1. loop through BBs and GIMPLE statements
125365 + FOR_EACH_BB_FN(bb, cfun) {
125366 + gimple_stmt_iterator gsi;
125367 +
125368 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125369 + gimple stmt;
125370 +
125371 + stmt = gsi_stmt(gsi);
125372 +
125373 + if (is_gimple_call(stmt))
125374 + is_leaf = false;
125375 +
125376 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
125377 + if (!is_alloca(stmt))
125378 + continue;
125379 +
125380 + // 2. insert stack overflow check before each __builtin_alloca call
125381 + stackleak_check_alloca(&gsi);
125382 +
125383 + // 3. insert track call after each __builtin_alloca call
125384 + stackleak_add_instrumentation(&gsi);
125385 + if (bb == entry_bb)
125386 + prologue_instrumented = true;
125387 + }
125388 + }
125389 +
125390 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
125391 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
125392 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
125393 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
125394 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
125395 + return 0;
125396 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
125397 + return 0;
125398 +
125399 + // 4. insert track call at the beginning
125400 + if (!prologue_instrumented) {
125401 + gimple_stmt_iterator gsi;
125402 +
125403 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125404 + if (dom_info_available_p(CDI_DOMINATORS))
125405 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125406 + gsi = gsi_start_bb(bb);
125407 + stackleak_add_instrumentation(&gsi);
125408 + }
125409 +
125410 + return 0;
125411 +}
125412 +
125413 +static unsigned int execute_stackleak_final(void)
125414 +{
125415 + rtx insn, next;
125416 +
125417 + if (cfun->calls_alloca)
125418 + return 0;
125419 +
125420 + // keep calls only if function frame is big enough
125421 + if (get_frame_size() >= track_frame_size)
125422 + return 0;
125423 +
125424 + // 1. find pax_track_stack calls
125425 + for (insn = get_insns(); insn; insn = next) {
125426 + // 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))
125427 + rtx body;
125428 +
125429 + next = NEXT_INSN(insn);
125430 + if (!CALL_P(insn))
125431 + continue;
125432 + body = PATTERN(insn);
125433 + if (GET_CODE(body) != CALL)
125434 + continue;
125435 + body = XEXP(body, 0);
125436 + if (GET_CODE(body) != MEM)
125437 + continue;
125438 + body = XEXP(body, 0);
125439 + if (GET_CODE(body) != SYMBOL_REF)
125440 + continue;
125441 +// if (strcmp(XSTR(body, 0), track_function))
125442 + if (SYMBOL_REF_DECL(body) != track_function_decl)
125443 + continue;
125444 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125445 + // 2. delete call
125446 + delete_insn_and_edges(insn);
125447 +#if BUILDING_GCC_VERSION >= 4007
125448 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
125449 + insn = next;
125450 + next = NEXT_INSN(insn);
125451 + delete_insn_and_edges(insn);
125452 + }
125453 +#endif
125454 + }
125455 +
125456 +// print_simple_rtl(stderr, get_insns());
125457 +// print_rtl(stderr, get_insns());
125458 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
125459 +
125460 + return 0;
125461 +}
125462 +
125463 +static bool gate_stackleak_track_stack(void)
125464 +{
125465 + tree section;
125466 +
125467 + if (ix86_cmodel != CM_KERNEL)
125468 + return false;
125469 +
125470 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
125471 + if (section && TREE_VALUE(section)) {
125472 + section = TREE_VALUE(TREE_VALUE(section));
125473 +
125474 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
125475 + return false;
125476 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
125477 + return false;
125478 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
125479 + return false;
125480 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
125481 + return false;
125482 + }
125483 +
125484 + return track_frame_size >= 0;
125485 +}
125486 +
125487 +static void stackleak_start_unit(void *gcc_data, void *user_data)
125488 +{
125489 + tree fntype;
125490 +
125491 + // void pax_track_stack(void)
125492 + fntype = build_function_type_list(void_type_node, NULL_TREE);
125493 + track_function_decl = build_fn_decl(track_function, fntype);
125494 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
125495 + TREE_PUBLIC(track_function_decl) = 1;
125496 + DECL_EXTERNAL(track_function_decl) = 1;
125497 + DECL_ARTIFICIAL(track_function_decl) = 1;
125498 +
125499 + // void pax_check_alloca(unsigned long)
125500 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
125501 + check_function_decl = build_fn_decl(check_function, fntype);
125502 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
125503 + TREE_PUBLIC(check_function_decl) = 1;
125504 + DECL_EXTERNAL(check_function_decl) = 1;
125505 + DECL_ARTIFICIAL(check_function_decl) = 1;
125506 +}
125507 +
125508 +#if BUILDING_GCC_VERSION >= 4009
125509 +static const struct pass_data stackleak_tree_instrument_pass_data = {
125510 +#else
125511 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
125512 + .pass = {
125513 +#endif
125514 + .type = GIMPLE_PASS,
125515 + .name = "stackleak_tree_instrument",
125516 +#if BUILDING_GCC_VERSION >= 4008
125517 + .optinfo_flags = OPTGROUP_NONE,
125518 +#endif
125519 +#if BUILDING_GCC_VERSION >= 4009
125520 + .has_gate = true,
125521 + .has_execute = true,
125522 +#else
125523 + .gate = gate_stackleak_track_stack,
125524 + .execute = execute_stackleak_tree_instrument,
125525 + .sub = NULL,
125526 + .next = NULL,
125527 + .static_pass_number = 0,
125528 +#endif
125529 + .tv_id = TV_NONE,
125530 + .properties_required = PROP_gimple_leh | PROP_cfg,
125531 + .properties_provided = 0,
125532 + .properties_destroyed = 0,
125533 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
125534 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
125535 +#if BUILDING_GCC_VERSION < 4009
125536 + }
125537 +#endif
125538 +};
125539 +
125540 +#if BUILDING_GCC_VERSION >= 4009
125541 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
125542 +#else
125543 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
125544 + .pass = {
125545 +#endif
125546 + .type = RTL_PASS,
125547 + .name = "stackleak_final",
125548 +#if BUILDING_GCC_VERSION >= 4008
125549 + .optinfo_flags = OPTGROUP_NONE,
125550 +#endif
125551 +#if BUILDING_GCC_VERSION >= 4009
125552 + .has_gate = true,
125553 + .has_execute = true,
125554 +#else
125555 + .gate = gate_stackleak_track_stack,
125556 + .execute = execute_stackleak_final,
125557 + .sub = NULL,
125558 + .next = NULL,
125559 + .static_pass_number = 0,
125560 +#endif
125561 + .tv_id = TV_NONE,
125562 + .properties_required = 0,
125563 + .properties_provided = 0,
125564 + .properties_destroyed = 0,
125565 + .todo_flags_start = 0,
125566 + .todo_flags_finish = TODO_dump_func
125567 +#if BUILDING_GCC_VERSION < 4009
125568 + }
125569 +#endif
125570 +};
125571 +
125572 +#if BUILDING_GCC_VERSION >= 4009
125573 +namespace {
125574 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
125575 +public:
125576 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
125577 + bool gate() { return gate_stackleak_track_stack(); }
125578 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
125579 +};
125580 +
125581 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
125582 +public:
125583 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
125584 + bool gate() { return gate_stackleak_track_stack(); }
125585 + unsigned int execute() { return execute_stackleak_final(); }
125586 +};
125587 +}
125588 +
125589 +static opt_pass *make_stackleak_tree_instrument_pass(void)
125590 +{
125591 + return new stackleak_tree_instrument_pass();
125592 +}
125593 +
125594 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
125595 +{
125596 + return new stackleak_final_rtl_opt_pass();
125597 +}
125598 +#else
125599 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
125600 +{
125601 + return &stackleak_tree_instrument_pass.pass;
125602 +}
125603 +
125604 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
125605 +{
125606 + return &stackleak_final_rtl_opt_pass.pass;
125607 +}
125608 +#endif
125609 +
125610 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125611 +{
125612 + const char * const plugin_name = plugin_info->base_name;
125613 + const int argc = plugin_info->argc;
125614 + const struct plugin_argument * const argv = plugin_info->argv;
125615 + int i;
125616 + struct register_pass_info stackleak_tree_instrument_pass_info;
125617 + struct register_pass_info stackleak_final_pass_info;
125618 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
125619 + {
125620 + .base = &track_function_decl,
125621 + .nelt = 1,
125622 + .stride = sizeof(track_function_decl),
125623 + .cb = &gt_ggc_mx_tree_node,
125624 + .pchw = &gt_pch_nx_tree_node
125625 + },
125626 + {
125627 + .base = &check_function_decl,
125628 + .nelt = 1,
125629 + .stride = sizeof(check_function_decl),
125630 + .cb = &gt_ggc_mx_tree_node,
125631 + .pchw = &gt_pch_nx_tree_node
125632 + },
125633 + LAST_GGC_ROOT_TAB
125634 + };
125635 +
125636 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
125637 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
125638 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
125639 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
125640 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125641 +
125642 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
125643 + stackleak_final_pass_info.reference_pass_name = "final";
125644 + stackleak_final_pass_info.ref_pass_instance_number = 1;
125645 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
125646 +
125647 + if (!plugin_default_version_check(version, &gcc_version)) {
125648 + error(G_("incompatible gcc/plugin versions"));
125649 + return 1;
125650 + }
125651 +
125652 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
125653 +
125654 + for (i = 0; i < argc; ++i) {
125655 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
125656 + if (!argv[i].value) {
125657 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125658 + continue;
125659 + }
125660 + track_frame_size = atoi(argv[i].value);
125661 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
125662 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125663 + continue;
125664 + }
125665 + if (!strcmp(argv[i].key, "initialize-locals")) {
125666 + if (argv[i].value) {
125667 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
125668 + continue;
125669 + }
125670 + init_locals = true;
125671 + continue;
125672 + }
125673 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125674 + }
125675 +
125676 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
125677 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
125678 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
125679 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
125680 +
125681 + return 0;
125682 +}
125683 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
125684 new file mode 100644
125685 index 0000000..4ee2231
125686 --- /dev/null
125687 +++ b/tools/gcc/structleak_plugin.c
125688 @@ -0,0 +1,274 @@
125689 +/*
125690 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
125691 + * Licensed under the GPL v2
125692 + *
125693 + * Note: the choice of the license means that the compilation process is
125694 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
125695 + * but for the kernel it doesn't matter since it doesn't link against
125696 + * any of the gcc libraries
125697 + *
125698 + * gcc plugin to forcibly initialize certain local variables that could
125699 + * otherwise leak kernel stack to userland if they aren't properly initialized
125700 + * by later code
125701 + *
125702 + * Homepage: http://pax.grsecurity.net/
125703 + *
125704 + * Usage:
125705 + * $ # for 4.5/4.6/C based 4.7
125706 + * $ 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
125707 + * $ # for C++ based 4.7/4.8+
125708 + * $ 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
125709 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
125710 + *
125711 + * TODO: eliminate redundant initializers
125712 + * increase type coverage
125713 + */
125714 +
125715 +#include "gcc-common.h"
125716 +
125717 +// unused C type flag in all versions 4.5-4.9
125718 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
125719 +
125720 +int plugin_is_GPL_compatible;
125721 +
125722 +static struct plugin_info structleak_plugin_info = {
125723 + .version = "201401260140",
125724 + .help = "disable\tdo not activate plugin\n",
125725 +};
125726 +
125727 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
125728 +{
125729 + *no_add_attrs = true;
125730 +
125731 + // check for types? for now accept everything linux has to offer
125732 + if (TREE_CODE(*node) != FIELD_DECL)
125733 + return NULL_TREE;
125734 +
125735 + *no_add_attrs = false;
125736 + return NULL_TREE;
125737 +}
125738 +
125739 +static struct attribute_spec user_attr = {
125740 + .name = "user",
125741 + .min_length = 0,
125742 + .max_length = 0,
125743 + .decl_required = false,
125744 + .type_required = false,
125745 + .function_type_required = false,
125746 + .handler = handle_user_attribute,
125747 +#if BUILDING_GCC_VERSION >= 4007
125748 + .affects_type_identity = true
125749 +#endif
125750 +};
125751 +
125752 +static void register_attributes(void *event_data, void *data)
125753 +{
125754 + register_attribute(&user_attr);
125755 +// register_attribute(&force_attr);
125756 +}
125757 +
125758 +static tree get_field_type(tree field)
125759 +{
125760 + return strip_array_types(TREE_TYPE(field));
125761 +}
125762 +
125763 +static bool is_userspace_type(tree type)
125764 +{
125765 + tree field;
125766 +
125767 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
125768 + tree fieldtype = get_field_type(field);
125769 + enum tree_code code = TREE_CODE(fieldtype);
125770 +
125771 + if (code == RECORD_TYPE || code == UNION_TYPE)
125772 + if (is_userspace_type(fieldtype))
125773 + return true;
125774 +
125775 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
125776 + return true;
125777 + }
125778 + return false;
125779 +}
125780 +
125781 +static void finish_type(void *event_data, void *data)
125782 +{
125783 + tree type = (tree)event_data;
125784 +
125785 + if (TYPE_USERSPACE(type))
125786 + return;
125787 +
125788 + if (is_userspace_type(type))
125789 + TYPE_USERSPACE(type) = 1;
125790 +}
125791 +
125792 +static void initialize(tree var)
125793 +{
125794 + basic_block bb;
125795 + gimple_stmt_iterator gsi;
125796 + tree initializer;
125797 + gimple init_stmt;
125798 +
125799 + // this is the original entry bb before the forced split
125800 + // TODO: check further BBs in case more splits occured before us
125801 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
125802 +
125803 + // first check if the variable is already initialized, warn otherwise
125804 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
125805 + gimple stmt = gsi_stmt(gsi);
125806 + tree rhs1;
125807 +
125808 + // we're looking for an assignment of a single rhs...
125809 + if (!gimple_assign_single_p(stmt))
125810 + continue;
125811 + rhs1 = gimple_assign_rhs1(stmt);
125812 +#if BUILDING_GCC_VERSION >= 4007
125813 + // ... of a non-clobbering expression...
125814 + if (TREE_CLOBBER_P(rhs1))
125815 + continue;
125816 +#endif
125817 + // ... to our variable...
125818 + if (gimple_get_lhs(stmt) != var)
125819 + continue;
125820 + // if it's an initializer then we're good
125821 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
125822 + return;
125823 + }
125824 +
125825 + // these aren't the 0days you're looking for
125826 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
125827 +
125828 + // build the initializer expression
125829 + initializer = build_constructor(TREE_TYPE(var), NULL);
125830 +
125831 + // build the initializer stmt
125832 + init_stmt = gimple_build_assign(var, initializer);
125833 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
125834 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
125835 + update_stmt(init_stmt);
125836 +}
125837 +
125838 +static unsigned int handle_function(void)
125839 +{
125840 + basic_block bb;
125841 + unsigned int ret = 0;
125842 + tree var;
125843 + unsigned int i;
125844 +
125845 + // split the first bb where we can put the forced initializers
125846 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
125847 + if (dom_info_available_p(CDI_DOMINATORS))
125848 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
125849 +
125850 + // enumarate all local variables and forcibly initialize our targets
125851 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
125852 + tree type = TREE_TYPE(var);
125853 +
125854 + gcc_assert(DECL_P(var));
125855 + if (!auto_var_in_fn_p(var, current_function_decl))
125856 + continue;
125857 +
125858 + // only care about structure types
125859 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
125860 + continue;
125861 +
125862 + // if the type is of interest, examine the variable
125863 + if (TYPE_USERSPACE(type))
125864 + initialize(var);
125865 + }
125866 +
125867 + return ret;
125868 +}
125869 +
125870 +#if BUILDING_GCC_VERSION >= 4009
125871 +static const struct pass_data structleak_pass_data = {
125872 +#else
125873 +static struct gimple_opt_pass structleak_pass = {
125874 + .pass = {
125875 +#endif
125876 + .type = GIMPLE_PASS,
125877 + .name = "structleak",
125878 +#if BUILDING_GCC_VERSION >= 4008
125879 + .optinfo_flags = OPTGROUP_NONE,
125880 +#endif
125881 +#if BUILDING_GCC_VERSION >= 4009
125882 + .has_gate = false,
125883 + .has_execute = true,
125884 +#else
125885 + .gate = NULL,
125886 + .execute = handle_function,
125887 + .sub = NULL,
125888 + .next = NULL,
125889 + .static_pass_number = 0,
125890 +#endif
125891 + .tv_id = TV_NONE,
125892 + .properties_required = PROP_cfg,
125893 + .properties_provided = 0,
125894 + .properties_destroyed = 0,
125895 + .todo_flags_start = 0,
125896 + .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
125897 +#if BUILDING_GCC_VERSION < 4009
125898 + }
125899 +#endif
125900 +};
125901 +
125902 +#if BUILDING_GCC_VERSION >= 4009
125903 +namespace {
125904 +class structleak_pass : public gimple_opt_pass {
125905 +public:
125906 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
125907 + unsigned int execute() { return handle_function(); }
125908 +};
125909 +}
125910 +
125911 +static opt_pass *make_structleak_pass(void)
125912 +{
125913 + return new structleak_pass();
125914 +}
125915 +#else
125916 +static struct opt_pass *make_structleak_pass(void)
125917 +{
125918 + return &structleak_pass.pass;
125919 +}
125920 +#endif
125921 +
125922 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
125923 +{
125924 + int i;
125925 + const char * const plugin_name = plugin_info->base_name;
125926 + const int argc = plugin_info->argc;
125927 + const struct plugin_argument * const argv = plugin_info->argv;
125928 + bool enable = true;
125929 + struct register_pass_info structleak_pass_info;
125930 +
125931 + structleak_pass_info.pass = make_structleak_pass();
125932 + structleak_pass_info.reference_pass_name = "ssa";
125933 + structleak_pass_info.ref_pass_instance_number = 1;
125934 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
125935 +
125936 + if (!plugin_default_version_check(version, &gcc_version)) {
125937 + error(G_("incompatible gcc/plugin versions"));
125938 + return 1;
125939 + }
125940 +
125941 + if (strcmp(lang_hooks.name, "GNU C")) {
125942 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
125943 + enable = false;
125944 + }
125945 +
125946 + for (i = 0; i < argc; ++i) {
125947 + if (!strcmp(argv[i].key, "disable")) {
125948 + enable = false;
125949 + continue;
125950 + }
125951 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
125952 + }
125953 +
125954 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
125955 + if (enable) {
125956 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
125957 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
125958 + }
125959 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
125960 +
125961 + return 0;
125962 +}
125963 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
125964 index 88461f0..6fb70a0 100644
125965 --- a/tools/include/linux/compiler.h
125966 +++ b/tools/include/linux/compiler.h
125967 @@ -35,6 +35,14 @@
125968 # define unlikely(x) __builtin_expect(!!(x), 0)
125969 #endif
125970
125971 +#ifndef __size_overflow
125972 +# define __size_overflow(...)
125973 +#endif
125974 +
125975 +#ifndef __intentional_overflow
125976 +# define __intentional_overflow(...)
125977 +#endif
125978 +
125979 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
125980
125981 #endif /* _TOOLS_LINUX_COMPILER_H */
125982 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
125983 index 36c08b1..87c72d1 100644
125984 --- a/tools/lib/api/Makefile
125985 +++ b/tools/lib/api/Makefile
125986 @@ -21,7 +21,7 @@ LIB_OBJS += $(OUTPUT)fd/array.o
125987
125988 LIBFILE = libapikfs.a
125989
125990 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125991 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
125992 EXTLIBS = -lelf -lpthread -lrt -lm
125993 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
125994 ALL_LDFLAGS = $(LDFLAGS)
125995 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
125996 index 6789d788..4afd019e 100644
125997 --- a/tools/perf/util/include/asm/alternative-asm.h
125998 +++ b/tools/perf/util/include/asm/alternative-asm.h
125999 @@ -5,4 +5,7 @@
126000
126001 #define altinstruction_entry #
126002
126003 + .macro pax_force_retaddr rip=0, reload=0
126004 + .endm
126005 +
126006 #endif
126007 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
126008 index 0a578fe..b81f62d 100644
126009 --- a/tools/virtio/linux/uaccess.h
126010 +++ b/tools/virtio/linux/uaccess.h
126011 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
126012 ({ \
126013 typeof(ptr) __pu_ptr = (ptr); \
126014 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
126015 - ACCESS_ONCE(*(__pu_ptr)) = x; \
126016 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
126017 0; \
126018 })
126019
126020 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
126021 index 3cee7b1..29cb7d8 100644
126022 --- a/virt/kvm/kvm_main.c
126023 +++ b/virt/kvm/kvm_main.c
126024 @@ -78,12 +78,17 @@ LIST_HEAD(vm_list);
126025
126026 static cpumask_var_t cpus_hardware_enabled;
126027 static int kvm_usage_count = 0;
126028 -static atomic_t hardware_enable_failed;
126029 +static atomic_unchecked_t hardware_enable_failed;
126030
126031 struct kmem_cache *kvm_vcpu_cache;
126032 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
126033
126034 -static __read_mostly struct preempt_ops kvm_preempt_ops;
126035 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
126036 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
126037 +static struct preempt_ops kvm_preempt_ops = {
126038 + .sched_in = kvm_sched_in,
126039 + .sched_out = kvm_sched_out,
126040 +};
126041
126042 struct dentry *kvm_debugfs_dir;
126043
126044 @@ -786,7 +791,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
126045 /* We can read the guest memory with __xxx_user() later on. */
126046 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
126047 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
126048 - !access_ok(VERIFY_WRITE,
126049 + !access_ok_noprefault(VERIFY_WRITE,
126050 (void __user *)(unsigned long)mem->userspace_addr,
126051 mem->memory_size)))
126052 goto out;
126053 @@ -1690,9 +1695,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
126054
126055 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
126056 {
126057 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
126058 + int r;
126059 + unsigned long addr;
126060
126061 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
126062 + addr = gfn_to_hva(kvm, gfn);
126063 + if (kvm_is_error_hva(addr))
126064 + return -EFAULT;
126065 + r = __clear_user((void __user *)addr + offset, len);
126066 + if (r)
126067 + return -EFAULT;
126068 + mark_page_dirty(kvm, gfn);
126069 + return 0;
126070 }
126071 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
126072
126073 @@ -1941,7 +1954,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
126074 return 0;
126075 }
126076
126077 -static struct file_operations kvm_vcpu_fops = {
126078 +static file_operations_no_const kvm_vcpu_fops __read_only = {
126079 .release = kvm_vcpu_release,
126080 .unlocked_ioctl = kvm_vcpu_ioctl,
126081 #ifdef CONFIG_COMPAT
126082 @@ -2650,7 +2663,7 @@ out:
126083 }
126084 #endif
126085
126086 -static struct file_operations kvm_vm_fops = {
126087 +static file_operations_no_const kvm_vm_fops __read_only = {
126088 .release = kvm_vm_release,
126089 .unlocked_ioctl = kvm_vm_ioctl,
126090 #ifdef CONFIG_COMPAT
126091 @@ -2721,7 +2734,7 @@ out:
126092 return r;
126093 }
126094
126095 -static struct file_operations kvm_chardev_ops = {
126096 +static file_operations_no_const kvm_chardev_ops __read_only = {
126097 .unlocked_ioctl = kvm_dev_ioctl,
126098 .compat_ioctl = kvm_dev_ioctl,
126099 .llseek = noop_llseek,
126100 @@ -2747,7 +2760,7 @@ static void hardware_enable_nolock(void *junk)
126101
126102 if (r) {
126103 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
126104 - atomic_inc(&hardware_enable_failed);
126105 + atomic_inc_unchecked(&hardware_enable_failed);
126106 printk(KERN_INFO "kvm: enabling virtualization on "
126107 "CPU%d failed\n", cpu);
126108 }
126109 @@ -2803,10 +2816,10 @@ static int hardware_enable_all(void)
126110
126111 kvm_usage_count++;
126112 if (kvm_usage_count == 1) {
126113 - atomic_set(&hardware_enable_failed, 0);
126114 + atomic_set_unchecked(&hardware_enable_failed, 0);
126115 on_each_cpu(hardware_enable_nolock, NULL, 1);
126116
126117 - if (atomic_read(&hardware_enable_failed)) {
126118 + if (atomic_read_unchecked(&hardware_enable_failed)) {
126119 hardware_disable_all_nolock();
126120 r = -EBUSY;
126121 }
126122 @@ -3213,7 +3226,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
126123 kvm_arch_vcpu_put(vcpu);
126124 }
126125
126126 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126127 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126128 struct module *module)
126129 {
126130 int r;
126131 @@ -3260,7 +3273,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126132 if (!vcpu_align)
126133 vcpu_align = __alignof__(struct kvm_vcpu);
126134 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
126135 - 0, NULL);
126136 + SLAB_USERCOPY, NULL);
126137 if (!kvm_vcpu_cache) {
126138 r = -ENOMEM;
126139 goto out_free_3;
126140 @@ -3270,9 +3283,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126141 if (r)
126142 goto out_free;
126143
126144 + pax_open_kernel();
126145 kvm_chardev_ops.owner = module;
126146 kvm_vm_fops.owner = module;
126147 kvm_vcpu_fops.owner = module;
126148 + pax_close_kernel();
126149
126150 r = misc_register(&kvm_dev);
126151 if (r) {
126152 @@ -3282,9 +3297,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
126153
126154 register_syscore_ops(&kvm_syscore_ops);
126155
126156 - kvm_preempt_ops.sched_in = kvm_sched_in;
126157 - kvm_preempt_ops.sched_out = kvm_sched_out;
126158 -
126159 r = kvm_init_debug();
126160 if (r) {
126161 printk(KERN_ERR "kvm: create debugfs files failed\n");